move the Log interface to o.a.m.plugin.logging in maven-plugin-api, breaking the dependency on maven-monitor

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@169431 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-05-10 07:39:33 +00:00
parent 12455bf6e3
commit d47f6c7dd6
15 changed files with 127 additions and 98 deletions

View File

@ -304,7 +304,7 @@ public class DefaultMaven
protected MavenSession createSession( MavenExecutionRequest request, MavenProject project )
{
return new MavenSession( project, container, request.getSettings(), request.getLocalRepository(),
request.getEventDispatcher(), request.getLog(), request.getGoals() );
request.getEventDispatcher(), request.getGoals() );
}
/**

View File

@ -44,6 +44,7 @@ import org.apache.maven.settings.Settings;
import org.codehaus.classworlds.ClassWorld;
import org.codehaus.plexus.PlexusContainerException;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException;
import org.codehaus.plexus.embed.ArtifactEnabledEmbedder;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.logging.LoggerManager;
@ -117,14 +118,14 @@ public class MavenCli
initializeSystemProperties( commandLine );
boolean debug = commandLine.hasOption( CLIManager.DEBUG );
boolean showErrors = debug || commandLine.hasOption( CLIManager.ERRORS );
if(showErrors)
{
System.out.println("+ Error stacktraces are turned on.");
}
// ----------------------------------------------------------------------
// Process particular command line options
// ----------------------------------------------------------------------
@ -196,10 +197,11 @@ public class MavenCli
Maven maven = null;
MavenExecutionRequest request = null;
LoggerManager manager = null;
try
{
// logger must be created first
LoggerManager manager = (LoggerManager) embedder.lookup( LoggerManager.ROLE );
manager = (LoggerManager) embedder.lookup( LoggerManager.ROLE );
if ( debug )
{
manager.setThreshold( Logger.LEVEL_DEBUG );
@ -214,6 +216,21 @@ public class MavenCli
showFatalError( "Unable to configure the Maven application", e, showErrors );
return 1;
}
finally
{
if ( manager != null )
{
try
{
embedder.release( manager );
}
catch ( ComponentLifecycleException e )
{
showFatalError( "Error releasing logging manager", e, showErrors );
return 1;
}
}
}
// TODO: this should be in default maven, and should accommodate default goals
if ( request.getGoals().isEmpty() )
@ -276,8 +293,6 @@ public class MavenCli
Logger logger = manager.getLoggerForComponent( Mojo.ROLE );
if ( logger != null )
{
request.setLog( new DefaultLog( logger ) );
request.addEventMonitor( new DefaultEventMonitor( logger ) );
}

View File

@ -20,7 +20,6 @@ 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 org.apache.maven.settings.Settings;
import java.util.List;
@ -43,8 +42,6 @@ public class DefaultMavenExecutionRequest
protected MavenSession session;
private Log log;
private final EventDispatcher eventDispatcher;
private final Settings settings;
@ -118,16 +115,6 @@ public class DefaultMavenExecutionRequest
this.session = session;
}
public void setLog( Log log )
{
this.log = log;
}
public Log getLog()
{
return log;
}
public void addEventMonitor( EventMonitor monitor )
{
eventDispatcher.addEventMonitor( monitor );

View File

@ -20,7 +20,6 @@ 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 org.apache.maven.settings.Settings;
import java.util.List;
@ -41,10 +40,6 @@ public interface MavenExecutionRequest
List getFiles();
void setLog( Log log );
Log getLog();
void addEventMonitor( EventMonitor monitor );
EventDispatcher getEventDispatcher();

View File

@ -19,7 +19,6 @@ package org.apache.maven.execution;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.monitor.event.EventDispatcher;
import org.apache.maven.monitor.logging.Log;
import org.apache.maven.project.MavenProject;
import org.apache.maven.settings.Settings;
import org.codehaus.plexus.PlexusContainer;
@ -45,13 +44,11 @@ public class MavenSession
private EventDispatcher eventDispatcher;
private Log log;
// TODO: make this the central one, get rid of build settings...
private final Settings settings;
public MavenSession( MavenProject project, PlexusContainer container, Settings settings,
ArtifactRepository localRepository, EventDispatcher eventDispatcher, Log log, List goals )
ArtifactRepository localRepository, EventDispatcher eventDispatcher, List goals )
{
this.project = project;
@ -63,8 +60,6 @@ public class MavenSession
this.eventDispatcher = eventDispatcher;
this.log = log;
this.goals = goals;
// TODO: Go back to this when we get the container ready to configure mojos...
@ -144,11 +139,6 @@ public class MavenSession
return eventDispatcher;
}
public Log getLog()
{
return log;
}
public Settings getSettings()
{
return settings;

View File

@ -1,5 +1,22 @@
package org.apache.maven.monitor.logging;
/*
* Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.apache.maven.plugin.logging.Log;
import org.codehaus.plexus.logging.Logger;
/**

View File

@ -28,10 +28,12 @@ import org.apache.maven.artifact.transform.ReleaseArtifactTransformation;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.monitor.event.EventDispatcher;
import org.apache.maven.monitor.event.MavenEvents;
import org.apache.maven.monitor.logging.DefaultLog;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.Parameter;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.artifact.MavenMetadataSource;
@ -54,6 +56,7 @@ import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
import org.codehaus.plexus.context.Context;
import org.codehaus.plexus.context.ContextException;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.logging.LoggerManager;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
import org.codehaus.plexus.util.StringUtils;
@ -88,6 +91,8 @@ public class DefaultPluginManager
private Set pluginsInProcess = new HashSet();
private Log mojoLogger;
public DefaultPluginManager()
{
pluginDescriptors = new HashMap();
@ -353,8 +358,7 @@ public class DefaultPluginManager
try
{
plugin = (Mojo) container.lookup( Mojo.ROLE, mojoDescriptor.getRoleHint() );
plugin.setLog( session.getLog() );
plugin.setLog( mojoLogger );
String goalId = mojoDescriptor.getGoal();
@ -378,7 +382,8 @@ public class DefaultPluginManager
// validatePomConfiguration( mojoDescriptor, pomConfiguration );
}
ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session, pathTranslator );
ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session, pathTranslator,
getLogger() );
PlexusConfiguration mergedConfiguration = mergeConfiguration( pomConfiguration,
mojoDescriptor.getMojoConfiguration() );
@ -599,7 +604,7 @@ public class DefaultPluginManager
List parameters = goal.getParameters();
List invalidParameters = new ArrayList();
for ( int i = 0; i < parameters.size(); i++ )
{
Parameter parameter = (Parameter) parameters.get( i );
@ -714,8 +719,8 @@ public class DefaultPluginManager
}
}
if( !invalidParameters.isEmpty() )
if ( !invalidParameters.isEmpty() )
{
throw new PluginParameterException( goal, invalidParameters );
}
@ -746,6 +751,33 @@ public class DefaultPluginManager
throws ContextException
{
container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
LoggerManager manager = null;
try
{
manager = (LoggerManager) container.lookup( LoggerManager.ROLE );
mojoLogger = new DefaultLog( manager.getLoggerForComponent( Mojo.ROLE ) );
}
catch ( ComponentLookupException e )
{
throw new ContextException( "Error locating a logger manager", e );
}
finally
{
if ( manager != null )
{
try
{
container.release( manager );
}
catch ( ComponentLifecycleException e )
{
getLogger().error( "Error releasing the logger manager - ignoring", e );
}
}
}
}
public void initialize()
@ -802,4 +834,4 @@ public class DefaultPluginManager
}
}
}
}

View File

@ -23,12 +23,13 @@ import org.apache.maven.reporting.MavenReport;
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.util.introspection.ReflectionValueExtractor;
import java.io.File;
import java.util.Iterator;
import java.util.Map;
import java.util.List;
import java.util.Map;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
@ -42,10 +43,13 @@ public class PluginParameterExpressionEvaluator
private final MavenSession context;
public PluginParameterExpressionEvaluator( MavenSession context, PathTranslator pathTranslator )
private final Logger logger;
public PluginParameterExpressionEvaluator( MavenSession context, PathTranslator pathTranslator, Logger logger )
{
this.context = context;
this.pathTranslator = pathTranslator;
this.logger = logger;
}
public Object evaluate( String expr )
@ -116,7 +120,7 @@ public class PluginParameterExpressionEvaluator
for ( Iterator i = ( (Map) value ).keySet().iterator(); i.hasNext(); )
{
String key = (String) i.next();
context.getLog().debug( key + " report is found." );
logger.debug( key + " report is found." );
}
}
catch ( ComponentLookupException cle )
@ -175,7 +179,7 @@ public class PluginParameterExpressionEvaluator
}
else
{
context.getLog().error( "Got expression '" + expression + "' that was not recognised" );
logger.error( "Got expression '" + expression + "' that was not recognised" );
}
}
else

View File

@ -65,8 +65,7 @@ public class PluginParameterExpressionEvaluatorTest
private static MavenSession createSession( MavenProject project, PlexusContainer container,
ArtifactRepository repo )
{
return new MavenSession( project, container, new Settings(), repo, new DefaultEventDispatcher(),
new DefaultLog( container.getLogger() ), Collections.EMPTY_LIST );
return new MavenSession( project, container, new Settings(), repo, new DefaultEventDispatcher(), Collections.EMPTY_LIST );
}
public void testLocalRepositoryExtraction()
@ -112,7 +111,7 @@ public class PluginParameterExpressionEvaluatorTest
PlexusContainer container = getContainer();
MavenSession session = createSession( project, container, repo );
ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session, null );
ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session, null, container.getLogger() );
return expressionEvaluator;
}
}

View File

@ -16,8 +16,8 @@ package org.apache.maven.plugin;
* limitations under the License.
*/
import org.apache.maven.monitor.logging.Log;
import org.apache.maven.monitor.logging.SystemStreamLog;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugin.logging.SystemStreamLog;
/**
* @version $Id$
@ -27,41 +27,6 @@ public abstract class AbstractMojo
{
private Log log;
/**
* Default behaviour to mimic old behaviour.
*
* @deprecated
*/
public void execute( MojoExecutionRequest request )
throws MojoExecutionException
{
MojoExecutionResponse response = new MojoExecutionResponse();
try
{
execute( request, response );
}
catch ( Exception e )
{
throw new MojoExecutionException( e.getMessage(), e );
}
if ( response.isExecutionFailure() )
{
throw new MojoExecutionException( response.getFailureResponse().getSource(),
response.getFailureResponse().shortMessage(),
response.getFailureResponse().longMessage() );
}
}
/**
* @deprecated
*/
public void execute( MojoExecutionRequest request, MojoExecutionResponse response )
throws Exception
{
throw new UnsupportedOperationException(
"If you are using the old technique, you must override execute(req,resp)" );
}
public void setLog( Log log )
{
this.log = log;

View File

@ -16,7 +16,7 @@ package org.apache.maven.plugin;
* limitations under the License.
*/
import org.apache.maven.monitor.logging.Log;
import org.apache.maven.plugin.logging.Log;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
@ -29,10 +29,6 @@ public interface Mojo
void execute()
throws MojoExecutionException;
/** @deprecated */
void execute( MojoExecutionRequest request )
throws MojoExecutionException;
// TODO: not sure about this here, and may want a getLog on here as well/instead
void setLog( Log log );
}

