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
This commit is contained in:
Jason van Zyl 2005-10-04 01:37:09 +00:00
parent def783e4cf
commit 027453d5b1
3 changed files with 34 additions and 10 deletions

View File

@ -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( "<<<<<<<<<<<<<<<<<<<<<<<<<");
}

View File

@ -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 );

View File

@ -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" );