Search in sources :

Example 36 with Profile

use of org.apache.maven.model.Profile in project pom-manipulation-ext by release-engineering.

the class ProjectVersionManipulatorTest method updateEffectiveAndOriginalModelDependencyVersions_OnlyWhenHasVersion_InProfile.

@Test
public void updateEffectiveAndOriginalModelDependencyVersions_OnlyWhenHasVersion_InProfile() throws Exception {
    final Model orig = new Model();
    orig.setGroupId("org.foo");
    orig.setArtifactId("bar");
    orig.setVersion("1.0");
    final Model depModel = new Model();
    depModel.setGroupId("org.foo");
    depModel.setArtifactId("bar-dep");
    depModel.setVersion("1.0");
    final Dependency dep = new Dependency();
    dep.setGroupId(depModel.getGroupId());
    dep.setArtifactId(depModel.getArtifactId());
    final Profile p = new Profile();
    p.setId("test");
    orig.addProfile(p);
    p.addDependency(dep);
    final DependencyManagement mgmt = new DependencyManagement();
    final Dependency managed = new Dependency();
    managed.setGroupId(depModel.getGroupId());
    managed.setArtifactId(depModel.getArtifactId());
    managed.setVersion(depModel.getVersion());
    mgmt.addDependency(managed);
    p.setDependencyManagement(mgmt);
    final String suff = "redhat-1";
    final String mv = orig.getVersion() + "." + suff;
    final Map<ProjectVersionRef, String> versionsByGA = new HashMap<>();
    versionsByGA.put(new SimpleProjectVersionRef(orig.getGroupId(), orig.getArtifactId(), orig.getVersion()), mv);
    versionsByGA.put(new SimpleProjectVersionRef(depModel.getGroupId(), depModel.getArtifactId(), depModel.getVersion()), mv);
    final List<MavenProject> projects = new ArrayList<>();
    MavenProject project = new MavenProject(depModel.clone());
    project.setOriginalModel(depModel);
    projects.add(project);
    project = new MavenProject(orig.clone());
    project.setOriginalModel(orig);
    projects.add(project);
    final Set<MavenProject> changes = newVersioningModifier().applyVersioningChanges(projects, versionsByGA);
    assertThat(changes.size(), equalTo(2));
    for (final MavenProject proj : changes) {
        final String a = proj.getArtifactId();
        if (a.equals("bar")) {
            assertThat(proj.getOriginalModel().getVersion(), equalTo(mv));
            assertThat(proj.getModel().getVersion(), equalTo(mv));
            final Profile op = proj.getOriginalModel().getProfiles().get(0);
            final Profile ep = proj.getModel().getProfiles().get(0);
            List<Dependency> deps = op.getDependencies();
            assertThat(deps.size(), equalTo(1));
            Dependency d = deps.get(0);
            assertThat(d, notNullValue());
            assertThat(d.getVersion(), nullValue());
            deps = ep.getDependencies();
            assertThat(deps.size(), equalTo(1));
            d = deps.get(0);
            assertThat(d, notNullValue());
            assertThat(d.getVersion(), nullValue());
            deps = op.getDependencyManagement().getDependencies();
            assertThat(deps.size(), equalTo(1));
            d = deps.get(0);
            assertThat(d, notNullValue());
            assertThat(d.getVersion(), equalTo(mv));
            deps = ep.getDependencyManagement().getDependencies();
            assertThat(deps.size(), equalTo(1));
            d = deps.get(0);
            assertThat(d, notNullValue());
            assertThat(d.getVersion(), equalTo(mv));
        } else {
            assertThat(proj.getOriginalModel().getVersion(), equalTo(mv));
            assertThat(proj.getModel().getVersion(), equalTo(mv));
        }
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Dependency(org.apache.maven.model.Dependency) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) Profile(org.apache.maven.model.Profile) MavenProject(org.apache.maven.project.MavenProject) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) Model(org.apache.maven.model.Model) DependencyManagement(org.apache.maven.model.DependencyManagement) Test(org.junit.Test)

Example 37 with Profile

use of org.apache.maven.model.Profile 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)

Example 38 with Profile

use of org.apache.maven.model.Profile in project pom-manipulation-ext by release-engineering.

the class ProfileInjectionManipulator method applyChanges.

/**
 * Apply the profile injection changes to the top level pom.
 */
