org.osgi.framework.Version Java Examples

The following examples show how to use org.osgi.framework.Version. 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: InitializeLaunchConfigurations.java    From wildwebdeveloper with Eclipse Public License 2.0 6 votes vote down vote up
private static void validateNodeVersion(String nodeJsLocation) {

		String nodeVersion = null;
		String[] nodeVersionCommand = new String[] { nodeJsLocation, "-v" };

		try (BufferedReader reader = new BufferedReader(
				new InputStreamReader(Runtime.getRuntime().exec(nodeVersionCommand).getInputStream()));) {
			nodeVersion = reader.readLine();
		} catch (IOException e) {
			Activator.getDefault().getLog().log(
					new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), e.getMessage(), e));
		}

		if (nodeVersion == null) {
			warnNodeJSVersionCouldNotBeDetermined();
		} else {
			Version parsedVersion = Version
					.parseVersion(nodeVersion.startsWith("v") ? nodeVersion.replace("v", "") : nodeVersion);
			if (!SUPPORT_NODEJS_MAJOR_VERSIONS.contains(parsedVersion.getMajor())) {
				warnNodeJSVersionUnsupported(nodeVersion);
			}
		}
	}
 
Example #2
Source File: VersionStringValidator.java    From packagedrone with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public boolean isValid ( final String value, final ConstraintValidatorContext context )
{
    if ( value == null )
    {
        return true;
    }
    if ( value.isEmpty () )
    {
        return true;
    }

    try
    {
        Version.parseVersion ( value );
        return true;
    }
    catch ( final Exception e )
    {
        return false;
    }
}
 
Example #3
Source File: OsgiClassPrefixerTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetPrefixWithBundle() throws Exception {
    final Class<?> classInBundle = String.class;
    
    final Bundle bundle = Mockito.mock(Bundle.class);
    Mockito.when(bundle.getSymbolicName()).thenReturn("my.symbolic.name");
    Mockito.when(bundle.getVersion()).thenReturn(Version.valueOf("1.2.3"));
    
    Function<Class<?>, Optional<Bundle>> bundleRetriever = new Function<Class<?>, Optional<Bundle>>() {
        @Override public Optional<Bundle> apply(Class<?> input) {
            return (classInBundle.equals(input)) ? Optional.of(bundle) : Optional.<Bundle>absent();
        }
    };
    OsgiClassPrefixer prefixer = new OsgiClassPrefixer(bundleRetriever);
    assertAbsent(prefixer.getPrefix(Number.class));
    assertPresent(prefixer.getPrefix(String.class), "my.symbolic.name:");
}
 
Example #4
Source File: RepositoryCommandGroup.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private boolean isInstalled(Resource r) {
  Map<String, Object> identity = r.getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE).iterator().next().getAttributes();
  String name = (String) identity.get(IdentityNamespace.IDENTITY_NAMESPACE);
  Version version = (Version) identity.get(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE);
  Map<String, Object> content = r.getCapabilities(ContentNamespace.CONTENT_NAMESPACE).iterator().next().getAttributes();
  Bundle lb = bc.getBundle((String)content.get(ContentNamespace.CAPABILITY_URL_ATTRIBUTE));
  if (lb != null && name.equals(lb.getSymbolicName()) && version.equals(lb.getVersion())) {
    return true;
  }
  for (Bundle b : bc.getBundles()) {
    if (name.equals(b.getSymbolicName()) && version.equals(b.getVersion())) {
      return true;
    }
  }
  return false;
}
 
Example #5
Source File: SARLRuntime.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Replies if the given JAR file contains a SRE.
 *
 * <p>The SRE detection is based on the content of the manifest.
 *
 * @param jarFile the JAR file to test.
 * @return <code>true</code> if the given directory contains a SRE. Otherwise <code>false</code>.
 * @see #isUnpackedSRE(File)
 */
public static boolean isPackedSRE(File jarFile) {
	try (JarFile jFile = new JarFile(jarFile)) {
		final Manifest manifest = jFile.getManifest();
		if (manifest == null) {
			return false;
		}
		final Attributes sarlSection = manifest.getAttributes(SREManifestPreferenceConstants.MANIFEST_SECTION_SRE);
		if (sarlSection == null) {
			return false;
		}
		final String sarlVersion = sarlSection.getValue(SREManifestPreferenceConstants.MANIFEST_SARL_SPEC_VERSION);
		if (sarlVersion == null || sarlVersion.isEmpty()) {
			return false;
		}
		final Version sarlVer = Version.parseVersion(sarlVersion);
		return sarlVer != null;
	} catch (IOException exception) {
		return false;
	}
}
 
