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

The following examples show how to use org.osgi.framework.Version#toString() . 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: 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 2
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());
}
 
Example 3
Source File: DependencyVersionPart.java    From tesb-studio-se with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the version.
 *
 * @return the version
 */
public String getVersion() {
	if (fIsRanged) {
		// if versions are equal they must be inclusive for a range to be
		// valid
		// blindly set for the user
		String minV = getMinVersion();
		String maxV = getMaxVersion();
		boolean minI = getMinInclusive();
		boolean maxI = getMaxInclusive();
		if (minV.equals(maxV))
			minI = maxI = true;
		VersionRange versionRange = new VersionRange(new Version(minV),
				minI, new Version(maxV), maxI);
		if (!versionRange.equals(VersionRange.emptyRange)) {
			return versionRange.toString();
		}
	} else {
		String singleversion = extractSingleVersionFromText();
		if (!singleversion.isEmpty()) {
			Version versionBean = new Version(singleversion);
			if (!versionBean.equals(Version.emptyVersion)) {
				return versionBean.toString();
			}
		}
	}
	return null;
}
 
Example 4
Source File: PackageAdminImpl.java    From concierge with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * @see org.osgi.service.packageadmin.ExportedPackage#getSpecificationVersion()
 */
public String getSpecificationVersion() {
	final Version version = getVersion();
	return version == null ? null : version.toString();
}
 
Example 5
Source File: FeatureInformation.java    From packagedrone with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public VersionRange makeRange ( final Version version )
{
    return new VersionRange ( version.toString () );
}
 
Example 6
Source File: VirtualizerImpl.java    From packagedrone with Eclipse Public License 1.0 4 votes vote down vote up
private void processVirtualize ( final Context context ) throws Exception
{
    // The group ID will be set using the provided channel meta data or the default one.
    String groupId = null;

    // Extract some informations (e.g. group ID) from the provided channel meta data.
    final Map<MetaKey, String> channelMetaData = context.getProvidedChannelMetaData ();
    for ( final Entry<MetaKey, String> entry : channelMetaData.entrySet () )
    {
        final MetaKey metaKey = entry.getKey ();

        if ( metaKey.getNamespace ().equals ( Constants.METADATA_NAMESPACE ) )
        {
            switch ( metaKey.getKey () )
            {
                case Constants.METADATA_KEY_GROUPID:
                    groupId = entry.getValue ();
                    break;
                default:
                    break;
            }
        }
    }

    // If the group ID is not set or empty, use the default one.
    if ( groupId == null || groupId.isEmpty () )
    {
        groupId = Constants.DEFAULT_GROUPID;
    }

    final ArtifactInformation art = context.getArtifactInformation ();

    final BundleInformation bi = OsgiAspectFactory.fetchBundleInformation ( art.getMetaData () );
    if ( bi != null )
    {
        final Version version = bi.getVersion ();
        final Pom pom = new Pom ( groupId, bi.getId (), version.toString () );
        createArtifact ( context, pom );
        return;
    }

    //final FeatureInformation fi = OsgiAspectFactory.fetchFeatureInformation ( art.getMetaData () );
}
 
Example 7
Source File: VersionedName.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
public VersionedName(String name, @Nullable Version v) {
    this.name = checkNotNull(name, "name").toString();
    this.v = v==null ? null : v.toString();
}
 
Example 8
Source File: VersionedName.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
@Nullable
public String getOsgiVersionString() {
    Version ov = getOsgiVersion();
    if (ov==null) return null;
    return ov.toString();
}
 
Example 9
Source File: Osgis.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
/** Finds all matching bundles, in decreasing version order. */
@SuppressWarnings("deprecation")
public List<Bundle> findAll() {
    boolean urlMatched = false;
    List<Bundle> result = MutableList.of();
    String v=null, vDep = null;
    VersionRange vRange = null;
    if (version!=null) {
        if (isVersionRange(version)) {
            vRange = VersionRange.valueOf(version);
        } else {
            v = BrooklynVersionSyntax.toValidOsgiVersion(version);
            vDep = OsgiUtils.toOsgiVersion(version);
        }
    }
    for (Bundle b: framework.getBundleContext().getBundles()) {
        if (symbolicName!=null && !symbolicName.equals(b.getSymbolicName())) continue;
        if (version!=null) {
            Version bv = b.getVersion();
            if (vRange != null) {
                if (!vRange.includes(bv)) {
                    continue;
                }
            } else {
                String bvString = bv.toString();
                if (!v.equals(bvString)) {
                    if (!vDep.equals(bvString)) {
                        continue;
                    }
                    LOG.warn("Legacy inferred OSGi version string '"+vDep+"' found to match "+symbolicName+":"+version+"; switch to '"+v+"' format to avoid issues with deprecated version syntax");
                }
            }
        }
        if (!Predicates.and(predicates).apply(b)) continue;

        // check url last, because if it isn't mandatory we should only clear if we find a url
        // for which the other items also match
        if (url!=null) {
            boolean matches = url.equals(b.getLocation());
            if (urlMandatory) {
                if (!matches) continue;
                else urlMatched = true;
            } else {
                if (matches) {
                    if (!urlMatched) {
                        result.clear();
                        urlMatched = true;
                    }
                } else {
                    if (urlMatched) {
                        // can't use this bundle as we have previously found a preferred bundle, with a matching url
                        continue;
                    }
                }
            }
        }
                        
        result.add(b);
    }
    
    if (symbolicName==null && url!=null && !urlMatched) {
        // if we only "preferred" the url, and we did not match it, and we did not have a symbolic name,
        // then clear the results list!
        result.clear();
    }

    Collections.sort(result, new Comparator<Bundle>() {
        @Override
        public int compare(Bundle o1, Bundle o2) {
            int r = NaturalOrderComparator.INSTANCE.compare(o1.getSymbolicName(), o2.getSymbolicName());
            if (r!=0) return r;
            return VersionComparator.INSTANCE.compare(o1.getVersion().toString(), o2.getVersion().toString());
        }
    });
    
    return result;
}
 
Example 10
Source File: Bundle.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
/**
 * Given a precise version create a version range suitable for an import
 * package specification. Currently an input version of M.N.U.Q will result in
 * an output range "[M.N.U.Q, M+1)" following the version usage recommended by
 * OSGi (a package that is not backwards compatible must increment the major
 * number in its version number).
 *
 * @param version
 *          an OSGi compatibel version on string form.
 * @return a quoted version range starting with the given version (inclusive)
 *         ending with the next major version (exclusive). If the specified
 *         version is <code>null</code> or an empty string a <code>null</code>
 *         is returned.
 */
private static String toImportRange(final String version)
    throws IllegalArgumentException
{
  if (null == version || 0 == version.length()) {
    return null;
  }

  final Version vStart = Version.parseVersion(version);
  final Version vEnd = new Version(vStart.getMajor() + 1, 0, 0, null);
  return "\"[" + vStart.toString() + "," + vEnd.toString() + ")\"";
}
 
Example 11
Source File: BundleInfoTask.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Given an OSGi version number on the form
 * <code>Major.Minor.Micro.Qualifier</code> return a version range
 * of the form <code>"[Major.Minor.Micro.Qualifier,Major)"</code>.
 *
 * @param version the version number to convert to a version range.
 * @return A quoted version range string.
 */
public static final String toDefaultVersionRange(final String version)
{
  final Version v = new Version(version);
  return "\"[" +v.toString() +"," +String.valueOf(v.getMajor()+1) +")\"";
}