Search in sources :

Example 11 with Project

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

the class PluginRemovalManipulator method applyChanges.

/**
 * Apply the alignment changes to the list of {@link Project}'s given.
 */
@Override
public Set<Project> applyChanges(final List<Project> projects) {
    final State state = session.getState(PluginRemovalState.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) PluginRemovalState(org.commonjava.maven.ext.core.state.PluginRemovalState) PluginState(org.commonjava.maven.ext.core.state.PluginState) State(org.commonjava.maven.ext.core.state.State) Model(org.apache.maven.model.Model) HashSet(java.util.HashSet)

Example 12 with Project

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

the class ProfileRemovalManipulator method applyChanges.

/**
 * Apply the profile removal changes to all pom files.
 */
@Override
public Set<Project> applyChanges(final List<Project> projects) {
    final ProfileRemovalState state = session.getState(ProfileRemovalState.class);
    if (!session.isEnabled() || !state.isEnabled()) {
        logger.debug(getClass().getSimpleName() + ": Nothing to do!");
        return Collections.emptySet();
    }
    final List<String> profilesToRemove = state.getProfileRemoval();
    final Set<Project> changed = new HashSet<>();
    for (final Project project : projects) {
        final String ga = ga(project);
        logger.info("Applying changes to: " + ga);
        final Model model = project.getModel();
        final List<Profile> profiles = model.getProfiles();
        Iterator<Profile> i = profiles.iterator();
        while (i.hasNext()) {
            Profile p = i.next();
            for (String id : profilesToRemove) {
                if (p.getId().equals(id)) {
                    logger.debug("Removing profile {}", p.getId());
                    i.remove();
                    break;
                }
            }
        }
    }
    return changed;
}
Also used : Project(org.commonjava.maven.ext.common.model.Project) ProfileRemovalState(org.commonjava.maven.ext.core.state.ProfileRemovalState) Model(org.apache.maven.model.Model) Profile(org.apache.maven.model.Profile) HashSet(java.util.HashSet)

Example 13 with Project

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

the class ProjectVersioningManipulator method applyChanges.

/**
 * Apply any project versioning changes accumulated in the {@link VersioningState} instance associated with the {@link ManipulationSession} to
 * the list of {@link Project}'s given. This happens near the end of the Maven session-bootstrapping sequence, before the projects are
 * discovered/read by the main Maven build initialization.
 */
@Override
public Set<Project> applyChanges(final List<Project> projects) throws ManipulationException {
    final VersioningState state = session.getState(VersioningState.class);
    if (!session.isEnabled() || state == null || !state.isEnabled()) {
        logger.debug(getClass().getSimpleName() + ": Nothing to do!");
        return Collections.emptySet();
    }
    /*
         * Use the {@link VersionCalculator} to calculate any project version changes, and store them in the {@link VersioningState} that was associated
         * with the {@link ManipulationSession} via the {@link ProjectVersioningManipulator#init(ManipulationSession)}
         */
    logger.info("Version Manipulator: Calculating the necessary versioning changes.");
    state.setVersionsByGAVMap(calculator.calculateVersioningChanges(projects, session));
    final Set<Project> changed = new HashSet<>();
    for (final Project project : projects) {
        if (applyVersioningChanges(project, state)) {
            changed.add(project);
        }
    }
    return changed;
}
Also used : Project(org.commonjava.maven.ext.common.model.Project) VersioningState(org.commonjava.maven.ext.core.state.VersioningState) HashSet(java.util.HashSet)

Example 14 with Project

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

the class RESTCollector method establishAllDependencies.

/**
 * Scans a list of projects and accumulates all dependencies and returns them.
 *
 * @param session the ManipulationSession
 * @param projects the projects to scan.
 * @param activeProfiles which profiles to check
 * @return an unsorted set of ArtifactRefs used.
 * @throws ManipulationException if an error occurs
 */
public static Set<ArtifactRef> establishAllDependencies(ManipulationSession session, final List<Project> projects, Set<String> activeProfiles) throws ManipulationException {
    Set<ArtifactRef> localDeps = new TreeSet<>();
    Set<String> activeModules = new HashSet<>();
    boolean scanAll = false;
    if (activeProfiles != null && !activeProfiles.isEmpty()) {
        for (final Project project : projects) {
            if (project.isInheritanceRoot()) {
                activeModules.addAll(project.getModel().getModules());
                List<Profile> profiles = project.getModel().getProfiles();
                if (profiles != null) {
                    for (Profile p : profiles) {
                        if (activeProfiles.contains(p.getId())) {
                            logger.debug("Adding modules for profile {}", p.getId());
                            activeModules.addAll(p.getModules());
                        }
                    }
                }
            }
        }
        logger.debug("Found {} active modules with {} active profiles.", activeModules, activeProfiles);
    } else {
        scanAll = true;
    }
    // Iterate over current project set and populate list of dependencies
    for (final Project project : projects) {
        if (project.isInheritanceRoot() || scanAll || activeModules.contains(project.getPom().getParentFile().getName())) {
            if (project.getModelParent() != null) {
                SimpleProjectVersionRef parent = new SimpleProjectVersionRef(project.getModelParent().getGroupId(), project.getModelParent().getArtifactId(), project.getModelParent().getVersion());
                localDeps.add(new SimpleArtifactRef(parent, new SimpleTypeAndClassifier("pom", null)));
            }
            recordDependencies(session, project, localDeps, project.getResolvedManagedDependencies(session));
            recordDependencies(session, project, localDeps, project.getResolvedDependencies(session));
            recordPlugins(localDeps, project.getResolvedManagedPlugins(session));
            recordPlugins(localDeps, project.getResolvedPlugins(session));
            List<Profile> profiles = project.getModel().getProfiles();
            if (profiles != null) {
                for (Profile p : profiles) {
                    if (!scanAll && !activeProfiles.contains(p.getId())) {
                        continue;
                    }
                    recordDependencies(session, project, localDeps, project.getResolvedProfileManagedDependencies(session).get(p));
                    recordDependencies(session, project, localDeps, project.getResolvedProfileDependencies(session).get(p));
                    recordPlugins(localDeps, project.getResolvedProfileManagedPlugins(session).get(p));
                    recordPlugins(localDeps, project.getResolvedProfilePlugins(session).get(p));
                }
            }
        }
    }
    return localDeps;
}
Also used : SimpleArtifactRef(org.commonjava.maven.atlas.ident.ref.SimpleArtifactRef) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) Profile(org.apache.maven.model.Profile) ArtifactRef(org.commonjava.maven.atlas.ident.ref.ArtifactRef) SimpleScopedArtifactRef(org.commonjava.maven.ext.common.model.SimpleScopedArtifactRef) SimpleArtifactRef(org.commonjava.maven.atlas.ident.ref.SimpleArtifactRef) Project(org.commonjava.maven.ext.common.model.Project) TreeSet(java.util.TreeSet) SimpleTypeAndClassifier(org.commonjava.maven.atlas.ident.ref.SimpleTypeAndClassifier) HashSet(java.util.HashSet)

