Author: ghuck
Date: 2011-07-14 07:50:06 -0700 (Thu, 14 Jul 2011)
New Revision: 26177
Added:
csplugins/trunk/soc/ghuck/IgraphPlugin/resources/
csplugins/trunk/soc/ghuck/IgraphPlugin/resources/jna.jar
Modified:
csplugins/trunk/soc/ghuck/IgraphPlugin/build.xml
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IgraphPlugin.java
Log:
Simplyfied intallation process
Modified: csplugins/trunk/soc/ghuck/IgraphPlugin/build.xml
===================================================================
--- csplugins/trunk/soc/ghuck/IgraphPlugin/build.xml 2011-07-14 00:14:05 UTC
(rev 26176)
+++ csplugins/trunk/soc/ghuck/IgraphPlugin/build.xml 2011-07-14 14:50:06 UTC
(rev 26177)
@@ -22,6 +22,7 @@
<property name="src.dir" value="${root.dir}/src"/>
<property name="build.dir" value="${root.dir}/build"/>
<property name="manifest.dir" value="${root.dir}/manifest"/>
+ <property name="resources.dir" value="${root.dir}/resources"/>
<!-- Define the Cytoscape directories -->
<property name="cytoscape.dir" value="/Applications/Cytoscape_v2.8.1"/>
@@ -43,12 +44,13 @@
<available file="${root.dir}/plugin.props" property="plugin.prop.present"/>
<available file="${root.dir}/License.txt" property="license.present"/>
<available file="${root.dir}/libigraphWrapper.dylib"
property="igraphWrapper.lib.present"/>
- <available file="${igraph.dir}/src/.libs/libigraph.0.dylib"
property="igraph.lib.present"/>
+ <available file="${resources.dir}/jna.jar" property="jna.jar.present"/>
<!-- Define the java class path -->
<path id="project.class.path">
<pathelement location="${cytoscape.dir}/cytoscape.jar"/>
<pathelement path="${java.class.path}/"/>
+ <pathelement location="${resources.dir}/jna.jar"/>
<fileset dir="${cytoscape.plugin.dir}">
<include name="**/*.jar"/>
</fileset>
@@ -90,7 +92,7 @@
<!-- Creates the plugin jar file
-->
<!-- =================================================================== -->
<target name="jar" depends="compile, copy_plugin_prop, copy_license,
- copy_igraphWrapper_lib, copy_igraph_lib">
+ copy_igraphWrapper_lib, copy_jna_jar">
<jar destfile="${project.jar}">
<manifest> <attribute name="Cytoscape-Plugin" value="${plugin_class}"/>
</manifest>
<fileset dir="${build.dir}" includes="**"/>
@@ -120,14 +122,13 @@
</target>
<!-- =================================================================== -->
- <!-- If igraph.lib exist, copy it to build directory -->
+ <!-- If jna.jar exists, copy it to build directory -->
<!-- =================================================================== -->
- <target name="copy_igraph_lib" if="igraph.lib.present">
- <echo message="copying igraph lib to build dir"/>
- <copy todir="${build.dir}/"
file="${igraph.dir}/src/.libs/libigraph.0.dylib"/>
+ <target name="copy_jna_jar" if="jna.jar.present">
+ <echo message="copying jna.jar to build dir"/>
+ <copy todir="${build.dir}/" file="${resources.dir}/jna.jar"/>
</target>
-
<!-- =================================================================== -->
<!-- Copy jar file to Cytoscape plugin folder -->
<!-- =================================================================== -->
Added: csplugins/trunk/soc/ghuck/IgraphPlugin/resources/jna.jar
===================================================================
(Binary files differ)
Property changes on: csplugins/trunk/soc/ghuck/IgraphPlugin/resources/jna.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Modified:
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IgraphPlugin.java
===================================================================
---
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IgraphPlugin.java
2011-07-14 00:14:05 UTC (rev 26176)
+++
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IgraphPlugin.java
2011-07-14 14:50:06 UTC (rev 26177)
@@ -37,6 +37,8 @@
import javax.swing.JPanel;
import com.sun.jna.*;
+import java.net.URL;
+import java.net.URLClassLoader;
/** ---------------------------IgraphPlugin-----------------------------
* This plugin allows to call some of igraph functions from Cytoscape
@@ -50,48 +52,58 @@
*/
public IgraphPlugin() {
+ extractFileFromJar("libigraphWrapper.dylib");
+
// Make sure libraries are extracted in the plugins folder
- checkLib("igraphWrapper");
- checkLib("igraph.0");
+ if (extractFileFromJar("jna.jar")) {
+ JOptionPane.showMessageDialog( Cytoscape.getDesktop(), "Igraph
plugin succesfully installed!\nIt will be available the next time you run
Cytoscape.");
+ return;
+ }
- String userDir = System.getProperty("user.dir");
- // JOptionPane.showMessageDialog( Cytoscape.getDesktop(), "user dir:"+
userDir);
- NativeLibrary.addSearchPath("igraphWrapper", userDir + "/plugins");
+ String userDir = System.getProperty("user.dir");
+// JOptionPane.showMessageDialog( Cytoscape.getDesktop(), "user dir:"+
userDir);
+
+ try {
+ NativeLibrary.addSearchPath("igraphWrapper", userDir + "/plugins");
+ //JOptionPane.showMessageDialog(Cytoscape.getDesktop(),
IgraphInterface.nativeAdd(10, 20));
+
+ // Create Igraph object
+ IgraphAPI igraph = new IgraphAPI();
+
+ // Add elements in menu toolbar
+ IgraphAPI.IsConnected isConnectedAction1 = igraph.new
IsConnected(this, "All nodes", false);
+
Cytoscape.getDesktop().getCyMenus().addCytoscapeAction((CytoscapeAction)
isConnectedAction1);
+
+ IgraphAPI.IsConnected isConnectedAction2 = igraph.new
IsConnected(this, "Selected Nodes", true);
+
Cytoscape.getDesktop().getCyMenus().addCytoscapeAction((CytoscapeAction)
isConnectedAction2);
+
+ // Layouts
+ CyLayouts.addLayout(new CircleLayout(), "Igraph");
+ CyLayouts.addLayout(new StarLayout(), "Igraph");
+ CyLayouts.addLayout(new FruchtermanReingoldLayout(true), "Igraph");
- // JOptionPane.showMessageDialog(Cytoscape.getDesktop(),
IgraphInterface.nativeAdd(10, 20));
-
- // Create Igraph object
- IgraphAPI igraph = new IgraphAPI();
-
- // Add elements in menu toolbar
- IgraphAPI.IsConnected isConnectedAction1 = igraph.new IsConnected(this,
"All nodes", false);
-
Cytoscape.getDesktop().getCyMenus().addCytoscapeAction((CytoscapeAction)
isConnectedAction1);
-
- IgraphAPI.IsConnected isConnectedAction2 = igraph.new IsConnected(this,
"Selected Nodes", true);
-
Cytoscape.getDesktop().getCyMenus().addCytoscapeAction((CytoscapeAction)
isConnectedAction2);
-
- // Layouts
- CyLayouts.addLayout(new CircleLayout(), "Igraph");
- CyLayouts.addLayout(new StarLayout(), "Igraph");
- CyLayouts.addLayout(new FruchtermanReingoldLayout(true), "Igraph");
-
+ } catch (Exception e) {
+ e.printStackTrace();
+ String message = "Error while initializing Igraph Plugin:\n" +
e.getMessage();
+ JOptionPane.showMessageDialog( Cytoscape.getDesktop(), message);
+ }
}
private boolean isOldVersion(){
return false;
}
- private void checkLib(String lib) {
+ /**
+ * @return true if file was extracted, false otherwise
+ */
+ private boolean extractFileFromJar(String fileName) {
// TODO: Make this cross-platform
- File dynamicLib = new File ("./plugins/lib" + lib + ".dylib");
- if (!dynamicLib.exists() || isOldVersion()){
- String message;
+ File file = new File ("./plugins/" + fileName);
+ boolean ret = false;
+ if (!file.exists() || isOldVersion()){
try {
- String home = getClass().getProtectionDomain().
- getCodeSource().getLocation().toString().
- substring(6);
JarFile jar = new JarFile("./plugins/igraphPlugin.jar");
- ZipEntry entry = jar.getEntry("lib" + lib + ".dylib");
+ ZipEntry entry = jar.getEntry(fileName);
File efile = new File("./plugins/", entry.getName());
InputStream in =
@@ -108,17 +120,17 @@
out.close();
in.close();
- message = lib + " library extracted!";
+ ret = true;
}
catch (Exception e) {
e.printStackTrace();
- message = "Igraph Plugin: Error While extracting library from
jar file:\n" + e.getMessage();
+ String message = "Igraph Plugin: Error While extracting file
from igraph plugin jar :\n" + e.getMessage();
+ JOptionPane.showMessageDialog( Cytoscape.getDesktop(), message);
}
- //Show message
- JOptionPane.showMessageDialog( Cytoscape.getDesktop(), message);
+
}
- return;
- } // checkLib
+ return ret;
+ } // extractFileFromJar
}
\ No newline at end of file
--
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.