use of org.apache.maven.shared.scriptinterpreter.ScriptRunner in project maven-plugins by apache.
the class AbstractInvokerMojo method handleScriptRunnerWithScriptClassPath.
private void handleScriptRunnerWithScriptClassPath() {
final List<String> scriptClassPath;
if (addTestClassPath) {
scriptClassPath = new ArrayList<String>(testClassPath);
for (Artifact pluginArtifact : pluginArtifacts) {
scriptClassPath.remove(pluginArtifact.getFile().getAbsolutePath());
}
} else {
scriptClassPath = null;
}
scriptRunner = new ScriptRunner(getLog());
scriptRunner.setScriptEncoding(encoding);
scriptRunner.setGlobalVariable("localRepositoryPath", localRepositoryPath);
if (scriptVariables != null) {
for (Entry<String, String> entry : scriptVariables.entrySet()) {
scriptRunner.setGlobalVariable(entry.getKey(), entry.getValue());
}
}
scriptRunner.setClassPath(scriptClassPath);
}
use of org.apache.maven.shared.scriptinterpreter.ScriptRunner in project maven-archetype by apache.
the class IntegrationTestMojo method invokePostArchetypeGenerationGoals.
private void invokePostArchetypeGenerationGoals(String goals, File basedir, File goalFile) throws IntegrationTestFailure, IOException, MojoExecutionException {
FileLogger logger = setupLogger(basedir);
if (!StringUtils.isBlank(goals)) {
getLog().info("Invoking post-archetype-generation goals: " + goals);
if (!localRepositoryPath.exists()) {
localRepositoryPath.mkdirs();
}
// @formatter:off
InvocationRequest request = new DefaultInvocationRequest().setBaseDirectory(basedir).setGoals(Arrays.asList(StringUtils.split(goals, ","))).setLocalRepositoryDirectory(localRepositoryPath).setInteractive(false).setShowErrors(true);
// @formatter:on
request.setDebug(debug);
request.setShowVersion(showVersion);
if (logger != null) {
request.setErrorHandler(logger);
request.setOutputHandler(logger);
}
File interpolatedSettingsFile = null;
if (settingsFile != null) {
File interpolatedSettingsDirectory = new File(project.getBuild().getOutputDirectory(), "archetype-it");
if (interpolatedSettingsDirectory.exists()) {
FileUtils.deleteDirectory(interpolatedSettingsDirectory);
}
interpolatedSettingsDirectory.mkdir();
interpolatedSettingsFile = new File(interpolatedSettingsDirectory, "interpolated-" + settingsFile.getName());
buildInterpolatedFile(settingsFile, interpolatedSettingsFile);
request.setUserSettingsFile(interpolatedSettingsFile);
}
try {
InvocationResult result = invoker.execute(request);
getLog().info("Post-archetype-generation invoker exit code: " + result.getExitCode());
if (result.getExitCode() != 0) {
throw new IntegrationTestFailure("Execution failure: exit code = " + result.getExitCode(), result.getExecutionException());
}
} catch (MavenInvocationException e) {
throw new IntegrationTestFailure("Cannot run additions goals.", e);
}
} else {
getLog().info("No post-archetype-generation goals to invoke.");
}
// verify result
ScriptRunner scriptRunner = new ScriptRunner(getLog());
scriptRunner.setScriptEncoding(encoding);
Map<String, Object> context = new LinkedHashMap<String, Object>();
context.put("projectDir", basedir);
try {
scriptRunner.run("post-build script", goalFile.getParentFile(), postBuildHookScript, context, logger, "failure post script", true);
} catch (RunFailureException e) {
throw new IntegrationTestFailure("post build script failure failure: " + e.getMessage(), e);
}
}
Aggregations