Search in sources :

Example 21 with Project

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

the class PropertiesUtilsTest method testUpdateProjectVersionProperty.

@Test
public void testUpdateProjectVersionProperty() throws Exception {
    Project pP = getProject();
    ManipulationSession session = createUpdateSession();
    assertFalse(updateProperties(session, pP, false, "project.version", "5.0.4.Final-redhat-1") == PropertiesUtils.PropertyUpdate.FOUND);
}
Also used : Project(org.commonjava.maven.ext.common.model.Project) ManipulationSession(org.commonjava.maven.ext.core.ManipulationSession) Test(org.junit.Test)

Example 22 with Project

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

the class ManipulationManager method scanAndApply.

/**
 * Encapsulates {@link #applyManipulations(List)}
 *
 * @param session the container session for manipulation.
 * @throws ManipulationException if an error occurs.
 */
public void scanAndApply(final ManipulationSession session) throws ManipulationException {
    final List<Project> projects = pomIO.parseProject(session.getPom());
    session.setProjects(projects);
    for (final Project project : projects) {
        logger.debug("Got " + project + " (POM: " + project.getPom() + ")");
    }
    Set<Project> changed = applyManipulations(projects);
    // Create a marker file if we made some changes to prevent duplicate runs.
    if (!changed.isEmpty()) {
        logger.info("Maven-Manipulation-Extension: Rewrite changed: " + projects);
        GAV gav = pomIO.rewritePOMs(changed);
        try {
            final VersioningState state = session.getState(VersioningState.class);
            state.setExecutionRootModified(gav);
            new File(session.getTargetDir().getParentFile(), ManipulationManager.MARKER_PATH).mkdirs();
            new File(session.getTargetDir().getParentFile(), ManipulationManager.MARKER_FILE).createNewFile();
            try (FileWriter writer = new FileWriter(new File(session.getTargetDir().getParentFile(), RESULT_FILE))) {
                writer.write(collectResults(session));
            }
        } catch (IOException e) {
            logger.error("Unable to create marker or result file", e);
            throw new ManipulationException("Marker/result file creation failed", e);
        }
    }
    // Ensure shutdown of GalleyInfrastructure Executor Service
    for (ExtensionInfrastructure e : infrastructure.values()) {
        e.finish();
    }
    logger.info("Maven-Manipulation-Extension: Finished.");
}
Also used : Project(org.commonjava.maven.ext.common.model.Project) ExtensionInfrastructure(org.commonjava.maven.ext.io.resolver.ExtensionInfrastructure) FileWriter(java.io.FileWriter) ManipulationException(org.commonjava.maven.ext.common.ManipulationException) VersioningState(org.commonjava.maven.ext.core.state.VersioningState) IOException(java.io.IOException) GAV(org.commonjava.maven.ext.common.model.GAV) File(java.io.File)

Example 23 with Project

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

the class PropertyResolver method resolveProperties.

/**
 * This recursively checks the supplied value and recursively resolves it if its a property.
 *
 * @param session the current session
 * @param projects set of projects
 * @param value value to check
 * @return the version string
 * @throws ManipulationException if an error occurs
 */
public static String resolveProperties(MavenSessionHandler session, List<Project> projects, String value) throws ManipulationException {
    final Properties amalgamated = new Properties();
    // so therefore there is no need to save the execution root.
    for (Project p : projects) {
        amalgamated.putAll(p.getModel().getProperties());
        amalgamated.putAll(searchProfiles(session, p));
    }
    PropertyInterpolator pi = new PropertyInterpolator(amalgamated, projects.get(0));
    return pi.interp(value);
}
Also used : Project(org.commonjava.maven.ext.common.model.Project) Properties(java.util.Properties)

Example 24 with Project

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

the class PluginManipulator 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 PluginState state = session.getState(PluginState.class);
    if (!session.isEnabled() || !state.isEnabled()) {
        logger.debug(getClass().getSimpleName() + ": Nothing to do!");
        return Collections.emptySet();
    }
    final Set<Project> changed = new HashSet<>();
    final Set<Plugin> mgmtOverrides = loadRemoteBOM(PluginType.RemotePM);
    final Set<Plugin> pluginOverrides = loadRemoteBOM(PluginType.RemoteP);
    for (final Project project : projects) {
        final Model model = project.getModel();
        if (!mgmtOverrides.isEmpty()) {
            apply(project, model, PluginType.RemotePM, mgmtOverrides);
            changed.add(project);
        }
        if (!pluginOverrides.isEmpty()) {
            apply(project, model, PluginType.RemoteP, pluginOverrides);
            changed.add(project);
        }
    }
    // If we've changed something now update any old properties with the new values.
    if (!changed.isEmpty()) {
        logger.info("Iterating for standard overrides...");
        for (Project project : versionPropertyUpdateMap.keySet()) {
            for (final Map.Entry<String, String> entry : versionPropertyUpdateMap.get(project).entrySet()) {
                // Ignore strict alignment for plugins ; if we're attempting to use a differing plugin
                // its unlikely to be an exact match.
                PropertiesUtils.PropertyUpdate found = PropertiesUtils.updateProperties(session, project, true, entry.getKey(), entry.getValue());
                if (found == PropertiesUtils.PropertyUpdate.NOTFOUND) {
                    // Problem in this scenario is that we know we have a property update map but we have not found a
                    // property to update. Its possible this property has been inherited from a parent. Override in the
                    // top pom for safety.
                    logger.info("Unable to find a property for {} to update", entry.getKey());
                    for (final Project p : changed) {
                        if (p.isInheritanceRoot()) {
                            logger.info("Adding property {} with {} ", entry.getKey(), entry.getValue());
                            p.getModel().getProperties().setProperty(entry.getKey(), entry.getValue());
                        }
                    }
                }
            }
        }
    }
    return changed;
}
Also used : PluginState(org.commonjava.maven.ext.core.state.PluginState) Project(org.commonjava.maven.ext.common.model.Project) Model(org.apache.maven.model.Model) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) PropertiesUtils(org.commonjava.maven.ext.core.util.PropertiesUtils) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Plugin(org.apache.maven.model.Plugin)

Example 25 with Project

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

the class RelocationManipulator method applyChanges.

/**
 * Apply the relocation 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(RelocationState.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) PluginState(org.commonjava.maven.ext.core.state.PluginState) State(org.commonjava.maven.ext.core.state.State) RelocationState(org.commonjava.maven.ext.core.state.RelocationState) 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