use of org.commonjava.maven.ext.core.groovy.BaseScript 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;
}
Aggregations