Author: ruschein
Date: 2011-06-10 09:10:56 -0700 (Fri, 10 Jun 2011)
New Revision: 25709
Added:
cytoscape/trunk/application/src/test/java/cytoscape/plugin/PluginVersionUtilsTest.java
Modified:
cytoscape/trunk/application/src/main/java/cytoscape/plugin/DownloadableInfo.java
cytoscape/trunk/application/src/main/java/cytoscape/plugin/PluginVersionUtils.java
Log:
Cleaned up part of the version checking mess.
Modified:
cytoscape/trunk/application/src/main/java/cytoscape/plugin/DownloadableInfo.java
===================================================================
---
cytoscape/trunk/application/src/main/java/cytoscape/plugin/DownloadableInfo.java
2011-06-10 15:57:08 UTC (rev 25708)
+++
cytoscape/trunk/application/src/main/java/cytoscape/plugin/DownloadableInfo.java
2011-06-10 16:10:56 UTC (rev 25709)
@@ -1,14 +1,7 @@
/*
File: DownloadableInfo.java
- Copyright (c) 2006, 2007, The Cytoscape Consortium (www.cytoscape.org)
+ Copyright (c) 2006, 2007, 2011 The Cytoscape Consortium (www.cytoscape.org)
- The Cytoscape Consortium is:
- - Institute for Systems Biology
- - University of California San Diego
- - Memorial Sloan-Kettering Cancer Center
- - Institut Pasteur
- - Agilent Technologies
-
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2.1 of the License, or
@@ -32,9 +25,10 @@
You should have received a copy of the GNU Lesser General Public License
along with this library; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
- */
+*/
package cytoscape.plugin;
+
import java.net.URL;
import java.io.IOException;
@@ -51,13 +45,10 @@
import java.util.ArrayList;
import java.util.Arrays;
+
public abstract class DownloadableInfo {
private static CyLogger logger =
CyLogger.getLogger(DownloadableInfo.class);
- protected String versionMatch = PluginVersionUtils.versionMatch;
-
- protected String versionSplit = PluginVersionUtils.versionSplit;
-
private String releaseDate;
private String uniqueID;
@@ -178,15 +169,14 @@
* @param cyVersion
* @throws NumberFormatException
*/
- public void addCytoscapeVersion(String cyVersion)
- throws NumberFormatException {
- if (versionOk(cyVersion, false)) {
+ public void addCytoscapeVersion(final String cyVersion) throws
NumberFormatException {
+ if (versionOk(cyVersion, false))
compatibleCyVersions.add(cyVersion);
-
-
- } else {
+ else {
throw new NumberFormatException(
- "Cytoscape version numbers must be in
the format: \\d+.\\d+ optional to add: .\\d+-[a-z]");
+ "Cytoscape version
numbers must be in the format: \""
+ +
PluginVersionUtils.VALID_CYTOSCAPE_VERSION_PATTERN + "\"!"
+ + " (Bad version is \""
+ cyVersion + "\".)");
}
}
@@ -195,14 +185,14 @@
* Sets the version of this object.
*/
public void setObjectVersion(double objVersion)
- throws NumberFormatException {
+ throws NumberFormatException {
String Version = Double.toString(objVersion);
if (versionOk(Version, true)) {
this.objVersion = Version;
} else {
throw new NumberFormatException("Bad version '" +
Version + "'."
- + this
- + " version numbers must be in the
format: \\d+.\\d+");
+ + this
+ + " version numbers
must be in the format: \\d+.\\d+");
}
}
@@ -328,11 +318,11 @@
}
logger.debug(getName() +": Compatible: " + all + " cyvers: " +
currentPluginVersion
- + "(cyversion " +
cytoscape.CytoscapeVersion.version +")");
+ + "(cyversion " +
cytoscape.CytoscapeVersion.version +")");
return currentPluginVersion;
}
- /**
+ /**
* @return All compatible Cytoscape versions.
*/
public List<String> getCytoscapeVersions() {
@@ -365,12 +355,12 @@
* @return true if given version is newer
*/
public boolean isNewerObjectVersion(DownloadableInfo New) {
- String[] CurrentVersion =
this.getObjectVersion().split(versionSplit);
- String[] NewVersion =
New.getObjectVersion().split(versionSplit);
+ String[] CurrentVersion =
this.getObjectVersion().split(PluginVersionUtils.VERSION_SEPARATOR);
+ String[] NewVersion =
New.getObjectVersion().split(PluginVersionUtils.VERSION_SEPARATOR);
// make sure it's the same object first
if (!(this.getID().equals(New.getID()) &&
this.getDownloadableURL()
- .equals(New.getDownloadableURL()))) {
+ .equals(New.getDownloadableURL()))) {
return false;
}
@@ -387,83 +377,83 @@
return true;
}
- /**
- * @param pluginVersion
+ /**
+ * @param pluginVersion
* @return true if the given version is compatible with the current
Cytoscape
* version major.minor (bugfix is only checked if the plugin
* specifies a bugfix version)
*/
- private boolean isCytoscapeVersionCurrent(String pluginVersion) {
- if (pluginVersion == null )
- return false;
+ private boolean isCytoscapeVersionCurrent(String pluginVersion) {
+ if (pluginVersion == null )
+ return false;
- String[] cyVersion = new
CytoscapeVersion().getFullVersion().split(versionSplit);
- String[] plVersion = pluginVersion.split(versionSplit);
+ String[] cyVersion = new
CytoscapeVersion().getFullVersion().split(PluginVersionUtils.VERSION_SEPARATOR);
+ String[] plVersion =
pluginVersion.split(PluginVersionUtils.VERSION_SEPARATOR);
- if ( cyVersion.length < plVersion.length )
- return false;
+ if ( cyVersion.length < plVersion.length )
+ return false;
- for (int i = 0; i < plVersion.length; i++)
- if (Integer.valueOf(cyVersion[i]).intValue() !=
Integer.valueOf(plVersion[i]).intValue())
- return false;
+ for (int i = 0; i < plVersion.length; i++)
+ if (Integer.valueOf(cyVersion[i]).intValue() !=
Integer.valueOf(plVersion[i]).intValue())
+ return false;
- return true;
- }
+ return true;
+ }
- private boolean compareVersions(String[] v1, String[] v2) {
- if (v1.length != v2.length) return false;
+ private boolean compareVersions(String[] v1, String[] v2) {
+ if (v1.length != v2.length) return false;
- for (int i = 0; i < v1.length; i++) {
- // Remove ".SNAPSHOT in versiopn number if any
- v1[i] = v1[i].toUpperCase();
- int idx = v1[i].indexOf("SNAPSHOT");
- if (idx >0){
- v1[i] = v1[i].substring(0, idx-1);
- }
+ for (int i = 0; i < v1.length; i++) {
+ // Remove ".SNAPSHOT in versiopn number if any
+ v1[i] = v1[i].toUpperCase();
+ int idx = v1[i].indexOf("SNAPSHOT");
+ if (idx >0){
+ v1[i] = v1[i].substring(0, idx-1);
+ }
- if (Integer.valueOf(v1[i]).intValue() != Integer.valueOf(
- v2[i]).intValue())
- return false;
- }
- return true;
- }
+ if (Integer.valueOf(v1[i]).intValue() !=
Integer.valueOf(
+
v2[i]).intValue())
+ return false;
+ }
+ return true;
+ }
-/**
- * @return true if the plugin is compatible with the current version of
Cytoscape.
- * NOTE: It is assumed that if a plugin is listed as being compatible with
the minor version number
- * it is compatible with all bug fix versions.
- */
- public boolean isPluginCompatibleWithCurrent() {
+ /**
+ * @return true if the plugin is compatible with the current version of
Cytoscape.
+ * NOTE: It is assumed that if a plugin is listed as being
compatible with the minor version number
+ * it is compatible with all bug fix versions.
+ */
+ public boolean isPluginCompatibleWithCurrent() {
- if (this.getCategory() != null &&
this.getCategory().equalsIgnoreCase("Core")){
- // core plugins already compatible with current version
- return true;
- }
+ if (this.getCategory() != null &&
this.getCategory().equalsIgnoreCase("Core")){
+ // core plugins already compatible with current version
+ return true;
+ }
- boolean compatible = false;
- CytoscapeVersion cv = new CytoscapeVersion();
- for (String pluginVersion: compatibleCyVersions) {
- String[] cyVersion = cv.getFullVersion().split(versionSplit);
- String[] plVersion = pluginVersion.split(versionSplit);
- if ( PluginVersionUtils.isVersion(pluginVersion,
PluginVersionUtils.MINOR) ) {
- cyVersion = new String[]{cyVersion[0], cyVersion[1]};
- }
- logger.debug("Comparing versions: " + Arrays.toString(cyVersion) + " : "
+ Arrays.toString(plVersion));
+ boolean compatible = false;
+ CytoscapeVersion cv = new CytoscapeVersion();
+ for (String pluginVersion: compatibleCyVersions) {
+ String[] cyVersion =
cv.getFullVersion().split(PluginVersionUtils.VERSION_SEPARATOR);
+ String[] plVersion =
pluginVersion.split(PluginVersionUtils.VERSION_SEPARATOR);
+ if ( PluginVersionUtils.isVersion(pluginVersion,
PluginVersionUtils.MINOR) ) {
+ cyVersion = new String[]{cyVersion[0],
cyVersion[1]};
+ }
+ logger.debug("Comparing versions: " +
Arrays.toString(cyVersion) + " : " + Arrays.toString(plVersion));
- if (compareVersions(cyVersion, plVersion)) {
- compatible = true;
- break;
- }
- }
- return compatible;
- }
+ if (compareVersions(cyVersion, plVersion)) {
+ compatible = true;
+ break;
+ }
+ }
+ return compatible;
+ }
/**
* Compare the two info objects. If the ID, downloadable url and object
* version are the same they are considered to be the same object.
- *
- * Careful, this overwrites the Object.equals method
+ *
+ * Careful, this overwrites the Object.equals method
*/
public boolean equals(Object Obj) {
DownloadableInfo obj = (DownloadableInfo) Obj;
@@ -471,11 +461,11 @@
if ( this.getType().equals(obj.getType()) ) {
if ( (this.getID() != null && obj.getID() != null) ) {
if (this.getID().equals(obj.getID()) &&
-
this.getDownloadableURL().equals(obj.getDownloadableURL()) &&
-
this.getObjectVersion().equals(obj.getObjectVersion()))
+
this.getDownloadableURL().equals(obj.getDownloadableURL()) &&
+
this.getObjectVersion().equals(obj.getObjectVersion()))
return true;
} else if
(this.getDownloadableURL().equals(obj.getDownloadableURL()) &&
-
this.getObjectVersion().equals(obj.getObjectVersion())) {
+
this.getObjectVersion().equals(obj.getObjectVersion())) {
// should I do this?? Without an id there is no
other good way to
// tell I suppose
return true;
@@ -494,14 +484,14 @@
public boolean equalsDifferentObjectVersion(Object Obj) {
DownloadableInfo obj = (DownloadableInfo) Obj;
if (this.getID().equals(obj.getID())
- && this.getType().equals(obj.getType())
- &&
this.getDownloadableURL().equals(obj.getDownloadableURL()))
+ && this.getType().equals(obj.getType())
+ &&
this.getDownloadableURL().equals(obj.getDownloadableURL()))
return true;
return false;
}
- /**
+ /**
* @return Returns String of downloadable name and version ex. MyPlugin
* v.1.0
*/
@@ -528,11 +518,11 @@
if (!isPluginCompatibleWithCurrent()) {
Html += "<br><b>Verified with the following Cytoscape
versions:</b> "
- + getCytoscapeVersions().toString() +
"<br>";
+ + getCytoscapeVersions().toString() + "<br>";
Html += "<font color='red'><i>" + toString()
- + " is not verfied to work in the
current version ("
- + cytoscape.CytoscapeVersion.version
- + ") of Cytoscape.</i></font>";
+ + " is not verfied to work in the current
version ("
+ + cytoscape.CytoscapeVersion.version
+ + ") of Cytoscape.</i></font>";
}
Html += "<p>";
Modified:
cytoscape/trunk/application/src/main/java/cytoscape/plugin/PluginVersionUtils.java
===================================================================
---
cytoscape/trunk/application/src/main/java/cytoscape/plugin/PluginVersionUtils.java
2011-06-10 15:57:08 UTC (rev 25708)
+++
cytoscape/trunk/application/src/main/java/cytoscape/plugin/PluginVersionUtils.java
2011-06-10 16:10:56 UTC (rev 25709)
@@ -1,28 +1,24 @@
-/**
- *
- */
package cytoscape.plugin;
+
import cytoscape.logger.CyLogger;
-public class PluginVersionUtils {
- protected static final CyLogger logger =
CyLogger.getLogger(PluginVersionUtils.class);
- public static final String versionMatch = "^\\d+\\.\\d+";
- public static final String versionSplit = "\\.";
- public static final int MAJOR = 1;
- public static final int MINOR = 2;
- public static final int BUGFIX = 3;
+public final class PluginVersionUtils {
+ public static final String VALID_CYTOSCAPE_VERSION_PATTERN =
"^\\d+\\.\\d+(\\.\\d+(-[a-zA-Z]+)?)?$";
+ public static final int MINOR = 2;
+ public static final String VERSION_SEPARATOR = "\\.";
+ private static final CyLogger logger =
CyLogger.getLogger(PluginVersionUtils.class);
- public static boolean isVersion(String vers, int vt) {
- String[] version = vers.split("\\.");
- if (version.length == 2 && version[1].equals("0"))
- version = new String[]{version[0]};
+ public static boolean isVersion(String vers, int vt) {
+ String[] version = vers.split("\\.");
+ if (version.length == 2 && version[1].equals("0"))
+ version = new String[]{version[0]};
- return vt == version.length;
- }
+ return vt == version.length;
+ }
- /**
+ /**
* Return the newer of the two versions.
*
* @param arg0
@@ -33,8 +29,8 @@
String MostRecentVersion = null;
int max = 3;
- String[] SplitVersionA = arg0.split(versionSplit);
- String[] SplitVersionB = arg1.split(versionSplit);
+ String[] SplitVersionA = arg0.split("\\.");
+ String[] SplitVersionB = arg1.split("\\.");
for (int i = 0; i < max; i++) {
int a = 0;
@@ -43,9 +39,9 @@
if (i == (max - 1)) {
logger.debug("A length: " +
SplitVersionA.length + " B length: " + SplitVersionB.length);
a = (SplitVersionA.length == max) ? Integer
- .valueOf(SplitVersionA[i]) : 0;
+ .valueOf(SplitVersionA[i]) : 0;
b = (SplitVersionB.length == max) ? Integer
- .valueOf(SplitVersionB[i]) : 0;
+ .valueOf(SplitVersionB[i]) : 0;
} else {
a = Integer.valueOf(SplitVersionA[i]);
b = Integer.valueOf(SplitVersionB[i]);
@@ -56,53 +52,12 @@
break;
}
}
- return MostRecentVersion;
+ return MostRecentVersion;
}
-
- // this just checks the downloadable object version and the cytoscape version
- protected static boolean versionOk(String version, boolean downloadObj) {
- // \d+.\+d ok
- String Match = versionMatch;
- String Split = versionSplit;
-
- if (downloadObj) {
- Match = Match + "$";
- } else { // cytoscape version
- Match = Match + "(\\.\\d+)?$";
- Split = "\\.|-";
- }
-
- if (!version.matches(Match)) {
- return false;
- }
-
- String[] SplitVersion = version.split(Split);
-
- int max = 2;
- if (!downloadObj) {
- max = 3; // cytoscape version numbers
- // if there's a fourth is must be alpha
- if (SplitVersion.length == 4) {
- if (!SplitVersion[3].matches("[a-z]+")) {
- return false;
- }
- }
- }
-
- // can't be longer than the accepted version types
- if (SplitVersion.length > max) {
- return false;
- }
-
- // must be digits
- for (int i = 0; i < max && i < SplitVersion.length; i++) {
- if (!SplitVersion[i].matches("\\d+")) {
- return false;
- }
- }
- return true;
- }
-
-
+ // this just checks the downloadable object version and the cytoscape
version
+ public static boolean versionOk(final String version, final boolean
downloadObj) {
+ final String pattern = downloadObj ? "^\\d+\\.\\d+$" :
VALID_CYTOSCAPE_VERSION_PATTERN;
+ return version.matches(pattern);
+ }
}
Added:
cytoscape/trunk/application/src/test/java/cytoscape/plugin/PluginVersionUtilsTest.java
===================================================================
---
cytoscape/trunk/application/src/test/java/cytoscape/plugin/PluginVersionUtilsTest.java
(rev 0)
+++
cytoscape/trunk/application/src/test/java/cytoscape/plugin/PluginVersionUtilsTest.java
2011-06-10 16:10:56 UTC (rev 25709)
@@ -0,0 +1,64 @@
+package cytoscape.plugin;
+
+
+import junit.framework.TestCase;
+
+
+public class PluginVersionUtilsTest extends TestCase {
+ public void testGoodCyVersion1() {
+ assertTrue(PluginVersionUtils.versionOk("2.8", false));
+ }
+
+ public void testGoodCyVersion2() {
+ assertTrue(PluginVersionUtils.versionOk("2.8.1", false));
+ }
+
+ public void testGoodCyVersion3() {
+ assertTrue(PluginVersionUtils.versionOk("2.8.1-lower", false));
+ }
+
+ public void testGoodCyVersion4() {
+ assertTrue(PluginVersionUtils.versionOk("2.8.1-UPPER", false));
+ }
+
+ public void testBadCyVersion1() {
+ assertFalse(PluginVersionUtils.versionOk("2", false));
+ }
+
+ public void testBadCyVersion2() {
+ assertFalse(PluginVersionUtils.versionOk("X.Y.Z", false));
+ }
+
+ public void testBadCyVersion3() {
+ assertFalse(PluginVersionUtils.versionOk("2.8.1-133t", false));
+ }
+
+ public void testBadCyVersion4() {
+ assertFalse(PluginVersionUtils.versionOk("2.8.1.4", false));
+ }
+
+ public void testGoodPluginVersion1() {
+ assertTrue(PluginVersionUtils.versionOk("2.8", true));
+ }
+
+ public void testBadPluginVersion1() {
+ assertFalse(PluginVersionUtils.versionOk("2", true));
+ }
+
+ public void testBadPluginVersion2() {
+ assertFalse(PluginVersionUtils.versionOk("X.Y", true));
+ }
+
+ public void testBadPluginVersion3() {
+ assertFalse(PluginVersionUtils.versionOk("2.8.1", true));
+ }
+
+ public void testBadPluginVersion4() {
+ assertFalse(PluginVersionUtils.versionOk("2-8", true));
+ }
+
+ public void testBadPluginVersion5() {
+ assertFalse(PluginVersionUtils.versionOk("2.8-SNAPSHOT", true));
+ }
+}
+
--
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.