int launcherVersionComparison = LaunchUtils.compareGetdownLauncherJarVersions(installerGetdown, appdirGetdown);
notes.add(Note.info("Comparing launchers: installation launcher '" + installerGetdown.getAbsolutePath()
+ "', user launcher '" + appdirGetdown.getAbsoluteFile() + "', comparison=" + launcherVersionComparison));
- if (launcherVersionComparison > 0) {
+ if (launcherVersionComparison < 0) { // installer appdir getdown version is < user appdir getdown version. Use the user's
notes.add(Note.info("Using user appdir launcher at '" + appdirGetdown.getAbsolutePath() + "'"));
// change classpath and restart. A null startClass looks it up from system property "sun.java.command"
String javaBin = LaunchUtils.findJavaBin(false);
}
if (!f0.exists())
{
- return 1;
+ return -1;
}
if (!f1.exists())
{
- return -1;
+ return 1;
}
String v0 = getJarImplementationVersion(f0);
String v1 = getJarImplementationVersion(f1);
syserr(true, false,
"Got launcher versions '" + v0 + "' and '" + v1 + "'");
+ return compareGetdownLauncherJarVersions(v0, v1);
+ }
+
+ public static int compareGetdownLauncherJarVersions(String v0, String v1)
+ {
if (v0 == null && v1 == null)
{
return 0;
}
if (v0 == null)
{
- return 1;
+ return -1;
}
if (v1 == null)
{
- return -1;
+ return 1;
}
- // now for the fun
+
+ // remove the subscript
if (v0.endsWith("JVL"))
{
v0 = v0.substring(0, v0.lastIndexOf('_'));
int compare = 0;
for (int j = 0; j < Math.min(v0parts.length, v1parts.length); j++)
{
- compare = 0;
- try
- {
- compare = compareVersions(v0parts[j], v1parts[j]);
- } catch (NumberFormatException e)
- {
- syserr(true, false,
- "Problem parsing one of the getdown launcher version numbers: '"
- + v0 + "', '" + v1 + "'");
- }
-
- if (compare != 0
- || (v0parts.length == j + 1 && v1parts.length == j + 1))
+ compare = compareVersions(v0parts[j], v1parts[j]);
+ if (compare != 0)
{
return compare;
}
}
- return v1parts.length - v0parts.length;
+ return v0parts.length - v1parts.length;
}
- // just comparing 1.2.3.4...n
+ /**
+ * comparing versions numbers of the form 1.2.3.4...n ONLY returns 0 if v0 and
+ * v1 are the same, a negative number if v0 < v1 and a positive number if v0 >
+ * v1. The number returned does NOT show how far apart the version numbers
+ * are.
+ */
public static int compareVersions(String v0, String v1)
- throws NumberFormatException
{
if (v0 == null && v1 == null)
{
}
if (v0 == null)
{
- return 1;
+ return -1;
}
if (v1 == null)
{
- return -1;
+ return 1;
}
String[] v0dots = v0.split("\\.");
String[] v1dots = v1.split("\\.");
+ int compare = 0;
for (int i = 0; i < Math.min(v0dots.length, v1dots.length); i++)
{
- if (!v0dots[i].equals(v1dots[i]))
+ if (!v0dots[i].equals(v1dots[i])) // avoids unnecessary
+ // NumberFormatException
{
- return Integer.parseInt(v1dots[i]) - Integer.parseInt(v0dots[i]);
+ try
+ {
+ compare = Integer.parseInt(v0dots[i])
+ - Integer.parseInt(v1dots[i]);
+ } catch (NumberFormatException e)
+ {
+ syserr(true, false, "Couldn't parse one of '" + v0dots[i]
+ + "' or '" + v1dots[i] + "': " + e.getMessage());
+ syserr(true, false, "Comparing as strings.");
+ compare = v0dots[i].compareTo(v1dots[i]);
+ }
+ if (compare != 0)
+ {
+ return compare;
+ }
}
}
// all numbers match up to min length. If one has more dots, assume it's
- // bigger.
- return v1dots.length - v0dots.length;
+ // a greater version (e.g. 1.3.2 > 1.3)
+ return v0dots.length - v1dots.length;
}
public static String getJarImplementationVersion(File jarFile)