@Override
public Set<Project> applyChanges(final List<Project> projects) throws ManipulationException {
    final ProfileInjectionState state = session.getState(ProfileInjectionState.class);
    if (!session.isEnabled() || !state.isEnabled()) {
        logger.debug(getClass().getSimpleName() + ": Nothing to do!");
        return Collections.emptySet();
    }
    final Set<Project> changed = new HashSet<>();
    final Model remoteModel = modelBuilder.resolveRawModel(state.getRemoteProfileInjectionMgmt());
    final List<Profile> remoteProfiles = remoteModel.getProfiles();
    for (final Project project : projects) {
        if (project.isInheritanceRoot()) {
            logger.info("Applying changes to: {} ", ga(project));
            project.updateProfiles(remoteProfiles);
            changed.add(project);
            break;
        }
    }
    return changed;
}
Also used : Project(org.commonjava.maven.ext.common.model.Project) Model(org.apache.maven.model.Model) ProfileInjectionState(org.commonjava.maven.ext.core.state.ProfileInjectionState) Profile(org.apache.maven.model.Profile) HashSet(java.util.HashSet)

Example 39 with Profile

use of org.apache.maven.model.Profile in project tesb-studio-se by Talend.

the class CreateMavenBundlePom method addProfileForCloud.

/**
 * skip depoly phase in publich to cloud in parent pom, enable in nexus.
 */
private Profile addProfileForCloud() {
    Profile deployCloudProfile = new Profile();
    deployCloudProfile.setId("deploy-cloud");
    Activation deployCloudActivation = new Activation();
    ActivationProperty activationProperty = new ActivationProperty();
    activationProperty.setName("!altDeploymentRepository");
    deployCloudActivation.setProperty(activationProperty);
    deployCloudProfile.setActivation(deployCloudActivation);
    deployCloudProfile.setBuild(new Build());
    deployCloudProfile.getBuild().addPlugin(addSkipDeployFeatureMavenPlugin());
    return deployCloudProfile;
}
Also used : Build(org.apache.maven.model.Build) Activation(org.apache.maven.model.Activation) ActivationProperty(org.apache.maven.model.ActivationProperty) Profile(org.apache.maven.model.Profile)

Example 40 with Profile

use of org.apache.maven.model.Profile in project tesb-studio-se by Talend.

the class CreateMavenDataServicePom method addProfileForCloud.

/**
 * DOC skip depoly phase in publich to cloud in parent pom, enable in nexus.
 */
private Profile addProfileForCloud() {
    Profile deployCloudProfile = new Profile();
    deployCloudProfile.setId("deploy-cloud");
    Activation deployCloudActivation = new Activation();
    ActivationProperty activationProperty = new ActivationProperty();
    activationProperty.setName("!altDeploymentRepository");
    deployCloudActivation.setProperty(activationProperty);
    deployCloudProfile.setActivation(deployCloudActivation);
    deployCloudProfile.setBuild(new Build());
    deployCloudProfile.getBuild().addPlugin(addSkipDeployFeatureMavenPlugin());
    return deployCloudProfile;
}
Also used : Build(org.apache.maven.model.Build) Activation(org.apache.maven.model.Activation) ActivationProperty(org.apache.maven.model.ActivationProperty) Profile(org.apache.maven.model.Profile)

Aggregations

Profile (org.apache.maven.model.Profile)52 HashMap (java.util.HashMap)12 Model (org.apache.maven.model.Model)12 ArrayList (java.util.ArrayList)9 Dependency (org.apache.maven.model.Dependency)8 HashSet (java.util.HashSet)7 DependencyManagement (org.apache.maven.model.DependencyManagement)7 File (java.io.File)6 Activation (org.apache.maven.model.Activation)6 MavenProject (org.apache.maven.project.MavenProject)6 Project (org.commonjava.maven.ext.common.model.Project)6 Build (org.apache.maven.model.Build)5 ArtifactRef (org.commonjava.maven.atlas.ident.ref.ArtifactRef)5 ProjectVersionRef (org.commonjava.maven.atlas.ident.ref.ProjectVersionRef)5 SimpleArtifactRef (org.commonjava.maven.atlas.ident.ref.SimpleArtifactRef)5 SimpleProjectVersionRef (org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef)5 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)4 ArtifactCoordinates (com.itemis.maven.aether.ArtifactCoordinates)3 IOException (java.io.IOException)3 Iterator (java.util.Iterator)3