Search in sources :

Example 1 with ExtensionInfrastructure

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

the class ManipulationManager method init.

/**
 * Initialize {@link ManipulationSession} using the given {@link MavenSession} instance, along with any state managed by the individual
 * {@link Manipulator} components.
 *
 * @param session the container session for manipulation.
 * @throws ManipulationException if an error occurs.
 */
public void init(final ManipulationSession session) throws ManipulationException {
    logger.debug("Initialising ManipulationManager with user properties {}", session.getUserProperties());
    for (final ExtensionInfrastructure infra : infrastructure.values()) {
        infra.init(session.getTargetDir(), session.getRemoteRepositories(), session.getLocalRepository(), session.getSettings(), session.getActiveProfiles());
    }
    orderedManipulators = new ArrayList<>(manipulators.values());
    // The RESTState depends upon the VersionState being initialised. Therefore initialise in reverse order
    // and do a final sort to run in the correct order. See the Manipulator interface for detailed discussion
    // on ordered.
    Collections.sort(orderedManipulators, Collections.reverseOrder(new ManipulatorPriorityComparator()));
    for (final Manipulator manipulator : orderedManipulators) {
        logger.debug("Initialising manipulator " + manipulator.getClass().getSimpleName());
        manipulator.init(session);
    }
    Collections.sort(orderedManipulators, new ManipulatorPriorityComparator());
    // Now init the common state
    session.setState(new CommonState(session.getUserProperties()));
}
Also used : CommonState(org.commonjava.maven.ext.core.state.CommonState) ExtensionInfrastructure(org.commonjava.maven.ext.io.resolver.ExtensionInfrastructure) ManipulatorPriorityComparator(org.commonjava.maven.ext.core.util.ManipulatorPriorityComparator) Manipulator(org.commonjava.maven.ext.core.impl.Manipulator)

Example 2 with ExtensionInfrastructure

use of org.commonjava.maven.ext.io.resolver.ExtensionInfrastructure 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)

Aggregations

ExtensionInfrastructure (org.commonjava.maven.ext.io.resolver.ExtensionInfrastructure)2 File (java.io.File)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 ManipulationException (org.commonjava.maven.ext.common.ManipulationException)1 GAV (org.commonjava.maven.ext.common.model.GAV)1 Project (org.commonjava.maven.ext.common.model.Project)1 Manipulator (org.commonjava.maven.ext.core.impl.Manipulator)1 CommonState (org.commonjava.maven.ext.core.state.CommonState)1 VersioningState (org.commonjava.maven.ext.core.state.VersioningState)1 ManipulatorPriorityComparator (org.commonjava.maven.ext.core.util.ManipulatorPriorityComparator)1