Example #6
Source File: Pkg.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Version compare two ImportPkg objects. If same version, order according
 * to bundle id, lowest first.
 *
 * @param a
 *          ImportPkg to compare.
 * @param b
 *          ImportPkg to compare.
 * @return Return 0 if equals, negative if first object is less than second
 *         object and positive if first object is larger then second object.
 * @exception ClassCastException
 *              if object is not a ImportPkg object.
 */
public int compare(ImportPkg a, ImportPkg b)
{
  int d;
  if (a.packageRange == null) {
    d = b.packageRange == null ? 0 : Version.emptyVersion.compareTo(b.packageRange.getLeft());
  } else if (b.packageRange == null) {
    d = a.packageRange.getLeft().compareTo(Version.emptyVersion);        
  } else {
    d = a.packageRange.getLeft().compareTo(b.packageRange.getLeft());
  }
  if (d == 0) {
    final long ld = b.bpkgs.bg.bundle.id - a.bpkgs.bg.bundle.id;
    if (ld < 0)
      d = -1;
    else if (ld > 0)
      d = 1;
  }
  return d;
}
 
Example #7
Source File: ImportPkg.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Create an import package entry.
 */
ImportPkg(ExportPkg p) {
  this.name = p.name;
  this.bpkgs = p.bpkgs;
  this.resolution = Constants.RESOLUTION_MANDATORY;
  this.bundleSymbolicName = null;
  if (p.version == Version.emptyVersion) {
    this.packageRange = null;
  } else {
    this.packageRange = new VersionRange(p.version.toString());
  }
  this.bundleRange = null;
  this.attributes = p.attributes;
  // TODO, should we import unknown directives?
  final Map<String,String> dirs = new HashMap<String, String>();
  final Filter filter = toFilter();
  if (null!=filter) {
    dirs.put(Constants.FILTER_DIRECTIVE, filter.toString());
  }
  this.directives = Collections.unmodifiableMap(dirs);
  this.parent = null;
}
 
Example #8
Source File: ShouldExtensions.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** 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 #9
Source File: NsToHtmlHost.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public String toHTML(Capability capability)
{
  // Make a modifiable clone of the attributes.
  final Map<String, Object> attrs =
    new HashMap<String, Object>(capability.getAttributes());

  final StringBuffer sb = new StringBuffer(50);
  sb.append(attrs.remove(BundleRevision.HOST_NAMESPACE));

  final Version version =
    (Version) attrs.remove(Constants.BUNDLE_VERSION_ATTRIBUTE);
  if (version != null) {
    sb.append("&nbsp;");
    sb.append(version);
  }

  if (!attrs.isEmpty()) {
    sb.append("&nbsp;");
    sb.append(attrs);
  }

  return sb.toString();
}
 
Example #10
Source File: BundleInfoTask.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Return the value of the Export-Package based on the analysis.
 *
 * @param exportPackages The sub-set of provided packages to be exported.
 */
protected String buildExportPackagesValue(final Set<String> exportPackages) {
  final String sep = ",";
  final String versionPrefix = ";version=";

  final StringBuffer sb = new StringBuffer();

  for(final String pkgName : exportPackages) {
    if (sb.length() > 0) {
      sb.append(sep);
    }

    sb.append(pkgName);

    final Version pkgVersion = bpInfo.getProvidedPackageVersion(pkgName);
    if (null!=pkgVersion) {
      sb.append(versionPrefix).append(pkgVersion);
    }

    appendUsesDirective(sb, pkgName);
  }
  return sb.toString();
}
 
Example #11
Source File: MiscClassesRebindTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public void testVersionedName() throws Exception {
    VersionedName vn = getTestKeyFromEntityMemento("2017-06-versionedname", "n7p20t5h4o", VersionedName.class);
    Assert.assertEquals(vn, new VersionedName("foo", "1.0.0-foo"));
    Assert.assertNotEquals(vn, new VersionedName("foo", "1.0.0.foo"));
    Assert.assertTrue(vn.equalsOsgi(new VersionedName("foo", Version.parseVersion("1.0.0.foo"))));
    
    String newEntityContent = getEntityMementoContent();
    // log.info("New VN persistence is\n"+newEntityContent);
    Asserts.assertStringContains(newEntityContent, "1.0.0-foo");
    // phrases from original persisted state are changed
    Asserts.assertStringDoesNotContain(newEntityContent, "<symbolicName>foo");
    Asserts.assertStringDoesNotContain(newEntityContent, "<version>1.0.0");
    Asserts.assertStringDoesNotContain(newEntityContent, "1.0.0.foo");
    // they should now be this
    Asserts.assertStringContains(newEntityContent, "<name>foo");
    Asserts.assertStringContains(newEntityContent, "<v>1.0.0-foo");
}
 