View File

@ -1,11 +1,26 @@
package org.apache.maven.monitor.logging;
package org.apache.maven.plugin.logging;
/*
* Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @author jdcasey
*/
public interface Log
{
boolean isDebugEnabled();
void debug( CharSequence content );
@ -37,5 +52,4 @@ public interface Log
void error( CharSequence content, Throwable error );
void error( Throwable error );
}

View File

@ -1,4 +1,20 @@
package org.apache.maven.monitor.logging;
package org.apache.maven.plugin.logging;
/*
* Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.io.PrintWriter;
import java.io.StringWriter;

View File

@ -16,7 +16,7 @@ package org.apache.maven.plugin.verifier;
* limitations under the License.
*/
import org.apache.maven.monitor.logging.Log;
import org.apache.maven.plugin.logging.Log;
import java.util.Iterator;

View File

@ -21,7 +21,6 @@ import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.reporting.MavenReport;
import org.apache.maven.reporting.MavenReportConfiguration;
import org.apache.maven.reporting.MavenReportException;
import org.codehaus.doxia.module.xhtml.XhtmlSink;
import org.codehaus.doxia.site.renderer.SiteRenderer;
import org.codehaus.plexus.util.FileUtils;
@ -29,8 +28,8 @@ import org.codehaus.plexus.util.StringInputStream;
import org.codehaus.plexus.util.StringUtils;
import java.io.File;
import java.io.InputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;