This commit is contained in:
Jason van Zyl 2008-08-24 23:24:41 +00:00
parent 4cb42c34a7
commit 2a94051f54
13 changed files with 1 additions and 431 deletions

View File

@ -22,7 +22,6 @@ package org.apache.maven.execution;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.errors.CoreErrorReporter;
import org.apache.maven.monitor.event.EventMonitor;
import org.apache.maven.monitor.event.MavenWorkspaceMonitor;
import org.apache.maven.profiles.ProfileManager;
import org.apache.maven.profiles.activation.ProfileActivationContext;
import org.apache.maven.project.DefaultProjectBuilderConfiguration;
@ -102,8 +101,6 @@ public class DefaultMavenExecutionRequest
private List eventMonitors;
private MavenWorkspaceMonitor workspaceMonitor;
private List activeProfiles;
private List inactiveProfiles;
@ -712,17 +709,6 @@ public class DefaultMavenExecutionRequest
return this;
}
public MavenWorkspaceMonitor getWorkspaceMonitor()
{
return workspaceMonitor;
}
public MavenExecutionRequest setWorkspaceMonitor( MavenWorkspaceMonitor workspaceMonitor )
{
this.workspaceMonitor = workspaceMonitor;
return this;
}
public Properties getUserProperties()
{
return userProperties;

View File

@ -23,7 +23,6 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
import org.apache.maven.errors.CoreErrorReporter;
import org.apache.maven.monitor.event.EventMonitor;
import org.apache.maven.monitor.event.MavenWorkspaceMonitor;
import org.apache.maven.profiles.ProfileManager;
import org.apache.maven.profiles.activation.ProfileActivationContext;
import org.apache.maven.project.ProjectBuilderConfiguration;
@ -222,8 +221,5 @@ public interface MavenExecutionRequest
MavenExecutionRequest setErrorReporter( CoreErrorReporter reporter );
CoreErrorReporter getErrorReporter();
MavenExecutionRequest setWorkspaceMonitor( MavenWorkspaceMonitor workspaceMonitor );
MavenWorkspaceMonitor getWorkspaceMonitor();
ProjectBuilderConfiguration getProjectBuildingConfiguration();
}

View File

@ -1,25 +0,0 @@
package org.apache.maven.monitor.event;
import org.apache.maven.workspace.MavenWorkspaceStore;
public abstract class AbstractWorkspaceMonitor
extends AbstractEmbedderLifecycleMonitor
implements MavenWorkspaceMonitor
{
private MavenWorkspaceStore workspaceManager;
public void setWorkspaceStore( MavenWorkspaceStore workspaceManager )
{
this.workspaceManager = workspaceManager;
}
/* (non-Javadoc)
* @see org.apache.maven.embedder.lifecycle.MavenWorkspaceMonitor#clearCache()
*/
public void clearCache()
{
workspaceManager.clear();
}
}

View File

@ -1,13 +0,0 @@
package org.apache.maven.monitor.event;
import org.apache.maven.workspace.MavenWorkspaceStore;
public interface MavenWorkspaceMonitor
extends EventMonitor
{
void setWorkspaceStore( MavenWorkspaceStore workspaceStore );
void clearCache();
}

View File

@ -1,12 +0,0 @@
package org.apache.maven.monitor.event;
public class OnStopWorkspaceMonitor
extends AbstractWorkspaceMonitor
{
public void embedderStopped( long timestamp )
{
clearCache();
}
}

View File

@ -1,23 +0,0 @@
package org.apache.maven.monitor.event;
public class PerCallWorkspaceMonitor
extends AbstractWorkspaceMonitor
{
public void embedderMethodEnded( String method,
long timestamp )
{
clearCache();
}
// Be double-sure that the cache is cleared when the embedder stops.
public void embedderStopped( long timestamp )
{
clearCache();
}
}

View File

@ -20,7 +20,6 @@ package org.apache.maven.embedder;
import org.apache.maven.errors.CoreErrorReporter;
import org.apache.maven.monitor.event.EventMonitor;
import org.apache.maven.monitor.event.MavenWorkspaceMonitor;
import org.apache.maven.realm.MavenRealmManager;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.classworlds.ClassWorld;
@ -152,8 +151,4 @@ public interface Configuration
Configuration setEventMonitors( List eventMonitors );
List getEventMonitors();
Configuration setWorkspaceMonitor( MavenWorkspaceMonitor workspaceMonitor );
MavenWorkspaceMonitor getWorkspaceMonitor();
}

