Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSarika Sinha2017-04-28 03:45:27 +0000
committerSarika Sinha2017-04-28 03:45:27 +0000
commit08aa1ad308e9c8f763e29445b30cdc88093c3159 (patch)
tree594a84599d140e4b4daf641591f8c86fd0284ca1
parentc95f654d8620228414cf5ec252be4573fa98d227 (diff)
downloadeclipse.platform-08aa1ad308e9c8f763e29445b30cdc88093c3159.tar.gz
eclipse.platform-08aa1ad308e9c8f763e29445b30cdc88093c3159.tar.xz
eclipse.platform-08aa1ad308e9c8f763e29445b30cdc88093c3159.zip
Bug 515929 - Version comparison in Ant does not support two numbers inI20170428-0445
-rw-r--r--ant/org.eclipse.ant.core/src_ant/org/eclipse/ant/internal/core/ant/InternalAntRunner.java7
-rw-r--r--ant/org.eclipse.ant.launching/remote/org/eclipse/ant/internal/launching/remote/InternalAntRunner.java92
2 files changed, 95 insertions, 4 deletions
diff --git a/ant/org.eclipse.ant.core/src_ant/org/eclipse/ant/internal/core/ant/InternalAntRunner.java b/ant/org.eclipse.ant.core/src_ant/org/eclipse/ant/internal/core/ant/InternalAntRunner.java
index d517ec80a..7f13cd8e8 100644
--- a/ant/org.eclipse.ant.core/src_ant/org/eclipse/ant/internal/core/ant/InternalAntRunner.java
+++ b/ant/org.eclipse.ant.core/src_ant/org/eclipse/ant/internal/core/ant/InternalAntRunner.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2015 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -71,6 +71,7 @@ import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.variables.VariablesPlugin;
import org.osgi.framework.Bundle;
+import org.osgi.framework.Version;
/**
* Eclipse application entry point into Ant. Derived from the original Ant Main class to ensure that the functionality is equivalent when running in
@@ -1017,7 +1018,9 @@ public class InternalAntRunner {
*/
protected boolean isVersionCompatible(String comparison) {
String version = getAntVersionNumber();
- return version.compareTo(comparison) >= 0;
+ Version osgiVersion = new Version(version);
+ Version osgiComparison = new Version(comparison);
+ return osgiVersion.compareTo(osgiComparison) >= 0;
}
/**
diff --git a/ant/org.eclipse.ant.launching/remote/org/eclipse/ant/internal/launching/remote/InternalAntRunner.java b/ant/org.eclipse.ant.launching/remote/org/eclipse/ant/internal/launching/remote/InternalAntRunner.java
index e3e6588b4..0daf97360 100644
--- a/ant/org.eclipse.ant.launching/remote/org/eclipse/ant/internal/launching/remote/InternalAntRunner.java
+++ b/ant/org.eclipse.ant.launching/remote/org/eclipse/ant/internal/launching/remote/InternalAntRunner.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2016 IBM Corporation and others.
+ * Copyright (c) 2000, 2017 IBM Corporation and others.
* Portions Copyright 2000-2005 The Apache Software Foundation
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the Apache Software License v2.0 which
@@ -29,7 +29,9 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.NoSuchElementException;
import java.util.Properties;
+import java.util.StringTokenizer;
import java.util.Vector;
import org.apache.tools.ant.AntTypeDefinition;
@@ -691,7 +693,93 @@ public class InternalAntRunner {
*/
private boolean isVersionCompatible(String comparison) {
String version = getAntVersionNumber();
- return version.compareTo(comparison) >= 0;
+ Version osgiVersion = new Version(version);
+ Version osgiComparison = new Version(comparison);
+ return osgiVersion.compareTo(osgiComparison) >= 0;
+ }
+
+ class Version {
+ private final int major;
+ private final int minor;
+ private final int micro;
+ private final String qualifier;
+ private static final String SEPARATOR = "."; //$NON-NLS-1$
+
+ public int compareTo(Version other) {
+ if (other == this) { // quick test
+ return 0;
+ }
+
+ int result = major - other.major;
+ if (result != 0) {
+ return result;
+ }
+
+ result = minor - other.minor;
+ if (result != 0) {
+ return result;
+ }
+
+ result = micro - other.micro;
+ if (result != 0) {
+ return result;
+ }
+
+ return qualifier.compareTo(other.qualifier);
+ }
+
+ public Version(String version) {
+ int maj = 0;
+ int min = 0;
+ int mic = 0;
+ String qual = ""; //$NON-NLS-1$
+
+ try {
+ StringTokenizer st = new StringTokenizer(version, SEPARATOR, true);
+ maj = parseInt(st.nextToken(), version);
+
+ if (st.hasMoreTokens()) { // minor
+ st.nextToken(); // consume delimiter
+ min = parseInt(st.nextToken(), version);
+
+ if (st.hasMoreTokens()) { // micro
+ st.nextToken(); // consume delimiter
+ mic = parseInt(st.nextToken(), version);
+
+ if (st.hasMoreTokens()) { // qualifier separator
+ st.nextToken(); // consume delimiter
+ qual = st.nextToken(""); // remaining string //$NON-NLS-1$
+
+ if (st.hasMoreTokens()) { // fail safe
+ throw new IllegalArgumentException("invalid version \"" + version + "\": invalid format"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+ }
+ }
+ }
+ catch (NoSuchElementException e) {
+ IllegalArgumentException iae = new IllegalArgumentException("invalid version \"" + version + "\": invalid format");//$NON-NLS-1$ //$NON-NLS-2$
+ iae.initCause(e);
+ throw iae;
+ }
+
+ major = maj;
+ minor = min;
+ micro = mic;
+ qualifier = qual;
+ // validate();
+ }
+
+ private int parseInt(String value, String version) {
+ try {
+ return Integer.parseInt(value);
+ }
+ catch (NumberFormatException e) {
+ IllegalArgumentException iae = new IllegalArgumentException("invalid version \"" + version + "\": non-numeric \"" + value + "\""); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
+ iae.initCause(e);
+ throw iae;
+ }
+ }
}
@SuppressWarnings("unused")

Back to the top