Search in sources :

Example 41 with Project

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

the class PropertiesUtilsTest method testResolvePluginsProject.

@Test
public void testResolvePluginsProject() throws Exception {
    final Model modelChild = TestUtils.resolveModelResource(RESOURCE_BASE, "inherited-properties.pom");
    ManipulationSession session = createUpdateSession();
    Project pC = new Project(modelChild);
    assertTrue(pC.getResolvedPlugins(session).size() == 0);
    assertTrue(pC.getResolvedManagedPlugins(session).size() == 0);
}
Also used : Project(org.commonjava.maven.ext.common.model.Project) Model(org.apache.maven.model.Model) ManipulationSession(org.commonjava.maven.ext.core.ManipulationSession) Test(org.junit.Test)

Example 42 with Project

use of org.commonjava.maven.ext.common.model.Project 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 43 with Project

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

the class BOMBuilderManipulator method getArtifacts.

// TODO: This will grab every module ; so those modules activated under profiles will also get included
private List<Dependency> getArtifacts(List<Project> projects) {
    List<Dependency> results = new ArrayList<>();
    for (Project p : projects) {
        Dependency d = new Dependency();
        d.setGroupId(p.getGroupId());
        d.setArtifactId(p.getArtifactId());
        d.setVersion(p.getVersion());
        d.setType(p.getModel().getPackaging());
        results.add(d);
    }
    return results;
}
Also used : Project(org.commonjava.maven.ext.common.model.Project) ArrayList(java.util.ArrayList) Dependency(org.apache.maven.model.Dependency)

Example 44 with Project

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

the class BOMBuilderManipulator method applyChanges.

/**
 * If enabled, grab the execution root pom (which will be the topmost POM in terms of directory structure). Within that
 * handle the manipulation of the bom injection.
 */
@Override
public Set<Project> applyChanges(final List<Project> projects) throws ManipulationException {
    final BOMInjectingState state = session.getState(BOMInjectingState.class);
    if (!session.isEnabled() || !state.isEnabled()) {
        logger.debug(getClass().getSimpleName() + ": Nothing to do!");
        return Collections.emptySet();
    }
    List<Dependency> projectArtifacts = getArtifacts(projects);
    for (final Project project : projects) {
        if (project.isExecutionRoot()) {
            logger.info("Examining {} to add BOM generation.", project);
            final Model model = project.getModel();
            Build build = model.getBuild();
            if (build == null) {
                build = new Build();
                model.setBuild(build);
            }
            Model bomModel = createModel(project, IDBOM);
            bomModel.setDescription("PME Generated BOM for other projects to use to align to.");
            DependencyManagement dm = new DependencyManagement();
            dm.setDependencies(projectArtifacts);
            bomModel.setDependencyManagement(dm);
            // Write new bom back out.
            File pmebom = new File(session.getTargetDir(), IDBOM + ".xml");
            session.getTargetDir().mkdir();
            pomIO.writeModel(bomModel, pmebom);
            final Map<String, Plugin> pluginMap = build.getPluginsAsMap();
            if (!pluginMap.containsKey(POM_DEPLOYER_COORD)) {
                final PluginExecution execution = new PluginExecution();
                execution.setId(IDBOM);
                execution.setPhase("install");
                execution.setGoals(Collections.singletonList("add-pom"));
                final Plugin plugin = new Plugin();
                plugin.setGroupId(POM_DEPLOYER_GID);
                plugin.setArtifactId(POM_DEPLOYER_AID);
                plugin.setVersion(POM_DEPLOYER_VID);
                plugin.addExecution(execution);
                plugin.setInherited(false);
                build.addPlugin(plugin);
                final Xpp3Dom xml = new Xpp3Dom("configuration");
                final Map<String, Object> config = new HashMap<>();
                config.put("pomName", "target" + File.separatorChar + pmebom.getName());
                config.put("errorOnMissing", false);
                config.put("artifactId", bomModel.getArtifactId());
                config.put("groupId", bomModel.getGroupId());
                for (final Map.Entry<String, Object> entry : config.entrySet()) {
                    final Xpp3Dom child = new Xpp3Dom(entry.getKey());
                    if (entry.getValue() != null) {
                        child.setValue(entry.getValue().toString());
                    }
                    xml.addChild(child);
                }
                execution.setConfiguration(xml);
            }
            return Collections.singleton(project);
        }
    }
    return Collections.emptySet();
}
Also used : PluginExecution(org.apache.maven.model.PluginExecution) Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) HashMap(java.util.HashMap) Dependency(org.apache.maven.model.Dependency) Project(org.commonjava.maven.ext.common.model.Project) Build(org.apache.maven.model.Build) Model(org.apache.maven.model.Model) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) BOMInjectingState(org.commonjava.maven.ext.core.state.BOMInjectingState) DependencyManagement(org.apache.maven.model.DependencyManagement) Plugin(org.apache.maven.model.Plugin)

Example 45 with Project

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

the class DependencyRemovalManipulator method applyChanges.

/**
 * Apply the alignment changes to the list of {@link Project}'s given.
 */
@Override
public Set<Project> applyChanges(final List<Project> projects) throws ManipulationException {
    final State state = session.getState(DependencyRemovalState.class);
    if (!session.isEnabled() || !state.isEnabled()) {
        logger.debug(getClass().getSimpleName() + ": Nothing to do!");
        return Collections.emptySet();
    }
    final Set<Project> changed = new HashSet<>();
    for (final Project project : projects) {
        final Model model = project.getModel();
        if (apply(project, model)) {
            changed.add(project);
        }
    }
    return changed;
}
Also used : Project(org.commonjava.maven.ext.common.model.Project) DependencyState(org.commonjava.maven.ext.core.state.DependencyState) State(org.commonjava.maven.ext.core.state.State) DependencyRemovalState(org.commonjava.maven.ext.core.state.DependencyRemovalState) Model(org.apache.maven.model.Model) HashSet(java.util.HashSet)

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