}
/**
+ * Compares two version numbers.
+ * Returns -1, 0, or 1 if v1 is less than, equal to, or greater than v2 respectively
+ * @param v1 The first version
+ * @param v2 The second version
+ * @return -1, 0, or 1 if v1 is less than, equal to, or greater than v2 respectively
+ * @since 4.8
+ */
+ public static int compareVersions(String v1, String v2) {
+ if (v1 == null || v2 == null) throw new NullPointerException();
+
+ String[] v1Parts = v1.split("\\."); //$NON-NLS-1$
+ String[] v2Parts = v2.split("\\."); //$NON-NLS-1$
+ for (int i = 0; i < v1Parts.length && i < v2Parts.length; i++) {
+ try {
+ int v1PartValue = Integer.parseInt(v1Parts[i]);
+ int v2PartValue = Integer.parseInt(v2Parts[i]);
+
+ if (v1PartValue > v2PartValue) {
+ return 1;
+ } else if (v1PartValue < v2PartValue) {
+ return -1;
+ }
+ } catch (NumberFormatException e) {
+ // Non-integer part, ignore it
+ continue;
+ }
+ }
+
+ // If we get here is means the versions are still equal
+ // but there could be extra parts to examine
+
+ if (v1Parts.length < v2Parts.length) {
+ // v2 has extra parts, which implies v1 is a lower version (e.g., v1 = 7.9 v2 = 7.9.1)
+ // unless each extra part is 0, in which case the two versions are equal (e.g., v1 = 7.9 v2 = 7.9.0)
+ for (int i = v1Parts.length; i < v2Parts.length; i++) {
+ try {
+ if (Integer.parseInt(v2Parts[i]) != 0) {
+ return -1;
+ }
+ } catch (NumberFormatException e) {
+ // Non-integer part, ignore it
+ continue;
+ }
+ }
+ }
+ if (v1Parts.length > v2Parts.length) {
+ // v1 has extra parts, which implies v1 is a higher version (e.g., v1 = 7.9.1 v2 = 7.9)
+ // unless each extra part is 0, in which case the two versions are equal (e.g., v1 = 7.9.0 v2 = 7.9)
+ for (int i = v2Parts.length; i < v1Parts.length; i++) {
+ try {
+ if (Integer.parseInt(v1Parts[i]) != 0) {
+ return 1;
+ }
+ } catch (NumberFormatException e) {
+ // Non-integer part, ignore it
+ continue;
+ }
+ }
+ }
+
+ return 0;
+ }
+
+ /**
* Read from the specified stream and return what was read.
*
* @param stream The input stream to be used to read the data. This method will close the stream.
import org.eclipse.cdt.dsf.debug.service.command.ICommandControl;
import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin;
import org.eclipse.cdt.dsf.gdb.launching.GdbLaunch;
+import org.eclipse.cdt.dsf.gdb.launching.LaunchUtils;
import org.eclipse.cdt.dsf.gdb.service.command.CommandFactory_6_8;
import org.eclipse.cdt.dsf.gdb.service.command.GDBControl;
import org.eclipse.cdt.dsf.gdb.service.command.GDBControl_7_0;
* @since 4.8
*/
protected int compareVersionWith(String version) {
- return compareVersions(getVersion(), version);
+ return LaunchUtils.compareVersions(getVersion(), version);
}
- /**
- * Compares two version numbers.
- * Returns -1, 0, or 1 if v1 is less than, equal to, or greater than v2 respectively
- * @param v1 The first version
- * @param v2 The second version
- * @return -1, 0, or 1 if v1 is less than, equal to, or greater than v2 respectively
- */
- private static int compareVersions(String v1, String v2) {
- if (v1 == null || v2 == null) throw new NullPointerException();
-
- String[] v1Parts = v1.split("\\."); //$NON-NLS-1$
- String[] v2Parts = v2.split("\\."); //$NON-NLS-1$
- for (int i = 0; i < v1Parts.length && i < v2Parts.length; i++) {
- try {
- int v1PartValue = Integer.parseInt(v1Parts[i]);
- int v2PartValue = Integer.parseInt(v2Parts[i]);
-
- if (v1PartValue > v2PartValue) {
- return 1;
- } else if (v1PartValue < v2PartValue) {
- return -1;
- }
- } catch (NumberFormatException e) {
- // Non-integer part, ignore it
- continue;
- }
- }
-
- // If we get here is means the versions are still equal
- // but there could be extra parts to examine
-
- if (v1Parts.length < v2Parts.length) {
- // v2 has extra parts, which implies v1 is a lower version (e.g., v1 = 7.9 v2 = 7.9.1)
- // unless each extra part is 0, in which case the two versions are equal (e.g., v1 = 7.9 v2 = 7.9.0)
- for (int i = v1Parts.length; i < v2Parts.length; i++) {
- try {
- if (Integer.parseInt(v2Parts[i]) != 0) {
- return -1;
- }
- } catch (NumberFormatException e) {
- // Non-integer part, ignore it
- continue;
- }
- }
- }
- if (v1Parts.length > v2Parts.length) {
- // v1 has extra parts, which implies v1 is a higher version (e.g., v1 = 7.9.1 v2 = 7.9)
- // unless each extra part is 0, in which case the two versions are equal (e.g., v1 = 7.9.0 v2 = 7.9)
- for (int i = v2Parts.length; i < v1Parts.length; i++) {
- try {
- if (Integer.parseInt(v1Parts[i]) != 0) {
- return 1;
- }
- } catch (NumberFormatException e) {
- // Non-integer part, ignore it
- continue;
- }
- }
- }
-
- return 0;
- }
/**
* A static method that will compare the version of GDB for the specified session and
IDsfDebugServicesFactory servicesFactory = ((GdbLaunch)launch).getServiceFactory();
if (servicesFactory instanceof GdbDebugServicesFactory) {
String version = ((GdbDebugServicesFactory)servicesFactory).getVersion();
- if (compareVersions(minVersion, version) > 0) {
+ if (LaunchUtils.compareVersions(minVersion, version) > 0) {
assert false;
GdbPlugin.log(