Author: mes
Date: 2010-02-02 12:07:25 -0800 (Tue, 02 Feb 2010)
New Revision: 19131
Added:
cytoscape/trunk/src/cytoscape/plugin/JarUtil.java
Modified:
cytoscape/trunk/src/cytoscape/plugin/InstallablePlugin.java
cytoscape/trunk/src/cytoscape/plugin/PluginManager.java
Log:
moved duplicate code into package protected static utility class
Modified: cytoscape/trunk/src/cytoscape/plugin/InstallablePlugin.java
===================================================================
--- cytoscape/trunk/src/cytoscape/plugin/InstallablePlugin.java 2010-02-02
20:01:00 UTC (rev 19130)
+++ cytoscape/trunk/src/cytoscape/plugin/InstallablePlugin.java 2010-02-02
20:07:25 UTC (rev 19131)
@@ -27,13 +27,17 @@
*/
public class InstallablePlugin implements Installable {
- // Bug 2055 changing regexp used to match jars
- // Was "\\w+\\.jar", which seemed unecessarily restrictive
- public static final String MATCH_JAR_REGEXP = ".*\\.jar$";
+ /**
+ * @deprecated This was only ever used internally, so now it is package
+ * protected and part of JarUtil. Use that one as an alternative.
+ * Will be removed Jan 2010.
+ */
+ @Deprecated
+ public static final String MATCH_JAR_REGEXP = JarUtil.MATCH_JAR_REGEXP;
- private static CyLogger logger = CyLogger.getLogger(InstallablePlugin.class);
+ private static CyLogger logger =
CyLogger.getLogger(InstallablePlugin.class);
- private PluginInfo infoObj;
+ private PluginInfo infoObj;
public InstallablePlugin(PluginInfo obj) {
this.infoObj = obj;
@@ -78,7 +82,7 @@
URLUtil.download(infoObj.getObjectUrl(), Download, taskMonitor);
try {
- String ClassName =
getPluginClass(Download.getAbsolutePath(),
+ String ClassName =
JarUtil.getPluginClass(Download.getAbsolutePath(),
infoObj.getFileType());
if (ClassName != null) {
@@ -263,87 +267,4 @@
private String createFileName(PluginInfo Obj) {
return Obj.getName() + "." + Obj.getFileType().toString();
}
-
- /*
- * Iterate through all class files, return the subclass of
CytoscapePlugin.
- * Similar to CytoscapeInit, however only plugins with manifest files
that
- * describe the class of the CytoscapePlugin are valid.
- */
- private String getPluginClass(String FileName, PluginInfo.FileType Type)
- throws IOException {
- String PluginClassName = null;
-
- switch (Type) {
- case JAR:
- JarFile Jar = new JarFile(FileName);
- try {
- PluginClassName = getManifestAttribute(Jar.getManifest());
- }
- finally {
- if (Jar != null) {
- Jar.close();
- }
- }
- break;
-
- case ZIP:
- List<ZipEntry> Entries = ZipUtil
- .getAllFiles(FileName,
MATCH_JAR_REGEXP);
- if (Entries.size() <= 0) {
- String[] FilePath = FileName.split("/");
- FileName = FilePath[FilePath.length - 1];
- throw new IOException(
- FileName
- + " does not
contain any jar files or is not a zip file.");
- }
-
- ZipFile zf = null;
-
- try {
- zf = new ZipFile(FileName);
- for (ZipEntry Entry : Entries) {
- String EntryName = Entry.getName();
-
- InputStream is = null;
-
- try {
- JarInputStream jis = null;
-
- is = ZipUtil.readFile(zf,
EntryName);
- try {
- jis = new
JarInputStream(is);
- PluginClassName =
getManifestAttribute(jis.getManifest());
- }
- finally {
- if (jis != null) {
- jis.close();
- }
- }
- }
- finally {
- if (is != null) {
- is.close();
- }
- }
- }
- }
- finally {
- zf.close();
- }
- }
-
- return PluginClassName;
- }
-
- /*
- * Gets the manifest file value for the Cytoscape-Plugin attribute
- */
- private String getManifestAttribute(Manifest m) {
- String Value = null;
- if (m != null) {
- Value =
m.getMainAttributes().getValue("Cytoscape-Plugin");
- }
- return Value;
- }
-
}
Added: cytoscape/trunk/src/cytoscape/plugin/JarUtil.java
===================================================================
--- cytoscape/trunk/src/cytoscape/plugin/JarUtil.java
(rev 0)
+++ cytoscape/trunk/src/cytoscape/plugin/JarUtil.java 2010-02-02 20:07:25 UTC
(rev 19131)
@@ -0,0 +1,109 @@
+package cytoscape.plugin;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.jar.JarFile;
+import java.util.jar.JarInputStream;
+import java.util.jar.Manifest;
+import java.util.zip.ZipEntry;
+
+import cytoscape.util.URLUtil;
+import cytoscape.util.ZipUtil;
+import java.util.zip.ZipFile;
+
+/**
+ * A utility class designed to capture methods used by multiple classes.
+ */
+class JarUtil {
+
+ // Bug 2055 changing regexp used to match jars
+ // Was "\\w+\\.jar", which seemed unecessarily restrictive
+ static final String MATCH_JAR_REGEXP = ".*\\.jar$";
+
+ /**
+ * Iterate through all class files, return the subclass of
CytoscapePlugin.
+ * Similar to CytoscapeInit, however only plugins with manifest files
that
+ * describe the class of the CytoscapePlugin are valid.
+ */
+ static String getPluginClass(String fileName, PluginInfo.FileType type)
throws IOException {
+
+ String pluginClassName = null;
+
+ try {
+
+ switch (type) {
+ case JAR:
+ JarFile jar = new JarFile(fileName);
+ try {
+ pluginClassName = getManifestAttribute(jar.getManifest());
+ } finally {
+ if (jar != null)
+ jar.close();
+ }
+ break;
+
+ case ZIP:
+ List<ZipEntry> Entries = ZipUtil
+ .getAllFiles(fileName,
MATCH_JAR_REGEXP);
+ if (Entries.size() <= 0) {
+ String[] FilePath = fileName.split("/");
+ fileName = FilePath[FilePath.length - 1];
+ throw new IOException(
+ fileName
+ + " does not
contain any jar files or is not a zip file.");
+ }
+
+ ZipFile zf = null;
+
+ try {
+ zf = new ZipFile(fileName);
+ for (ZipEntry entry : Entries) {
+ String entryName = entry.getName();
+
+ InputStream is = null;
+
+ try {
+ JarInputStream jis = null;
+
+ is = ZipUtil.readFile(zf,
entryName);
+ try {
+ jis = new
JarInputStream(is);
+ pluginClassName =
getManifestAttribute(jis.getManifest());
+ } finally {
+ if (jis != null)
+ jis.close();
+ }
+ } finally {
+ if (is != null)
+ is.close();
+ }
+ }
+ } finally {
+ if (zf != null)
+ zf.close();
+ }
+ }
+
+ } catch (Throwable t) {
+ throw new IOException(t);
+ }
+
+ return pluginClassName;
+ }
+
+ /*
+ * Gets the manifest file value for the Cytoscape-Plugin attribute
+ */
+ static String getManifestAttribute(Manifest m) {
+ String value = null;
+ if (m != null) {
+ value =
m.getMainAttributes().getValue("Cytoscape-Plugin");
+ }
+ return value;
+ }
+}
Modified: cytoscape/trunk/src/cytoscape/plugin/PluginManager.java
===================================================================
--- cytoscape/trunk/src/cytoscape/plugin/PluginManager.java 2010-02-02
20:01:00 UTC (rev 19130)
+++ cytoscape/trunk/src/cytoscape/plugin/PluginManager.java 2010-02-02
20:07:25 UTC (rev 19131)
@@ -853,7 +853,7 @@
}
// try to get class name from the manifest file
- String className = getPluginClass(jar.getName(),
+ String className =
JarUtil.getPluginClass(jar.getName(),
PluginInfo.FileType.JAR);
if (className != null) {
@@ -986,87 +986,6 @@
return new URL(uString);
}
- /*
- * Iterate through all class files, return the subclass of
CytoscapePlugin.
- * Only plugins with manifest files that describe the class of the
- * CytoscapePlugin are valid.
- */
- private String getPluginClass(String FileName, PluginInfo.FileType Type)
- throws IOException {
- String PluginClassName = null;
-
- switch (Type) {
- case JAR:
- JarFile Jar = new JarFile(FileName);
- try {
- PluginClassName = getManifestAttribute(Jar.getManifest());
- }
- finally {
- if (Jar != null) {
- Jar.close();
- }
- }
- break;
-
- case ZIP:
- List<ZipEntry> Entries = ZipUtil
- .getAllFiles(FileName,
InstallablePlugin.MATCH_JAR_REGEXP);
- if (Entries.size() <= 0) {
- String[] FilePath = FileName.split("/");
- FileName = FilePath[FilePath.length - 1];
- throw new IOException(
- FileName
- + " does not
contain any jar files or is not a zip file.");
- }
-
- ZipFile zf = null;
- try {
- zf = new ZipFile(FileName);
- for (ZipEntry Entry : Entries) {
- String EntryName = Entry.getName();
-
- InputStream is = null;
- try {
- JarInputStream jis = null;
-
- is = ZipUtil.readFile(zf,
EntryName);
- try {
- jis = new
JarInputStream(is);
- PluginClassName =
getManifestAttribute(jis.getManifest());
- }
- finally {
- if (jis != null) {
- jis.close();
- }
- }
- }
- finally {
- if (is != null) {
- is.close();
- }
- }
- }
- }
- finally {
- if (zf != null) {
- zf.close();
- }
- }
- }
- return PluginClassName;
- }
-
- /*
- * Gets the manifest file value for the Cytoscape-Plugin attribute
- */
- private String getManifestAttribute(Manifest m) {
- String Value = null;
- if (m != null) {
- Value =
m.getMainAttributes().getValue("Cytoscape-Plugin");
- }
- return Value;
- }
-
/**
* This will be used to add plugin jars' URL to the System Loader's
* classpath.
--
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.