public void expose()

in src/main/java/org/apache/maven/shared/jar/identification/exposers/EmbeddedMavenModelExposer.java [49:94]


    public void expose(JarIdentification identification, JarAnalyzer jarAnalyzer) {
        List<JarEntry> entries = jarAnalyzer.getMavenPomEntries();
        if (entries.isEmpty()) {
            return;
        }

        if (entries.size() > 1) {
            logger.warn("More than one Maven model entry was found in the JAR, using only the first of: " + entries);
        }

        JarEntry pom = entries.get(0);
        MavenXpp3Reader pomreader = new MavenXpp3Reader();
        try (InputStream is = jarAnalyzer.getEntryInputStream(pom);
                InputStreamReader isreader = new InputStreamReader(is)) {
            Model model = pomreader.read(isreader);

            if (model.getParent() != null) {
                // use parent values only if project values not exists
                if (model.getGroupId() == null) {
                    identification.addAndSetGroupId(model.getParent().getGroupId());
                }
                if (model.getVersion() == null) {
                    identification.addAndSetVersion(model.getParent().getVersion());
                }
            }

            identification.addAndSetGroupId(model.getGroupId());
            identification.addAndSetArtifactId(model.getArtifactId());
            identification.addAndSetVersion(model.getVersion());
            identification.addAndSetName(model.getName());

            // TODO: suboptimal - we are reproducing Maven's built in default
            if (model.getName() == null) {
                identification.addAndSetName(model.getArtifactId());
            }

            Organization org = model.getOrganization();
            if (org != null) {
                identification.addAndSetVendor(org.getName());
            }
        } catch (IOException e) {
            logger.error("Unable to read model " + pom.getName() + " in " + jarAnalyzer.getFile() + ".", e);
        } catch (XmlPullParserException e) {
            logger.error("Unable to parse model " + pom.getName() + " in " + jarAnalyzer.getFile() + ".", e);
        }
    }