Search in sources :

Example 1 with Project

use of org.commonjava.maven.ext.common.model.Project in project pom-manipulation-ext by release-engineering.

the class PomIOTest method testGAVReturnPOMs.

@Test
public void testGAVReturnPOMs() throws Exception {
    URL resource = PomIOTest.class.getResource(filename);
    assertNotNull(resource);
    File pom = new File(resource.getFile());
    assertTrue(pom.exists());
    File targetFile = folder.newFile("target.xml");
    FileUtils.copyFile(pom, targetFile);
    Model model = new Model();
    model.setGroupId("org.commonjava.maven.ext.versioning.test");
    model.setArtifactId("dospom");
    model.setVersion("1.0");
    model.setPackaging("pom");
    model.setModelVersion("4.0.0");
    Project p = new Project(targetFile, model);
    p.setExecutionRoot();
    HashSet<Project> changed = new HashSet<>();
    changed.add(p);
    GAV gav = pomIO.rewritePOMs(changed);
    assertTrue(gav.version.equals("1.0"));
    assertTrue(gav.groupId.equals("org.commonjava.maven.ext.versioning.test"));
    assertTrue(gav.artifactId.equals("dospom"));
}
Also used : Project(org.commonjava.maven.ext.common.model.Project) Model(org.apache.maven.model.Model) File(java.io.File) GAV(org.commonjava.maven.ext.common.model.GAV) URL(java.net.URL) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with Project

use of org.commonjava.maven.ext.common.model.Project in project pom-manipulation-ext by release-engineering.

the class PomIOTest method testRewritePOMs.

@Test
public void testRewritePOMs() throws Exception {
    URL resource = PomIOTest.class.getResource(filename);
    assertNotNull(resource);
    File pom = new File(resource.getFile());
    assertTrue(pom.exists());
    File targetFile = folder.newFile("target.xml");
    FileUtils.copyFile(pom, targetFile);
    Model model = new Model();
    model.setGroupId("org.commonjava.maven.ext.versioning.test");
    model.setArtifactId("dospom");
    model.setVersion("1.0");
    model.setPackaging("pom");
    model.setModelVersion("4.0.0");
    Project p = new Project(targetFile, model);
    HashSet<Project> changed = new HashSet<>();
    changed.add(p);
    pomIO.rewritePOMs(changed);
    assertTrue(FileUtils.contentEqualsIgnoreEOL(pom, targetFile, "UTF-8"));
    assertTrue(FileUtils.contentEquals(targetFile, pom));
}
Also used : Project(org.commonjava.maven.ext.common.model.Project) Model(org.apache.maven.model.Model) File(java.io.File) URL(java.net.URL) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with Project

use of org.commonjava.maven.ext.common.model.Project in project pom-manipulation-ext by release-engineering.

the class ProjectInheritanceTest method testVerifyExecutionRoot.

@Test
public void testVerifyExecutionRoot() throws Exception {
    // Locate the PME project pom file. Use that to verify inheritance tracking.
    final File projectroot = new File(TestUtils.resolveFileResource(RESOURCE_BASE, "").getParentFile().getParentFile().getParentFile().getParentFile(), "integration-test/src/it/project-inheritance/common/pom.xml");
    PomIO pomIO = new PomIO();
    List<Project> projects = pomIO.parseProject(projectroot);
    for (Project p : projects) {
        if (p.getKey().toString().equals("io.apiman:apiman-common:1.2.7-SNAPSHOT")) {
            assertTrue(p.isExecutionRoot());
            assertTrue(p.isInheritanceRoot());
        } else {
            assertFalse(p.isExecutionRoot());
            assertFalse(p.isInheritanceRoot());
        }
    }
}
Also used : Project(org.commonjava.maven.ext.common.model.Project) File(java.io.File) PomIO(org.commonjava.maven.ext.io.PomIO) Test(org.junit.Test)

Example 4 with Project

use of org.commonjava.maven.ext.common.model.Project in project pom-manipulation-ext by release-engineering.

the class ProjectInheritanceTest method testVerifyInheritance.

@Test
public void testVerifyInheritance() throws Exception {
    // Locate the PME project pom file. Use that to verify inheritance tracking.
    final File projectroot = new File(TestUtils.resolveFileResource(RESOURCE_BASE, "").getParentFile().getParentFile().getParentFile().getParentFile(), "pom.xml");
    PomIO pomIO = new PomIO();
    List<Project> projects = pomIO.parseProject(projectroot);
    for (Project p : projects) {
        if (!p.getPom().equals(projectroot)) {
            assertTrue(p.getProjectParent().getPom().equals(projectroot));
        }
    }
}
Also used : Project(org.commonjava.maven.ext.common.model.Project) File(java.io.File) PomIO(org.commonjava.maven.ext.io.PomIO) Test(org.junit.Test)

Example 5 with Project

use of org.commonjava.maven.ext.common.model.Project in project pom-manipulation-ext by release-engineering.

the class PropertyInterpolatorTest method testInteropolateDependencies.

@Test
public void testInteropolateDependencies() throws Exception {
    final Model model = TestUtils.resolveModelResource(RESOURCE_BASE, "infinispan-bom-8.2.0.Final.pom");
    Project project = new Project(model);
    PropertyInterpolator pi = new PropertyInterpolator(project.getModel().getProperties(), project);
    String nonInterp = "", interp = "";
    // Explicitly calling the non-resolved model dependencies...
    for (Dependency d : project.getModel().getDependencyManagement().getDependencies()) {
        nonInterp += (d.getGroupId().equals("${project.groupId}") ? project.getGroupId() : d.getGroupId()) + ":" + (d.getArtifactId().equals("${project.artifactId}") ? project.getArtifactId() : d.getArtifactId()) + System.lineSeparator();
        interp += pi.interp(d.getGroupId().equals("${project.groupId}") ? project.getGroupId() : d.getGroupId()) + ":" + pi.interp(d.getArtifactId().equals("${project.artifactId}") ? project.getArtifactId() : d.getArtifactId()) + System.lineSeparator();
    }
    assertTrue(nonInterp.contains("${"));
    assertFalse(interp.contains("${"));
}
Also used : Project(org.commonjava.maven.ext.common.model.Project) Model(org.apache.maven.model.Model) Dependency(org.apache.maven.model.Dependency) PropertyInterpolator(org.commonjava.maven.ext.common.util.PropertyInterpolator) Test(org.junit.Test)

Aggregations

Project (org.commonjava.maven.ext.common.model.Project)56 Model (org.apache.maven.model.Model)27 Test (org.junit.Test)25 HashSet (java.util.HashSet)21 File (java.io.File)19 HashMap (java.util.HashMap)11 ManipulationSession (org.commonjava.maven.ext.core.ManipulationSession)9 Profile (org.apache.maven.model.Profile)7 ManipulationException (org.commonjava.maven.ext.common.ManipulationException)7 PomIO (org.commonjava.maven.ext.io.PomIO)7 ArrayList (java.util.ArrayList)6 Properties (java.util.Properties)6 ArtifactRef (org.commonjava.maven.atlas.ident.ref.ArtifactRef)6 ProjectVersionRef (org.commonjava.maven.atlas.ident.ref.ProjectVersionRef)6 Map (java.util.Map)5 Dependency (org.apache.maven.model.Dependency)5 SimpleProjectVersionRef (org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef)5 SimpleArtifactRef (org.commonjava.maven.atlas.ident.ref.SimpleArtifactRef)4 DependencyState (org.commonjava.maven.ext.core.state.DependencyState)4 IOException (java.io.IOException)3