View File

@ -20,7 +20,6 @@ package org.apache.maven.embedder;
import org.apache.maven.errors.CoreErrorReporter;
import org.apache.maven.monitor.event.EventMonitor;
import org.apache.maven.monitor.event.MavenWorkspaceMonitor;
import org.apache.maven.realm.MavenRealmManager;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.classworlds.ClassWorld;
@ -69,8 +68,6 @@ public class DefaultConfiguration
/** List<EventMonitor>. */
private List eventMonitors;
private MavenWorkspaceMonitor workspaceMonitor;
/** Creates a new instance of DefaultConfiguration */
public DefaultConfiguration()
{
@ -276,15 +273,4 @@ public class DefaultConfiguration
this.eventMonitors = eventMonitors;
return this;
}
public MavenWorkspaceMonitor getWorkspaceMonitor()
{
return workspaceMonitor;
}
public Configuration setWorkspaceMonitor( MavenWorkspaceMonitor workspaceMonitor )
{
this.workspaceMonitor = workspaceMonitor;
return this;
}
}

View File

@ -167,9 +167,6 @@ public class MavenEmbedder
private BuildPlanner buildPlanner;
// TODO: Remove this once we have better control over cache-cleaning.
private MavenWorkspaceStore workspaceStore;
// ----------------------------------------------------------------------
// Configuration
// ----------------------------------------------------------------------
@ -203,11 +200,6 @@ public class MavenEmbedder
return request;
}
protected MavenWorkspaceStore getWorkspaceStore()
{
return workspaceStore;
}
// ----------------------------------------------------------------------
// Accessors
// ----------------------------------------------------------------------
@ -710,8 +702,6 @@ public class MavenEmbedder
buildPlanner = (BuildPlanner) container.lookup( BuildPlanner.class );
workspaceStore = (MavenWorkspaceStore) container.lookup( MavenWorkspaceStore.class );
artifactHandlerManager = (ArtifactHandlerManager) container.lookup( ArtifactHandlerManager.ROLE );
// This is temporary as we can probably cache a single request and use it for default values and

View File

