Author: mes
Date: 2012-07-31 16:24:25 -0700 (Tue, 31 Jul 2012)
New Revision: 30056

Added:
   csplugins/trunk/ucsd/mes/genomespace/weblaunch-webstart/
   csplugins/trunk/ucsd/mes/genomespace/weblaunch-webstart/README.txt
   csplugins/trunk/ucsd/mes/genomespace/weblaunch-webstart/pom.xml
   csplugins/trunk/ucsd/mes/genomespace/weblaunch-webstart/src/
   csplugins/trunk/ucsd/mes/genomespace/weblaunch-webstart/src/main/
   csplugins/trunk/ucsd/mes/genomespace/weblaunch-webstart/src/main/jnlp/
   
csplugins/trunk/ucsd/mes/genomespace/weblaunch-webstart/src/main/jnlp/template.vm
   csplugins/trunk/ucsd/mes/genomespace/weblaunch/
   csplugins/trunk/ucsd/mes/genomespace/weblaunch/pom.xml
   csplugins/trunk/ucsd/mes/genomespace/weblaunch/src/
   csplugins/trunk/ucsd/mes/genomespace/weblaunch/src/main/
   csplugins/trunk/ucsd/mes/genomespace/weblaunch/src/main/java/
   csplugins/trunk/ucsd/mes/genomespace/weblaunch/src/main/java/cytoscape/
   
csplugins/trunk/ucsd/mes/genomespace/weblaunch/src/main/java/cytoscape/weblaunch/
   
csplugins/trunk/ucsd/mes/genomespace/weblaunch/src/main/java/cytoscape/weblaunch/LaunchHelper.java
   
csplugins/trunk/ucsd/mes/genomespace/weblaunch/src/main/java/cytoscape/weblaunch/StreamGobbler.java
Modified:
   csplugins/trunk/ucsd/mes/genomespace/pom.xml
Log:
added new weblaunch code

Modified: csplugins/trunk/ucsd/mes/genomespace/pom.xml
===================================================================
--- csplugins/trunk/ucsd/mes/genomespace/pom.xml        2012-07-31 23:04:06 UTC 
(rev 30055)
+++ csplugins/trunk/ucsd/mes/genomespace/pom.xml        2012-07-31 23:24:25 UTC 
(rev 30056)
@@ -13,6 +13,8 @@
                <module>genomespace-plugin</module>
                <module>ndb-reader</module>
                <module>cytable-reader</module>
+               <module>weblaunch</module>
+               <module>weblaunch-webstart</module>
                <!-- webstart actually has a different parent 
(cytoscape-webstart)
                     so we don't include it here!  It needs to be built 
separately.
                <module>genomespace-webstart</module>

Added: csplugins/trunk/ucsd/mes/genomespace/weblaunch/pom.xml
===================================================================
--- csplugins/trunk/ucsd/mes/genomespace/weblaunch/pom.xml                      
        (rev 0)
+++ csplugins/trunk/ucsd/mes/genomespace/weblaunch/pom.xml      2012-07-31 
23:24:25 UTC (rev 30056)
@@ -0,0 +1,82 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <artifactId>genomespace-parent</artifactId>
+    <groupId>cytoscape</groupId>
+    <version>1.0-SNAPSHOT</version>
+  </parent>
+
+  <groupId>cytoscape</groupId>
+  <artifactId>weblaunch</artifactId>
+  <packaging>jar</packaging>
+  <name>Cytoscape Web Launch</name>
+
+
+
+  <build>
+
+    <!-- This block allows fields to be substituted into resource files, 
+         such as the version number in cytoscape.props.  -->
+    <resources>
+      <resource>
+        <directory>src/main/resources</directory>
+        <filtering>true</filtering>
+      </resource>
+    </resources>
+
+      <plugins>
+        <plugin>
+          <artifactId>maven-assembly-plugin</artifactId>
+          <version>2.2</version>
+          <configuration>
+            <descriptorRefs>
+              <descriptorRef>jar-with-dependencies</descriptorRef>
+            </descriptorRefs>
+            <archive>
+              <manifest>
+                <mainClass>cytoscape.weblaunch.LaunchHelper</mainClass>
+              </manifest>
+            </archive>
+          </configuration>
+          <executions>
+            <execution>
+              <id>make-assembly</id>
+              <phase>package</phase>
+              <goals>
+                <goal>single</goal>
+              </goals>
+            </execution>
+          </executions>
+        </plugin>
+      </plugins>
+  </build>
+
+    <!-- bootstrap for cytoscape dependencies, namely the parent POM snapshots 
-->
+    <repositories>
+        <repository>
+            <id>cytoscape_snapshots</id>
+            <snapshots>
+                <enabled>true</enabled>
+            </snapshots>
+            <releases>
+                <enabled>false</enabled>
+            </releases>
+            <name>Cytoscape Snapshots</name>
+            
<url>http://cytoscape.wodaklab.org/nexus/content/repositories/snapshots/</url>
+        </repository>
+        <repository>
+            <id>cytoscape_releases</id>
+            <snapshots>
+                <enabled>false</enabled>
+            </snapshots>
+            <releases>
+                <enabled>true</enabled>
+            </releases>
+            <name>Cytoscape Releases</name>
+            
<url>http://cytoscape.wodaklab.org/nexus/content/repositories/releases/</url>
+        </repository>
+    </repositories>
+
+</project>
+

