o fixes to the embedder for finding settings and cleaning up embedder initialization

Submitted by: Eugene Kuleshov


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@505612 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2007-02-10 02:01:42 +00:00
parent f151b661dd
commit 5288374ef1
15 changed files with 167 additions and 113 deletions

View File

@ -27,7 +27,7 @@
<artifactId>maven-embedder</artifactId>
<name>Maven Embedder</name>
<properties>
<bundleVersion>2.1.0.v20070110-1023</bundleVersion>
<bundleVersion>2.1.0.v20070209-2050</bundleVersion>
</properties>
<build>
<resources>

View File

@ -23,7 +23,7 @@ import java.io.File;
* @version $Id$
*/
public abstract class AbstractMavenEmbedderLogger
implements MavenEmbedderLogger
implements MavenEmbedderLogger
{
private int threshold = MavenEmbedderLogger.LEVEL_INFO;
@ -43,7 +43,7 @@ public abstract class AbstractMavenEmbedderLogger
{
return name;
}
public void debug( String message )
{
debug( message, null );

View File

@ -22,6 +22,7 @@ import java.util.List;
import java.util.Properties;
import org.apache.maven.settings.Settings;
import org.codehaus.plexus.classworlds.ClassWorld;
/**
* Default implementation of MavenEmbedRequest intefrace.
@ -45,14 +46,14 @@ public class DefaultMavenEmbedRequest
private Properties systemProperties;
/**
* List&lt;URL>.
*/
/** List&lt;URL>. */
private List extensions = new ArrayList();
/**
* Creates a new instance of DefaultMavenEmbedRequest
*/
private MavenEmbedderLogger logger;
private ClassWorld classWorld;
/** Creates a new instance of DefaultMavenEmbedRequest */
public DefaultMavenEmbedRequest()
{
}
@ -132,13 +133,13 @@ public class DefaultMavenEmbedRequest
return customizer;
}
public MavenEmbedRequest setSystemProperties(Properties properties)
public MavenEmbedRequest setSystemProperties( Properties properties )
{
systemProperties = properties;
return this;
}
public Properties getSystemProperties()
public Properties getSystemProperties()
{
return systemProperties != null ? systemProperties : System.getProperties();
}
@ -152,4 +153,32 @@ public class DefaultMavenEmbedRequest
{
return extensions;
}
public MavenEmbedRequest setMavenEmbedderLogger( MavenEmbedderLogger logger )
{
this.logger = logger;
return this;
}
public MavenEmbedderLogger getMavenEmbedderLogger()
{
return logger;
}
public ClassWorld getClassWorld()
{
return classWorld;
}
public MavenEmbedRequest setClassWorld( ClassWorld classWorld )
{
this.classWorld = classWorld;
return this;
}
public MavenEmbedRequest setClassLoader( ClassLoader loader )
{
this.classWorld = new ClassWorld( "plexus.core", loader );
return this;
}
}

View File

