Search in sources :

Example 1 with ScriptRunner

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);
}
Also used : ScriptRunner(org.apache.maven.shared.scriptinterpreter.ScriptRunner) Artifact(org.apache.maven.artifact.Artifact)

Example 2 with ScriptRunner

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);
    }
}
Also used : DefaultInvocationRequest(org.apache.maven.shared.invoker.DefaultInvocationRequest) InvocationRequest(org.apache.maven.shared.invoker.InvocationRequest) MavenInvocationException(org.apache.maven.shared.invoker.MavenInvocationException) ScriptRunner(org.apache.maven.shared.scriptinterpreter.ScriptRunner) InvocationResult(org.apache.maven.shared.invoker.InvocationResult) LinkedHashMap(java.util.LinkedHashMap) RunFailureException(org.apache.maven.shared.scriptinterpreter.RunFailureException) DefaultInvocationRequest(org.apache.maven.shared.invoker.DefaultInvocationRequest) File(java.io.File)

Aggregations

ScriptRunner (org.apache.maven.shared.scriptinterpreter.ScriptRunner)2 File (java.io.File)1 LinkedHashMap (java.util.LinkedHashMap)1 Artifact (org.apache.maven.artifact.Artifact)1 DefaultInvocationRequest (org.apache.maven.shared.invoker.DefaultInvocationRequest)1 InvocationRequest (org.apache.maven.shared.invoker.InvocationRequest)1 InvocationResult (org.apache.maven.shared.invoker.InvocationResult)1 MavenInvocationException (org.apache.maven.shared.invoker.MavenInvocationException)1 RunFailureException (org.apache.maven.shared.scriptinterpreter.RunFailureException)1