mirror of https://github.com/apache/maven.git
o Added first-pass logging and event-monitoring impls. Converted all System.out calls in maven-component plugins to use logger.
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163457 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
0c42b64caf
commit
dfbae27c44
|
@ -21,6 +21,11 @@
|
|||
<version>1.0-alpha-2-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<!-- maven component -->
|
||||
<dependency>
|
||||
<groupId>maven</groupId>
|
||||
<artifactId>maven-monitor</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>maven</groupId>
|
||||
<artifactId>maven-model</artifactId>
|
||||
|
|
|
@ -27,6 +27,8 @@ import org.apache.maven.execution.MavenSession;
|
|||
import org.apache.maven.lifecycle.LifecycleExecutor;
|
||||
import org.apache.maven.lifecycle.goal.GoalNotFoundException;
|
||||
import org.apache.maven.lifecycle.session.MavenSessionPhaseManager;
|
||||
import org.apache.maven.monitor.event.EventDispatcher;
|
||||
import org.apache.maven.monitor.event.MavenEvents;
|
||||
import org.apache.maven.plugin.PluginManager;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.project.MavenProjectBuilder;
|
||||
|
@ -103,7 +105,26 @@ public class DefaultMaven
|
|||
|
||||
resolveParameters( request );
|
||||
|
||||
MavenExecutionResponse response = lifecycleExecutor.execute( request.getGoals(), session );
|
||||
// !! This is ripe for refactoring to an aspect.
|
||||
// Event monitoring.
|
||||
EventDispatcher dispatcher = request.getEventDispatcher();
|
||||
String event = MavenEvents.PROJECT_EXECUTION;
|
||||
|
||||
dispatcher.dispatchStart( event, project.getId() );
|
||||
|
||||
MavenExecutionResponse response = null;
|
||||
try
|
||||
{
|
||||
// Actual meat of the code.
|
||||
response = lifecycleExecutor.execute( request.getGoals(), session );
|
||||
|
||||
dispatcher.dispatchEnd( event, project.getId() );
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
dispatcher.dispatchError( event, project.getId(), e );
|
||||
}
|
||||
// End event monitoring.
|
||||
|
||||
// TODO: is this perhaps more appropriate in the CLI?
|
||||
if ( response.isExecutionFailure() )
|
||||
|
@ -132,6 +153,12 @@ public class DefaultMaven
|
|||
|
||||
public MavenExecutionResponse handleReactor( MavenReactorExecutionRequest request )
|
||||
throws ReactorException
|
||||
{
|
||||
EventDispatcher dispatcher = request.getEventDispatcher();
|
||||
String event = MavenEvents.REACTOR_EXECUTION;
|
||||
|
||||
dispatcher.dispatchStart( event, request.getBaseDirectory().getPath() );
|
||||
try
|
||||
{
|
||||
List projects = new ArrayList();
|
||||
|
||||
|
@ -151,6 +178,7 @@ public class DefaultMaven
|
|||
}
|
||||
|
||||
projects = projectBuilder.getSortedProjects( projects );
|
||||
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
|
@ -204,9 +232,18 @@ public class DefaultMaven
|
|||
|
||||
}
|
||||
|
||||
dispatcher.dispatchEnd( event, request.getBaseDirectory().getPath() );
|
||||
|
||||
// TODO: not really satisfactory
|
||||
return null;
|
||||
}
|
||||
catch ( ReactorException e )
|
||||
{
|
||||
dispatcher.dispatchError( event, request.getBaseDirectory().getPath(), e );
|
||||
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public MavenProject getProject( File pom, ArtifactRepository localRepository )
|
||||
throws ProjectBuildingException
|
||||
|
@ -232,7 +269,7 @@ public class DefaultMaven
|
|||
|
||||
protected MavenSession createSession( MavenExecutionRequest request )
|
||||
{
|
||||
return new MavenSession( container, pluginManager, request.getLocalRepository(), request.getGoals() );
|
||||
return new MavenSession( container, pluginManager, request.getLocalRepository(), request.getEventDispatcher(), request.getLog(), request.getGoals() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -33,8 +33,13 @@ import org.apache.maven.execution.MavenExecutionResponse;
|
|||
import org.apache.maven.execution.MavenInitializingExecutionRequest;
|
||||
import org.apache.maven.execution.MavenProjectExecutionRequest;
|
||||
import org.apache.maven.execution.MavenReactorExecutionRequest;
|
||||
import org.apache.maven.monitor.event.DefaultEventDispatcher;
|
||||
import org.apache.maven.monitor.event.DefaultEventMonitor;
|
||||
import org.apache.maven.monitor.event.EventDispatcher;
|
||||
import org.apache.maven.monitor.logging.DefaultLog;
|
||||
import org.codehaus.classworlds.ClassWorld;
|
||||
import org.codehaus.plexus.embed.ArtifactEnabledEmbedder;
|
||||
import org.codehaus.plexus.logging.Logger;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
|
@ -109,6 +114,8 @@ public class MavenCli
|
|||
|
||||
File projectFile = new File( userDir, POMv4 );
|
||||
|
||||
EventDispatcher eventDispatcher = new DefaultEventDispatcher();
|
||||
|
||||
if ( projectFile.exists() )
|
||||
{
|
||||
if ( commandLine.hasOption( CLIManager.REACTOR ) )
|
||||
|
@ -118,6 +125,7 @@ public class MavenCli
|
|||
String excludes = System.getProperty( "maven.reactor.excludes", POMv4 );
|
||||
|
||||
request = new MavenReactorExecutionRequest( localRepository,
|
||||
eventDispatcher,
|
||||
mavenProperties,
|
||||
commandLine.getArgList(),
|
||||
includes,
|
||||
|
@ -127,6 +135,7 @@ public class MavenCli
|
|||
else
|
||||
{
|
||||
request = new MavenProjectExecutionRequest( localRepository,
|
||||
eventDispatcher,
|
||||
mavenProperties,
|
||||
commandLine.getArgList(),
|
||||
projectFile );
|
||||
|
@ -134,7 +143,7 @@ public class MavenCli
|
|||
}
|
||||
else
|
||||
{
|
||||
request = new MavenInitializingExecutionRequest( localRepository, mavenProperties, commandLine.getArgList() );
|
||||
request = new MavenInitializingExecutionRequest( localRepository, eventDispatcher, mavenProperties, commandLine.getArgList() );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
@ -146,6 +155,14 @@ public class MavenCli
|
|||
|
||||
embedder.start( classWorld );
|
||||
|
||||
Logger logger = embedder.getContainer().getLogger();
|
||||
if( logger != null )
|
||||
{
|
||||
request.setLog( new DefaultLog( logger ) );
|
||||
|
||||
request.addEventMonitor( new DefaultEventMonitor( logger ) );
|
||||
}
|
||||
|
||||
// TODO [BP]: doing this here as it is CLI specific, though it doesn't feel like the right place.
|
||||
WagonManager wagonManager = (WagonManager) embedder.lookup( WagonManager.ROLE );
|
||||
|
||||
|
|
|
@ -18,7 +18,10 @@ package org.apache.maven.execution;
|
|||
*/
|
||||
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.monitor.event.DefaultEventDispatcher;
|
||||
import org.apache.maven.monitor.event.EventDispatcher;
|
||||
import org.apache.maven.monitor.event.EventMonitor;
|
||||
import org.apache.maven.monitor.logging.Log;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
@ -41,13 +44,19 @@ implements MavenExecutionRequest
|
|||
|
||||
protected MavenSession session;
|
||||
|
||||
public AbstractMavenExecutionRequest( ArtifactRepository localRepository, Properties parameters, List goals )
|
||||
private Log log;
|
||||
|
||||
private EventDispatcher eventDispatcher;
|
||||
|
||||
public AbstractMavenExecutionRequest( ArtifactRepository localRepository, EventDispatcher eventDispatcher, Properties parameters, List goals )
|
||||
{
|
||||
this.localRepository = localRepository;
|
||||
|
||||
this.parameters = parameters;
|
||||
|
||||
this.goals = goals;
|
||||
|
||||
this.eventDispatcher = eventDispatcher;
|
||||
}
|
||||
|
||||
public ArtifactRepository getLocalRepository()
|
||||
|
@ -83,4 +92,25 @@ implements MavenExecutionRequest
|
|||
{
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
public void setLog(Log log)
|
||||
{
|
||||
this.log = log;
|
||||
}
|
||||
|
||||
public Log getLog()
|
||||
{
|
||||
return log;
|
||||
}
|
||||
|
||||
public void addEventMonitor(EventMonitor monitor)
|
||||
{
|
||||
eventDispatcher.addEventMonitor(monitor);
|
||||
}
|
||||
|
||||
public EventDispatcher getEventDispatcher()
|
||||
{
|
||||
return eventDispatcher;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,6 +18,9 @@ package org.apache.maven.execution;
|
|||
*/
|
||||
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.monitor.event.EventDispatcher;
|
||||
import org.apache.maven.monitor.event.EventMonitor;
|
||||
import org.apache.maven.monitor.logging.Log;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
@ -41,4 +44,12 @@ public interface MavenExecutionRequest
|
|||
MavenSession getSession();
|
||||
|
||||
List getProjectFiles() throws IOException;
|
||||
|
||||
void setLog( Log log );
|
||||
|
||||
Log getLog();
|
||||
|
||||
void addEventMonitor( EventMonitor monitor );
|
||||
|
||||
EventDispatcher getEventDispatcher();
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.apache.maven.execution;
|
|||
*/
|
||||
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.monitor.event.EventDispatcher;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
@ -29,9 +30,9 @@ import java.util.Properties;
|
|||
public class MavenInitializingExecutionRequest
|
||||
extends AbstractMavenExecutionRequest
|
||||
{
|
||||
public MavenInitializingExecutionRequest( ArtifactRepository localRepository, Properties properties, List goals )
|
||||
public MavenInitializingExecutionRequest( ArtifactRepository localRepository, EventDispatcher eventDispatcher, Properties properties, List goals )
|
||||
{
|
||||
super( localRepository, properties, goals );
|
||||
super( localRepository, eventDispatcher, properties, goals );
|
||||
|
||||
type = "initializing";
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.apache.maven.execution;
|
|||
*/
|
||||
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.monitor.event.EventDispatcher;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
|
@ -34,11 +35,12 @@ extends AbstractMavenExecutionRequest
|
|||
private File pom;
|
||||
|
||||
public MavenProjectExecutionRequest( ArtifactRepository localRepository,
|
||||
EventDispatcher eventDispatcher,
|
||||
Properties properties,
|
||||
List goals,
|
||||
File pom )
|
||||
{
|
||||
super( localRepository, properties, goals );
|
||||
super( localRepository, eventDispatcher, properties, goals );
|
||||
|
||||
this.pom = pom;
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.apache.maven.execution;
|
|||
*/
|
||||
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.monitor.event.EventDispatcher;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.codehaus.plexus.util.FileUtils;
|
||||
|
||||
|
@ -39,10 +40,11 @@ extends AbstractMavenExecutionRequest
|
|||
|
||||
private File baseDirectory;
|
||||
|
||||
public MavenReactorExecutionRequest( ArtifactRepository localRepository, Properties properties, List goals,
|
||||
String includes, String excludes, File baseDirectory )
|
||||
public MavenReactorExecutionRequest( ArtifactRepository localRepository, EventDispatcher eventDispatcher,
|
||||
Properties properties, List goals, String includes,
|
||||
String excludes, File baseDirectory )
|
||||
{
|
||||
super( localRepository, properties, goals );
|
||||
super( localRepository, eventDispatcher, properties, goals );
|
||||
|
||||
this.includes = includes;
|
||||
|
||||
|
@ -76,6 +78,6 @@ extends AbstractMavenExecutionRequest
|
|||
|
||||
public MavenProjectExecutionRequest createProjectExecutionRequest( MavenProject project )
|
||||
{
|
||||
return new MavenProjectExecutionRequest( localRepository, parameters, goals, project.getFile() );
|
||||
return new MavenProjectExecutionRequest( localRepository, getEventDispatcher(), parameters, goals, project.getFile() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,8 @@ package org.apache.maven.execution;
|
|||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.model.PostGoal;
|
||||
import org.apache.maven.model.PreGoal;
|
||||
import org.apache.maven.monitor.event.EventDispatcher;
|
||||
import org.apache.maven.monitor.logging.Log;
|
||||
import org.apache.maven.plugin.PluginManager;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.repository.RepositoryUtils;
|
||||
|
@ -61,9 +63,15 @@ public class MavenSession
|
|||
|
||||
private Map postGoalMappings;
|
||||
|
||||
private EventDispatcher eventDispatcher;
|
||||
|
||||
private Log log;
|
||||
|
||||
public MavenSession( PlexusContainer container,
|
||||
PluginManager pluginManager,
|
||||
ArtifactRepository localRepository,
|
||||
EventDispatcher eventDispatcher,
|
||||
Log log,
|
||||
List goals )
|
||||
{
|
||||
this.container = container;
|
||||
|
@ -72,6 +80,10 @@ public class MavenSession
|
|||
|
||||
this.localRepository = localRepository;
|
||||
|
||||
this.eventDispatcher = eventDispatcher;
|
||||
|
||||
this.log = log;
|
||||
|
||||
this.dag = new DAG();
|
||||
|
||||
this.goals = goals;
|
||||
|
@ -159,6 +171,16 @@ public class MavenSession
|
|||
}
|
||||
}
|
||||
|
||||
public EventDispatcher getEventDispatcher()
|
||||
{
|
||||
return eventDispatcher;
|
||||
}
|
||||
|
||||
public Log getLog()
|
||||
{
|
||||
return log;
|
||||
}
|
||||
|
||||
//!! this should probably not be done here as there are request types that
|
||||
// have no project
|
||||
|
||||
|
|
|
@ -24,6 +24,8 @@ import org.apache.maven.execution.MavenExecutionResponse;
|
|||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.lifecycle.goal.GoalExecutionException;
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.monitor.event.EventDispatcher;
|
||||
import org.apache.maven.monitor.event.MavenEvents;
|
||||
import org.apache.maven.plugin.PluginExecutionResponse;
|
||||
import org.apache.maven.plugin.PluginManager;
|
||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||
|
@ -229,10 +231,19 @@ public class DefaultLifecycleExecutor
|
|||
// only execute up to the given phase
|
||||
int index = phases.indexOf( phaseMap.get( phase ) );
|
||||
|
||||
EventDispatcher dispatcher = session.getEventDispatcher();
|
||||
|
||||
for ( int j = 0; j <= index; j++ )
|
||||
{
|
||||
Phase p = (Phase) phases.get( j );
|
||||
|
||||
String event = MavenEvents.PHASE_EXECUTION;
|
||||
|
||||
// !! This is ripe for refactoring to an aspect.
|
||||
// Event monitoring.
|
||||
dispatcher.dispatchStart( event, p.getId() );
|
||||
try
|
||||
{
|
||||
if ( p.getGoals() != null )
|
||||
{
|
||||
for ( Iterator i = p.getGoals().iterator(); i.hasNext(); )
|
||||
|
@ -248,6 +259,16 @@ public class DefaultLifecycleExecutor
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
dispatcher.dispatchEnd( event, p.getId() );
|
||||
}
|
||||
catch ( LifecycleExecutionException e )
|
||||
{
|
||||
dispatcher.dispatchError( event, p.getId(), e );
|
||||
|
||||
throw e;
|
||||
}
|
||||
// End event monitoring.
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
package org.apache.maven.monitor.event;
|
||||
|
||||
import org.codehaus.plexus.logging.Logger;
|
||||
|
||||
/**
|
||||
* @author jdcasey
|
||||
*/
|
||||
public class DefaultEventMonitor
|
||||
extends AbstractSelectiveEventMonitor
|
||||
{
|
||||
|
||||
private static final String[] START_EVENTS = {
|
||||
MavenEvents.MOJO_EXECUTION
|
||||
};
|
||||
|
||||
private final Logger logger;
|
||||
|
||||
public DefaultEventMonitor( Logger logger )
|
||||
{
|
||||
super( START_EVENTS, MavenEvents.NO_EVENTS, MavenEvents.NO_EVENTS );
|
||||
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
protected void doStartEvent( String event, String target, long time )
|
||||
{
|
||||
logger.info( "[" + target + "]" );
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
package org.apache.maven.monitor.logging;
|
||||
|
||||
import org.codehaus.plexus.logging.Logger;
|
||||
|
||||
/**
|
||||
* @author jdcasey
|
||||
*/
|
||||
public class DefaultLog
|
||||
implements Log
|
||||
{
|
||||
|
||||
private final Logger logger;
|
||||
|
||||
public DefaultLog( Logger logger )
|
||||
{
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
public void debug( CharSequence content )
|
||||
{
|
||||
logger.debug( content.toString() );
|
||||
}
|
||||
|
||||
public void debug( CharSequence content, Throwable error )
|
||||
{
|
||||
logger.debug( content.toString(), error );
|
||||
}
|
||||
|
||||
public void debug( Throwable error )
|
||||
{
|
||||
logger.debug( "", error );
|
||||
}
|
||||
|
||||
public void info( CharSequence content )
|
||||
{
|
||||
logger.info( content.toString() );
|
||||
}
|
||||
|
||||
public void info( CharSequence content, Throwable error )
|
||||
{
|
||||
logger.info( content.toString(), error );
|
||||
}
|
||||
|
||||
public void info( Throwable error )
|
||||
{
|
||||
logger.info( "", error );
|
||||
}
|
||||
|
||||
public void warn( CharSequence content )
|
||||
{
|
||||
logger.warn( content.toString() );
|
||||
}
|
||||
|
||||
public void warn( CharSequence content, Throwable error )
|
||||
{
|
||||
logger.warn( content.toString(), error );
|
||||
}
|
||||
|
||||
public void warn( Throwable error )
|
||||
{
|
||||
logger.warn( "", error );
|
||||
}
|
||||
|
||||
public void error( CharSequence content )
|
||||
{
|
||||
logger.error( content.toString() );
|
||||
}
|
||||
|
||||
public void error( CharSequence content, Throwable error )
|
||||
{
|
||||
logger.error( content.toString(), error );
|
||||
}
|
||||
|
||||
public void error( Throwable error )
|
||||
{
|
||||
logger.error( "", error );
|
||||
}
|
||||
|
||||
}
|
|
@ -29,6 +29,8 @@ import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
|||
import org.apache.maven.artifact.resolver.filter.ExclusionSetFilter;
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.lifecycle.goal.GoalExecutionException;
|
||||
import org.apache.maven.monitor.event.EventDispatcher;
|
||||
import org.apache.maven.monitor.event.MavenEvents;
|
||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||
import org.apache.maven.plugin.descriptor.Parameter;
|
||||
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||
|
@ -279,9 +281,11 @@ public class DefaultPluginManager
|
|||
|
||||
try
|
||||
{
|
||||
getLogger().info( "[" + mojoDescriptor.getId() + "]" );
|
||||
// getLogger().info( "[" + mojoDescriptor.getId() + "]" );
|
||||
|
||||
request = new PluginExecutionRequest( DefaultPluginManager.createParameters( mojoDescriptor, session ) );
|
||||
|
||||
request.setLog( session.getLog() );
|
||||
}
|
||||
catch ( PluginConfigurationException e )
|
||||
{
|
||||
|
@ -296,8 +300,25 @@ public class DefaultPluginManager
|
|||
{
|
||||
plugin = (Plugin) container.lookup( Plugin.ROLE, goalName );
|
||||
|
||||
// !! This is ripe for refactoring to an aspect.
|
||||
// Event monitoring.
|
||||
String event = MavenEvents.MOJO_EXECUTION;
|
||||
EventDispatcher dispatcher = session.getEventDispatcher();
|
||||
|
||||
dispatcher.dispatchStart( event, goalName );
|
||||
try
|
||||
{
|
||||
plugin.execute( request, response );
|
||||
|
||||
dispatcher.dispatchEnd( event, goalName );
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
session.getEventDispatcher().dispatchError( event, goalName, e );
|
||||
throw e;
|
||||
}
|
||||
// End event monitoring.
|
||||
|
||||
releaseComponents( mojoDescriptor, request );
|
||||
|
||||
container.release( plugin );
|
||||
|
@ -455,7 +476,7 @@ public class DefaultPluginManager
|
|||
public void initialize()
|
||||
{
|
||||
artifactFilter = new ExclusionSetFilter( new String[]{"maven-core", "maven-artifact", "maven-model",
|
||||
"maven-plugin", "plexus-container-api",
|
||||
"maven-monitor", "maven-plugin", "plexus-container-api",
|
||||
"plexus-container-default", "plexus-artifact-container",
|
||||
"classworlds"} );
|
||||
|
||||
|
|
|
@ -22,6 +22,9 @@ import java.util.List;
|
|||
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.lifecycle.goal.MavenGoalExecutionContext;
|
||||
import org.apache.maven.monitor.event.DefaultEventDispatcher;
|
||||
import org.apache.maven.monitor.logging.DefaultLog;
|
||||
import org.apache.maven.monitor.logging.Log;
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.plugin.PluginManager;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
|
@ -130,7 +133,9 @@ public class MavenTestCase
|
|||
{
|
||||
List goals = new ArrayList();
|
||||
|
||||
MavenSession session = new MavenSession( getContainer(), pluginManager, localRepository, goals );
|
||||
Log log = new DefaultLog(getContainer().getLogger());
|
||||
|
||||
MavenSession session = new MavenSession( getContainer(), pluginManager, localRepository, new DefaultEventDispatcher(), log, goals );
|
||||
|
||||
session.setProject( project );
|
||||
|
||||
|
|
|
@ -78,6 +78,7 @@ public class MBoot
|
|||
|
||||
String[] builds = new String[] {
|
||||
"maven-model",
|
||||
"maven-monitor",
|
||||
"maven-plugin",
|
||||
"maven-artifact",
|
||||
"maven-script/maven-script-marmalade",
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>maven</groupId>
|
||||
<artifactId>maven-component</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<groupId>maven</groupId>
|
||||
<artifactId>maven-monitor</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
</project>
|
|
@ -0,0 +1,62 @@
|
|||
package org.apache.maven.monitor.event;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author jdcasey
|
||||
*/
|
||||
public abstract class AbstractSelectiveEventMonitor
|
||||
implements EventMonitor
|
||||
{
|
||||
|
||||
private List boundStartEvents;
|
||||
private List boundErrorEvents;
|
||||
private List boundEndEvents;
|
||||
|
||||
protected AbstractSelectiveEventMonitor(String[] startEvents, String[] endEvents, String[] errorEvents)
|
||||
{
|
||||
this.boundStartEvents = Arrays.asList( startEvents );
|
||||
|
||||
this.boundEndEvents = Arrays.asList( endEvents );
|
||||
|
||||
this.boundErrorEvents = Arrays.asList( errorEvents );
|
||||
}
|
||||
|
||||
public final void startEvent( String eventName, String target, long timestamp )
|
||||
{
|
||||
if( boundStartEvents.contains( eventName ) )
|
||||
{
|
||||
doStartEvent( eventName, target, timestamp );
|
||||
}
|
||||
}
|
||||
|
||||
protected void doStartEvent( String eventName, String target, long timestamp )
|
||||
{
|
||||
}
|
||||
|
||||
public final void endEvent( String eventName, String target, long timestamp )
|
||||
{
|
||||
if( boundEndEvents.contains( eventName ) )
|
||||
{
|
||||
doEndEvent( eventName, target, timestamp );
|
||||
}
|
||||
}
|
||||
|
||||
protected void doEndEvent( String eventName, String target, long timestamp )
|
||||
{
|
||||
}
|
||||
|
||||
public final void errorEvent( String eventName, String target, long timestamp, Throwable cause )
|
||||
{
|
||||
if( boundErrorEvents.contains( eventName ) )
|
||||
{
|
||||
doErrorEvent( eventName, target, timestamp, cause );
|
||||
}
|
||||
}
|
||||
|
||||
protected void doErrorEvent( String eventName, String target, long timestamp, Throwable cause )
|
||||
{
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
package org.apache.maven.monitor.event;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author jdcasey
|
||||
*/
|
||||
public class DefaultEventDispatcher
|
||||
implements EventDispatcher
|
||||
{
|
||||
|
||||
private List eventMonitors = new ArrayList();
|
||||
|
||||
public void addEventMonitor( EventMonitor monitor )
|
||||
{
|
||||
eventMonitors.add( monitor );
|
||||
}
|
||||
|
||||
public void dispatchStart( String event, String target )
|
||||
{
|
||||
for ( Iterator it = eventMonitors.iterator(); it.hasNext(); )
|
||||
{
|
||||
EventMonitor monitor = (EventMonitor) it.next();
|
||||
monitor.startEvent( event, target, System.currentTimeMillis() );
|
||||
}
|
||||
}
|
||||
|
||||
public void dispatchEnd( String event, String target )
|
||||
{
|
||||
for ( Iterator it = eventMonitors.iterator(); it.hasNext(); )
|
||||
{
|
||||
EventMonitor monitor = (EventMonitor) it.next();
|
||||
monitor.endEvent( event, target, System.currentTimeMillis() );
|
||||
}
|
||||
}
|
||||
|
||||
public void dispatchError( String event, String target, Throwable cause )
|
||||
{
|
||||
for ( Iterator it = eventMonitors.iterator(); it.hasNext(); )
|
||||
{
|
||||
EventMonitor monitor = (EventMonitor) it.next();
|
||||
monitor.errorEvent( event, target, System.currentTimeMillis(), cause );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package org.apache.maven.monitor.event;
|
||||
|
||||
/**
|
||||
* @author jdcasey
|
||||
*/
|
||||
public interface EventDispatcher
|
||||
{
|
||||
|
||||
void addEventMonitor( EventMonitor monitor );
|
||||
|
||||
void dispatchStart( String event, String target );
|
||||
|
||||
void dispatchEnd( String event, String target );
|
||||
|
||||
void dispatchError( String event, String target, Throwable cause );
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package org.apache.maven.monitor.event;
|
||||
|
||||
/**
|
||||
* @author jdcasey
|
||||
*/
|
||||
public interface EventMonitor
|
||||
{
|
||||
|
||||
void startEvent( String eventName, String target, long timestamp );
|
||||
|
||||
void endEvent( String eventName, String target, long timestamp );
|
||||
|
||||
void errorEvent( String eventName, String target, long timestamp, Throwable cause );
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package org.apache.maven.monitor.event;
|
||||
|
||||
/**
|
||||
* @author jdcasey
|
||||
*/
|
||||
public final class MavenEvents
|
||||
{
|
||||
|
||||
public static final String PHASE_EXECUTION = "phase-execute";
|
||||
public static final String MOJO_EXECUTION = "mojo-execute";
|
||||
public static final String PROJECT_EXECUTION = "project-execute";
|
||||
public static final String REACTOR_EXECUTION = "reactor-execute";
|
||||
|
||||
public static final String[] ALL_EVENTS = {
|
||||
PHASE_EXECUTION,
|
||||
MOJO_EXECUTION,
|
||||
PROJECT_EXECUTION,
|
||||
REACTOR_EXECUTION
|
||||
};
|
||||
|
||||
public static final String[] NO_EVENTS = {};
|
||||
|
||||
private MavenEvents()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package org.apache.maven.monitor.logging;
|
||||
|
||||
/**
|
||||
* @author jdcasey
|
||||
*/
|
||||
public interface Log
|
||||
{
|
||||
|
||||
void debug( CharSequence content );
|
||||
|
||||
void debug( CharSequence content, Throwable error );
|
||||
|
||||
void debug( Throwable error );
|
||||
|
||||
void info( CharSequence content );
|
||||
|
||||
void info( CharSequence content, Throwable error );
|
||||
|
||||
void info( Throwable error );
|
||||
|
||||
void warn( CharSequence content );
|
||||
|
||||
void warn( CharSequence content, Throwable error );
|
||||
|
||||
void warn( Throwable error );
|
||||
|
||||
void error( CharSequence content );
|
||||
|
||||
void error( CharSequence content, Throwable error );
|
||||
|
||||
void error( Throwable error );
|
||||
|
||||
}
|
|
@ -0,0 +1,108 @@
|
|||
package org.apache.maven.monitor.logging;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
|
||||
/**
|
||||
* @author jdcasey
|
||||
*/
|
||||
public class SystemStreamLog
|
||||
implements Log
|
||||
{
|
||||
|
||||
public void debug( CharSequence content )
|
||||
{
|
||||
print( "debug", content );
|
||||
}
|
||||
|
||||
public void debug( CharSequence content, Throwable error )
|
||||
{
|
||||
print( "debug", content, error );
|
||||
}
|
||||
|
||||
public void debug( Throwable error )
|
||||
{
|
||||
print( "debug", error );
|
||||
}
|
||||
|
||||
public void info( CharSequence content )
|
||||
{
|
||||
print( "info", content );
|
||||
}
|
||||
|
||||
public void info( CharSequence content, Throwable error )
|
||||
{
|
||||
print( "info", content, error );
|
||||
}
|
||||
|
||||
public void info( Throwable error )
|
||||
{
|
||||
print( "info", error );
|
||||
}
|
||||
|
||||
public void warn( CharSequence content )
|
||||
{
|
||||
print( "warn", content );
|
||||
}
|
||||
|
||||
public void warn( CharSequence content, Throwable error )
|
||||
{
|
||||
print( "warn", content, error );
|
||||
}
|
||||
|
||||
public void warn( Throwable error )
|
||||
{
|
||||
print( "warn", error );
|
||||
}
|
||||
|
||||
public void error( CharSequence content )
|
||||
{
|
||||
System.err.println( "[error] " + content.toString() );
|
||||
}
|
||||
|
||||
public void error( CharSequence content, Throwable error )
|
||||
{
|
||||
StringWriter sWriter = new StringWriter();
|
||||
PrintWriter pWriter = new PrintWriter( sWriter );
|
||||
|
||||
error.printStackTrace( pWriter );
|
||||
|
||||
System.err.println( "[error] " + content.toString() + "\n\n" + sWriter.toString() );
|
||||
}
|
||||
|
||||
public void error( Throwable error )
|
||||
{
|
||||
StringWriter sWriter = new StringWriter();
|
||||
PrintWriter pWriter = new PrintWriter( sWriter );
|
||||
|
||||
error.printStackTrace( pWriter );
|
||||
|
||||
System.err.println( "[error] " + sWriter.toString() );
|
||||
}
|
||||
|
||||
private void print( String prefix, CharSequence content )
|
||||
{
|
||||
System.out.println( "[" + prefix + "] " + content.toString() );
|
||||
}
|
||||
|
||||
private void print( String prefix, Throwable error )
|
||||
{
|
||||
StringWriter sWriter = new StringWriter();
|
||||
PrintWriter pWriter = new PrintWriter( sWriter );
|
||||
|
||||
error.printStackTrace( pWriter );
|
||||
|
||||
System.out.println( "[" + prefix + "] " + sWriter.toString() );
|
||||
}
|
||||
|
||||
private void print( String prefix, CharSequence content, Throwable error )
|
||||
{
|
||||
StringWriter sWriter = new StringWriter();
|
||||
PrintWriter pWriter = new PrintWriter( sWriter );
|
||||
|
||||
error.printStackTrace( pWriter );
|
||||
|
||||
System.out.println( "[" + prefix + "] " + content.toString() + "\n\n" + sWriter.toString() );
|
||||
}
|
||||
|
||||
}
|
|
@ -12,6 +12,11 @@
|
|||
<name>Maven Plugin Tools for Marmalade</name>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>maven</groupId>
|
||||
<artifactId>maven-monitor</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>plexus</groupId>
|
||||
<artifactId>plexus-container-default</artifactId>
|
||||
|
|
|
@ -90,7 +90,8 @@ public class MarmaladeMojoDescriptorExtractor
|
|||
}
|
||||
else
|
||||
{
|
||||
System.out.println("This script is not a mojo. Its root tag is {element: " + rootTag.getTagInfo().getElement() + ", class: " + rootTag.getClass().getName() + "}");
|
||||
System.out.println( "This script is not a mojo. Its root tag is {element: "
|
||||
+ rootTag.getTagInfo().getElement() + ", class: " + rootTag.getClass().getName() + "}" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,7 +55,8 @@ public class MarmaladeMojoDescriptorExtractorTest
|
|||
|
||||
project.setFile( new File( basedir, "pom.xml" ) );
|
||||
|
||||
MarmaladeMojoDescriptorExtractor extractor = (MarmaladeMojoDescriptorExtractor) lookup(MojoDescriptorExtractor.ROLE, "marmalade");
|
||||
MarmaladeMojoDescriptorExtractor extractor = (MarmaladeMojoDescriptorExtractor) lookup( MojoDescriptorExtractor.ROLE,
|
||||
"marmalade" );
|
||||
|
||||
Set descriptors = extractor.execute( project );
|
||||
|
||||
|
|
|
@ -12,6 +12,11 @@
|
|||
<name>Maven Plugin</name>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>maven</groupId>
|
||||
<artifactId>maven-monitor</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>qdox</groupId>
|
||||
<artifactId>qdox</artifactId>
|
||||
|
|
|
@ -16,6 +16,9 @@ package org.apache.maven.plugin;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.monitor.logging.Log;
|
||||
import org.apache.maven.monitor.logging.SystemStreamLog;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -29,6 +32,8 @@ public class PluginExecutionRequest
|
|||
|
||||
private Map context;
|
||||
|
||||
private Log log;
|
||||
|
||||
public PluginExecutionRequest( Map parameters )
|
||||
{
|
||||
context = new HashMap();
|
||||
|
@ -60,4 +65,22 @@ public class PluginExecutionRequest
|
|||
{
|
||||
return context.get( key );
|
||||
}
|
||||
|
||||
public void setLog( Log log )
|
||||
{
|
||||
this.log = log;
|
||||
}
|
||||
|
||||
public Log getLog()
|
||||
{
|
||||
synchronized(this)
|
||||
{
|
||||
if(log == null)
|
||||
{
|
||||
log = new SystemStreamLog();
|
||||
}
|
||||
}
|
||||
|
||||
return log;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,4 +14,11 @@
|
|||
<version>1.0-SNAPSHOT</version>
|
||||
<inceptionYear>2001</inceptionYear>
|
||||
<package>org.apache.maven.plugin.clean</package>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>maven</groupId>
|
||||
<artifactId>maven-monitor</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -16,6 +16,7 @@ package org.apache.maven.plugin.clean;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.monitor.logging.Log;
|
||||
import org.apache.maven.plugin.AbstractPlugin;
|
||||
import org.apache.maven.plugin.PluginExecutionRequest;
|
||||
import org.apache.maven.plugin.PluginExecutionResponse;
|
||||
|
@ -47,13 +48,19 @@ public class CleanPlugin
|
|||
|
||||
private boolean failOnError;
|
||||
|
||||
private Log log;
|
||||
|
||||
public void execute( PluginExecutionRequest request, PluginExecutionResponse response )
|
||||
throws Exception
|
||||
{
|
||||
try
|
||||
{
|
||||
outputDirectory = (String) request.getParameter( "outputDirectory" );
|
||||
|
||||
failOnError = Boolean.valueOf( (String) request.getParameter( "failedOnError" ) ).booleanValue();
|
||||
|
||||
log = request.getLog();
|
||||
|
||||
if ( outputDirectory != null )
|
||||
{
|
||||
File dir = new File( outputDirectory );
|
||||
|
@ -65,6 +72,14 @@ public class CleanPlugin
|
|||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
// clean up state.
|
||||
failOnError = false;
|
||||
outputDirectory = null;
|
||||
log = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Accommodate Windows bug encountered in both Sun and IBM JDKs.
|
||||
|
@ -148,6 +163,6 @@ public class CleanPlugin
|
|||
|
||||
private void log( String message )
|
||||
{
|
||||
System.out.println( message );
|
||||
log.info( message );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,11 @@
|
|||
<inceptionYear>2001</inceptionYear>
|
||||
<package>org.apache.maven</package>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>maven</groupId>
|
||||
<artifactId>maven-monitor</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>plexus</groupId>
|
||||
<artifactId>plexus</artifactId>
|
||||
|
|
|
@ -119,7 +119,8 @@ public class CompilerMojo
|
|||
message = "Warning! not present in repository!";
|
||||
}
|
||||
|
||||
System.out.println( "classpathElements[ "+ i +" ] = " + classpathElements[i] + ": " + message );
|
||||
// System.out.println( "classpathElements[ "+ i +" ] = " + classpathElements[i] + ": " + message );
|
||||
request.getLog().debug( "classpathElements[ "+ i +" ] = " + classpathElements[i] + ": " + message );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,11 @@
|
|||
<version>1.0-SNAPSHOT</version>
|
||||
<package>org.apache.maven.plugin.war</package>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>maven</groupId>
|
||||
<artifactId>maven-monitor</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>maven</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
|
|
|
@ -114,7 +114,7 @@ public class ExplodedMojo
|
|||
// ----------------------------------------------------------------------
|
||||
//
|
||||
// ----------------------------------------------------------------------
|
||||
System.out.println("webapp");
|
||||
request.getLog().info("webapp");
|
||||
|
||||
}
|
||||
}
|
|
@ -114,7 +114,7 @@ public class WarMojo
|
|||
// ----------------------------------------------------------------------
|
||||
//
|
||||
// ----------------------------------------------------------------------
|
||||
System.out.println("war");
|
||||
request.getLog().info("war");
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,6 +45,11 @@
|
|||
</developers>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>maven</groupId>
|
||||
<artifactId>maven-monitor</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>maven</groupId>
|
||||
<artifactId>maven-plugin</artifactId>
|
||||
|
|
|
@ -12,6 +12,11 @@
|
|||
<name>Maven Marmalade Mojo Support</name>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>maven</groupId>
|
||||
<artifactId>maven-monitor</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>maven</groupId>
|
||||
<artifactId>maven-plugin</artifactId>
|
||||
|
|
|
@ -38,7 +38,6 @@ public class ExecuteTag
|
|||
for ( Iterator it = children().iterator(); it.hasNext(); )
|
||||
{
|
||||
MarmaladeTag child = (MarmaladeTag) it.next();
|
||||
System.out.println("Will execute: " + child);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,11 @@
|
|||
<name>Maven Script Support Root</name>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>maven</groupId>
|
||||
<artifactId>maven-monitor</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>maven</groupId>
|
||||
<artifactId>maven-plugin</artifactId>
|
||||
|
|
Loading…
Reference in New Issue