@ -20,7 +20,7 @@ import java.net.URL;
import java.util.List;
import java.util.Properties;
import org.apache.maven.settings.Settings;
import org.codehaus.plexus.classworlds.ClassWorld;
/**
* Configuration of embedder, used when starting up.
@ -83,4 +83,14 @@ public interface MavenEmbedRequest
void addExtension( URL url );
List getExtensions();
public MavenEmbedRequest setMavenEmbedderLogger( MavenEmbedderLogger logger );
public MavenEmbedderLogger getMavenEmbedderLogger();
public ClassWorld getClassWorld();
public MavenEmbedRequest setClassWorld( ClassWorld classWorld );
public MavenEmbedRequest setClassLoader( ClassLoader loader );
}

View File

@ -65,6 +65,7 @@ import org.codehaus.plexus.configuration.PlexusConfiguration;
import org.codehaus.plexus.configuration.PlexusConfigurationException;
import org.codehaus.plexus.logging.LoggerManager;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
@ -76,6 +77,7 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.PluginManager;
import org.apache.maven.plugin.PluginManagerException;
@ -156,28 +158,7 @@ public class MavenEmbedder
MavenEmbedderLogger logger )
throws MavenEmbedderException
{
this.classWorld = classWorld;
this.logger = logger;
// ----------------------------------------------------------------------------
// Don't override any existing SecurityManager if one has been installed. Our
// SecurityManager just checks to make sure
// ----------------------------------------------------------------------------
try
{
if ( System.getSecurityManager() == null && activateSystemManager )
{
System.setSecurityManager( new MavenEmbedderSecurityManager() );
}
}
catch ( RuntimeException e )
{
logger.warn( "Error trying to set the SecurityManager: " + e.getMessage() );
}
start();
this( new DefaultMavenEmbedRequest().setClassWorld( classWorld ).setMavenEmbedderLogger( logger ) );
}
public MavenEmbedder( ClassLoader classLoader )
@ -193,6 +174,12 @@ public class MavenEmbedder
this( new ClassWorld( "plexus.core", classLoader ), logger );
}
public MavenEmbedder( MavenEmbedRequest req )
throws MavenEmbedderException
{
start( req );
}
// ----------------------------------------------------------------------
// Accessors
// ----------------------------------------------------------------------
@ -247,30 +234,24 @@ public class MavenEmbedder
{
return mavenProjectBuilder.build( mavenProject, localRepository, profileManager );
}
/**
* mkleint: protected so that IDE integrations can selectively allow downloading artifacts
* from remote repositories (if they prohibit by default on project loading)
*/
protected void verifyPlugin( Plugin plugin, MavenProject project )
throws ComponentLookupException,
ArtifactResolutionException,
PluginVersionResolutionException,
ArtifactNotFoundException,
InvalidVersionSpecificationException,
InvalidPluginException,
PluginManagerException,
PluginNotFoundException,
PluginVersionNotFoundException
* from remote repositories (if they prohibit by default on project loading)
*/
protected void verifyPlugin( Plugin plugin,
MavenProject project )
throws ComponentLookupException, ArtifactResolutionException, PluginVersionResolutionException,
ArtifactNotFoundException, InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException,
PluginNotFoundException, PluginVersionNotFoundException
{
PluginManager pluginManager = (PluginManager) container.lookup( PluginManager.ROLE );
pluginManager.verifyPlugin(plugin, project, settings, localRepository);
pluginManager.verifyPlugin( plugin, project, settings, localRepository );
}
/**
* protected for tests only..
*/
protected Map getPluginExtensionComponents(Plugin plugin) throws PluginManagerException
/** protected for tests only.. */
protected Map getPluginExtensionComponents( Plugin plugin )
throws PluginManagerException
{
try
{
@ -283,29 +264,27 @@ public class MavenEmbedder
return new HashMap();
}
}
/**
* mkleint: copied from DefaultLifecycleExecutor
*
*
* @todo Not particularly happy about this. Would like WagonManager and ArtifactTypeHandlerManager to be able to
* lookup directly, or have them passed in
*
* @todo Move this sort of thing to the tail end of the project-building process
*/
private Map findArtifactTypeHandlers( MavenProject project )
throws Exception
{
Map map = new HashMap();
for ( Iterator i = project.getBuildPlugins().iterator(); i.hasNext(); )
{
Plugin plugin = (Plugin) i.next();
if ( plugin.isExtensions() )
{
verifyPlugin( plugin, project);
map.putAll( getPluginExtensionComponents(plugin));
verifyPlugin( plugin, project );
map.putAll( getPluginExtensionComponents( plugin ) );
// shudder...
for ( Iterator j = map.values().iterator(); j.hasNext(); )
@ -320,7 +299,7 @@ public class MavenEmbedder
}
return map;
}
/**
* This method is used to grab the list of dependencies that belong to a project so that a UI
@ -334,18 +313,18 @@ public class MavenEmbedder
try
{
request = defaultsPopulator.populateDefaults( request );
project = readProject( new File (request.getPomFile()) );
project = readProject( new File( request.getPomFile() ) );
//mkleint: copied from DefaultLifecycleExecutor
Map handlers = findArtifactTypeHandlers( project );
//is this necessary in this context, I doubt it..mkleint
artifactHandlerManager.addHandlers( handlers );
project = mavenProjectBuilder.buildWithDependencies( new File( request.getPomFile() ),
request.getLocalRepository(), profileManager,
request.getTransferListener() );
}
catch (PluginManagerException e)
catch ( PluginManagerException e )
{
return new DefaultMavenExecutionResult( project, Collections.singletonList( e ) );
}
@ -370,7 +349,7 @@ public class MavenEmbedder
return new DefaultMavenExecutionResult( project, Collections.singletonList( e ) );
}
//mkleint: why do we have so many various exception handlings with same result?
catch (Exception e)
catch ( Exception e )
{
return new DefaultMavenExecutionResult( project, Collections.singletonList( e ) );
}
@ -509,15 +488,30 @@ public class MavenEmbedder
// Lifecycle
// ----------------------------------------------------------------------
private void start()
private void start( MavenEmbedRequest req )
throws MavenEmbedderException
{
start( new DefaultMavenEmbedRequest() );
}
this.classWorld = req.getClassWorld();
this.logger = req.getMavenEmbedderLogger();
// ----------------------------------------------------------------------------
// Don't override any existing SecurityManager if one has been installed. Our
// SecurityManager just checks to make sure
// ----------------------------------------------------------------------------
try
{
if ( System.getSecurityManager() == null && activateSystemManager )
{
System.setSecurityManager( new MavenEmbedderSecurityManager() );
}
}
catch ( RuntimeException e )
{
logger.warn( "Error trying to set the SecurityManager: " + e.getMessage() );
}
public void start( MavenEmbedRequest req )
throws MavenEmbedderException
{
this.embedderRequest = req;
try
@ -670,11 +664,11 @@ public class MavenEmbedder
{
LoggerManager loggerManager = container.getLoggerManager();
int oldThreshold = loggerManager.getThreshold();
try
{
loggerManager.setThresholds( request.getLoggingLevel() );
try
{
request = defaultsPopulator.populateDefaults( request );

View File

@ -25,7 +25,8 @@ package org.apache.maven.embedder;/*
public final class MavenEmbedderConsoleLogger
extends AbstractMavenEmbedderLogger
{
public void debug( String message, Throwable throwable )
public void debug( String message,
Throwable throwable )
{
if ( isDebugEnabled() )
{
@ -39,7 +40,8 @@ public final class MavenEmbedderConsoleLogger
}
}
public void info( String message, Throwable throwable )
public void info( String message,
Throwable throwable )
{
if ( isInfoEnabled() )
{
@ -53,7 +55,8 @@ public final class MavenEmbedderConsoleLogger
}
}
public void warn( String message, Throwable throwable )
public void warn( String message,
Throwable throwable )
{
if ( isWarnEnabled() )
{
@ -67,7 +70,8 @@ public final class MavenEmbedderConsoleLogger
}
}
public void error( String message, Throwable throwable )
public void error( String message,
Throwable throwable )
{
if ( isErrorEnabled() )
{
@ -81,7 +85,8 @@ public final class MavenEmbedderConsoleLogger
}
}
public void fatalError( String message, Throwable throwable )
public void fatalError( String message,
Throwable throwable )
{
if ( isFatalErrorEnabled() )
{

View File

@ -33,7 +33,8 @@ public class MavenEmbedderException
super( cause );
}
public MavenEmbedderException( String message, Throwable cause )
public MavenEmbedderException( String message,
Throwable cause )
{
super( message, cause );
}

View File

@ -36,31 +36,36 @@ public interface MavenEmbedderLogger
void debug( String message );
void debug( String message, Throwable throwable );
void debug( String message,
Throwable throwable );
boolean isDebugEnabled();
void info( String message );
void info( String message, Throwable throwable );
void info( String message,
Throwable throwable );
boolean isInfoEnabled();
void warn( String message );
void warn( String message, Throwable throwable );
void warn( String message,
Throwable throwable );
boolean isWarnEnabled();
void error( String message );
void error( String message, Throwable throwable );
void error( String message,
Throwable throwable );
boolean isErrorEnabled();
void fatalError( String message );
void fatalError( String message, Throwable throwable );
void fatalError( String message,
Throwable throwable );
boolean isFatalErrorEnabled();

View File

@ -85,29 +85,32 @@ public class MavenEmbedderLoggerManager
logger.setThreshold( currentThreshold );
}
/**
* @return Returns the threshold.
*/
/** @return Returns the threshold. */
public int getThreshold()
{
return currentThreshold;
}
public void setThreshold( String role, String roleHint, int threshold )
public void setThreshold( String role,
String roleHint,
int threshold )
{
}
public int getThreshold( String role, String roleHint )
public int getThreshold( String role,
String roleHint )
{
return currentThreshold;
}
public Logger getLoggerForComponent( String role, String roleHint )
public Logger getLoggerForComponent( String role,
String roleHint )
{
return logger;
}
public void returnComponentLogger( String role, String roleHint )
public void returnComponentLogger( String role,
String roleHint )
{
}

View File

@ -35,7 +35,8 @@ public class PlexusLoggerAdapter
logger.debug( message );
}
public void debug( String message, Throwable throwable )
public void debug( String message,
Throwable throwable )
{
logger.debug( message, throwable );
}
@ -50,7 +51,8 @@ public class PlexusLoggerAdapter
logger.info( message );
}
public void info( String message, Throwable throwable )
public void info( String message,
Throwable throwable )
{
logger.info( message, throwable );
}
@ -65,7 +67,8 @@ public class PlexusLoggerAdapter
logger.warn( message );
}
public void warn( String message, Throwable throwable )
public void warn( String message,
Throwable throwable )
{
logger.warn( message, throwable );
}
@ -80,7 +83,8 @@ public class PlexusLoggerAdapter
logger.error( message );
}
public void error( String message, Throwable throwable )
public void error( String message,
Throwable throwable )
{
logger.error( message );
}
@ -95,7 +99,8 @@ public class PlexusLoggerAdapter
logger.fatalError( message );
}
public void fatalError( String message, Throwable throwable )
public void fatalError( String message,
Throwable throwable )
{
logger.fatalError( message, throwable );
}

