Example usage for org.apache.maven.cli MavenCli doMain

List of usage examples for org.apache.maven.cli MavenCli doMain

Introduction

In this page you can find the example usage for org.apache.maven.cli MavenCli doMain.

Prototype

public int doMain(String[] args, String workingDirectory, PrintStream stdout, PrintStream stderr) 

Source Link

Document

This supports painless invocation by the Verifier during embedded execution of the core ITs.

Usage

From source file:org.jboss.forge.maven.facets.MavenCoreFacetImpl.java

License:Open Source License

@Override
public boolean executeMavenEmbedded(final PrintStream out, final PrintStream err, String[] parms) {
    if ((parms == null) || (parms.length == 0)) {
        parms = new String[] { "" };
    }/*from  w w w  .  j  av a2s.  com*/
    MavenCli cli = new MavenCli();
    int i = cli.doMain(parms, project.getProjectRoot().getFullyQualifiedName(), out, err);
    return i == 0;
}

From source file:org.kie.server.integrationtests.shared.KieServerDeployer.java

License:Apache License

public static void buildAndDeployMavenProject(String basedir) {
    // need to backup (and later restore) the current class loader, because the Maven/Plexus does some classloader
    // magic which then results in CNFE in RestEasy client
    // run the Maven build which will create the kjar. The kjar is then either installed or deployed to local and
    // remote repo
    logger.debug("Building and deploying Maven project from basedir '{}'.", basedir);
    ClassLoader classLoaderBak = Thread.currentThread().getContextClassLoader();
    System.setProperty("maven.multiModuleProjectDirectory", basedir); // required by MavenCli 3.3.0+
    MavenCli cli = new MavenCli();
    List<String> mvnArgs;
    if (TestConfig.isLocalServer()) {
        // just install into local repository when running the local server. Deploying to remote repo will fail
        // if the repo does not exist.

        // wrapping explicitly in ArrayList as we may need to update the list later (and Arrays.toList() returns
        // just read-only list)
        mvnArgs = new ArrayList<String>(Arrays.asList("-B", "clean", "install"));
    } else {/*from  w w  w  . j a v  a  2  s  .  co  m*/
        mvnArgs = new ArrayList<String>(Arrays.asList("-B", "-e", "clean", "deploy"));
    }

    // use custom settings.xml file, if one specified
    String kjarsBuildSettingsXml = TestConfig.getKjarsBuildSettingsXml();
    if (kjarsBuildSettingsXml != null && !kjarsBuildSettingsXml.isEmpty()) {
        mvnArgs.add("-s");
        mvnArgs.add(kjarsBuildSettingsXml);
    }
    int mvnRunResult = cli.doMain(mvnArgs.toArray(new String[mvnArgs.size()]), basedir, System.out, System.err);

    Thread.currentThread().setContextClassLoader(classLoaderBak);

    if (mvnRunResult != 0) {
        throw new RuntimeException(
                "Error while building Maven project from basedir " + basedir + ". Return code=" + mvnRunResult);
    }
    logger.debug("Maven project successfully built and deployed!");
}

From source file:org.rapidoid.platform.MavenUtil.java

License:Apache License

public static int build(String basedir, String mavenRepo, List<String> mvnArgs) {
    Log.info("Building Maven project", "location", basedir);

    System.setProperty("maven.repo.local", mavenRepo);
    System.setProperty("request.baseDirectory", basedir);
    System.setProperty("maven.multiModuleProjectDirectory", basedir);

    // make sure the Maven repository folder exists
    new File(mavenRepo).mkdirs();

    MavenCli cli = new MavenCli();
    String[] args = U.arrayOf(String.class, mvnArgs);

    int result = cli.doMain(args, basedir, System.out, System.err);

    if (result != 0) {
        Log.error("The Maven build failed!", "status", result);
    }//from   w  w w .jav a  2  s  .c  o  m

    return result;
}

From source file:org.safaertekin.dailycitrixsynchronizer.MavenUtils.java

License:Open Source License

public void compileDirectory(String directory) {
    MavenCli mavenCli = new MavenCli();
    int result = mavenCli.doMain(new String[] { "compile" }, directory, System.out, System.out);
    System.out.println("result: " + result);
}

From source file:org.testeditor.dsl.common.util.MavenExecutor.java

License:Open Source License

/**
 * Executes the maven build using maven embedder. It allways starts with a
 * clean operation to delete old test results.
 * //  w  ww  .  ja  v a  2s  .  c om
 * @param parameters
 *            for maven (separated by spaces, e.g. "clean integration-test"
 *            to execute the given goals)
 * @param pathToPom
 *            path to the folder where the pom.xml is located.
 * @return int with exit code
 * 
 */
public int execute(String parameters, String pathToPom) {
    System.setProperty("maven.multiModuleProjectDirectory", pathToPom);
    MavenCli cli = new MavenCli();
    List<String> params = new ArrayList<String>();
    params.addAll(Arrays.asList(parameters.split(" ")));
    String mavenSettings = System.getProperty("TE.MAVENSETTINGSPATH");
    if (mavenSettings != null && mavenSettings.length() > 0) {
        params.add("-s");
        params.add(mavenSettings);
    }
    int result = cli.doMain(params.toArray(new String[] {}), pathToPom, System.out, System.err);
    return result;
}

From source file:org.utgenome.shell.Maven.java

License:Apache License

public static int runMaven(String[] args, File workingDir, Properties systemProperties)
        throws UTGBShellException {

    // Preserve the context class loader
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    // preserve the current system properties
    Properties prevSystemProperties = (Properties) System.getProperties().clone();

    try {//w  w  w .  ja  v a  2s . c o m
        // add the hook for killing the Maven process when ctrl+C is pressed
        if (!addedShutdownHook) {
            addedShutdownHook = true;
            Runtime.getRuntime().addShutdownHook(new Thread() {
                @Override
                public void run() {
                    _logger.debug("shutdown hook is called");
                }
            });
        }

        MavenCli maven = new MavenCli();
        if (workingDir == null)
            workingDir = new File(".");

        if (systemProperties != null) {
            // add the user-specified system properties
            for (Object key : systemProperties.keySet()) {
                System.setProperty(key.toString(), systemProperties.get(key).toString());
            }
        }

        int returnCode = maven.doMain(args, workingDir.getPath(), new PrintStream(new StandardOutputStream()),
                new PrintStream(new StandardErrorStream()));

        if (returnCode != 0)
            throw new UTGBShellException("error: " + returnCode);

        return returnCode;

    } catch (Exception e) {
        throw new UTGBShellException(e);
    } finally {
        Thread.currentThread().setContextClassLoader(cl);
        // reset the system properties
        if (prevSystemProperties != null)
            System.setProperties(prevSystemProperties);
    }
}

From source file:wiitty.manager.service.impl.MavenServiceImpl.java

License:Open Source License

/**
 * {@inheritDoc}/*from w  w w .ja  v  a2 s  .c  o m*/
 */
@Override
public Scenario runScenario(int scenarioId) {
    MavenCli cli = new MavenCli();
    cli.doMain(
            new String[] { "clean", "test", "-Dhttp.proxyHost=renn.proxy.corp.sopra", "-Dhttp.proxyPort=8080",
                    "-Dcucumber.options=--tags @2-LoginLogout", "-Dmaven.test.failure.ignore=true",
                    "-PscenarioInitiator,dev,rapid" },
            "C:\\workspaceSALTO\\RAPID\\java", System.out, System.out);
    return null;
}