Example #12
Source File: BundleUtilTest.java    From sarl with Apache License 2.0 5 votes vote down vote up
@Test
public void resolveBundleDependenciesBundleBundleURLMappingsStringArray_noRootDependencies() {
	Bundle bundle = Platform.getBundle("io.sarl.lang.core");
	Assume.assumeNotNull(bundle);
	//
	IBundleDependencies dependencies = BundleUtil.resolveBundleDependencies(bundle, (BundleURLMappings) null);
	assertNotNull(dependencies);
	assertEquals("io.sarl.lang.core", dependencies.getBundleSymbolicName());
	assertOsgiVersionEquals(Version.parseVersion(SARLVersion.SARL_RELEASE_VERSION_OSGI), dependencies.getBundleVersion());
	assertPartlyContains(dependencies.getDirectSymbolicNames(),
			"io.sarl.lang.core",
			"javax.inject",
			"org.eclipse.xtext.xbase.lib");
	assertPartlyContains(dependencies.getTransitiveSymbolicNames(false),
			"io.sarl.lang.core",
			"javax.inject",
			"org.eclipse.xtext.xbase.lib",
			"com.google.guava",
			"org.eclipse.osgi");
	if (isEclipseRuntimeEnvironment()) {
		assertPartlyContains(dependencies.getTransitiveSymbolicNames(true),
				"io.sarl.lang.core",
				"org.eclipse.xtext.xbase.lib",
				"javax.inject",
				"com.google.guava",
				"org.eclipse.osgi",
				"org.eclipse.osgi.compatibility.state"
				);
	} else {
		assertPartlyContains(dependencies.getTransitiveSymbolicNames(true),
				"io.sarl.lang.core",
				"javax.inject",
				"org.eclipse.xtext.xbase.lib",
				"com.google.guava",
				"org.eclipse.osgi");
	}
}
 
Example #13
Source File: ServletUserHandler.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
public boolean handleRequest(HttpServletRequest request, HttpServletResponse response, String userPathInfo) throws ServletException {
	String versionString = request.getHeader(ProtocolConstants.HEADER_ORION_VERSION);
	Version version = versionString == null ? null : new Version(versionString);
	ServletResourceHandler<String> handler;
	if (version != null && VERSION1.isIncluded(version))
		handler = userHandlerV1;
	else
		handler = genericUserHandler;
	return handler.handleRequest(request, response, userPathInfo);
}
 
Example #14
Source File: BundleLocator.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Get the bundle archive with the highest version within the given
 * interval for the given bundle.
 *
 * @param name Name of the bundle to look for. Either the part of
 *             the file name that comes before the file version or
 *             the bundle symbolic name.
 * @param min  The lowest acceptable version number (inclusive).
 * @param max  The highest acceptable version number (exclusive). If
 *             null the highest version of this bundle will be
 *             selected.
 * @return <code>null</code> if no matching bundle archive was found.
 *
 */
private BundleArchives.BundleArchive getBundleArchive(final String name,
                                                      Version min,
                                                      final Version max)
{
  SortedSet<BundleArchive> baSet = bas.bnToBundleArchives.get(name);
  if (null==baSet) {
    baSet = bas.bsnToBundleArchives.get(BundleArchives.encodeBundleName(name));
  }
  BundleArchives.BundleArchive ba = null;

  if (null!=baSet) {
    if (null==max) { // Select highest available version
      ba = baSet.last();
    } else {
      if (null==min) {
        min = Version.emptyVersion;
      }
      for (final Object element : baSet) {
        final BundleArchives.BundleArchive candBa
          = (BundleArchives.BundleArchive) element;
        if (candBa.version.compareTo(min)<0) {
          continue;
        }
        if (candBa.version.compareTo(max)>=0) {
          break;
        }
        ba = candBa;
      }
    }
  }

  log("getBundleArchive("+name +", " +min +", " +max +")->"+ba,
      Project.MSG_VERBOSE);
  return ba;
}
 