View File

@ -26,7 +26,9 @@ public class SummaryPluginDescriptor
private String name;
public SummaryPluginDescriptor( String groupId, String artifactId, String name )
public SummaryPluginDescriptor( String groupId,
String artifactId,
String name )
{
this.groupId = groupId;
this.artifactId = artifactId;

View File

@ -50,7 +50,7 @@ import java.io.File;
import java.util.Iterator;
/**
* DefaultMavenExecutionRequestDefaultsPopulator
* DefaultMavenExecutionRequestDefaultsPopulator
*
* @version $Id$
*/
@ -216,15 +216,15 @@ public class DefaultMavenExecutionRequestDefaultsPopulator
for ( Iterator i = settings.getMirrors().iterator(); i.hasNext(); )
{
Mirror mirror = (Mirror) i.next();
try
{
wagonManager.addRepositoryMirror( mirror.getMirrorOf(), mirror.getId(), mirror.getUrl() );
}
catch ( IllegalArgumentException e )
{
throw new SettingsConfigurationException( "Unable to configure mirror " + mirror + ": "
+ e.getMessage(), e );
throw new SettingsConfigurationException(
"Unable to configure mirror " + mirror + ": " + e.getMessage(), e );
}
}
}

View File

@ -3,10 +3,10 @@ package org.apache.maven.embedder.execution;
import org.apache.maven.embedder.MavenEmbedderException;
import org.apache.maven.execution.MavenExecutionRequest;
public interface MavenExecutionRequestDefaultsPopulator
public interface MavenExecutionRequestDefaultsPopulator
{
String ROLE = MavenExecutionRequestDefaultsPopulator.class.getName();
MavenExecutionRequest populateDefaults( MavenExecutionRequest request )
throws MavenEmbedderException;
throws MavenEmbedderException;
}

