use of org.commonjava.maven.ext.common.model.Project in project pom-manipulation-ext by release-engineering.
the class RepoAndReportingRemovalManipulator method applyChanges.
/**
* Apply the reporting and repository removal changes to the list of {@link Project}'s given.
*/
@Override
public Set<Project> applyChanges(final List<Project> projects) throws ManipulationException {
final RepoReportingState state = session.getState(RepoReportingState.class);
if (!session.isEnabled() || !state.isEnabled()) {
logger.debug(getClass().getSimpleName() + ": Nothing to do!");
return Collections.emptySet();
}
final Set<Project> changed = new HashSet<>();
Settings backupSettings = new Settings();
Profile backupProfile = new Profile();
backupProfile.setId("removed-by-pme");
backupSettings.addActiveProfile("removed-by-pme");
for (final Project project : projects) {
final String ga = ga(project);
logger.debug("Applying changes to: " + ga);
final Model model = project.getModel();
Iterator<Repository> it = model.getRepositories().iterator();
while (it.hasNext()) {
Repository repository = it.next();
if (removeRepository(state, repository)) {
backupProfile.addRepository(repository);
it.remove();
changed.add(project);
}
}
it = model.getPluginRepositories().iterator();
while (it.hasNext()) {
Repository repository = it.next();
if (removeRepository(state, repository)) {
backupProfile.addPluginRepository(repository);
it.remove();
changed.add(project);
}
}
if (model.getReporting() != null) {
backupProfile.setReporting(model.getReporting());
model.setReporting(null);
changed.add(project);
}
// remove repositories in the profiles as well
final List<Profile> profiles = ProfileUtils.getProfiles(session, model);
for (final Profile profile : profiles) {
Profile repoProfile = new Profile();
repoProfile.setId(profile.getId());
it = profile.getRepositories().iterator();
while (it.hasNext()) {
Repository repository = it.next();
if (removeRepository(state, repository)) {
repoProfile.addRepository(repository);
it.remove();
changed.add(project);
}
}
it = profile.getPluginRepositories().iterator();
while (it.hasNext()) {
Repository repository = it.next();
if (removeRepository(state, repository)) {
repoProfile.addPluginRepository(repository);
it.remove();
changed.add(project);
}
}
if (profile.getReporting() != null) {
repoProfile.setReporting(profile.getReporting());
profile.setReporting(null);
changed.add(project);
}
if (!repoProfile.getRepositories().isEmpty() || !repoProfile.getPluginRepositories().isEmpty() || repoProfile.getReporting() != null) {
backupSettings.addProfile(SettingsUtils.convertToSettingsProfile(repoProfile));
}
}
}
// create new settings file with the removed repositories and reporting
if (!backupProfile.getRepositories().isEmpty() || !backupProfile.getPluginRepositories().isEmpty() || backupProfile.getReporting() != null) {
backupSettings.addProfile(SettingsUtils.convertToSettingsProfile(backupProfile));
String settingsFilePath = state.getRemovalBackupSettings();
if (!isEmpty(settingsFilePath)) {
File settingsFile;
if (settingsFilePath.equals("settings.xml")) {
String topDir = session.getTargetDir().getParentFile().getPath();
settingsFile = new File(topDir, settingsFilePath);
} else {
settingsFile = new File(settingsFilePath);
}
settingsWriter.update(backupSettings, settingsFile);
}
}
return changed;
}
use of org.commonjava.maven.ext.common.model.Project in project pom-manipulation-ext by release-engineering.
the class PropertiesUtilsTest method testUpdateNestedProperties.
@Test
public void testUpdateNestedProperties() throws Exception {
Project pP = getProject();
ManipulationSession session = createUpdateSession();
assertTrue(updateProperties(session, pP, false, "version.hibernate.core", "5.0.4.Final-redhat-1") == PropertiesUtils.PropertyUpdate.FOUND);
assertTrue(updateProperties(session, pP, false, "version.scala", "2.11.7.redhat-1") == PropertiesUtils.PropertyUpdate.FOUND);
try {
updateProperties(session, pP, false, "version.scala", "3.11.7-redhat-1");
} catch (ManipulationException e) {
// Pass.
}
}
use of org.commonjava.maven.ext.common.model.Project in project pom-manipulation-ext by release-engineering.
the class PropertiesUtilsTest method testCacheProperty.
@Test
public void testCacheProperty() throws Exception {
Map<Project, Map<String, String>> propertyMap = new HashMap<>();
CommonState state = new CommonState(new Properties());
Project project = getProject();
assertFalse(PropertiesUtils.cacheProperty(project, state, propertyMap, "${foobar}${foobar2}", null, null, false));
assertFalse(PropertiesUtils.cacheProperty(project, state, propertyMap, "suffix.${foobar}", null, null, false));
assertFalse(PropertiesUtils.cacheProperty(project, state, propertyMap, null, "2.0", null, false));
assertFalse(PropertiesUtils.cacheProperty(project, state, propertyMap, "1.0", "2.0", null, false));
assertTrue(PropertiesUtils.cacheProperty(project, state, propertyMap, "${version.org.jboss}", "2.0", null, false));
assertFalse(PropertiesUtils.cacheProperty(project, state, propertyMap, "${project.version}", "2.0", null, false));
// DependencyManipulator does dependency.getVersion(). This could return e.g. ${version.scala} which can
// refer to <version.scala>${version.scala.major}.7</version.scala>. If we are attempting to change version.scala
// to e.g. 2.11.7.redhat-1 then in this case we need to ignore the version.scala.major property and append the .redhat-1.
// If the property is ${...}.foobar then we only want to append suffix to foobar to change the version
// However we don't need to change the value of the property. If the property is foobar.${....} then
// we want to append suffix to the property ... but we need to handle that part of the property is hardcoded.
assertFalse(PropertiesUtils.cacheProperty(project, state, propertyMap, "${version.scala}.7", "2.0", null, false));
assertFalse(PropertiesUtils.cacheProperty(project, state, propertyMap, "${version.foo}.${version.scala}.7", "2.0", null, false));
try {
PropertiesUtils.cacheProperty(project, state, propertyMap, "${version.scala}.7.${version.scala2}", "2.0", null, false);
} catch (ManipulationException e) {
// Pass.
}
}
use of org.commonjava.maven.ext.common.model.Project in project pom-manipulation-ext by release-engineering.
the class PropertiesUtilsTest method testResolveProperties.
@Test
public void testResolveProperties() throws Exception {
final Model modelChild = TestUtils.resolveModelResource(RESOURCE_BASE, "inherited-properties.pom");
final Model modelParent = TestUtils.resolveModelResource(RESOURCE_BASE, "infinispan-bom-8.2.0.Final.pom");
ManipulationSession session = createUpdateSession();
Project pP = new Project(modelParent);
Project pC = new Project(modelChild);
List<Project> al = new ArrayList<>();
al.add(pC);
al.add(pP);
String result = PropertyResolver.resolveProperties(session, al, "${version.scala.major}.${version.scala.minor}");
assertTrue(result.equals("2.11.7"));
result = PropertyResolver.resolveProperties(session, al, "TestSTART.and.${version.scala.major}.now.${version.scala.minor}");
assertTrue(result.equals("TestSTART.and.2.11.now.7"));
result = PropertyResolver.resolveProperties(session, al, "${project.version}");
assertTrue(result.equals("1"));
}
use of org.commonjava.maven.ext.common.model.Project in project pom-manipulation-ext by release-engineering.
the class PropertiesUtilsTest method testUpdateNestedProperties3.
@Test
public void testUpdateNestedProperties3() throws Exception {
// io.hawt:project:1.4.9
final Model modelParent = TestUtils.resolveModelResource(RESOURCE_BASE, "project-1.4.9.pom");
Project pP = new Project(modelParent);
ManipulationSession session = createUpdateSession();
assertTrue(updateProperties(session, pP, false, "perfectus-build", "610379.redhat-1") == PropertiesUtils.PropertyUpdate.FOUND);
try {
assertTrue(updateProperties(session, pP, false, "perfectus-build", "610.NOTTHEVALUE.redhat-1") == PropertiesUtils.PropertyUpdate.FOUND);
} catch (ManipulationException e) {
e.printStackTrace();
// Pass.
}
try {
assertTrue(updateProperties(session, pP, true, "perfectus-build", "610.NOTTHEVALUE.redhat-1") == PropertiesUtils.PropertyUpdate.FOUND);
} catch (ManipulationException e) {
e.printStackTrace();
// Pass.
}
}
Aggregations