From fca0b52ab4ab3d5e1306a72f91df30227cbd554b Mon Sep 17 00:00:00 2001 From: Benjamin Bentmann Date: Tue, 27 Oct 2009 13:32:56 +0000 Subject: [PATCH] o Restored support for IT execution using embedded Maven git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@830178 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/maven/cli/MavenCli.java | 64 ++++++++++++++++--- 1 file changed, 54 insertions(+), 10 deletions(-) diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java index def73a7cd9..f5de33be86 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java @@ -79,6 +79,11 @@ public class MavenCli public static final File DEFAULT_USER_TOOLCHAINS_FILE = new File( userMavenConfigurationHome, "toolchains.xml" ); + private ClassWorld classWorld; + + // Per-instance container supports fast embedded execution of core ITs + private DefaultPlexusContainer container; + private PrintStreamLogger logger; private ModelProcessor modelProcessor; @@ -91,6 +96,17 @@ public class MavenCli private DefaultSecDispatcher dispatcher; + public MavenCli() + { + this( null ); + } + + // This supports painless invocation by the Verifier during embedded execution of the core ITs + public MavenCli( ClassWorld classWorld ) + { + this.classWorld = classWorld; + } + public static void main( String[] args ) { int result = main( args, null ); @@ -112,6 +128,17 @@ public class MavenCli return cli.doMain( new CliRequest( args, classWorld ) ); } + // This supports painless invocation by the Verifier during embedded execution of the core ITs + public int doMain( String[] args, String workingDirectory, PrintStream stdout, PrintStream stderr ) + { + CliRequest cliRequest = new CliRequest( args, classWorld ); + cliRequest.workingDirectory = workingDirectory; + cliRequest.stdout = stdout; + cliRequest.stderr = stderr; + + return doMain( cliRequest ); + } + // TODO: need to externalize CliRequest public int doMain( CliRequest cliRequest ) { @@ -157,8 +184,15 @@ public class MavenCli { cliRequest.stderr = System.err; } - - logger = new PrintStreamLogger( cliRequest.stdout ); + + if ( logger == null ) + { + logger = new PrintStreamLogger( cliRequest.stdout ); + } + else + { + logger.setStream( cliRequest.stdout ); + } if ( cliRequest.workingDirectory == null ) { @@ -295,17 +329,27 @@ public class MavenCli cliRequest.classWorld = new ClassWorld( "plexus.core", Thread.currentThread().getContextClassLoader() ); } - ContainerConfiguration cc = new DefaultContainerConfiguration() - .setClassWorld( cliRequest.classWorld ) - .setName( "maven" ); + DefaultPlexusContainer container = this.container; - DefaultPlexusContainer container = new DefaultPlexusContainer( cc ); + if ( container == null ) + { + ContainerConfiguration cc = new DefaultContainerConfiguration() + .setClassWorld( cliRequest.classWorld ) + .setName( "maven" ); - container.setLoggerManager( new MavenLoggerManager( logger ) ); + container = new DefaultPlexusContainer( cc ); - container.getLoggerManager().setThresholds( cliRequest.request.getLoggingLevel() ); - - customizeContainer( container ); + container.setLoggerManager( new MavenLoggerManager( logger ) ); + + container.getLoggerManager().setThresholds( cliRequest.request.getLoggingLevel() ); + + customizeContainer( container ); + + if ( cliRequest.classWorld == classWorld ) + { + this.container = container; + } + } maven = container.lookup( Maven.class );