private static ArtifactId readGavFromPomProperties()

in src/main/java/org/apache/sling/feature/r2f/impl/Bundle2ArtifactMapper.java [91:136]


    private static ArtifactId readGavFromPomProperties(Bundle bundle) {
        Properties pomProperties = new Properties();

        BundleWiring bundleWiring = bundle.adapt(BundleWiring.class);
        Collection<String> pomPropertiesResources = bundleWiring.listResources(MAVEN_METADATA_PATH, POM_PROPERTIES_RESOURCE_NAME, LISTRESOURCES_RECURSE);

        if (pomPropertiesResources == null || pomPropertiesResources.isEmpty()) {
            return null;
        }

        URL pomPropertiesURL = getPomPropertiesURL(pomPropertiesResources, bundle);
        if (pomPropertiesURL == null) {
            return null;
        }

        try {
            URLConnection connection = pomPropertiesURL.openConnection();
            connection.connect();

            try (InputStream inStream = connection.getInputStream()) {
                pomProperties.load(inStream);
            }

            if (connection instanceof HttpURLConnection) {
                ((HttpURLConnection) connection).disconnect();
            }
        } catch (Throwable t) {
            throw new RuntimeException("An error occurred while reading "
                                       + pomPropertiesURL
                                       + " properties file from Bundle "
                                       + bundle.getSymbolicName(), t);
        }

        if (pomProperties.isEmpty()) {
            throw new RuntimeException("Bundle "
                                      + bundle.getSymbolicName()
                                      + " does not export valid Maven metadata");
        }

        String groupId = pomProperties.getProperty(GROUP_ID);
        String artifactId = pomProperties.getProperty(ARTIFACT_ID);
        String version = pomProperties.getProperty(VERSION);
        String classifier = pomProperties.getProperty(CLASSIFIER);

        return new ArtifactId(groupId, artifactId, version, classifier, null);
    }