Search in sources :

Example 1 with PomIO

use of org.commonjava.maven.ext.io.PomIO 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 2 with PomIO

use of org.commonjava.maven.ext.io.PomIO 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 3 with PomIO

use of org.commonjava.maven.ext.io.PomIO in project pom-manipulation-ext by release-engineering.

the class Cli method createSession.

private void createSession(File target, File settings) {
    try {
        PlexusContainer container = new DefaultPlexusContainer();
        pomIO = container.lookup(PomIO.class);
        session = container.lookup(ManipulationSession.class);
        manipulationManager = container.lookup(ManipulationManager.class);
        final MavenExecutionRequest req = new DefaultMavenExecutionRequest().setUserProperties(System.getProperties()).setUserProperties(userProps).setRemoteRepositories(Collections.<ArtifactRepository>emptyList());
        ArtifactRepository ar = null;
        if (settings == null) {
            // No, this is not a typo. If current default is null, supply new local and global.
            // This function passes in settings to make it easier to test.
            this.settings = settings = new File(System.getProperty("user.home"), ".m2/settings.xml");
            ar = new MavenArtifactRepository();
            ar.setUrl("file://" + System.getProperty("user.home") + "/.m2/repository");
            req.setLocalRepository(ar);
        }
        req.setUserSettingsFile(settings);
        req.setGlobalSettingsFile(settings);
        MavenExecutionRequestPopulator executionRequestPopulator = container.lookup(MavenExecutionRequestPopulator.class);
        executionRequestPopulator.populateFromSettings(req, parseSettings(settings));
        executionRequestPopulator.populateDefaults(req);
        if (ar != null) {
            ar.setUrl("file://" + req.getLocalRepositoryPath());
        }
        if (userProps != null && userProps.containsKey("maven.repo.local")) {
            if (ar == null) {
                ar = new MavenArtifactRepository();
            }
            ar.setUrl("file://" + userProps.getProperty("maven.repo.local"));
            req.setLocalRepository(ar);
        }
        final MavenSession mavenSession = new MavenSession(container, null, req, new DefaultMavenExecutionResult());
        mavenSession.getRequest().setPom(target);
        session.setMavenSession(mavenSession);
    } catch (ComponentLookupException e) {
        logger.debug("Caught problem instantiating ", e);
        System.err.println("Unable to start Cli subsystem");
        System.exit(100);
    } catch (PlexusContainerException e) {
        logger.debug("Caught problem instantiating ", e);
        System.err.println("Unable to start Cli subsystem");
        System.exit(100);
    } catch (SettingsBuildingException e) {
        logger.debug("Caught problem parsing settings file ", e);
        System.err.println("Unable to parse settings.xml file");
        System.exit(100);
    } catch (MavenExecutionRequestPopulationException e) {
        logger.debug("Caught problem populating maven request from settings file ", e);
        System.err.println("Unable to create maven execution request from settings.xml file");
        System.exit(100);
    }
}
Also used : PlexusContainerException(org.codehaus.plexus.PlexusContainerException) SettingsBuildingException(org.apache.maven.settings.building.SettingsBuildingException) DefaultPlexusContainer(org.codehaus.plexus.DefaultPlexusContainer) PlexusContainer(org.codehaus.plexus.PlexusContainer) DefaultMavenExecutionResult(org.apache.maven.execution.DefaultMavenExecutionResult) MavenExecutionRequestPopulationException(org.apache.maven.execution.MavenExecutionRequestPopulationException) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) ManipulationManager(org.commonjava.maven.ext.core.ManipulationManager) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) PomIO(org.commonjava.maven.ext.io.PomIO) MavenSession(org.apache.maven.execution.MavenSession) DefaultPlexusContainer(org.codehaus.plexus.DefaultPlexusContainer) ManipulationSession(org.commonjava.maven.ext.core.ManipulationSession) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) File(java.io.File) MavenExecutionRequestPopulator(org.apache.maven.execution.MavenExecutionRequestPopulator)

