1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-24 17:35:35 +02:00

Bug 476432 - GDB version comparison fails for GDB 7.10

Move the new comparison method to LaunchUtils.

Change-Id: I97e5ff61ba1173525a5d1060e1b07ba2136eb49e
This commit is contained in:
Marc Khouzam 2015-09-02 14:02:50 -04:00
parent 377202feb1
commit b5bdc32883
2 changed files with 67 additions and 64 deletions

View file

@ -363,6 +363,70 @@ public class LaunchUtils {
}
}
/**
* 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.
*

View file

@ -38,6 +38,7 @@ import org.eclipse.cdt.dsf.debug.service.IStack;
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;
@ -319,71 +320,9 @@ public class GdbDebugServicesFactory extends AbstractDsfDebugServicesFactory {
* @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
@ -402,7 +341,7 @@ public class GdbDebugServicesFactory extends AbstractDsfDebugServicesFactory {
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(