use of org.commonjava.maven.ext.core.state.GroovyState 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.core.state.GroovyState in project pom-manipulation-ext by release-engineering.
the class GroovyManipulator method init.
/**
* Initialize the {@link GroovyState} state holder in the {@link ManipulationSession}. This state holder detects
* version-change configuration from the Maven user properties (-D properties from the CLI) and makes it available for
* later.
*/
@Override
public void init(final ManipulationSession session) {
GroovyState gs = new GroovyState(session.getUserProperties());
this.session = session;
this.executionIndex = gs.getExecutionIndex();
session.setState(gs);
}
Aggregations