Example 4 with PomIO

use of org.commonjava.maven.ext.io.PomIO in project pom-manipulation-ext by release-engineering.

the class ResolveArtifactTest method testResolveArtifacts.

@Test
public void testResolveArtifacts() throws Exception {
    final ManipulationSession session = new ManipulationSession();
    // Locate the PME project pom file.
    final File projectroot = new File(TestUtils.resolveFileResource("properties/", "").getParentFile().getParentFile().getParentFile().getParentFile(), "pom.xml");
    PomIO pomIO = new PomIO();
    List<Project> projects = pomIO.parseProject(projectroot);
    Set<ArtifactRef> artifacts = RESTCollector.establishAllDependencies(session, projects, null);
    // NB If this test fails then check if PME deps/plugins have changed...
    assertTrue(artifacts.size() == 59);
}
Also used : Project(org.commonjava.maven.ext.common.model.Project) ManipulationSession(org.commonjava.maven.ext.core.ManipulationSession) File(java.io.File) PomIO(org.commonjava.maven.ext.io.PomIO) ArtifactRef(org.commonjava.maven.atlas.ident.ref.ArtifactRef) Test(org.junit.Test)

Example 5 with PomIO

use of org.commonjava.maven.ext.io.PomIO in project pom-manipulation-ext by release-engineering.

the class ProjectInheritanceTest method testVerifyInheritanceMultiple.

@Test
public void testVerifyInheritanceMultiple() 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/pom.xml");
    PomIO pomIO = new PomIO();
    List<Project> projects = pomIO.parseProject(projectroot);
    for (int i = 0; i <= 3; i++) {
        if (i == 0) {
            // First project should be root
            assertTrue(projects.get(i).getProjectParent() == null);
            assertTrue(projects.get(i).getPom().equals(projectroot));
            assertTrue(projects.get(i).getInheritedList().size() == 1);
        } else if (i == 1) {
            List<Project> inherited = projects.get(i).getInheritedList();
            assertTrue(inherited.size() == 2);
            assertTrue(inherited.get(1).getProjectParent().getPom().equals(projectroot));
        } else if (i == 2) {
            List<Project> inherited = projects.get(i).getInheritedList();
            assertTrue(inherited.size() == 3);
            assertTrue(inherited.get(0).getPom().equals(projectroot));
        }
    }
}
Also used : Project(org.commonjava.maven.ext.common.model.Project) List(java.util.List) File(java.io.File) PomIO(org.commonjava.maven.ext.io.PomIO) Test(org.junit.Test)

Aggregations

File (java.io.File)8 PomIO (org.commonjava.maven.ext.io.PomIO)8 Project (org.commonjava.maven.ext.common.model.Project)7 Test (org.junit.Test)7 ManipulationSession (org.commonjava.maven.ext.core.ManipulationSession)3 List (java.util.List)2 ArtifactRef (org.commonjava.maven.atlas.ident.ref.ArtifactRef)2 Path (java.nio.file.Path)1 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)1 MavenArtifactRepository (org.apache.maven.artifact.repository.MavenArtifactRepository)1 DefaultMavenExecutionRequest (org.apache.maven.execution.DefaultMavenExecutionRequest)1 DefaultMavenExecutionResult (org.apache.maven.execution.DefaultMavenExecutionResult)1 MavenExecutionRequest (org.apache.maven.execution.MavenExecutionRequest)1 MavenExecutionRequestPopulationException (org.apache.maven.execution.MavenExecutionRequestPopulationException)1 MavenExecutionRequestPopulator (org.apache.maven.execution.MavenExecutionRequestPopulator)1 MavenSession (org.apache.maven.execution.MavenSession)1 Dependency (org.apache.maven.model.Dependency)1 SettingsBuildingException (org.apache.maven.settings.building.SettingsBuildingException)1 DefaultPlexusContainer (org.codehaus.plexus.DefaultPlexusContainer)1 PlexusContainer (org.codehaus.plexus.PlexusContainer)1