Search in sources :

Example 1 with DependencyRemovalState

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

the class DependencyRemovalManipulator method init.

/**
 * Initialize the {@link DependencyState} 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) {
    session.setState(new DependencyRemovalState(session.getUserProperties()));
    this.session = session;
}
Also used : DependencyRemovalState(org.commonjava.maven.ext.core.state.DependencyRemovalState)

Example 2 with DependencyRemovalState

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

the class DependencyRemovalManipulator method apply.

private boolean apply(final Project project, final Model model) throws ManipulationException {
    final DependencyRemovalState state = session.getState(DependencyRemovalState.class);
    logger.info("Applying Dependency changes to: " + ga(project));
    List<ProjectRef> dependenciesToRemove = state.getDependencyRemoval();
    boolean result = scanDependencies(project.getAllResolvedDependencies(session), dependenciesToRemove, model.getDependencies());
    if (model.getDependencyManagement() != null && scanDependencies(project.getResolvedManagedDependencies(session), dependenciesToRemove, model.getDependencyManagement().getDependencies())) {
        result = true;
    }
    final HashMap<Profile, HashMap<ArtifactRef, Dependency>> pd = project.getAllResolvedProfileDependencies(session);
    final HashMap<Profile, HashMap<ArtifactRef, Dependency>> pmd = project.getResolvedProfileManagedDependencies(session);
    for (Profile profile : pd.keySet()) {
        int index = model.getProfiles().indexOf(profile);
        if (scanDependencies(pd.get(profile), dependenciesToRemove, model.getProfiles().get(index).getDependencies())) {
            result = true;
        }
    }
    for (Profile profile : pmd.keySet()) {
        int index = model.getProfiles().indexOf(profile);
        DependencyManagement dm = model.getProfiles().get(index).getDependencyManagement();
        if (dm != null) {
            if (scanDependencies(pmd.get(profile), dependenciesToRemove, dm.getDependencies())) {
                result = true;
            }
        }
    }
    return result;
}
Also used : DependencyRemovalState(org.commonjava.maven.ext.core.state.DependencyRemovalState) HashMap(java.util.HashMap) ProjectRef(org.commonjava.maven.atlas.ident.ref.ProjectRef) Profile(org.apache.maven.model.Profile) DependencyManagement(org.apache.maven.model.DependencyManagement)

Aggregations

DependencyRemovalState (org.commonjava.maven.ext.core.state.DependencyRemovalState)2 HashMap (java.util.HashMap)1 DependencyManagement (org.apache.maven.model.DependencyManagement)1 Profile (org.apache.maven.model.Profile)1 ProjectRef (org.commonjava.maven.atlas.ident.ref.ProjectRef)1