protected 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(); MavenCli cli = new MavenCli(); 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. mvnArgs = new String[] {"-B", "clean", "install"}; } else { mvnArgs = new String[] {"-B", "clean", "deploy"}; } int mvnRunResult = cli.doMain(mvnArgs, basedir, System.out, System.out); if (mvnRunResult != 0) { throw new RuntimeException( "Error while building Maven project from basedir " + basedir + ". Return code=" + mvnRunResult); } Thread.currentThread().setContextClassLoader(classLoaderBak); logger.debug("Maven project successfully built and deployed!"); }
public boolean executeMavenEmbedded( final PrintStream out, final PrintStream err, String[] parms) { if ((parms == null) || (parms.length == 0)) { parms = new String[] {""}; } MavenCli cli = new MavenCli(); int i = cli.doMain(parms, getFaceted().getRoot().getFullyQualifiedName(), out, err); return i == 0; }
protected String execute(String dir, String... args) throws IOException, InterruptedException { OutputStream outos = null; PrintStream outps = null; OutputStream erros = null; PrintStream errps = null; try { outos = new ByteArrayOutputStream(); outps = new PrintStream(outos); erros = new ByteArrayOutputStream(); errps = new PrintStream(erros); MavenCli cli = new MavenCli(); int code = cli.doMain(args, dir, outps, errps); String out = outos.toString(); String err = erros.toString(); System.out.println("TEST MAVEN EXECUTION START >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); System.out.print("Executing: mvn"); for (String arg : args) { System.out.print(' '); System.out.print(arg); } System.out.println(); System.out.print("Exit code: "); System.out.println(code); System.out.print(out); System.err.print(err); System.out.println("TEST MAVEN EXECUTION END <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"); return out + err; } finally { closeQuietly(errps); closeQuietly(erros); closeQuietly(outps); closeQuietly(outos); } }
// TODO: need to externalize CliRequest public static int doMain(String[] args, ClassWorld classWorld) { MavenCli cli = new MavenCli(); return cli.doMain(new CliRequest(args, classWorld)); }