Search in sources :

Example 1 with PomPeek

use of org.commonjava.maven.galley.maven.parse.PomPeek in project galley by Commonjava.

the class PomPeekTest method findGAVDirectlyInProjectBelowProperties.

@Test
public void findGAVDirectlyInProjectBelowProperties() {
    final File pom = getResourceFile(BASE + "direct-gav-below-props.pom");
    final PomPeek peek = new PomPeek(pom);
    assertThat(peek.getKey(), notNullValue());
    final ProjectVersionRef key = peek.getKey();
    assertThat(key.getGroupId(), equalTo("test"));
    assertThat(key.getArtifactId(), equalTo("direct-gav-below-props"));
    assertThat(key.getVersionString(), equalTo("1"));
}
Also used : ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) PomPeek(org.commonjava.maven.galley.maven.parse.PomPeek) File(java.io.File) Test(org.junit.Test)

Example 2 with PomPeek

use of org.commonjava.maven.galley.maven.parse.PomPeek in project pom-manipulation-ext by release-engineering.

the class PomIO method peekAtPomHierarchy.

private List<PomPeek> peekAtPomHierarchy(final File topPom) throws ManipulationException {
    final List<PomPeek> peeked = new ArrayList<>();
    try {
        final LinkedList<File> pendingPoms = new LinkedList<>();
        pendingPoms.add(topPom.getCanonicalFile());
        final String topDir = topPom.getAbsoluteFile().getParentFile().getCanonicalPath();
        final Set<File> seen = new HashSet<>();
        File topLevelParent = topPom;
        while (!pendingPoms.isEmpty()) {
            final File pom = pendingPoms.removeFirst();
            seen.add(pom);
            logger.debug("PEEK: " + pom);
            final PomPeek peek = new PomPeek(pom);
            final ProjectVersionRef key = peek.getKey();
            if (key != null) {
                peeked.add(peek);
                final File dir = pom.getParentFile();
                final String relPath = peek.getParentRelativePath();
                if (relPath != null) {
                    logger.debug("Found parent relativePath: " + relPath + " in pom: " + pom);
                    File parent = new File(dir, relPath);
                    if (parent.isDirectory()) {
                        parent = new File(parent, "pom.xml");
                    }
                    parent = parent.getCanonicalFile();
                    if (parent.getParentFile().getCanonicalPath().startsWith(topDir) && parent.exists() && !seen.contains(parent) && !pendingPoms.contains(parent)) {
                        topLevelParent = parent;
                        logger.debug("Possible top level parent " + parent);
                        pendingPoms.add(parent);
                    } else {
                        logger.debug("Skipping reference to non-existent parent relativePath: '" + relPath + "' in: " + pom);
                    }
                }
                final Set<String> modules = peek.getModules();
                if (modules != null && !modules.isEmpty()) {
                    for (final String module : modules) {
                        logger.debug("Found module: " + module + " in pom: " + pom);
                        File modPom = new File(dir, module);
                        if (modPom.isDirectory()) {
                            modPom = new File(modPom, "pom.xml");
                        }
                        if (modPom.exists() && !seen.contains(modPom) && !pendingPoms.contains(modPom)) {
                            pendingPoms.addLast(modPom);
                        } else {
                            logger.debug("Skipping reference to non-existent module: '" + module + "' in: " + pom);
                        }
                    }
                }
            } else {
                logger.debug("Skipping " + pom + " as its a template file.");
            }
        }
        final HashSet<ProjectVersionRef> projectrefs = new HashSet<>();
        for (final PomPeek p : peeked) {
            projectrefs.add(p.getKey());
            if (p.getPom().equals(topLevelParent)) {
                logger.debug("Setting top level parent to " + p.getPom() + " :: " + p.getKey());
                p.setInheritanceRoot(true);
            }
        }
        for (final PomPeek p : peeked) {
            if (p.getParentKey() == null || !seenThisParent(projectrefs, p.getParentKey())) {
                logger.debug("Found a standalone pom " + p.getPom() + " :: " + p.getKey());
                p.setInheritanceRoot(true);
            }
        }
    } catch (final IOException e) {
        throw new ManipulationException("Problem peeking at POMs.", e);
    }
    return peeked;
}
Also used : ArrayList(java.util.ArrayList) PomPeek(org.commonjava.maven.galley.maven.parse.PomPeek) IOException(java.io.IOException) LinkedList(java.util.LinkedList) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) ManipulationException(org.commonjava.maven.ext.common.ManipulationException) File(java.io.File) HashSet(java.util.HashSet)

