use of org.commonjava.maven.ext.common.model.Project in project pom-manipulation-ext by release-engineering.
the class GroovyManipulator method applyChanges.
/**
* Apply the groovy script changes to the top level pom.
*/
@Override
public Set<Project> applyChanges(final List<Project> projects) throws ManipulationException {
final GroovyState state = session.getState(GroovyState.class);
if (!session.isEnabled() || !state.isEnabled()) {
logger.debug(getClass().getSimpleName() + ": Nothing to do!");
return Collections.emptySet();
}
final Set<Project> changed = new HashSet<>();
for (File groovyScript : parseGroovyScripts(state.getGroovyScripts())) {
GroovyShell shell = new GroovyShell();
Script script;
for (final Project project : projects) {
if (project.isExecutionRoot()) {
logger.info("Executing {} on {}", groovyScript, project);
try {
script = shell.parse(groovyScript);
if (script instanceof BaseScript) {
((BaseScript) script).setValues(session.getUserProperties(), projects, project);
} else {
throw new ManipulationException("Cannot cast " + groovyScript + " to a BaseScript to set values.");
}
} catch (MissingMethodException e) {
try {
logger.debug("Failure when injecting into script {} ", FileUtils.readFileToString(groovyScript), e);
} catch (IOException e1) {
logger.debug("Unable to read script file {} for debugging! {} ", groovyScript, e1);
}
throw new ManipulationException("Unable to inject values into base script", e);
} catch (CompilationFailedException e) {
try {
logger.debug("Failure when parsing script {} ", FileUtils.readFileToString(groovyScript), e);
} catch (IOException e1) {
logger.debug("Unable to read script file {} for debugging! {} ", groovyScript, e1);
}
throw new ManipulationException("Unable to parse script", e);
} catch (IOException e) {
throw new ManipulationException("Unable to parse script", e);
}
try {
script.run();
} catch (Exception e) {
throw new ManipulationException("Unable to parse script", e);
}
changed.add(project);
}
}
}
return changed;
}
use of org.commonjava.maven.ext.common.model.Project 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.commonjava.maven.ext.common.model.Project in project pom-manipulation-ext by release-engineering.
the class PropertyManipulator method applyChanges.
/**
* Apply the property changes to the list of {@link Project}'s given.
*/
@Override
public Set<Project> applyChanges(final List<Project> projects) throws ManipulationException {
final PropertyState state = session.getState(PropertyState.class);
if (!session.isEnabled() || !state.isEnabled()) {
logger.debug(getClass().getSimpleName() + ": Nothing to do!");
return Collections.emptySet();
}
final Properties overrides = loadRemotePOMProperties(state.getRemotePropertyMgmt());
final Set<Project> changed = new HashSet<>();
for (final Project project : projects) {
final Model model = project.getModel();
if (!overrides.isEmpty()) {
// Only inject the new properties at the top level.
if (project.isInheritanceRoot()) {
logger.info("Applying property changes to: " + ga(project) + " with " + overrides);
model.getProperties().putAll(overrides);
changed.add(project);
} else {
// For any matching property that exists in the current project overwrite that value.
@SuppressWarnings({ "unchecked", "rawtypes" }) final Set<String> keyClone = new HashSet(model.getProperties().keySet());
keyClone.retainAll(overrides.keySet());
if (!keyClone.isEmpty()) {
final Iterator<String> keys = keyClone.iterator();
while (keys.hasNext()) {
final String matchingKey = keys.next();
logger.info("Overwriting property (" + matchingKey + " in: " + ga(project) + " with value " + overrides.get(matchingKey));
model.getProperties().put(matchingKey, overrides.get(matchingKey));
changed.add(project);
}
}
}
}
}
return changed;
}
use of org.commonjava.maven.ext.common.model.Project in project pom-manipulation-ext by release-engineering.
the class ProjectInheritanceTest method testVerifyInheritanceMultiple.
@Test
public void testVerifyInheritanceMultiple() throws Exception {
// Locate the PME project pom file. Use that to verify inheritance tracking.
final File projectroot = new File(TestUtils.resolveFileResource(RESOURCE_BASE, "").getParentFile().getParentFile().getParentFile().getParentFile(), "integration-test/src/it/project-inheritance/pom.xml");
PomIO pomIO = new PomIO();
List<Project> projects = pomIO.parseProject(projectroot);
for (int i = 0; i <= 3; i++) {
if (i == 0) {
// First project should be root
assertTrue(projects.get(i).getProjectParent() == null);
assertTrue(projects.get(i).getPom().equals(projectroot));
assertTrue(projects.get(i).getInheritedList().size() == 1);
} else if (i == 1) {
List<Project> inherited = projects.get(i).getInheritedList();
assertTrue(inherited.size() == 2);
assertTrue(inherited.get(1).getProjectParent().getPom().equals(projectroot));
} else if (i == 2) {
List<Project> inherited = projects.get(i).getInheritedList();
assertTrue(inherited.size() == 3);
assertTrue(inherited.get(0).getPom().equals(projectroot));
}
}
}
use of org.commonjava.maven.ext.common.model.Project in project pom-manipulation-ext by release-engineering.
the class ProjectInheritanceTest method testVerifyInheritanceReversedMultiple.
@Test
public void testVerifyInheritanceReversedMultiple() throws Exception {
// Locate the PME project pom file. Use that to verify inheritance tracking.
final File projectroot = new File(TestUtils.resolveFileResource(RESOURCE_BASE, "").getParentFile().getParentFile().getParentFile().getParentFile(), "integration-test/src/it/project-inheritance/pom.xml");
PomIO pomIO = new PomIO();
List<Project> projects = pomIO.parseProject(projectroot);
for (int i = 0; i <= 3; i++) {
if (i == 0) {
// First project should be root
assertTrue(projects.get(i).getProjectParent() == null);
assertTrue(projects.get(i).getPom().equals(projectroot));
assertTrue(projects.get(i).getReverseInheritedList().size() == 1);
} else if (i == 1) {
List<Project> inherited = projects.get(i).getReverseInheritedList();
assertTrue(inherited.size() == 2);
assertTrue(inherited.get(0).getProjectParent().getPom().equals(projectroot));
} else if (i == 2) {
List<Project> inherited = projects.get(i).getReverseInheritedList();
assertTrue(inherited.size() == 3);
assertTrue(inherited.get(2).getPom().equals(projectroot));
}
}
}
Aggregations