/** * Finds the best (highest) matching version among a set. * * @return the matching version, or null if there are no matches */ protected static Version findBestMatch(VersionSpecification versionSpec, Set<Version> versions) { Version bestMatch=null; for (Version version : versions) { //No version is set if getSpecifiedMajor() == null //In that case we allow all versions if (version == null || !versionSpec.matches(version)) continue; if (bestMatch==null || bestMatch.compareTo(version)<0) bestMatch=version; } return bestMatch; }
/** * Returns true if the given version matches this specification. * It matches if all the numeric components specified are the same * as in the version, and both qualifiers are either null or set * to the same value. I.e, a version which includes a qualifier * will only match exactly and will never return true from a * request for an unspecified qualifier. */ public boolean matches(Version version) { if (matches(this.major, version.getMajor()) && matches(this.minor, version.getMinor()) && matches(this.micro, version.getMicro())) { return (version.getQualifier().equals(this.getQualifier())); } else { return false; } }
/** * Returns the bundle of a given name having the highest matching version * * @param id the id of the component to return. May not include a version, or include * an underspecified version, in which case the highest (mathcing) version which * does not contain a qualifier is returned * @return the bundle match having the highest version, or null if there was no matches */ public Bundle getBundle(ComponentSpecification id) { Bundle highestMatch=null; for (Bundle bundle : getBundles()) { assert bundle.getSymbolicName() != null : "ensureHasBundleSymbolicName not called during installation"; if ( ! bundle.getSymbolicName().equals(id.getName())) continue; if ( ! id.getVersionSpecification().matches(versionOf(bundle))) continue; if (highestMatch==null || versionOf(highestMatch).compareTo(versionOf(bundle))<0) highestMatch=bundle; } return highestMatch; }
/** * Checks if a componentId matches a given spec */ public boolean matches(ComponentId id) { boolean versionMatch = getVersionSpecification().matches(id.getVersion()); return getName().equals(id.getName()) && versionMatch && namespaceMatch(id.getNamespace()); }