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));
}
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations