Java Code Examples for org.osgi.framework.Version#getQualifier()

The following examples show how to use org.osgi.framework.Version#getQualifier() . 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: BundleManifestTask.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * If we have a bundle version suffix add it to the 
 * <code>Bundle-Version</code> attribute.
 */
private void appendVersionSuffix(Manifest mf)
{
  if (versionSuffix != null && !versionSuffix.equals("")) {
    final Manifest.Attribute bundleVerAttr
      = mf.getMainSection().getAttribute("Bundle-Version");
    if (null!=bundleVerAttr) {
      final Version ver = new Version(bundleVerAttr.getValue());
      String q = ver.getQualifier();
      int major = ver.getMajor();
      int minor = ver.getMinor();
      int micro = ver.getMicro();
      if (q.length() == 0) {
        bundleVerAttr.setValue(new Version(major, minor, micro, versionSuffix).toString());
      } else if (!q.endsWith(versionSuffix)) {
        bundleVerAttr.setValue(new Version(major, minor, micro, q + "-" + versionSuffix).toString());
      }
    }
  }
}
 
Example 2
Source File: BundleLocator.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Get the set of version patterns (partial versions) used in the
 * keys in replacement filters for the given version.
 * @param version The version to create patterns for.
 * @return Set of version patterns.
 */
private static String[] getVersionPatterns(Version version)
{
  if (null==version) {
    return new String[]{"-N.N.N"};
  }

  final String qualifier = version.getQualifier();
  final boolean usesQualifier = null != qualifier && qualifier.length() > 0;
  final String[] res = new String[usesQualifier ? 5 : 4];

  res[0] = "-N.N.N";
  res[1] = "-" +version.getMajor() +".N.N";
  res[2] = "-" +version.getMajor() +"." +version.getMinor() +".N";
  res[3] = "-" +version.getMajor() +"." +version.getMinor()
    +"." +version.getMicro();
  if (usesQualifier) {
    res[4] = "-" +version.getMajor() +"." +version.getMinor()
      +"." +version.getMicro() +"." +version.getQualifier();
  }

  return res;
}
 
Example 3
Source File: BundleArchives.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Format the OSGi version as Maven 2 does in versioned file names.
 */
static private String toMavenVersion(final Version version) {
  final StringBuffer sb = new StringBuffer(40);

  sb.append(String.valueOf(version.getMajor())).append(".");
  sb.append(String.valueOf(version.getMinor())).append(".");
  sb.append(String.valueOf(version.getMicro()));

  final String qualifier = version.getQualifier();
  if (0 < qualifier.length()) {
    sb.append("-").append(qualifier);
  }

  return sb.toString();
}
 
Example 4
Source File: TestAssertions.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Assert if the two OSGI version are equal.
 *
 * @param expected the expected value.
 * @param actual the actual value.
 */
public static void assertOsgiVersionEquals(Version expected, Version actual) {
	if (Objects.equal(expected, actual)) {
		return;
	}
	if (expected == null) {
		fail("Version not null");
	}
	if (actual == null) {
		fail("Unexpected null value");
	}
	if (expected.getMajor() == actual.getMajor()
			&& expected.getMinor() == actual.getMinor()
			&& expected.getMicro() == actual.getMicro()) {
		if (!Strings.isNullOrEmpty(expected.getQualifier())) {
			final String expectedQualifier = expected.getQualifier();
			if ("qualifier".equals(expectedQualifier)) {
				if (!Strings.isNullOrEmpty(actual.getQualifier())) {
					return;
				}
			}
			if (Objects.equal(expected, actual.getQualifier())) {
				return;
			}
		} else {
			return;
		}
	}
	throw new AssertionFailedError("Not same versions", expected.toString(), actual.toString());
}