Search in sources :

Example 51 with Project

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

the class ProjectInheritanceTest method testVerifyProjectVersion.

@Test
public void testVerifyProjectVersion() throws Exception {
    final ManipulationSession session = new ManipulationSession();
    final File projectroot = new File(TestUtils.resolveFileResource(RESOURCE_BASE, "").getParentFile().getParentFile().getParentFile().getParentFile(), "integration-test/src/it/project-inheritance/pom.xml");
    PomIO pomIO = new PomIO();
    List<Project> projects = pomIO.parseProject(projectroot);
    for (Project p : projects) {
        if (p.getPom().equals(projectroot)) {
            HashMap<ArtifactRef, Dependency> deps = p.getResolvedManagedDependencies(session);
            for (ArtifactRef a : deps.keySet()) {
                assertFalse(a.getVersionString().contains("project.version"));
            }
            deps = p.getResolvedDependencies(session);
            assertTrue(deps.size() == 1);
            for (ArtifactRef a : deps.keySet()) {
                assertFalse(a.getVersionString().contains("project.version"));
            }
            assertFalse(deps.containsKey("org.mockito:mockito-all:jar:*"));
            deps = p.getAllResolvedDependencies(session);
            assertTrue(deps.size() == 3);
            for (ArtifactRef a : deps.keySet()) {
                assertFalse(a.getVersionString().contains("project.version"));
                if (a.getGroupId().equals("org.mockito")) {
                    assertTrue(a.getVersionString().contains("*"));
                }
            }
            assertTrue(deps.containsKey(SimpleArtifactRef.parse("org.mockito:mockito-all:jar:*")));
        }
    }
}
Also used : Project(org.commonjava.maven.ext.common.model.Project) ManipulationSession(org.commonjava.maven.ext.core.ManipulationSession) Dependency(org.apache.maven.model.Dependency) File(java.io.File) PomIO(org.commonjava.maven.ext.io.PomIO) SimpleArtifactRef(org.commonjava.maven.atlas.ident.ref.SimpleArtifactRef) ArtifactRef(org.commonjava.maven.atlas.ident.ref.ArtifactRef) Test(org.junit.Test)

Example 52 with Project

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

the class PropertyInterpolatorTest method testInteropolateProperties.

@Test
public void testInteropolateProperties() throws Exception {
    final Model model = TestUtils.resolveModelResource(RESOURCE_BASE, "infinispan-bom-8.2.0.Final.pom");
    Project p = new Project(model);
    Properties props = p.getModel().getProperties();
    boolean containsProperty = false;
    for (Object o : props.values()) {
        if (((String) o).contains("${")) {
            containsProperty = true;
        }
    }
    assertTrue(containsProperty);
    PropertyInterpolator pi = new PropertyInterpolator(props, p);
    assertTrue(pi.interp("${version.hibernate.osgi}").equals("5.0.4.Final"));
}
Also used : Project(org.commonjava.maven.ext.common.model.Project) Model(org.apache.maven.model.Model) Properties(java.util.Properties) PropertyInterpolator(org.commonjava.maven.ext.common.util.PropertyInterpolator) Test(org.junit.Test)

Example 53 with Project

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

the class PropertyInterpolatorTest method testResolveProjectDependencies.

@Test
public void testResolveProjectDependencies() throws Exception {
    final Model model = TestUtils.resolveModelResource(RESOURCE_BASE, "infinispan-bom-8.2.0.Final.pom");
    final Project project = new Project(model);
    HashMap<ArtifactRef, Dependency> deps = project.getResolvedManagedDependencies(new ManipulationSession());
    assertTrue(deps.size() == 66);
}
Also used : Project(org.commonjava.maven.ext.common.model.Project) Model(org.apache.maven.model.Model) ManipulationSession(org.commonjava.maven.ext.core.ManipulationSession) Dependency(org.apache.maven.model.Dependency) ArtifactRef(org.commonjava.maven.atlas.ident.ref.ArtifactRef) Test(org.junit.Test)

Example 54 with Project

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

the class XMLManipulatorTest method testNotFound.

@Test(expected = ManipulationException.class)
public void testNotFound() throws Exception {
    String path = "//include[starts-with(.,'i-do-not-exist')]";
    File target = tf.newFile();
    FileUtils.copyFile(xmlFile, target);
    Project p = new Project(null, target, null);
    xmlManipulator.internalApplyChanges(p, new XMLState.XMLOperation(target.getName(), path, null));
}
Also used : Project(org.commonjava.maven.ext.common.model.Project) XMLState(org.commonjava.maven.ext.core.state.XMLState) Input.fromFile(org.xmlunit.builder.Input.fromFile) File(java.io.File) Test(org.junit.Test) XMLIOTest(org.commonjava.maven.ext.io.XMLIOTest)

Example 55 with Project

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

the class XMLManipulatorTest method alterFile.

@Test
public void alterFile() throws Exception {
    String replacementGA = "com.rebuild:servlet-api";
    String tomcatPath = "//include[starts-with(.,'org.apache.tomcat')]";
    File target = tf.newFile();
    FileUtils.copyFile(xmlFile, target);
    Project project = new Project(null, target, null);
    xmlManipulator.internalApplyChanges(project, new XMLState.XMLOperation(target.getName(), tomcatPath, replacementGA));
    Diff diff = DiffBuilder.compare(fromFile(xmlFile)).withTest(fromFile(target)).build();
    assertTrue(diff.toString(), diff.hasDifferences());
    String xpathForHamcrest = "/*/*/*/*/*[starts-with(.,'com.rebuild') and local-name() = 'include']";
    Iterable<Node> i = new JAXPXPathEngine().selectNodes(xpathForHamcrest, fromFile(target).build());
    int count = 0;
    for (Node anI : i) {
        count++;
        assertTrue(anI.getTextContent().startsWith("com.rebuild:servlet-api"));
    }
    assertEquals(1, count);
}
Also used : Project(org.commonjava.maven.ext.common.model.Project) XMLState(org.commonjava.maven.ext.core.state.XMLState) Diff(org.xmlunit.diff.Diff) JAXPXPathEngine(org.xmlunit.xpath.JAXPXPathEngine) Node(org.w3c.dom.Node) Input.fromFile(org.xmlunit.builder.Input.fromFile) File(java.io.File) Test(org.junit.Test) XMLIOTest(org.commonjava.maven.ext.io.XMLIOTest)

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