Example #15
Source File: InstallableUnit.java    From packagedrone with Eclipse Public License 1.0 5 votes vote down vote up
private static String makeVersion ( final Version version )
{
    if ( version == null )
    {
        return "0.0.0";
    }
    return version.toString ();
}
 
Example #16
Source File: Processor.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
private static String readQualifier ( final Path jarFile ) throws IOException
{
    final String version = readManifest ( jarFile ).getMainAttributes ().getValue ( Constants.BUNDLE_VERSION );
    if ( version == null )
    {
        return version;
    }

    return Version.parseVersion ( version ).getQualifier ();
}
 
Example #17
Source File: WiringHTMLDisplayer.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
String getCapName(final BundleCapability capability)
{
  // Make a modifiable clone of the attributes.
  final Map<String, Object> attrs =
    new HashMap<String, Object>(capability.getAttributes());

  final StringBuffer sb = new StringBuffer(50);
  sb.append(attrs.remove(BundleRevision.BUNDLE_NAMESPACE));

  final Version version =
    (Version) attrs.remove(Constants.BUNDLE_VERSION_ATTRIBUTE);
  if (version != null) {
    sb.append("&nbsp;");
    sb.append(version);
  }

  if (!attrs.isEmpty()) {
    sb.append("&nbsp;");
    sb.append(attrs);
  }

  final BundleWiring capWiring = capability.getRevision().getWiring();
  appendPendingRemovalOnRefresh(sb, capWiring);

  return sb.toString();
}
 
Example #18
Source File: Processor.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
private static String readQualifier ( final Path jarFile ) throws IOException
{
    final String version = readManifest ( jarFile ).getMainAttributes ().getValue ( Constants.BUNDLE_VERSION );
    if ( version == null )
    {
        return version;
    }

    return Version.parseVersion ( version ).getQualifier ();
}
 
Example #19
Source File: PipPackageManager.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
private static String getPipModuleName(IInterpreterInfo interpreterInfo) {
    String version = interpreterInfo.getVersion();
    Version version2 = new Version(version);
    if (version2.getMajor() <= 2 && version2.getMinor() <= 6) {
        return "pip.__main__";
    }
    return "pip";
}
 
Example #20
Source File: SREsPreferencePage.java    From sarl with Apache License 2.0 5 votes vote down vote up
private boolean verifyValidity(ISREInstall sre, boolean errorMessages) {
	if (!sre.getValidity().isOK()) {
		if (errorMessages) {
			setErrorMessage(MessageFormat.format(
					io.sarl.eclipse.launching.dialog.Messages.RuntimeEnvironmentTab_5,
					sre.getName()));
		}
		return false;
	}
	// Check the SARL version.
	final Bundle bundle = Platform.getBundle("io.sarl.lang"); //$NON-NLS-1$
	if (bundle != null) {
		final Version sarlVersion = bundle.getVersion();
		final Version minVersion = Utilities.parseVersion(sre.getMinimalSARLVersion());
		final Version maxVersion = Utilities.parseVersion(sre.getMaximalSARLVersion());
		final int cmp = Utilities.compareVersionToRange(sarlVersion, minVersion, maxVersion);
		if (cmp < 0) {
			if (errorMessages) {
				setErrorMessage(MessageFormat.format(
						io.sarl.eclipse.runtime.Messages.AbstractSREInstall_0,
						sarlVersion.toString(),
						minVersion.toString()));
			}
			return false;
		} else if (cmp > 0) {
			if (errorMessages) {
				setErrorMessage(MessageFormat.format(
						io.sarl.eclipse.runtime.Messages.AbstractSREInstall_1,
						sarlVersion.toString(),
						maxVersion.toString()));
			}
			return false;
		}
	}
	return true;
}
 
Example #21
Source File: UtilitiesTest.java    From sarl with Apache License 2.0 5 votes vote down vote up
@Test
public void compareVersionToRange_3_1_2() {
	Version v1 = new Version(1, 0, 0);
	Version v2 = new Version(2, 0, 0);
	Version v3 = new Version(0, 10, 0);
	assertStrictlyNegative(Utilities.compareVersionToRange(v3, v1, v2));
}
 
