public static Properties getBundleIDtoBSNandVersionMap()

in src/main/java/org/apache/sling/feature/extension/apiregions/launcher/LauncherProperties.java [50:81]


    public static Properties getBundleIDtoBSNandVersionMap(Feature app, ArtifactProvider artifactProvider) {
        Properties result = new Properties();

        for (Artifact bundle : app.getBundles()) {
            final String key = bundle.getId().toMvnId();
            if ( result.getProperty(key) == null ) {
                String bsn = bundle.getMetadata().get(Constants.BUNDLE_SYMBOLICNAME);
                String version = bundle.getMetadata().get(Constants.BUNDLE_VERSION);
                if ( bsn == null || version == null ) {
                    try(JarFile jarFile = IOUtils.getJarFileFromURL(artifactProvider.provide(bundle.getId()), true, null)) {
                        Attributes manifest = jarFile.getManifest().getMainAttributes();
                        bsn = manifest.getValue(Constants.BUNDLE_SYMBOLICNAME);
                        if (bsn != null) {
                            final int idx = bsn.indexOf(';');
                            if (idx != -1) {
                                bsn = bsn.substring(0, idx);
                            }
                            version = manifest.getValue(Constants.BUNDLE_VERSION);
                        }
                    } catch (IOException ex) {
                        throw new UncheckedIOException(ex);
                    }
    
                }
                if ( bsn != null && version != null ) {
                    result.setProperty(key, bsn.concat("~").concat(Version.parseVersion(version).toString()));
                }
            }
        }

        return result;
    }