@ -34,8 +34,6 @@ import org.apache.maven.model.Profile;
import org.apache.maven.model.Repository;
import org.apache.maven.monitor.event.DefaultEventMonitor;
import org.apache.maven.monitor.event.EventMonitor;
import org.apache.maven.monitor.event.MavenWorkspaceMonitor;
import org.apache.maven.monitor.event.PerCallWorkspaceMonitor;
import org.apache.maven.plugin.Mojo;
import org.apache.maven.profiles.DefaultProfileManager;
import org.apache.maven.profiles.ProfileManager;
@ -96,8 +94,6 @@ public class DefaultMavenExecutionRequestPopulator
private WagonManager wagonManager;
private MavenWorkspaceStore workspaceManager;
private MavenSettingsBuilder settingsBuilder;
public MavenExecutionRequest populateDefaults( MavenExecutionRequest request,
@ -106,8 +102,6 @@ public class DefaultMavenExecutionRequestPopulator
{
eventing( request, configuration );
workspaceMonitor( request, configuration );
reporter( request, configuration );
executionProperties( request, configuration );
@ -136,44 +130,6 @@ public class DefaultMavenExecutionRequestPopulator
return request;
}
private void workspaceMonitor( MavenExecutionRequest request,
Configuration configuration )
{
MavenWorkspaceMonitor workspaceMonitor = request.getWorkspaceMonitor();
if ( workspaceMonitor == null )
{
workspaceMonitor = configuration.getWorkspaceMonitor();
}
List requestEventMonitors = request.getEventMonitors();
if ( ( requestEventMonitors != null ) && !requestEventMonitors.isEmpty() )
{
for ( Iterator it = requestEventMonitors.iterator(); it.hasNext(); )
{
Object monitor = it.next();
if ( monitor instanceof MavenWorkspaceMonitor )
{
if ( workspaceMonitor == null )
{
workspaceMonitor = (MavenWorkspaceMonitor) monitor;
}
it.remove();
break;
}
}
}
if ( workspaceMonitor == null )
{
workspaceMonitor = new PerCallWorkspaceMonitor();
}
workspaceMonitor.setWorkspaceStore( workspaceManager );
request.addEventMonitor( workspaceMonitor );
}
private void reporter( MavenExecutionRequest request,
Configuration configuration )
{

View File

@ -23,9 +23,6 @@ under the License.
<role>org.apache.maven.embedder.execution.MavenExecutionRequestPopulator</role>
<implementation>org.apache.maven.embedder.execution.DefaultMavenExecutionRequestPopulator</implementation>
<requirements>
<requirement>
<role>org.apache.maven.workspace.MavenWorkspaceStore</role>
</requirement>
<requirement>
<role>org.apache.maven.artifact.manager.WagonManager</role>
<role-hint>default</role-hint>
@ -75,6 +72,5 @@ under the License.
</httpHeaders>
</configuration>
</component>
</components>
</component-set>

View File

@ -1,261 +0,0 @@
package org.apache.maven.embedder;
import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.extension.ExtensionScanningException;
import org.apache.maven.monitor.event.AbstractWorkspaceMonitor;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.reactor.MavenExecutionException;
import org.apache.maven.workspace.MavenWorkspaceStore;
import org.codehaus.plexus.util.FileUtils;
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import junit.framework.TestCase;
public class MavenEmbedderEventingTest
extends TestCase
{
protected String basedir;
protected void setUp()
throws Exception
{
super.setUp();
basedir = System.getProperty( "basedir" );
if ( basedir == null )
{
basedir = new File( "." ).getCanonicalPath();
}
}
public void testEmbedderInitializeAndStopEventsFired()
throws MavenEmbedderException
{
TestWorkspaceMonitor testWSMonitor = new TestWorkspaceMonitor();
Configuration config = new DefaultConfiguration();
config.setWorkspaceMonitor( testWSMonitor );
assertEquals( 0, testWSMonitor.initializeCaught );
assertEquals( 0, testWSMonitor.setManagerCaught );
MavenEmbedder embedder = new MavenEmbedder( config );
assertEquals( 1, testWSMonitor.initializeCaught );
assertEquals( 1, testWSMonitor.setManagerCaught );
assertEquals( 0, testWSMonitor.stopCaught );
assertEquals( 0, testWSMonitor.clearCaught );
assertSame( embedder.getWorkspaceStore(), testWSMonitor.workspaceManager );
embedder.stop();
assertEquals( 1, testWSMonitor.stopCaught );
assertEquals( 1, testWSMonitor.clearCaught );
assertEquals( 0, testWSMonitor.startMethodCaught );
assertEquals( 0, testWSMonitor.endMethodCaught );
}
public void testStartAndEndMethodEventsFiredOnSimpleReadProject()
throws IOException, MavenEmbedderException, ProjectBuildingException,
ExtensionScanningException, MavenExecutionException
{
EmbedderAndMonitor em = newEmbedder();
assertEquals( 0, em.monitor.startMethodCaught );
assertEquals( 0, em.monitor.endMethodCaught );
File dir = getFile( "simple-read-project" );
File pomFile = new File( dir, "pom.xml" );
em.embedder.readProject( pomFile );
assertEquals( 1, em.monitor.startMethodCaught );
assertEquals( 1, em.monitor.endMethodCaught );
assertEquals( 1, em.monitor.clearCaught );
assertSame( em.embedder.getWorkspaceStore(), em.monitor.workspaceManager );
em.embedder.stop();
}
public void testStartAndEndMethodEventsFiredOnReadWithDeps()
throws IOException, MavenEmbedderException, ProjectBuildingException,
ExtensionScanningException, MavenExecutionException
{
File dir = getFile( "read-with-deps" );
File pomFile = new File( dir, "pom.xml" );
File localRepoDir = new File( dir, "repo" );
EmbedderAndMonitor em = newEmbedder( localRepoDir );
assertEquals( 0, em.monitor.startMethodCaught );
assertEquals( 0, em.monitor.endMethodCaught );
em.embedder.readProject( pomFile );
assertEquals( 1, em.monitor.startMethodCaught );
assertEquals( 1, em.monitor.endMethodCaught );
assertEquals( 1, em.monitor.clearCaught );
assertSame( em.embedder.getWorkspaceStore(), em.monitor.workspaceManager );
em.embedder.stop();
}
public void testStartAndEndMethodEventsFiredOnExecute()
throws IOException, MavenEmbedderException, ProjectBuildingException,
ExtensionScanningException, MavenExecutionException
{
EmbedderAndMonitor em = newEmbedder();
assertEquals( 0, em.monitor.startMethodCaught );
assertEquals( 0, em.monitor.endMethodCaught );
File dir = getFile( "simple-read-project" );
MavenExecutionRequest request = new DefaultMavenExecutionRequest();
request.setGoals( Collections.singletonList( "clean" ) );
request.setBaseDirectory( dir );
em.embedder.execute( request );
assertEquals( 1, em.monitor.startMethodCaught );
assertEquals( 1, em.monitor.endMethodCaught );
assertEquals( 1, em.monitor.clearCaught );
assertSame( em.embedder.getWorkspaceStore(), em.monitor.workspaceManager );
em.embedder.stop();
}
private EmbedderAndMonitor newEmbedder()
throws MavenEmbedderException
{
return newEmbedder( null );
}
private EmbedderAndMonitor newEmbedder( File localRepoDir )
throws MavenEmbedderException
{
TestWorkspaceMonitor testWSMonitor = new TestWorkspaceMonitor();
Configuration config = new DefaultConfiguration();
config.setWorkspaceMonitor( testWSMonitor );
config.setMavenEmbedderLogger( new MavenEmbedderConsoleLogger() );
if ( localRepoDir != null )
{
config.setLocalRepository( localRepoDir );
}
return new EmbedderAndMonitor( new MavenEmbedder( config ), testWSMonitor );
}
private static final class EmbedderAndMonitor
{
private MavenEmbedder embedder;
private TestWorkspaceMonitor monitor;
private EmbedderAndMonitor( MavenEmbedder embedder,
TestWorkspaceMonitor monitor )
{
this.embedder = embedder;
this.monitor = monitor;
}
}
private File getFile( String path )
throws IOException
{
File testDirectory = new File( basedir, "src/test/eventing-projects/" + path );
System.out.println( "Test source dir: " + testDirectory );
File targetDirectory = new File( basedir, "target/eventing-projects/" + path );
System.out.println( "Test temp dir: " + targetDirectory );
targetDirectory.getParentFile().mkdirs();
FileUtils.copyDirectoryStructure( testDirectory, targetDirectory );
return targetDirectory;
}
private static final class TestWorkspaceMonitor
extends AbstractWorkspaceMonitor
{
private int initializeCaught = 0;
private int startMethodCaught = 0;
private int endMethodCaught = 0;
private int stopCaught = 0;
private int setManagerCaught = 0;
private int clearCaught = 0;
private MavenWorkspaceStore workspaceManager;
private boolean clearOnEndMethod = true;
private boolean clearOnStop = true;
public void embedderInitialized( long timestamp )
{
initializeCaught++;
}
public void embedderMethodEnded( String method,
long timestamp )
{
endMethodCaught++;
if ( clearOnEndMethod )
{
clearCache();
}
}
public void embedderMethodStarted( String method,
long timestamp )
{
startMethodCaught++;
}
public void embedderStopped( long timestamp )
{
stopCaught++;
if ( clearOnStop )
{
clearCache();
}
}
public void setWorkspaceStore( MavenWorkspaceStore workspaceManager )
{
setManagerCaught++;
this.workspaceManager = workspaceManager;
super.setWorkspaceStore( workspaceManager );
}
public void clearCache()
{
clearCaught++;
super.clearCache();
}
}
}

View File

@ -256,7 +256,6 @@
<module>maven-project</module>
<module>maven-reporting-api</module>
<module>maven-embedder</module>
<module>maven-workspace</module>
<module>maven-toolchain</module>
</modules>
<properties>
@ -267,7 +266,7 @@
<doxiaVersion>1.0-alpha-9</doxiaVersion>
<easyMockVersion>1.2_Java1.3</easyMockVersion>
<junitVersion>3.8.1</junitVersion>
<plexusVersion>1.0-alpha-48</plexusVersion>
<plexusVersion>1.0-alpha-50-SNAPSHOT</plexusVersion>
<plexusInteractivityVersion>1.0-alpha-6</plexusInteractivityVersion>
<plexusInterpolationVersion>1.1</plexusInterpolationVersion>
<plexusUtilsVersion>1.5.5</plexusUtilsVersion>