Example #22
Source File: ParallelBuildEnabledTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testIsParallelBuildEnabledInWorkspace() {
	// preference and constant ResourcesPlugin#PREF_MAX_CONCURRENT_BUILDS only available on o.e.core.resources >= 3.13 
	if (Platform.getBundle(ResourcesPlugin.PI_RESOURCES).getVersion().compareTo(new Version(3,13,0)) < 0) {
		return; // running on too old platform
	}
	int maxConcurrentProjectBuilds = new ScopedPreferenceStore(InstanceScope.INSTANCE, ResourcesPlugin.PI_RESOURCES).getInt("maxConcurrentBuilds");
	assertEquals("parallel build was not enabled", 8, maxConcurrentProjectBuilds);
}
 
Example #23
Source File: UtilitiesTest.java    From sarl with Apache License 2.0 5 votes vote down vote up
@Test(expected = AssertionError.class)
public void compareVersionToRange_2_1_3() {
	Version v1 = new Version(1, 0, 0);
	Version v2 = new Version(2, 0, 0);
	Version v3 = new Version(0, 10, 0);
	Utilities.compareVersionToRange(v2, v1, v3);
}
 
Example #24
Source File: JdtBasedTypeFactory.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private static JdtCompliance getComplianceLevel() {
	if (isJdtGreaterOrEqual(new Version(3,7,0))) {
		if (isJdtGreaterOrEqual(new Version(3,10,0))) {
			return JdtCompliance.LunaOrBetter;
		}
		return JdtCompliance.Other;
	}
	return JdtCompliance.Galileo;
}
 
Example #25
Source File: BundleTestUtil.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
public static Bundle newMockBundle(VersionedName name, Map<String, String> rawHeaders) {
    Dictionary<String, String> headers = new Hashtable<>(rawHeaders);
    Bundle result;
    try {
        result = Mockito.mock(Bundle.class);
    } catch (Exception e) {
        throw new IllegalStateException("Java too old.  There is a bug in really early java 1.8.0 "
                + "that causes mocks to fail, and has probably caused this.", e);
    }
    Mockito.when(result.getHeaders()).thenReturn(headers);
    Mockito.when(result.getSymbolicName()).thenReturn(name.getSymbolicName());
    Mockito.when(result.getVersion()).thenReturn(Version.valueOf(name.getOsgiVersionString()));
    return result;
}
 
Example #26
Source File: ParserHelper.java    From packagedrone with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void write ( final JsonWriter writer, final Version value ) throws IOException
{
    if ( value == null )
    {
        writer.nullValue ();
    }
    else
    {
        writer.value ( value.toString () );
    }
}
 
Example #27
Source File: BundleUtilTest.java    From sarl with Apache License 2.0 5 votes vote down vote up
@Test
public void resolveBundleDependenciesBundleBundleURLMappingsStringArray_rootDependencies() {
	Bundle bundle = Platform.getBundle("io.sarl.lang.core");
	Assume.assumeNotNull(bundle);
	//
	IBundleDependencies dependencies = BundleUtil.resolveBundleDependencies(bundle, (BundleURLMappings) null,
			"org.eclipse.xtext.xbase.lib");
	assertNotNull(dependencies);
	assertEquals("io.sarl.lang.core", dependencies.getBundleSymbolicName());
	assertOsgiVersionEquals(Version.parseVersion(SARLVersion.SARL_RELEASE_VERSION_OSGI), dependencies.getBundleVersion());
	assertPartlyContains(dependencies.getDirectSymbolicNames(),
			"io.sarl.lang.core",
			"org.eclipse.xtext.xbase.lib");
	assertPartlyContains(dependencies.getTransitiveSymbolicNames(false),
			"io.sarl.lang.core",
			"org.eclipse.xtext.xbase.lib",
			"com.google.guava",
			"org.eclipse.osgi");
	if (isEclipseRuntimeEnvironment()) {
		assertPartlyContains(dependencies.getTransitiveSymbolicNames(true),
				"io.sarl.lang.core",
				"org.eclipse.xtext.xbase.lib",
				"com.google.guava",
				"org.eclipse.osgi",
				"org.eclipse.osgi.compatibility.state"
				);
	} else {
		assertPartlyContains(dependencies.getTransitiveSymbolicNames(true),
				"io.sarl.lang.core",
				"org.eclipse.xtext.xbase.lib",
				"com.google.guava",
				"org.eclipse.osgi");
	}
}
 
Example #28
Source File: Concierge.java    From concierge with Eclipse Public License 1.0 5 votes vote down vote up
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 #29
Source File: Utils.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** 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 #30
Source File: FeatureInformation.java    From packagedrone with Eclipse Public License 1.0 4 votes vote down vote up
public Version getVersion ()
{
    return this.version;
}