From 027453d5b16e9c7c3391747d37919e46745db4ac Mon Sep 17 00:00:00 2001 From: Jason van Zyl Date: Tue, 4 Oct 2005 01:37:09 +0000 Subject: [PATCH] o create a new dispatcher on every invocation git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@293482 13f79535-47bb-0310-9956-ffa450edef68 --- maven-embedder/Plugin.java | 2 +- .../apache/maven/embedder/MavenEmbedder.java | 30 +++++++++++++++---- .../maven/embedder/MavenEmbedderTest.java | 12 +++++--- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/maven-embedder/Plugin.java b/maven-embedder/Plugin.java index 766550f7e7..c84e6dad15 100644 --- a/maven-embedder/Plugin.java +++ b/maven-embedder/Plugin.java @@ -38,7 +38,7 @@ public class Plugin System.out.println( "<<<<<<<<<<<<<<<<<<<<<<<<<"); - maven.execute( pom, Collections.singletonList( "package" ), eventMonitor, new ConsoleDownloadMonitor(), targetDirectory ); + maven.execute( pom, Collections.singletonList( "package" ), eventMonitor, new ConsoleDownloadMonitor(), null, targetDirectory ); System.out.println( "<<<<<<<<<<<<<<<<<<<<<<<<<"); } diff --git a/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java b/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java index 5ce5edb78d..d2a304588f 100644 --- a/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java +++ b/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java @@ -70,6 +70,7 @@ import java.util.List; import java.util.ArrayList; import java.util.Iterator; import java.util.Collections; +import java.util.Properties; /** * Class intended to be used by clients who wish to embed Maven into their applications @@ -108,8 +109,6 @@ public class MavenEmbedder private PluginDescriptorBuilder pluginDescriptorBuilder; - private EventDispatcher eventDispatcher; - // ---------------------------------------------------------------------- // Configuration // ---------------------------------------------------------------------- @@ -372,21 +371,25 @@ public class MavenEmbedder List goals, EventMonitor eventMonitor, TransferListener transferListener, + Properties properties, File executionRootDirectory ) throws CycleDetectedException, LifecycleExecutionException, MojoExecutionException { - execute( Collections.singletonList( project ), goals, eventMonitor, transferListener, executionRootDirectory ); + execute( Collections.singletonList( project ), goals, eventMonitor, transferListener, properties, executionRootDirectory ); } public void execute( List projects, List goals, EventMonitor eventMonitor, TransferListener transferListener, + Properties properties, File executionRootDirectory ) throws CycleDetectedException, LifecycleExecutionException, MojoExecutionException { ReactorManager rm = new ReactorManager( projects ); + EventDispatcher eventDispatcher = new DefaultEventDispatcher(); + eventDispatcher.addEventMonitor( eventMonitor ); rm.setFailureBehavior( ReactorManager.FAIL_AT_END ); @@ -406,6 +409,25 @@ public class MavenEmbedder wagonManager.setDownloadMonitor( transferListener ); } + // ---------------------------------------------------------------------- + // Maven should not be using system properties internally but because + // it does for now I'll just take properties that are handed to me + // and set them so that the plugin expression evaluator will work + // as expected. + // ---------------------------------------------------------------------- + + if ( properties != null ) + { + for ( Iterator i = properties.keySet().iterator(); i.hasNext(); ) + { + String key = (String) i.next(); + + String value = properties.getProperty( key ); + + System.setProperty( key, value ); + } + } + MavenExecutionResponse response = lifecycleExecutor.execute( session, rm, session.getEventDispatcher() ); @@ -575,8 +597,6 @@ public class MavenEmbedder pluginDescriptorBuilder = new PluginDescriptorBuilder(); - eventDispatcher = new DefaultEventDispatcher(); - profileManager = new DefaultProfileManager( embedder.getContainer() ); mavenProjectBuilder = (MavenProjectBuilder) embedder.lookup( MavenProjectBuilder.ROLE ); diff --git a/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderTest.java b/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderTest.java index 39916be95a..d7cfe382ba 100644 --- a/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderTest.java +++ b/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderTest.java @@ -8,13 +8,12 @@ import org.apache.maven.monitor.event.DefaultEventMonitor; import org.apache.maven.monitor.event.EventMonitor; import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.logging.Logger; -import org.codehaus.plexus.logging.console.ConsoleLogger; import org.codehaus.plexus.util.FileUtils; import java.io.File; import java.util.Collections; import java.util.List; +import java.util.Properties; import java.util.Set; public class MavenEmbedderTest @@ -71,11 +70,16 @@ public class MavenEmbedderTest File pomFile = new File( targetDirectory, "pom.xml" ); - MavenProject pom = maven.readProjectWithDependencies( pomFile ); + MavenProject pom = maven.readProjectWithDependencies( pomFile ); EventMonitor eventMonitor = new DefaultEventMonitor( new PlexusLoggerAdapter( new MavenEmbedderConsoleLogger() ) ); - maven.execute( pom, Collections.singletonList( "package" ), eventMonitor, new ConsoleDownloadMonitor(), targetDirectory ); + maven.execute( pom, + Collections.singletonList( "package" ), + eventMonitor, + new ConsoleDownloadMonitor(), + null, + targetDirectory ); File jar = new File( targetDirectory, "target/embedder-test-project-1.0-SNAPSHOT.jar" );