Example 15 with Project

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

the class RESTCollector method parseVersions.

/**
 * Parse the rest result for the project GAs and store them in versioning state for use
 * there by incremental suffix calculation.
 */
private Map<ProjectRef, Set<String>> parseVersions(ManipulationSession session, List<Project> projects, RESTState state, ArrayList<ProjectVersionRef> newProjectKeys, Map<ProjectVersionRef, String> restResult) throws ManipulationException {
    Map<ProjectRef, Set<String>> versionStates = new HashMap<>();
    for (final ProjectVersionRef p : newProjectKeys) {
        if (restResult.containsKey(p)) {
            // Found part of the current project to store in Versioning State
            Set<String> versions = versionStates.get(p.asProjectRef());
            if (versions == null) {
                versions = new HashSet<>();
                versionStates.put(p.asProjectRef(), versions);
            }
            versions.add(restResult.get(p));
        }
    }
    logger.debug("Added the following ProjectRef:Version from REST call into VersionState {}", versionStates);
    // We know we have ProjectVersionRef(s) of the current project(s). We need to establish potential
    // blacklist by calling
    // GET /listings/blacklist/ga?groupid=GROUP_ID&artifactid=ARTIFACT_ID
    // passing in the groupId and artifactId.
    // From the results we then need to establish whether the community version occurs in the blacklist
    // causing a total abort and whether any redhat versions occur in the blacklist. If they do, that will
    // affect the incremental potential options. The simplest option is simply to add those results to versionStates
    // list. This will cause the incremental build number to be set to greater than those.
    List<ProjectVersionRef> blacklist;
    for (Project p : projects) {
        if (p.isExecutionRoot()) {
            logger.debug("Calling REST client for blacklist with {}...", p.getKey().asProjectRef());
            blacklist = state.getVersionTranslator().findBlacklisted(p.getKey().asProjectRef());
            if (blacklist.size() > 0) {
                String suffix = PropertiesUtils.getSuffix(session);
                String bVersion = blacklist.get(0).getVersionString();
                String pVersion = p.getVersion();
                logger.debug("REST Client returned for blacklist {} ", blacklist);
                if (isEmpty(suffix)) {
                    logger.warn("No version suffix found ; unable to verify community blacklisting.");
                } else if (blacklist.size() == 1 && !bVersion.contains(suffix)) {
                    if (pVersion.contains(suffix)) {
                        pVersion = pVersion.substring(0, pVersion.indexOf(suffix) - 1);
                    }
                    if (pVersion.equals(bVersion)) {
                        throw new ManipulationException("community artifact '" + blacklist.get(0) + "' has been blacklisted. Unable to build project version " + p.getVersion());
                    }
                }
                // Found part of the current project to store in Versioning State
                Set<String> versions = versionStates.get(p.getKey().asProjectRef());
                if (versions == null) {
                    versions = new HashSet<>();
                    versionStates.put(p.getKey().asProjectRef(), versions);
                }
                for (ProjectVersionRef b : blacklist) {
                    versions.add(b.getVersionString());
                }
            }
            break;
        }
    }
    return versionStates;
}
Also used : Project(org.commonjava.maven.ext.common.model.Project) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) ManipulationException(org.commonjava.maven.ext.common.ManipulationException) ProjectRef(org.commonjava.maven.atlas.ident.ref.ProjectRef)

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