Search in sources :

Example 1 with ProfileRemovalState

use of org.commonjava.maven.ext.core.state.ProfileRemovalState 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 2 with ProfileRemovalState

use of org.commonjava.maven.ext.core.state.ProfileRemovalState in project pom-manipulation-ext by release-engineering.

the class ProfileRemovalManipulator method init.

/**
 * Initialize the {@link ProfileRemovalState} state holder in the {@link ManipulationSession}. This state holder detects
 * version-change configuration from the Maven user properties (-D properties from the CLI) and makes it available for
 * later.
 */
@Override
public void init(final ManipulationSession session) {
    this.session = session;
    session.setState(new ProfileRemovalState(session.getUserProperties()));
}
Also used : ProfileRemovalState(org.commonjava.maven.ext.core.state.ProfileRemovalState)

Aggregations

ProfileRemovalState (org.commonjava.maven.ext.core.state.ProfileRemovalState)2 HashSet (java.util.HashSet)1 Model (org.apache.maven.model.Model)1 Profile (org.apache.maven.model.Profile)1 Project (org.commonjava.maven.ext.common.model.Project)1