Added: 
csplugins/trunk/ucsd/mes/genomespace/weblaunch/src/main/java/cytoscape/weblaunch/LaunchHelper.java
===================================================================
--- 
csplugins/trunk/ucsd/mes/genomespace/weblaunch/src/main/java/cytoscape/weblaunch/LaunchHelper.java
                          (rev 0)
+++ 
csplugins/trunk/ucsd/mes/genomespace/weblaunch/src/main/java/cytoscape/weblaunch/LaunchHelper.java
  2012-07-31 23:24:25 UTC (rev 30056)
@@ -0,0 +1,226 @@
+package cytoscape.weblaunch;
+
+import java.awt.Desktop;
+import java.awt.Font;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URL;
+import java.net.URISyntaxException;
+import java.net.MalformedURLException;
+import javax.swing.JEditorPane;
+import javax.swing.JLabel;
+import javax.swing.JOptionPane;
+import javax.swing.event.HyperlinkListener;
+import javax.swing.event.HyperlinkEvent;
+import javax.swing.JFileChooser;
+import java.nio.channels.*;
+import java.io.FileOutputStream;
+
+public class LaunchHelper {
+       private static String version = "Cytoscape_v2.8.3";
+       private static String installerURL = 
"http://www.cytoscape.org/download.html";;
+
+       private static final String MAC = "mac os x";
+       private static final String WINDOWS = "windows";
+
+       public static void main(String[] args) {
+
+               String os = System.getProperty("os.name").toLowerCase();
+
+               String exe = getExecutable(os);
+               String path = getBestGuessPath(os);
+
+               if ( !executableExists(path,exe) ) {
+                       File file = getDirectory();
+                       if ( file != null )
+                               path = file.getAbsolutePath();
+               }
+
+               while ( !executableExists(path,exe) ) {
+                       int res = JOptionPane.showConfirmDialog(null, "We can't 
find the Cytoscape executable in the specified location.\nWould you like to try 
another location?", "Select Cytoscape Installation Directory", 
JOptionPane.YES_NO_OPTION);      
+
+                       if ( res == JOptionPane.YES_OPTION ) {
+                               JFileChooser fc = new JFileChooser();
+                               
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
+                               fc.setDialogTitle("Select Cytoscape 
Installation Directory");
+ 
+                               int returnVal = fc.showOpenDialog(null);
+                               if (returnVal == JFileChooser.APPROVE_OPTION) 
+                                       path = 
fc.getSelectedFile().getAbsolutePath();
+                       } else {
+                               return;
+                       }
+               }
+
+               String[] command = 
createCommand(getFile(path,exe),downloadPlugins());
+
+               try {
+                       Runtime rt = Runtime.getRuntime();
+                       Process p = rt.exec(command);
+                       StreamGobbler errorGobbler = new 
StreamGobbler(p.getErrorStream(), "ERROR");
+                       StreamGobbler outputGobbler = new 
StreamGobbler(p.getInputStream(), "OUTPUT");
+                       errorGobbler.start();
+                       outputGobbler.start();
+                       int exitVal = p.waitFor();
+               } catch (Exception e) {
+                       JOptionPane.showMessageDialog(null,
+                                                         "Cannot launch 
"+exe+" in\n" + path,
+                                                         "Cannot Launch 
Executable",
+                                                         
JOptionPane.ERROR_MESSAGE);
+               }
+       }
+
+       private static String[] createCommand(File f, String[] plugins) {
+               String[] command = new String[ (plugins.length * 2) + 1];
+               int i = 0;
+               command[i] = f.getAbsolutePath();
+               for ( String p : plugins ) {
+                       command[++i] = "-p";
+                       command[++i] = p;
+               }
+               return command;
+       }
+
+       private static String[] downloadPlugins() {
+
+               String[] urls = new String[] { 
+                       
"http://chianti.ucsd.edu/cyto_web/plugins/pluginjardownload.php?id=496";, // 
GenomeSpace libs
+                       
"http://chianti.ucsd.edu/cyto_web/plugins/pluginjardownload.php?id=495";, // 
GenomeSpace
+                       
"http://chianti.ucsd.edu/cyto_web/plugins/pluginjardownload.php?id=494";, // 
CyTable reader
+                       
"http://chianti.ucsd.edu/cyto_web/plugins/pluginjardownload.php?id=493";  // NDB 
Reader
+               };
+
+               String[] filePaths = new String[urls.length];
+               for (int i = 0; i < urls.length; i++) { 
+                       filePaths[i] = downloadURL(urls[i]).getAbsolutePath();  
+               }
+               return filePaths;
+       }
+
+       private static File downloadURL(String u) {
+               File f = null;
+               FileOutputStream fos = null; 
+               try {
+                       URL url = new URL(u);
+                       f = File.createTempFile("plugin",".jar");
+                       ReadableByteChannel rbc = 
Channels.newChannel(url.openStream());
+                       fos = new FileOutputStream(f);
+                       fos.getChannel().transferFrom(rbc, 0, 1 << 24);
+                       fos.close();
+               } catch (Exception e) {
+                       e.printStackTrace();
+               } finally {
+                       if ( fos != null ) {
+                               try { fos.close(); } catch (IOException ioe) { }
+                               fos = null;
+                       }
+               }
+               return f;
+       }
+
+       private static boolean executableExists(String path, String exe) {
+               File file = getFile(path,exe); 
+               return file.exists(); 
+       }
+
+       private static File getFile(String path, String exe) {
+               return new File(path + System.getProperty("file.separator") + 
exe);
+       }
+
+       private static String getExecutable(String os) {
+               String exe; 
+               if (os.startsWith(WINDOWS))     
+                       exe = "cytoscape.bat"; 
+               else 
+                       exe = "cytoscape.sh";
+
+               return exe;
+       }
+
+       private static String getBestGuessPath(String os) {
+               String path;
+               if (os.equals(MAC))  
+                       path = "/Applications";
+               else                                            
+                       path = System.getProperty("user.home");
+               path += "/" + version;
+               return path;
+       }
+
+       private static void openURL(String urlString) {
+               URL url = null; 
+
+               try {
+
+                       url = new URL(urlString);
+
+                       if (!Desktop.isDesktopSupported()) {
+                               JOptionPane.showMessageDialog(null,
+                                                                 "Java Desktop 
is not supported",
+                                                                 "Cannot 
Launch Link",
+                                                                 
JOptionPane.WARNING_MESSAGE);
+                               return;
+                       }
+
+                       Desktop desktop = Desktop.getDesktop();
+                       if (!desktop.isSupported(Desktop.Action.BROWSE)) {
+                               JOptionPane.showMessageDialog(null,
+                                                                 "Java Desktop 
doesn't support the browse action",
+                                                                 "Cannot 
Launch Link",
+                                                                 
JOptionPane.WARNING_MESSAGE);
+                               return;
+                       }
+
+                       if (url == null) {
+                               JOptionPane.showMessageDialog(null,
+                                                                 "InvalidURL: 
Failed to launch the link to installer:\n"+installerURL,
+                                                                 "Cannot 
Launch Link",
+                                                                 
JOptionPane.ERROR_MESSAGE);
+                               return;
+                       }
+       
+                       URI uri = new URI(url.toString());
+                       desktop.browse(uri);
+               } catch (URISyntaxException e) {
+                       JOptionPane.showMessageDialog(null,
+                                                         "URISyntaxException: 
Failed to launch the link to installer:\n"+url,
+                                                         "Cannot Launch Link",
+                                                         
JOptionPane.ERROR_MESSAGE);
+               } catch (MalformedURLException e) {
+                       JOptionPane.showMessageDialog(null,
+                                                         
"MalformedURLException: Failed to launch the link to installer:\n"+url,
+                                                         "Cannot Launch Link",
+                                                         
JOptionPane.ERROR_MESSAGE);
+               } catch (IOException e) {
+                       JOptionPane.showMessageDialog(null,
+                                                         "IOException: Failed 
to launch the link to installer:\n"+url,
+                                                         "Cannot Launch Link",
+                                                         
JOptionPane.ERROR_MESSAGE);
+               }
+       }
+
+       private static File getDirectory() {
+               int res = JOptionPane.showConfirmDialog(null, "Is Cytoscape 
installed on this computer?", "Select Cytoscape Installation Directory", 
JOptionPane.YES_NO_OPTION);        
+
+               if ( res == JOptionPane.YES_OPTION ) {
+                       JOptionPane.showMessageDialog(null, "Please choose the 
directory where\nCytoscape is installed on your system.", "Select Cytoscape 
Installation Directory", JOptionPane.INFORMATION_MESSAGE);   
+                       JFileChooser fc = new JFileChooser();
+                       fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
+                       fc.setDialogTitle("Select Cytoscape Installation 
Directory");
+ 
+                       int returnVal = fc.showOpenDialog(null);
+                       if (returnVal == JFileChooser.APPROVE_OPTION) 
+                               return fc.getSelectedFile();
+                       else
+                               return null;
+               } else {
+                       JOptionPane.showMessageDialog(null, "Please download 
and install Cytoscape.\nWe'll open a browser to the download page.", "Select 
Cytoscape Installation Directory", JOptionPane.INFORMATION_MESSAGE);  
+                       openURL(installerURL);
+                       return null;
+               }
+       }
+}

Added: 
csplugins/trunk/ucsd/mes/genomespace/weblaunch/src/main/java/cytoscape/weblaunch/StreamGobbler.java
===================================================================
--- 
csplugins/trunk/ucsd/mes/genomespace/weblaunch/src/main/java/cytoscape/weblaunch/StreamGobbler.java
                         (rev 0)
+++ 
csplugins/trunk/ucsd/mes/genomespace/weblaunch/src/main/java/cytoscape/weblaunch/StreamGobbler.java
 2012-07-31 23:24:25 UTC (rev 30056)
@@ -0,0 +1,29 @@
+package cytoscape.weblaunch;
+
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.IOException;
+
+public class StreamGobbler extends Thread {
+       InputStream is;
+       String type;
+
+       StreamGobbler(InputStream is, String type) {
+               this.is = is;
+               this.type = type;
+       }
+
+       public void run() {
+               try {
+                       InputStreamReader isr = new InputStreamReader(is);
+                       BufferedReader br = new BufferedReader(isr);
+                       String line = null;
+                       while ((line = br.readLine()) != null){
+                               System.out.println(type + ">" + line);
+                       }
+               } catch (IOException ioe) {
+                       ioe.printStackTrace();
+               }
+       }
+}

Added: csplugins/trunk/ucsd/mes/genomespace/weblaunch-webstart/README.txt
===================================================================
--- csplugins/trunk/ucsd/mes/genomespace/weblaunch-webstart/README.txt          
                (rev 0)
+++ csplugins/trunk/ucsd/mes/genomespace/weblaunch-webstart/README.txt  
2012-07-31 23:24:25 UTC (rev 30056)
@@ -0,0 +1,17 @@
+
+This project generates a JNLP file and associated jars suitable for running
+Cytoscape as a webstart. To generate things run:
+
+       mvn webstart:jnlp-inline -Dwebstart.url=http://example.com
+
+Note that the "-Dwebstart.url=http://example.com"; argument is manadatory to 
+provide the jnlp file with a codebase.
+
+
+If this is your first time using Webstart you must create a keystore:
+
+       keytool -genkey -alias cytoscape -keypass secret
+       enter "secret" for the password.
+
+The actual keystore file created is assumed to be in:  ${user.home}/.keystore
+

Added: csplugins/trunk/ucsd/mes/genomespace/weblaunch-webstart/pom.xml
===================================================================
--- csplugins/trunk/ucsd/mes/genomespace/weblaunch-webstart/pom.xml             
                (rev 0)
+++ csplugins/trunk/ucsd/mes/genomespace/weblaunch-webstart/pom.xml     
2012-07-31 23:24:25 UTC (rev 30056)
@@ -0,0 +1,94 @@
+<!-- Test project which creates and signs a jar artifact -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <artifactId>genomespace-parent</artifactId>
+    <groupId>cytoscape</groupId>
+    <version>1.0-SNAPSHOT</version>
+  </parent>
+
+  <groupId>cytoscape</groupId>
+  <artifactId>weblaunch-webstart</artifactId>
+  <packaging>pom</packaging>
+  <name>Cytoscape Web Launch Webstart</name>
+
+  <!-- This is the url used to define the codebase of the jnlp file. -->
+  <url>${webstart.url}</url>
+
+    <!-- bootstrap for cytoscape dependencies, namely the parent POM snapshots 
-->
+    <repositories>
+        <repository>
+            <id>cytoscape_snapshots</id>
+            <snapshots>
+                <enabled>true</enabled>
+            </snapshots>
+            <releases>
+                <enabled>false</enabled>
+            </releases>
+            <name>Cytoscape Snapshots</name>
+            
<url>http://cytoscape.wodaklab.org/nexus/content/repositories/snapshots/</url>
+        </repository>
+        <repository>
+            <id>cytoscape_releases</id>
+            <snapshots>
+                <enabled>false</enabled>
+            </snapshots>
+            <releases>
+                <enabled>true</enabled>
+            </releases>
+            <name>Cytoscape Releases</name>
+            
<url>http://cytoscape.wodaklab.org/nexus/content/repositories/releases/</url>
+        </repository>
+    </repositories>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.codehaus.mojo.webstart</groupId>
+        <artifactId>webstart-maven-plugin</artifactId>
+        <version>1.0-beta-1</version>
+        <executions>
+          <execution>
+            <goals>
+              <goal>jnlp-inline</goal>
+            </goals>
+          </execution>
+        </executions>
+        <configuration>
+          <excludeTransitive>true</excludeTransitive>
+          
<resourcesDirectory>${project.basedir}/src/main/resources</resourcesDirectory>
+          <libPath>lib</libPath>
+          <jnlp>
+            
<inputTemplateResourcePath>${project.basedir}/src/main/jnlp</inputTemplateResourcePath>
+            <inputTemplate>template.vm</inputTemplate>
+            <outputFile>cytoscape.jnlp</outputFile>
+            <mainClass>cytoscape.weblaunch.LaunchHelper</mainClass>
+          </jnlp>
+          <!-- 
+            If this is your first time using Webstart you must create a 
keystore:
+            keytool -genkey -alias cytoscape -keypass secret
+            enter "secret" for the password.
+            The actual keystore file created is assumed to be in:  
${user.home}/.keystore
+          -->
+          <sign>
+            <keypass>secret</keypass>
+            <storepass>secret</storepass>
+            <alias>cytoscape</alias>
+            <verify>true</verify>
+          </sign>
+          <verbose>true</verbose>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+  <dependencies>
+    <dependency>
+      <groupId>cytoscape</groupId>
+      <artifactId>weblaunch</artifactId>
+      <version>1.0-SNAPSHOT</version>
+    </dependency>
+  </dependencies>
+
+</project>

Added: 
csplugins/trunk/ucsd/mes/genomespace/weblaunch-webstart/src/main/jnlp/template.vm
===================================================================
--- 
csplugins/trunk/ucsd/mes/genomespace/weblaunch-webstart/src/main/jnlp/template.vm
                           (rev 0)
+++ 
csplugins/trunk/ucsd/mes/genomespace/weblaunch-webstart/src/main/jnlp/template.vm
   2012-07-31 23:24:25 UTC (rev 30056)
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<jnlp codebase="$project.Url" href="$outputFile">
+  <information>
+    <title>Cytoscape</title>
+    <vendor>Cytoscape Consortium</vendor>
+    <homepage href="http://cytoscape.org"/>
+    <offline-allowed/>
+  </information>
+  <security>
+     <all-permissions/>
+  </security>
+  <resources>
+    <j2se version="$j2seVersion"/>
+     $dependencies
+  </resources>
+  <application-desc main-class="$mainClass">
+  </application-desc>
+</jnlp>
+

-- 
You received this message because you are subscribed to the Google Groups 
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cytoscape-cvs?hl=en.

Reply via email to