List of usage examples for org.eclipse.jdt.core JavaCore compareJavaVersions
public static int compareJavaVersions(String first, String second)
From source file:org.eclipse.ant.internal.launching.launchConfigurations.AntLaunchDelegate.java
License:Open Source License
@Override public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException { String path = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, new String("")); //$NON-NLS-1$ if (!path.isEmpty()) { IPath jrePath = Path.fromPortableString(path); IVMInstall vm = JavaRuntime.getVMInstall(jrePath); if (vm instanceof AbstractVMInstall) { AbstractVMInstall install = (AbstractVMInstall) vm; String vmver = install.getJavaVersion(); // versionToJdkLevel only handles 3 char versions = 1.5, 1.6, 1.9, etc if (vmver.length() > 3) { vmver = vmver.substring(0, 3); }/*from w w w .j a v a 2s . c o m*/ // int ver = (int) (CompilerOptions.versionToJdkLevel(vmver) >>> 16); if (JavaCore.compareJavaVersions(vmver, JavaCore.VERSION_1_7) < 0) { boolean useDefault = configuration .getAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, true); if (useDefault) { // Java 1.7 and above is required if Default Ant Home is used IStatus status = new Status(IStatus.ERROR, AntLaunching.PLUGIN_ID, 1, AntLaunchConfigurationMessages.AntLaunchDelegate_Launching__0__2, null); throw new CoreException(status); } } } } if (monitor.isCanceled()) { return; } fUserSpecifiedLogger = false; fMode = mode; launchManager = DebugPlugin.getDefault().getLaunchManager(); // migrate the config to the new classpath format if required AntLaunchingUtil.migrateToNewClasspathFormat(configuration); boolean isSeparateJRE = AntLaunchingUtil.isSeparateJREAntBuild(configuration); if (AntLaunchingUtil.isLaunchInBackground(configuration)) { monitor.beginTask(MessageFormat.format(AntLaunchConfigurationMessages.AntLaunchDelegate_Launching__0__1, new Object[] { configuration.getName() }), 10); } else { monitor.beginTask(MessageFormat.format(AntLaunchConfigurationMessages.AntLaunchDelegate_Running__0__2, new Object[] { configuration.getName() }), 100); } // resolve location IPath location = ExternalToolsCoreUtil.getLocation(configuration); monitor.worked(1); if (monitor.isCanceled()) { return; } if (!isSeparateJRE && AntRunner.isBuildRunning()) { IStatus status = new Status(IStatus.ERROR, AntLaunching.PLUGIN_ID, 1, MessageFormat.format(AntLaunchConfigurationMessages.AntLaunchDelegate_Build_In_Progress, new Object[] { location.toOSString() }), null); throw new CoreException(status); } // resolve working directory IPath workingDirectory = ExternalToolsCoreUtil.getWorkingDirectory(configuration); String basedir = null; if (workingDirectory != null) { basedir = workingDirectory.toOSString(); } monitor.worked(1); if (monitor.isCanceled()) { return; } // link the process to its build logger via a timestamp long timeStamp = System.currentTimeMillis(); String idStamp = Long.toString(timeStamp); StringBuffer idProperty = new StringBuffer("-D"); //$NON-NLS-1$ idProperty.append(AbstractEclipseBuildLogger.ANT_PROCESS_ID); idProperty.append('='); idProperty.append(idStamp); // resolve arguments String[] arguments = ExternalToolsCoreUtil.getArguments(configuration); Map<String, String> userProperties = AntLaunchingUtil.getProperties(configuration); if (userProperties != null) {// create a copy so as to not affect the // configuration with transient // properties userProperties = new HashMap<>(userProperties); } String[] propertyFiles = AntLaunchingUtil.getPropertyFiles(configuration); String[] targets = AntLaunchingUtil.getTargetNames(configuration); URL[] customClasspath = AntLaunchingUtil.getCustomClasspath(configuration); String antHome = AntLaunchingUtil.getAntHome(configuration); boolean setInputHandler = true; try { // check if set specify inputhandler setInputHandler = configuration.getAttribute(AntLaunching.SET_INPUTHANDLER, true); } catch (CoreException ce) { AntLaunching.log(ce); } AntRunner runner = null; if (!isSeparateJRE) { runner = configureAntRunner(configuration, location, basedir, idProperty, arguments, userProperties, propertyFiles, targets, customClasspath, antHome, setInputHandler); } monitor.worked(1); if (monitor.isCanceled()) { return; } boolean captureOutput = ExternalToolsCoreUtil.getCaptureOutput(configuration); int port = -1; int requestPort = -1; if (isSeparateJRE && captureOutput) { if (userProperties == null) { userProperties = new HashMap<>(); } port = SocketUtil.findFreePort(); userProperties.put(AbstractEclipseBuildLogger.ANT_PROCESS_ID, idStamp); userProperties.put("eclipse.connect.port", Integer.toString(port)); //$NON-NLS-1$ if (fMode.equals(ILaunchManager.DEBUG_MODE)) { requestPort = SocketUtil.findFreePort(); userProperties.put("eclipse.connect.request_port", Integer.toString(requestPort)); //$NON-NLS-1$ } } StringBuffer commandLine = generateCommandLine(location, arguments, userProperties, propertyFiles, targets, antHome, basedir, isSeparateJRE, captureOutput, setInputHandler); if (isSeparateJRE) { monitor.beginTask(MessageFormat.format(AntLaunchConfigurationMessages.AntLaunchDelegate_Launching__0__1, new Object[] { configuration.getName() }), 10); runInSeparateVM(configuration, launch, monitor, idStamp, antHome, port, requestPort, commandLine, captureOutput, setInputHandler); } else { runInSameVM(configuration, launch, monitor, location, idStamp, runner, commandLine); } monitor.done(); }
From source file:org.eclipse.ant.tests.ui.APITests.java
License:Open Source License
public void testCompareJavaVersions() throws CoreException { String vmver = "1.6"; //$NON-NLS-1$ int comparison = JavaCore.compareJavaVersions(vmver, JavaCore.VERSION_1_7); assertEquals("VM less than 1.7 version: ", -1, comparison); //$NON-NLS-1$ vmver = "1.7"; //$NON-NLS-1$ comparison = JavaCore.compareJavaVersions(vmver, JavaCore.VERSION_1_7); assertEquals("VM equal to 1.7: ", 0, comparison); //$NON-NLS-1$ vmver = "1.8"; //$NON-NLS-1$ comparison = JavaCore.compareJavaVersions(vmver, JavaCore.VERSION_1_7); assertEquals("VM more than 1.7: ", 1, comparison); //$NON-NLS-1$ }