Revision: 4019
Author: [email protected]
Date: Fri Dec 3 12:58:29 2010
Log: Refactored the Wabit update checker for use in Architect Enterprise.
The Wabit update checker has also been cleaned up with the use of
BrowserUtils.
ArchitectVersion now extends the Version in the library as they were almost
identical and the update checker uses the Version in the library.
http://code.google.com/p/power-architect/source/detail?r=4019
Modified:
/trunk/src/main/java/ca/sqlpower/architect/ArchitectVersion.java
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/ArchitectVersion.java Fri
Dec 3 07:31:24 2010
+++ /trunk/src/main/java/ca/sqlpower/architect/ArchitectVersion.java Fri
Dec 3 12:58:29 2010
@@ -18,11 +18,11 @@
*/
package ca.sqlpower.architect;
-import java.util.ArrayList;
-import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import ca.sqlpower.util.Version;
+
/**
* The ArchitectVersion class exists as a means of finding out which
* version of the Architect application you are dealing with. It is
@@ -32,7 +32,7 @@
* XXX It is extremely important that this class has no dependencies aside
* from the standard Java libraries.
*/
-public class ArchitectVersion implements Comparable<ArchitectVersion> {
+public class ArchitectVersion extends Version {
/**
* The major version number. Currently we're working toward the 1.0
release.
@@ -82,13 +82,6 @@
? "-" + APP_VERSION_SUFFIX
: ""));
- /**
- * The components of this version, from most major to least major.
Parts
- * will either be Integer values or String values. If there is a String
- * part, it will be the last part, and is referred to as the "Suffix."
- */
- private Object[] parts;
-
/**
* Creates a new ArchitectVersion object from the given string. The
format is
* <tt>a1.a2.(...).aN[suffix]</tt>. Examples: <tt>1.2.3-alpha</tt>
@@ -100,57 +93,12 @@
* @param version The version string
*/
public ArchitectVersion(String version) {
- String[] rawParts = version.split("\\.");
- List<Object> parsedParts = new ArrayList<Object>();
- Pattern p = Pattern.compile("[0-9]+");
- Pattern suffixPattern = Pattern.compile("([0-9]+)(.+)");
- for (int i = 0; i < rawParts.length; i++) {
- Matcher m = p.matcher(rawParts[i]);
- if (m.matches()) {
- parsedParts.add(Integer.parseInt(rawParts[i]));
- } else {
- Matcher suffixMatcher = suffixPattern.matcher((String)
rawParts[i]);
- if (suffixMatcher.matches()) {
-
parsedParts.add(Integer.parseInt(suffixMatcher.group(1)));
- parsedParts.add(suffixMatcher.group(2));
- } else {
- throw new ArchitectVersionParseException(version);
- }
- }
- }
- parts = parsedParts.toArray();
+ super(version);
}
- /**
- * Returns the String representation of this version number in the
same format
- * accepted by the {...@link #ArchitectVersion(String)} constructor.
- */
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder();
- boolean first = true;
- for (Object part : parts) {
- if (!first && part instanceof Integer) {
- sb.append(".");
- }
- sb.append(part);
- first = false;
- }
- return sb.toString();
- }
-
- /**
- * Returns an array of the parts represented by this ArchitectVersion,
contents
- * are either Integer or String.
- *
- */
- public Object[] getParts() {
- return parts;
- }
-
/**
* ArchitectVersion numbers are mutually comparable even if they have
different
- * numbers of parts, and in that case, version <tt>2.0</tt> is older
+ * numbers of getParts(), and in that case, version <tt>2.0</tt> is
older
* than <tt>2.0.0</tt> or <tt>2.0.1</tt> but still newer than
* <tt>1.0.0</tt>.
* <p>
@@ -171,15 +119,15 @@
*/
public int compareTo(ArchitectVersion o) {
int i;
- for (i = 0; i < parts.length && i < o.parts.length; i++) {
- if (parts[i] instanceof Integer && o.parts[i] instanceof
Integer) {
- int v = (Integer) parts[i];
- int ov = (Integer) o.parts[i];
+ for (i = 0; i < getParts().length && i < o.getParts().length; i++)
{
+ if (getParts()[i] instanceof Integer && o.getParts()[i]
instanceof Integer) {
+ int v = (Integer) getParts()[i];
+ int ov = (Integer) o.getParts()[i];
if (v > ov) return 1;
if (v < ov) return -1;
- } else if (parts[i] instanceof String && o.parts[i] instanceof
String) {
- String v = (String) parts[i];
- String ov = (String) o.parts[i];
+ } else if (getParts()[i] instanceof String && o.getParts()[i]
instanceof String) {
+ String v = (String) getParts()[i];
+ String ov = (String) o.getParts()[i];
// Splits into name and final number
Pattern p = Pattern.compile("([^0-9]*)([0-9]*)");
Matcher vm = p.matcher(v);
@@ -196,9 +144,9 @@
}
}
}
- } else if (parts[i] instanceof Integer && o.parts[i]
instanceof String) {
+ } else if (getParts()[i] instanceof Integer && o.getParts()[i]
instanceof String) {
return 1;
- } else if (parts[i] instanceof String && o.parts[i] instanceof
Integer) {
+ } else if (getParts()[i] instanceof String && o.getParts()[i]
instanceof Integer) {
return -1;
} else {
throw new IllegalStateException("Found a version part
that's not a String or Integer");
@@ -206,12 +154,12 @@
}
// check for special case where comparing 1.0a to 1.0 (1.0 should
be newer)
- if (parts.length == o.parts.length + 1 && parts[parts.length-1]
instanceof String) return -1;
- if (o.parts.length == parts.length + 1 &&
o.parts[o.parts.length-1] instanceof String) return 1;
-
- // otherwise if one version has more integer parts, it's newer.
- if (parts.length > o.parts.length) return 1;
- if (parts.length < o.parts.length) return -1;
+ if (getParts().length == o.getParts().length + 1 &&
getParts()[getParts().length-1] instanceof String) return -1;
+ if (o.getParts().length == getParts().length + 1 &&
o.getParts()[o.getParts().length-1] instanceof String) return 1;
+
+ // otherwise if one version has more integer getParts(), it's
newer.
+ if (getParts().length > o.getParts().length) return 1;
+ if (getParts().length < o.getParts().length) return -1;
// they're actually the same
return 0;