Search in sources :

Example 1 with ExecutionParser

use of org.commonjava.maven.ext.integrationtest.invoker.ExecutionParser in project pom-manipulation-ext by release-engineering.

the class TestUtils method runLikeInvoker.

/**
 * Run the same/similar execution to what invoker plugin would run.
 *
 * @param workingDir - Working directory where the invoker properties are.
 * @param url The URL to either the REST server that manages versions, or HTTP server for static Groovy scripts or null
 * @throws Exception if an error occurs
 */
public static void runLikeInvoker(String workingDir, String url) throws Exception {
    ExecutionParser executionParser = new DefaultExecutionParser(DefaultExecutionParser.DEFAULT_HANDLERS);
    Collection<Execution> executions = executionParser.parse(workingDir);
    // Execute
    for (Execution e : executions) {
        // Setup
        runScript(workingDir, "setup");
        if (url != null) {
            logger.info("Resetting URL to: {}", url);
            if (url.matches(".*[0-9]+$")) {
                e.getJavaParams().put("restURL", url);
            } else {
                e.getJavaParams().put("groovyScripts", url);
            }
        }
        List<String> args = new ArrayList<>();
        args.add("-s");
        args.add(getDefaultTestLocation("settings.xml"));
        args.add("-d");
        args.add(toFlagsParams(e.getFlags()));
        // Run PME-Cli
        Integer cliExitValue = runCli(args, e.getJavaParams(), e.getLocation());
        logger.info("Returned {} from running {} ", cliExitValue, args);
        // Run Maven
        Map<String, String> mavenParams = new HashMap<>();
        mavenParams.putAll(DEFAULT_MVN_PARAMS);
        mavenParams.putAll(e.getJavaParams());
        Integer mavenExitValue = runMaven(e.getMvnCommand(), mavenParams, e.getLocation());
        // Test return codes
        if (e.isSuccess()) {
            if (cliExitValue != 0) {
                throw new ManipulationException("PME-Cli (running in: " + workingDir + ") exited with a non zero value : " + cliExitValue);
            }
            if (mavenExitValue != 0) {
                throw new ManipulationException("Maven (running in: " + workingDir + ") exited with a non zero value." + mavenExitValue);
            }
        } else {
            if (cliExitValue == 0 && mavenExitValue == 0) {
                throw new ManipulationException("Exit value of either PME-Cli (" + cliExitValue + ") or Maven (" + mavenExitValue + ") (running in: " + workingDir + ") must be non-zero.");
            }
        }
    }
    // Verify
    runScript(workingDir, "verify");
}
Also used : DefaultExecutionParser(org.commonjava.maven.ext.integrationtest.invoker.DefaultExecutionParser) Execution(org.commonjava.maven.ext.integrationtest.invoker.Execution) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ManipulationException(org.commonjava.maven.ext.common.ManipulationException) DefaultExecutionParser(org.commonjava.maven.ext.integrationtest.invoker.DefaultExecutionParser) ExecutionParser(org.commonjava.maven.ext.integrationtest.invoker.ExecutionParser)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ManipulationException (org.commonjava.maven.ext.common.ManipulationException)1 DefaultExecutionParser (org.commonjava.maven.ext.integrationtest.invoker.DefaultExecutionParser)1 Execution (org.commonjava.maven.ext.integrationtest.invoker.Execution)1 ExecutionParser (org.commonjava.maven.ext.integrationtest.invoker.ExecutionParser)1