Java Code Examples for org.osgi.framework.Version#compareTo()
The following examples show how to use
org.osgi.framework.Version#compareTo() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PyEdit.java From Pydev with Eclipse Public License 1.0 | 6 votes |
private void checkEclipseRunning() { if (checkedEclipseVersion) { return; } checkedEclipseVersion = true; try { String string = Platform.getBundle("org.eclipse.jface.text").getHeaders().get("Bundle-Version"); Version version = new Version(string); if (version.compareTo(new Version("3.11.0")) < 0) { Log.log("Error: This version of PyDev requires a newer version of Eclipse to run properly."); RunInUiThread.async(new Runnable() { @Override public void run() { PyDialogHelpers.openCritical("Eclipse version too old (4.6 -- Neon -- required).", "This version of PyDev requires a newer version of Eclipse to run properly.\n\n" + "Please upgrade Eclipse or use an older version of PyDev.\n\n" + "See: http://www.pydev.org/download.html for requirements\n" + "(for this version or older versions)."); } }, false); } } catch (Exception e) { Log.log(e); } }
Example 2
Source File: IOSSimulatorLaunchDelegate.java From thym with Eclipse Public License 1.0 | 6 votes |
@Override public boolean preLaunchCheck(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor) throws CoreException { XCodeBuild xcode = new XCodeBuild(); String version = xcode.version(); try{ Version v = Version.parseVersion(version); if(v.compareTo(MIN_VERSION) < 0){ throw new CoreException(new HybridMobileStatus(IStatus.ERROR, IOSCore.PLUGIN_ID, 300/*see org.eclipse.thym.ios.ui.xcodeVersionStatusHandler in plugin.xml*/, NLS.bind("Hybrid mobile projects require XCode version {0} or greater to build iOS applications",XCodeBuild.MIN_REQUIRED_VERSION ), null)); } }catch (IllegalArgumentException e) { //We could not parse the version //still let the build continue HybridCore.log(IStatus.WARNING, "Error parsing the xcode version. Version String is "+ version, e); return true; } monitor.done(); return true; }
Example 3
Source File: ShouldExtensions.java From sarl with Apache License 2.0 | 6 votes |
/** Ensure that the version of the current Java specification is in * the range given by the minVersion (inclusive) and maxVersion (exclusive). * If the maxVersion is not given or is not a properly formated version * number, then all versions after the minVersion are valid. * * @param minVersion the minimal version. * @param maxVersion the maximal version. * @return the validation status. */ public static boolean shouldBeJavaRange(String minVersion, String maxVersion) { final Version jreV = parseJavaVersion(System.getProperty("java.version"), null); //$NON-NLS-1$ if (jreV != null && minVersion != null) { final Version minV = parseJavaVersion(minVersion, null); if (minV != null) { Version maxV = null; if (maxVersion != null) { maxV = parseJavaVersion(maxVersion, null); } if (maxV == null) { return jreV.compareTo(minV) >= 0; } return jreV.compareTo(minV) >= 0 && jreV.compareTo(maxV) < 0; } } return false; }
Example 4
Source File: NativeRequirement.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
NativeCodeEntry(List<String> files, List<String> procs, List<String> oses, List<String> vers, List<String> langs, String sf) throws InvalidSyntaxException { this.files = files; matchLang = langs != null; if (vers != null) { Version mv = null; List<VersionRange> vrs = new ArrayList<VersionRange>(vers.size()); for (String s : vers) { VersionRange vr = new VersionRange(s); if (mv == null || mv.compareTo(vr.getLeft()) > 0) { mv = vr.getLeft(); } vrs.add(vr); } minVersion = mv; filter = toFilter(procs, oses, vrs, langs, sf); } else { minVersion = null; filter = toFilter(procs, oses, null, langs, sf); } }
Example 5
Source File: ProductVersion.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
public static boolean canBeImported(final String version) { if (version == null) { return true; } final Version initialVersion = new Version("6.0.0"); Version current = new Version("0.0.0"); try { current = Version.parseVersion(version); } catch (final IllegalArgumentException e) { return false; } final Version productVersion = new Version(CURRENT_VERSION); return current.compareTo(productVersion) <= 0 && current.compareTo(initialVersion) >= 0; }
Example 6
Source File: ProductVersion.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
public static boolean canBeMigrated(final String version) { if (version == null) { return false; } Version current = new Version("0.0.0"); try { current = Version.parseVersion(version); } catch (final IllegalArgumentException e) { } final Version productVersion = new Version(CURRENT_VERSION); return current.compareTo(productVersion) < 0; }
Example 7
Source File: RequirementsUtility.java From thym with Eclipse Public License 1.0 | 5 votes |
/** * Checks if the Cordova requirements are available. * Returns one of the error codes from {@link CordovaCLIErrors}. * * @param project * @return error code or 0 */ private static int doCheckCordovaRequirements() { try { CordovaCLI cli = new CordovaCLI(); ErrorDetectingCLIResult cordovaResult = cli.version(new NullProgressMonitor()) .convertTo(ErrorDetectingCLIResult.class); IStatus cordovaStatus = cordovaResult.asStatus(); if (cordovaStatus.isOK()) { return 0; } if (cordovaStatus.getCode() == CordovaCLIErrors.ERROR_COMMAND_MISSING) { // check if node.js is missing as well IStatus nodeStatus = cli.nodeVersion(new NullProgressMonitor()) .convertTo(ErrorDetectingCLIResult.class) .asStatus(); if(nodeStatus.getCode() == CordovaCLIErrors.ERROR_COMMAND_MISSING){ return CordovaCLIErrors.ERROR_NODE_COMMAND_MISSING; } return CordovaCLIErrors.ERROR_CORDOVA_COMMAND_MISSING; } Version cVer = Version.parseVersion(cordovaResult.getMessage()); Version mVer = Version.parseVersion(MIN_CORDOVA_VERSION); if(cVer.compareTo(mVer) < 0 ){ return CordovaCLIErrors.ERROR_CORDOVA_VERSION_OLD; } return 0; } catch (CoreException e) { return CordovaCLIErrors.ERROR_GENERAL; } }
Example 8
Source File: IOSLaunchShortcut.java From thym with Eclipse Public License 1.0 | 5 votes |
@Override protected boolean validateBuildToolsReady() throws CoreException { XCodeBuild xcode = new XCodeBuild(); String version = xcode.version(); if ( version == null ){ throw new CoreException(new Status(IStatus.ERROR, IOSUI.PLUGIN_ID, "Can not retrieve xcode version, is xcode properly installed?")); } try{ Version minVersion = new Version(XCodeBuild.MIN_REQUIRED_VERSION); Version v = Version.parseVersion(version); if(v.compareTo(minVersion)<0){ throw new CoreException(new HybridMobileStatus(IStatus.ERROR, IOSCore.PLUGIN_ID, 300/*see org.eclipse.thym.ios.ui.xcodeVersionStatusHandler in plugin.xml*/, NLS.bind("Hybrid mobile projects require XCode version {0} or greater to build iOS applications", XCodeBuild.MIN_REQUIRED_VERSION),null)); } }catch (IllegalArgumentException e) { //ignored } List <XCodeSDK> sdks = xcode.showSdks(); boolean iosSdkAvailable = false; for (XCodeSDK xcodeSDK : sdks) { if(xcodeSDK.isIOS()){ iosSdkAvailable =true; break; } } if(!iosSdkAvailable){ throw new CoreException(new Status(IStatus.ERROR, IOSUI.PLUGIN_ID, "No iOS SDKs are found. Please install an iOS SDK and try again.")); } return true; }
Example 9
Source File: Utils.java From sarl with Apache License 2.0 | 5 votes |
/** Compare the two strings as they are version numbers. * * @param v1 - first version to compare. * @param v2 - second version to compare. * @return Negative integer of <code>v1</code> is lower than <code>v2</code>; * positive integer of <code>v1</code> is greater than <code>v2</code>; * {@code 0} if they are strictly equal. */ public static int compareVersions(String v1, String v2) { // Remove the SNAPSHOT version. //final String fixedv1 = v1.replaceFirst("-SNAPSHOT$", ""); //$NON-NLS-1$ //$NON-NLS-2$ //final String fixedv2 = v2.replaceFirst("-SNAPSHOT$", ""); //$NON-NLS-1$ //$NON-NLS-2$ //final Version vobject1 = Version.parseVersion(fixedv1); //final Version vobject2 = Version.parseVersion(fixedv2); final Version vobject1 = Version.parseVersion(v1); final Version vobject2 = Version.parseVersion(v2); return vobject1.compareTo(vobject2); }
Example 10
Source File: EclipseUtil.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
/** * The 3.10.0 version of the OSGI bundle made a lot of breaking changes to internals (that we unfortunately used). * * @return */ private synchronized static boolean isNewOSGIAPI() { if (fgNewAPI == null) { Bundle b = Platform.getBundle("org.eclipse.osgi"); //$NON-NLS-1$ Version v = b.getVersion(); fgNewAPI = v.compareTo(Version.parseVersion("3.9.100")) >= 0; //$NON-NLS-1$ } return fgNewAPI; }
Example 11
Source File: RepositoryDisplayer.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public int compare(Resource r1, Resource r2) { final String s1 = Util.getResourceName(r1).toLowerCase(); final String s2 = Util.getResourceName(r2).toLowerCase(); int n = 0; try { n = s1.compareTo(s2); if (n == 0) { final Version v1 = Util.getResourceVersion(r1); final Version v2 = Util.getResourceVersion(r2); n = v1.compareTo(v2); if (n == 0) { final String loc1 = Util.getLocation(r1); final String loc2 = Util.getLocation(r2); if (loc1 != null && loc2 != null) { n = loc1.compareTo(loc2); } else if (loc1 == null) { n = -1; } else { n = loc2 == null ? 0 : 1; } } } } catch (final Exception e) { } return n; }
Example 12
Source File: Concierge.java From concierge with Eclipse Public License 1.0 | 5 votes |
@SuppressWarnings({ "unchecked" }) protected <T> T getService(final Class<T> cls, final Version version) { final List<ServiceReference<?>> refs = serviceRegistry .lookup(cls.getName()); for (final ServiceReference<?> ref : refs) { final Version other = (Version) ref .getProperty(Constants.VERSION_ATTRIBUTE); if (other != null && other.compareTo(version) == 0) { return (T) ((ServiceReferenceImpl<?>) ref).service; } } return null; }
Example 13
Source File: Concierge.java From concierge with Eclipse Public License 1.0 | 5 votes |
public int compare(final Capability c1, final Capability c2) { if (!(c1 instanceof BundleCapability && c2 instanceof BundleCapability)) { return 0; } final BundleCapability cap1 = (BundleCapability) c1; final BundleCapability cap2 = (BundleCapability) c2; final int cap1Resolved = cap1.getResource().getWiring() == null ? 0 : 1; final int cap2Resolved = cap2.getResource().getWiring() == null ? 0 : 1; int score = cap2Resolved - cap1Resolved; if (score != 0) { return score; } final Version cap1Version = (Version) cap1.getAttributes() .get(PackageNamespace.CAPABILITY_VERSION_ATTRIBUTE); final Version cap2Version = (Version) cap2.getAttributes() .get(PackageNamespace.CAPABILITY_VERSION_ATTRIBUTE); score = cap2Version.compareTo(cap1Version); if (score != 0) { return score; } final long cap1BundleId = cap1.getRevision().getBundle() .getBundleId(); final long cap2BundleId = cap2.getRevision().getBundle() .getBundleId(); return (int) (cap1BundleId - cap2BundleId); }
Example 14
Source File: Concierge.java From concierge with Eclipse Public License 1.0 | 5 votes |
public int compare(final Capability cap1, final Capability cap2) { final Version cap1Version = (Version) cap1.getAttributes().get( AbstractWiringNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE); final Version cap2Version = (Version) cap2.getAttributes().get( AbstractWiringNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE); return cap2Version.compareTo(cap1Version); }
Example 15
Source File: ServerConnectionManager.java From aem-ide-tooling-4-intellij with Apache License 2.0 | 4 votes |
public boolean checkModule(@NotNull OsgiClient osgiClient, @NotNull final Module module) { boolean ret = true; try { if(module.isPartOfBuild()) { // Check Binding if(checkBinding(module.getParent(), new ProgressHandlerImpl("Check Bindings"))) { UnifiedModule unifiedModule = module.getUnifiedModule(); if(unifiedModule != null) { String moduleName = unifiedModule.getName(); String symbolicName = unifiedModule.getSymbolicName(); String version = unifiedModule.getVersion(); version = checkBundleVersion(version); updateModuleStatus(module, ServerConfiguration.SynchronizationStatus.checking); if(module.isOSGiBundle()) { Version remoteVersion = osgiClient.getBundleVersion(module.getSymbolicName()); //AS TODO: Remove the check for the Felix Maven Bundle Plugin's behavior to remove leading //AS TODO: parts of the Artifact Id if they match the trailing parts of the group id. //AS TODO: It is up to the user now to handle it by reconciling the Symbolic Name with //AS TODO: the Maven Bundle Plugin or the Sling Facet if(remoteVersion == null && !module.isIgnoreSymbolicNameMismatch()) { WaitableRunner<AtomicInteger> runner = new WaitableRunner<AtomicInteger>() { private AtomicInteger response = new AtomicInteger(1); @Override // public boolean isAsynchronous() { // return true; // } public boolean isAsynchronous() { return true; } @Override public AtomicInteger getResponse() { return response; } @Override public void run() { int selection = messageManager.showAlertWithOptions( NotificationType.WARNING, "module.check.possible.symbolic.name.mismatch", module.getSymbolicName() ); getResponse().set(selection); } }; com.headwire.aem.tooling.intellij.util.ExecutionUtil.runAndWait(runner); if(runner.getResponse().get() == 0) { // If ignore is selected then save it on that moduleL module.setIgnoreSymbolicNameMismatch(true); } } Version localVersion = new Version(version); messageManager.sendDebugNotification("debug.check.osgi.module", moduleName, symbolicName, remoteVersion, localVersion); boolean moduleUpToDate = remoteVersion != null && remoteVersion.compareTo(localVersion) >= 0; String bundleState = BundleDataUtil.getData(osgiClient, module.getSymbolicName()).get("state"); messageManager.sendDebugNotification("debug.bundle.module.state", module.getName(), bundleState); if(remoteVersion == null) { // Mark as not deployed yet updateModuleStatus(module, ServerConfiguration.SynchronizationStatus.notDeployed); ret = false; } else if(moduleUpToDate) { // Mark as synchronized updateModuleStatus(module, ServerConfiguration.SynchronizationStatus.upToDate); } else { // Mark as out of date updateModuleStatus(module, ServerConfiguration.SynchronizationStatus.outdated); ret = false; } } else if(module.isSlingPackage()) { long lastModificationTimestamp = getLastModificationTimestamp(module); long moduleModificationTimestamp = module.getLastModificationTimestamp(); if(lastModificationTimestamp > moduleModificationTimestamp) { updateModuleStatus(module, ServerConfiguration.SynchronizationStatus.outdated); ret = false; } else { updateModuleStatus(module, ServerConfiguration.SynchronizationStatus.upToDate); } } else { updateModuleStatus(module, ServerConfiguration.SynchronizationStatus.unsupported); } } else { updateModuleStatus(module, ServerConfiguration.SynchronizationStatus.failed); ret = false; } } else { updateModuleStatus(module, ServerConfiguration.SynchronizationStatus.failed); ret = false; } } else { updateModuleStatus(module, ServerConfiguration.SynchronizationStatus.excluded); } } catch(OsgiClientException e1) { // Mark connection as failed updateModuleStatus(module, ServerConfiguration.SynchronizationStatus.failed); ret = false; } return ret; }
Example 16
Source File: ResolverStressTest.java From concierge with Eclipse Public License 1.0 | 4 votes |
public void run(final BundleContext context) throws BundleException, IOException { final Bundle[] bundles = new Bundle[NUM]; long installationTime = 0; for (int i = 0; i < NUM; i++) { final BundleGenerator gen = new BundleGenerator("bundle" + i, new Version(1, 0, i)); final int dirs = random.nextInt(MAX_IMPORTS_EXPORTS); final Set<String> imports = new HashSet<String>(); final Set<String> exports = new HashSet<String>(); for (int j = 0; j < dirs; j++) { if (random.nextBoolean()) { // IMPORT final int v1Major = MIN_VERSION_MAJOR + random.nextInt(MAX_VERSION_MAJOR - MIN_VERSION_MAJOR + 1); final int v2Major = MIN_VERSION_MAJOR + random.nextInt(MAX_VERSION_MAJOR - MIN_VERSION_MAJOR + 1); final Version v1 = new Version(v1Major, random.nextInt(10), random.nextInt(10)); final Version v2 = new Version(v2Major, random.nextInt(10), random.nextInt(10)); final Version lowerBound = v1.compareTo(v2) < 1 ? v1 : v2; final Version upperBound = v1.compareTo(v2) >= 1 ? v1 : v2; gen.addPackageImport(drawPackage(imports), new VersionRange('[', lowerBound, upperBound, ')')); } else { // EXPORT final Version version = new Version( random.nextInt(MAX_VERSION_MAJOR - MIN_VERSION_MAJOR + 1), random.nextInt(10), random.nextInt(10)); gen.addPackageExport(drawPackage(exports), version); } } final long t = System.nanoTime(); bundles[i] = gen.install(context); installationTime += (System.nanoTime() - t); } System.err.println("INSTALLATION TIME " + (installationTime / 1000000)); final FrameworkWiring fw = context.getBundle(0).adapt( FrameworkWiring.class); System.err.println("RESOLVING"); final long time = System.nanoTime(); fw.resolveBundles(Arrays.asList(bundles)); System.err.println("RESOLVE TIME " + (System.nanoTime() - time) / 1000000); }
Example 17
Source File: ZWaveDbProduct.java From openhab1-addons with Eclipse Public License 2.0 | 4 votes |
public String getConfigFile(String version) { if (ConfigFile == null) { return null; } Version vIn = new Version(version); String filename = null; // Check for a version'ed file // There are multiple permutations of the file that we need to account for -: // * No version information // * Only a min version // * Only a max version // * Both min and max versions // Versions need to be evaluated with the max and min specifiers separately // i.e. the part either side of the decimal. // So, version 1.3 is lower than version 1.11 for (ZWaveDbConfigFile cfg : ConfigFile) { // Find a default - ie one with no version information if (cfg.VersionMin == null && cfg.VersionMax == null && filename == null) { filename = cfg.Filename; continue; } if (cfg.VersionMin != null) { Version vMin = new Version(cfg.VersionMin); if (vIn.compareTo(vMin) < 0) { continue; } } if (cfg.VersionMax != null) { Version vMax = new Version(cfg.VersionMax); if (vIn.compareTo(vMax) > 0) { continue; } } // This version matches the criterea return cfg.Filename; } // Otherwise return the default if there was one! return filename; }
Example 18
Source File: Repository.java From bonita-studio with GNU General Public License v2.0 | 4 votes |
protected void removeLegacyFolders(Version oldVersion, final IProgressMonitor monitor) { if (oldVersion.compareTo(new Version("7.8.0")) < 0) { LEGACY_REPOSITORIES.stream().forEach(folderName -> removeFolder(folderName, monitor)); } }
Example 19
Source File: XdsPluginUpdater.java From xds-ide with Eclipse Public License 1.0 | 4 votes |
private static int comparePluginVersions(File firstPlugin, File secondPlugin) { Version firstVersion = new Version(getVersion(firstPlugin)); Version secondVersion = new Version(getVersion(secondPlugin)); return firstVersion.compareTo(secondVersion); }
Example 20
Source File: N4JSApplication.java From n4js with Eclipse Public License 1.0 | 4 votes |
/** * Return true if the argument directory is ok to use as a workspace and false otherwise. A version check will be * performed, and a confirmation box may be displayed on the argument shell if an older version is detected. * * @return true if the argument URL is ok to use as a workspace and false otherwise. */ private boolean checkValidWorkspace(final Shell shell, final URL url) { // a null url is not a valid workspace if (url == null) { return false; } if (WORKSPACE_CHECK_REFERENCE_BUNDLE_VERSION == null) { // no reference bundle installed, no check possible return true; } final Version version = readWorkspaceVersion(url); // if the version could not be read, then there is not any existing // workspace data to trample, e.g., perhaps its a new directory that // is just starting to be used as a workspace if (version == null) { return true; } final Version ide_version = toMajorMinorVersion(WORKSPACE_CHECK_REFERENCE_BUNDLE_VERSION); final Version workspace_version = toMajorMinorVersion(version); final int versionCompareResult = workspace_version.compareTo(ide_version); // equality test is required since any version difference (newer // or older) may result in data being trampled if (versionCompareResult == 0) { return true; } // At this point workspace has been detected to be from a version // other than the current ide version -- find out if the user wants // to use it anyhow. int severity; String title; String message; if (versionCompareResult < 0) { // Workspace < IDE. Update must be possible without issues, // so only inform user about it. severity = INFORMATION; title = IDEApplication_versionTitle_olderWorkspace; message = NLS.bind(IDEApplication_versionMessage_olderWorkspace, url.getFile()); } else { // Workspace > IDE. It must have been opened with a newer IDE version. // Downgrade might be problematic, so warn user about it. severity = WARNING; title = IDEApplication_versionTitle_newerWorkspace; message = NLS.bind(IDEApplication_versionMessage_newerWorkspace, url.getFile()); } final MessageDialog dialog = new MessageDialog(shell, title, null, message, severity, new String[] { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }, 0); return dialog.open() == Window.OK; }