public static Bundle getMatchingBundle()

in src/main/java/org/apache/sling/installer/core/impl/tasks/BundleInfo.java [68:104]


    public static Bundle getMatchingBundle(final BundleContext bundleContext,
            final String bundleSymbolicName, final String version) {
        Bundle match = null;
        if (bundleSymbolicName != null) {
            // check if this is the system bundle
            if ( Constants.SYSTEM_BUNDLE_SYMBOLICNAME.equals(bundleSymbolicName) ) {
                return bundleContext.getBundle(Constants.SYSTEM_BUNDLE_LOCATION);
            }
            final List<Bundle> matchingBundles = new ArrayList<Bundle>();
            final Bundle[] bundles = bundleContext.getBundles();
            for (Bundle bundle : bundles) {
                if (bundleSymbolicName.equals(bundle.getSymbolicName())) {
                    matchingBundles.add(bundle);
                }
            }
            if ( matchingBundles.size() > 0 ) {
                final Version searchVersion = (version == null ? null : new Version(version));
                if ( searchVersion == null || searchVersion.compareTo(matchingBundles.get(0).getVersion()) == 0 ) {
                    match = matchingBundles.get(0);
                }
                for(int i=1; i<matchingBundles.size(); i++) {
                    final Bundle current = matchingBundles.get(i);
                    if ( searchVersion == null ) {
                        if ( match.getVersion().compareTo(current.getVersion()) < 0 ) {
                            match = current;
                        }
                    } else {
                        if ( searchVersion.compareTo(current.getVersion()) == 0 ) {
                            match = current;
                            break;
                        }
                    }
                }
            }
        }
        return match;
    }