View File

@ -6,7 +6,7 @@ import org.apache.maven.settings.Settings;
import java.util.List;
/**
* Adapt a {@link MavenExecutionRequest} to a {@link Settings} object for use in the Maven core.
* Adapt a {@link MavenExecutionRequest} to a {@link Settings} object for use in the Maven core.
*
* @author Jason van Zyl
*/

View File

@ -8,11 +8,7 @@ import java.io.File;
import junit.framework.TestCase;
/**
*
* @author <a href="mailto:kenney@apache.org">Kenney Westerhof</a>
*
*/
/** @author <a href="mailto:kenney@apache.org">Kenney Westerhof</a> */
public class TestComponentOverride
extends TestCase
{
@ -27,10 +23,14 @@ public class TestComponentOverride
{
basedir = System.getProperty( "basedir" );
maven = new MavenEmbedder( Thread.currentThread().getContextClassLoader(), new MavenEmbedderConsoleLogger() );
ClassLoader loader = Thread.currentThread().getContextClassLoader();
MavenEmbedRequest request = new DefaultMavenEmbedRequest();
request.setClassLoader( loader );
request.setMavenEmbedderLogger( new MavenEmbedderConsoleLogger() );
request.addExtension( new File( basedir, "src/test/extensions" ).toURI().toURL() );
// register callback to get a hold of the container
@ -42,7 +42,7 @@ public class TestComponentOverride
}
} );
maven.start( request );
maven = new MavenEmbedder( request );
}
public void testComponentOverride()