Example 3 with PomPeek

use of org.commonjava.maven.galley.maven.parse.PomPeek in project galley by Commonjava.

the class PomPeekTest method findGAVDirectlyInProjectAtTop.

@Test
public void findGAVDirectlyInProjectAtTop() {
    final File pom = getResourceFile(BASE + "direct-gav-at-top.pom");
    final PomPeek peek = new PomPeek(pom);
    assertThat(peek.getKey(), notNullValue());
    final ProjectVersionRef key = peek.getKey();
    assertThat(key.getGroupId(), equalTo("test"));
    assertThat(key.getArtifactId(), equalTo("direct-gav-at-top"));
    assertThat(key.getVersionString(), equalTo("1"));
}
Also used : ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) PomPeek(org.commonjava.maven.galley.maven.parse.PomPeek) File(java.io.File) Test(org.junit.Test)

Example 4 with PomPeek

use of org.commonjava.maven.galley.maven.parse.PomPeek in project galley by Commonjava.

the class PomPeekTest method findGAVInheritedFromParentWithGroupAndVersionOverrideAtTop.

@Test
public void findGAVInheritedFromParentWithGroupAndVersionOverrideAtTop() throws Exception {
    final File pom = getResourceFile(BASE + "inherited-gav-with-group-override-at-top.pom");
    final PomPeek peek = new PomPeek(pom);
    final ProjectVersionRef key = peek.getKey();
    assertThat(key, notNullValue());
    assertThat(key.getGroupId(), equalTo("a-different-test-group"));
    assertThat(key.getArtifactId(), equalTo("inherited-gav-with-group-override-at-top"));
    assertThat(key.getVersionString(), equalTo("1"));
}
Also used : ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) PomPeek(org.commonjava.maven.galley.maven.parse.PomPeek) File(java.io.File) Test(org.junit.Test)

Example 5 with PomPeek

use of org.commonjava.maven.galley.maven.parse.PomPeek in project galley by Commonjava.

the class PomPeekTest method findGAVInheritedFromParentWithVersionOverrideAtTop.

@Test
public void findGAVInheritedFromParentWithVersionOverrideAtTop() {
    final File pom = getResourceFile(BASE + "inherited-gav-with-override-at-top.pom");
    final PomPeek peek = new PomPeek(pom);
    assertThat(peek.getKey(), notNullValue());
    final ProjectVersionRef key = peek.getKey();
    assertThat(key.getGroupId(), equalTo("test"));
    assertThat(key.getArtifactId(), equalTo("inherited-gav-with-override-at-top"));
    assertThat(key.getVersionString(), equalTo("2"));
}
Also used : ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) PomPeek(org.commonjava.maven.galley.maven.parse.PomPeek) File(java.io.File) Test(org.junit.Test)

Aggregations

PomPeek (org.commonjava.maven.galley.maven.parse.PomPeek)11 File (java.io.File)8 ProjectVersionRef (org.commonjava.maven.atlas.ident.ref.ProjectVersionRef)7 Test (org.junit.Test)6 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4 Map (java.util.Map)3 ProjectVersionRef (org.commonjava.atlas.maven.ident.ref.ProjectVersionRef)3 ArrayList (java.util.ArrayList)2 ManipulationException (org.commonjava.maven.ext.common.ManipulationException)2 BufferedInputStream (java.io.BufferedInputStream)1 FileInputStream (java.io.FileInputStream)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 Model (org.apache.maven.model.Model)1 MavenXpp3Reader (org.apache.maven.model.io.xpp3.MavenXpp3Reader)1 MavenProject (org.apache.maven.project.MavenProject)1 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)1 Project (org.commonjava.maven.ext.common.model.Project)1