o first pass at cleaning up the embedding pattern

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@820905 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2009-10-02 06:51:50 +00:00
parent cfdc74af79
commit dc92f34610
32 changed files with 270 additions and 2383 deletions

View File

@ -24,7 +24,7 @@ class Maven
include_class 'java.io.File'
include_class 'org.apache.maven.embedder.MavenEmbedder'
include_class 'org.apache.maven.embedder.DefaultConfiguration'
include_class 'org.apache.maven.cli.DefaultConfiguration'
include_class 'org.apache.maven.execution.DefaultMavenExecutionRequest'
def run

View File

@ -1,4 +1,4 @@
package org.apache.maven.embedder.execution;
package org.apache.maven.execution;
/*
* Licensed to the Apache Software Foundation (ASF) under one
@ -28,8 +28,6 @@ import java.util.Set;
import org.apache.maven.Maven;
import org.apache.maven.artifact.InvalidRepositoryException;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.embedder.MavenEmbedderException;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.settings.Mirror;
import org.apache.maven.settings.Proxy;
@ -58,7 +56,7 @@ public class DefaultMavenExecutionRequestPopulator
private SecDispatcher securityDispatcher;
public MavenExecutionRequest populateFromSettings( MavenExecutionRequest request, Settings settings )
throws MavenEmbedderException
throws MavenExecutionRequestPopulationException
{
if ( settings == null )
{
@ -197,7 +195,7 @@ public class DefaultMavenExecutionRequestPopulator
}
private void injectDefaultRepositories( MavenExecutionRequest request )
throws MavenEmbedderException
throws MavenExecutionRequestPopulationException
{
Set<String> definedRepositories = getRepoIds( request.getRemoteRepositories() );
@ -209,13 +207,13 @@ public class DefaultMavenExecutionRequestPopulator
}
catch ( InvalidRepositoryException e )
{
throw new MavenEmbedderException( "Cannot create default remote repository.", e );
throw new MavenExecutionRequestPopulationException( "Cannot create default remote repository.", e );
}
}
}
private void injectDefaultPluginRepositories( MavenExecutionRequest request )
throws MavenEmbedderException
throws MavenExecutionRequestPopulationException
{
Set<String> definedRepositories = getRepoIds( request.getPluginArtifactRepositories() );
@ -227,7 +225,7 @@ public class DefaultMavenExecutionRequestPopulator
}
catch ( InvalidRepositoryException e )
{
throw new MavenEmbedderException( "Cannot create default remote repository.", e );
throw new MavenExecutionRequestPopulationException( "Cannot create default remote repository.", e );
}
}
}
@ -248,7 +246,7 @@ public class DefaultMavenExecutionRequestPopulator
}
private void processRepositoriesInSettings( MavenExecutionRequest request )
throws MavenEmbedderException
throws MavenExecutionRequestPopulationException
{
repositorySystem.injectMirror( request.getRemoteRepositories(), request.getMirrors() );
repositorySystem.injectProxy( request.getRemoteRepositories(), request.getProxies() );
@ -264,7 +262,7 @@ public class DefaultMavenExecutionRequestPopulator
}
private void localRepository( MavenExecutionRequest request )
throws MavenEmbedderException
throws MavenExecutionRequestPopulationException
{
// ------------------------------------------------------------------------
// Local Repository
@ -290,7 +288,7 @@ public class DefaultMavenExecutionRequestPopulator
// ------------------------------------------------------------------------
public ArtifactRepository createLocalRepository( MavenExecutionRequest request )
throws MavenEmbedderException
throws MavenExecutionRequestPopulationException
{
String localRepositoryPath = null;
@ -310,12 +308,12 @@ public class DefaultMavenExecutionRequestPopulator
}
catch ( InvalidRepositoryException e )
{
throw new MavenEmbedderException( "Cannot create local repository.", e );
throw new MavenExecutionRequestPopulationException( "Cannot create local repository.", e );
}
}
public MavenExecutionRequest populateDefaults( MavenExecutionRequest request )
throws MavenEmbedderException
throws MavenExecutionRequestPopulationException
{
pom( request );

View File

@ -1,4 +1,4 @@
package org.apache.maven.embedder;
package org.apache.maven.execution;
/*
* Licensed to the Apache Software Foundation (ASF) under one
@ -22,20 +22,20 @@ package org.apache.maven.embedder;
/**
* @author Jason van Zyl
*/
public class MavenEmbedderException
public class MavenExecutionRequestPopulationException
extends Exception
{
public MavenEmbedderException( String message )
public MavenExecutionRequestPopulationException( String message )
{
super( message );
}
public MavenEmbedderException( Throwable cause )
public MavenExecutionRequestPopulationException( Throwable cause )
{
super( cause );
}
public MavenEmbedderException( String message,
public MavenExecutionRequestPopulationException( String message,
Throwable cause )
{
super( message, cause );

View File

@ -1,4 +1,4 @@
package org.apache.maven.embedder.execution;
package org.apache.maven.execution;
/*
* Licensed to the Apache Software Foundation (ASF) under one
@ -19,8 +19,6 @@ package org.apache.maven.embedder.execution;
* under the License.
*/
import org.apache.maven.embedder.MavenEmbedderException;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.settings.Settings;
/**
@ -39,19 +37,19 @@ public interface MavenExecutionRequestPopulator
* @param request The execution request to populate, must not be {@code null}.
* @param settings The settings to copy into the execution request, may be {@code null}.
* @return The populated execution request, never {@code null}.
* @throws MavenEmbedderException If the execution request could not be populated.
* @throws MavenExecutionRequestPopulationException If the execution request could not be populated.
*/
MavenExecutionRequest populateFromSettings( MavenExecutionRequest request, Settings settings )
throws MavenEmbedderException;
throws MavenExecutionRequestPopulationException;
/**
* Injects default values like plugin groups or repositories into the specified execution request.
*
* @param request The execution request to populate, must not be {@code null}.
* @return The populated execution request, never {@code null}.
* @throws MavenEmbedderException If the execution request could not be populated.
* @throws MavenExecutionRequestPopulationException If the execution request could not be populated.
*/
MavenExecutionRequest populateDefaults( MavenExecutionRequest request )
throws MavenEmbedderException;
throws MavenExecutionRequestPopulationException;
}

View File

@ -28,7 +28,7 @@ import java.util.Locale;
import java.util.Properties;
import java.util.TimeZone;
import org.apache.maven.embedder.MavenEmbedderLogger;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.Os;
@ -89,7 +89,7 @@ public final class CLIReportingUtils
}
private static void stats( Date start, MavenEmbedderLogger logger )
private static void stats( Date start, Logger logger )
{
Date finish = new Date();
@ -182,7 +182,7 @@ public final class CLIReportingUtils
return properties;
}
public static void showError( MavenEmbedderLogger logger, String message, Exception e, boolean showStackTrace )
public static void showError( Logger logger, String message, Exception e, boolean showStackTrace )
{
if ( showStackTrace )
{

View File

@ -31,7 +31,6 @@ import java.util.Map.Entry;
import org.apache.commons.cli.CommandLine;
import org.apache.maven.Maven;
import org.apache.maven.MavenTransferListener;
import org.apache.maven.embedder.MavenEmbedder;
import org.apache.maven.execution.MavenExecutionRequest;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.cli.CommandLineUtils;
@ -224,7 +223,7 @@ final class CLIRequestUtils
}
else
{
userToolchainsFile = MavenEmbedder.DEFAULT_USER_TOOLCHAINS_FILE;
userToolchainsFile = MavenCli.DEFAULT_USER_TOOLCHAINS_FILE;
}
request

View File

@ -1,4 +1,4 @@
package org.apache.maven.embedder;
package org.apache.maven.cli;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@ -25,6 +25,7 @@ import java.util.Properties;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.classworlds.ClassWorld;
import org.codehaus.plexus.logging.Logger;
/**
* Configuration of embedder, used when starting up.
@ -52,9 +53,9 @@ public interface Configuration
// Logger
// ----------------------------------------------------------------------------
Configuration setMavenEmbedderLogger( MavenEmbedderLogger logger );
Configuration setMavenEmbedderLogger( Logger logger );
MavenEmbedderLogger getMavenEmbedderLogger();
Logger getMavenEmbedderLogger();
// ----------------------------------------------------------------------------
// ClassWorld/ClassLoader
@ -86,9 +87,6 @@ public interface Configuration
/** Add a list of String instances with names of profiles to inactivate. */
Configuration addInactiveProfiles( List<String> profiles );
/** Set a customizer callback implemetation that will be given a chance to modify the plexus container on startup. */
Configuration setConfigurationCustomizer( ContainerCustomizer customizer );
/** set the system properties to be used during the lifecycle of the embedder. Excluding the time when executing the project, then the properties from MavenExecutionRequestare used. */
Configuration setSystemProperties( Properties properties );
@ -96,12 +94,6 @@ public interface Configuration
List<String> getInactiveProfiles();
// ----------------------------------------------------------------------------
// Container Customizer
// ----------------------------------------------------------------------------
ContainerCustomizer getContainerCustomizer();
// ----------------------------------------------------------------------------
// System Properties
// ----------------------------------------------------------------------------

View File

@ -1,4 +1,4 @@
package org.apache.maven.embedder;
package org.apache.maven.cli;
/*
* Licensed to the Apache Software Foundation (ASF) under one

View File

@ -1,4 +1,4 @@
package org.apache.maven.embedder;
package org.apache.maven.cli;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@ -26,6 +26,7 @@ import java.util.Properties;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.classworlds.ClassWorld;
import org.codehaus.plexus.logging.Logger;
/**
* Default implementation of Configuration intefrace.
@ -43,13 +44,11 @@ public class DefaultConfiguration
private File globalSettings;
private ContainerCustomizer customizer;
private Properties systemProperties;
private List<URL> extensions = new ArrayList<URL>();
private MavenEmbedderLogger logger;
private Logger logger;
private ClassWorld classWorld;
@ -128,17 +127,6 @@ public class DefaultConfiguration
return globalSettings;
}
public Configuration setConfigurationCustomizer( ContainerCustomizer customizer )
{
this.customizer = customizer;
return this;
}
public ContainerCustomizer getContainerCustomizer()
{
return customizer;
}
public Configuration setSystemProperties( Properties properties )
{
systemProperties = properties;
@ -160,13 +148,13 @@ public class DefaultConfiguration
return extensions;
}
public Configuration setMavenEmbedderLogger( MavenEmbedderLogger logger )
public Configuration setMavenEmbedderLogger( Logger logger )
{
this.logger = logger;
return this;
}
public MavenEmbedderLogger getMavenEmbedderLogger()
public Logger getMavenEmbedderLogger()
{
return logger;
}

View File

@ -1,4 +1,4 @@
package org.apache.maven.embedder;
package org.apache.maven.cli;
/*
* Licensed to the Apache Software Foundation (ASF) under one

View File

@ -24,7 +24,6 @@ import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
import org.apache.maven.embedder.MavenEmbedderLogger;
import org.apache.maven.execution.AbstractExecutionListener;
import org.apache.maven.execution.BuildFailure;
import org.apache.maven.execution.BuildSuccess;
@ -34,6 +33,7 @@ import org.apache.maven.execution.MavenExecutionResult;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.logging.Logger;
/**
* Logs execution events to a user-supplied logger.
@ -43,12 +43,11 @@ import org.apache.maven.project.MavenProject;
class ExecutionEventLogger
extends AbstractExecutionListener
{
private final MavenEmbedderLogger logger;
private final Logger logger;
private static final int LINE_LENGTH = 72;
public ExecutionEventLogger( MavenEmbedderLogger logger )
public ExecutionEventLogger( Logger logger )
{
if ( logger == null )
{

View File

@ -1,4 +1,4 @@
package org.apache.maven.embedder;
package org.apache.maven.cli;
/*
* Licensed to the Apache Software Foundation (ASF) under one
@ -27,11 +27,11 @@ import java.io.PrintStream;
* @author Jason van Zyl
* @todo document the need to call close() once successfully constructed, otherwise file handles can be leaked. Might be good to add a finalizer too, just in case.
*/
public final class MavenEmbedderFileLogger
extends MavenEmbedderPrintStreamLogger
public final class FileLogger
extends PrintStreamLogger
{
public MavenEmbedderFileLogger( File logFile )
public FileLogger( File logFile )
{
super( openStream( logFile ) );
}

View File

@ -17,27 +17,32 @@ package org.apache.maven.cli;
import java.io.File;
import java.io.IOException;
import java.io.Reader;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.ParseException;
import org.apache.maven.embedder.Configuration;
import org.apache.maven.embedder.ConfigurationValidationResult;
import org.apache.maven.embedder.DefaultConfiguration;
import org.apache.maven.embedder.MavenEmbedder;
import org.apache.maven.embedder.MavenEmbedderConsoleLogger;
import org.apache.maven.embedder.MavenEmbedderException;
import org.apache.maven.embedder.MavenEmbedderFileLogger;
import org.apache.maven.embedder.MavenEmbedderLogger;
import org.apache.maven.embedder.execution.MavenExecutionRequestPopulator;
import org.apache.maven.Maven;
import org.apache.maven.exception.ExceptionSummary;
import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.DefaultMavenExecutionResult;
import org.apache.maven.execution.MavenExecutionRequestPopulationException;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionRequestPopulator;
import org.apache.maven.execution.MavenExecutionResult;
import org.apache.maven.settings.MavenSettingsBuilder;
import org.apache.maven.settings.Settings;
import org.apache.maven.settings.io.xpp3.SettingsXpp3Reader;
import org.codehaus.plexus.ContainerConfiguration;
import org.codehaus.plexus.DefaultContainerConfiguration;
import org.codehaus.plexus.DefaultPlexusContainer;
import org.codehaus.plexus.PlexusContainerException;
import org.codehaus.plexus.classworlds.ClassWorld;
import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.logging.console.ConsoleLogger;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.sonatype.plexus.components.cipher.DefaultPlexusCipher;
import org.sonatype.plexus.components.sec.dispatcher.DefaultSecDispatcher;
@ -53,6 +58,17 @@ public class MavenCli
{
public static final String LOCAL_REPO_PROPERTY = "maven.repo.local";
public static final String userHome = System.getProperty( "user.home" );
public static final File userMavenConfigurationHome = new File( userHome, ".m2" );
public static final File DEFAULT_USER_SETTINGS_FILE = new File( userMavenConfigurationHome, "settings.xml" );
public static final File DEFAULT_GLOBAL_SETTINGS_FILE =
new File( System.getProperty( "maven.home", System.getProperty( "user.dir", "" ) ), "conf/settings.xml" );
public static final File DEFAULT_USER_TOOLCHAINS_FILE = new File( userMavenConfigurationHome, "toolchains.xml" );
public static void main( String[] args )
{
ClassWorld classWorld = new ClassWorld( "plexus.core", Thread.currentThread().getContextClassLoader() );
@ -122,23 +138,41 @@ public class MavenCli
System.setProperty( "maven.home", new File( mavenHome ).getAbsolutePath() );
}
Configuration configuration = buildEmbedderConfiguration( commandLine, classWorld );
MavenEmbedderLogger logger = configuration.getMavenEmbedderLogger();
MavenEmbedder mavenEmbedder;
//
Maven maven;
DefaultPlexusContainer container;
Logger logger;
try
{
mavenEmbedder = new MavenEmbedder( configuration );
ContainerConfiguration cc = new DefaultContainerConfiguration()
.setClassWorld( classWorld )
.setName( "embedder" );
container = new DefaultPlexusContainer( cc );
logger = container.getLogger();
maven = container.lookup( Maven.class );
}
catch ( MavenEmbedderException e )
catch ( PlexusContainerException e )
{
CLIReportingUtils.showError( logger, "Unable to start the embedder: ", e, showErrors );
CLIReportingUtils.showError( new ConsoleLogger( Logger.LEVEL_ERROR, Maven.class.getName() ), "Unable to start the embedder: ", e, showErrors );
return 1;
}
catch ( ComponentLookupException e )
{
CLIReportingUtils.showError( new ConsoleLogger( Logger.LEVEL_ERROR, Maven.class.getName() ), "Unable to start the embedder: ", e, showErrors );
return 1;
}
Configuration configuration = buildEmbedderConfiguration( commandLine );
MavenExecutionRequest request = new DefaultMavenExecutionRequest();
request.setGlobalSettingsFile( configuration.getGlobalSettingsFile() );
@ -150,8 +184,7 @@ public class MavenCli
try
{
MavenSettingsBuilder settingsBuilder =
mavenEmbedder.getPlexusContainer().lookup( MavenSettingsBuilder.class );
MavenSettingsBuilder settingsBuilder = container.lookup( MavenSettingsBuilder.class );
try
{
@ -161,7 +194,7 @@ public class MavenCli
{
try
{
mavenEmbedder.getPlexusContainer().release( settingsBuilder );
container.release( settingsBuilder );
}
catch ( ComponentLifecycleException e )
{
@ -190,8 +223,7 @@ public class MavenCli
try
{
MavenExecutionRequestPopulator requestPopulator =
mavenEmbedder.getPlexusContainer().lookup( MavenExecutionRequestPopulator.class );
MavenExecutionRequestPopulator requestPopulator = container.lookup( MavenExecutionRequestPopulator.class );
try
{
@ -201,7 +233,7 @@ public class MavenCli
{
try
{
mavenEmbedder.getPlexusContainer().release( requestPopulator );
container.release( requestPopulator );
}
catch ( ComponentLifecycleException e )
{
@ -215,7 +247,7 @@ public class MavenCli
return 1;
}
catch ( MavenEmbedderException e )
catch ( MavenExecutionRequestPopulationException e )
{
CLIReportingUtils.showError( logger, "Failed to process settings: ", e, showErrors );
@ -245,20 +277,18 @@ public class MavenCli
logger.info( "Enabling strict checksum verification on all artifact downloads." );
}
ConfigurationValidationResult cvr = MavenEmbedder.validateConfiguration( configuration );
ConfigurationValidationResult cvr = validateConfiguration( configuration );
if ( cvr.isUserSettingsFilePresent() && !cvr.isUserSettingsFileParses() )
{
CLIReportingUtils.showError( logger, "Error reading user settings: ", cvr.getUserSettingsException(),
showErrors );
CLIReportingUtils.showError( logger, "Error reading user settings: ", cvr.getUserSettingsException(), showErrors );
return 1;
}
if ( cvr.isGlobalSettingsFilePresent() && !cvr.isGlobalSettingsFileParses() )
{
CLIReportingUtils.showError( logger, "Error reading global settings: ", cvr.getGlobalSettingsException(),
showErrors );
CLIReportingUtils.showError( logger, "Error reading global settings: ", cvr.getGlobalSettingsException(), showErrors );
return 1;
}
@ -291,14 +321,14 @@ public class MavenCli
String passwd = commandLine.getOptionValue( CLIManager.ENCRYPT_PASSWORD );
DefaultSecDispatcher dispatcher;
dispatcher = (DefaultSecDispatcher) mavenEmbedder.getPlexusContainer().lookup( SecDispatcher.class );
dispatcher = (DefaultSecDispatcher) container.lookup( SecDispatcher.class );
String configurationFile = dispatcher.getConfigurationFile();
if ( configurationFile.startsWith( "~" ) )
{
configurationFile = System.getProperty( "user.home" ) + configurationFile.substring( 1 );
}
String file = System.getProperty( DefaultSecDispatcher.SYSTEM_PROPERTY_SEC_LOCATION, configurationFile );
mavenEmbedder.getPlexusContainer().release( dispatcher );
container.release( dispatcher );
String master = null;
@ -316,8 +346,7 @@ public class MavenCli
}
DefaultPlexusCipher cipher = new DefaultPlexusCipher();
String masterPasswd =
cipher.decryptDecorated( master, DefaultSecDispatcher.SYSTEM_PROPERTY_SEC_LOCATION );
String masterPasswd = cipher.decryptDecorated( master, DefaultSecDispatcher.SYSTEM_PROPERTY_SEC_LOCATION );
System.out.println( cipher.encryptAndDecorate( passwd, masterPasswd ) );
return 0;
@ -326,21 +355,28 @@ public class MavenCli
catch ( Exception e )
{
System.err.println( "FATAL ERROR: " + "Error encrypting password: " + e.getMessage() );
e.printStackTrace();
return 1;
}
MavenExecutionResult result = mavenEmbedder.execute( request );
MavenExecutionResult result = new DefaultMavenExecutionResult();
try
{
mavenEmbedder.stop();
MavenExecutionRequestPopulator populator = container.lookup( MavenExecutionRequestPopulator.class );
request = populator.populateDefaults( request );
}
catch ( MavenEmbedderException e )
catch ( MavenExecutionRequestPopulationException e )
{
result.addException( e );
}
catch ( ComponentLookupException e )
{
result.addException( e );
}
result = maven.execute( request );
// The exception handling should be handled in Maven itself.
@ -381,7 +417,7 @@ public class MavenCli
}
}
private Configuration buildEmbedderConfiguration( CommandLine commandLine, ClassWorld classWorld )
private Configuration buildEmbedderConfiguration( CommandLine commandLine )
{
File userSettingsFile;
@ -391,7 +427,7 @@ public class MavenCli
}
else
{
userSettingsFile = MavenEmbedder.DEFAULT_USER_SETTINGS_FILE;
userSettingsFile = DEFAULT_USER_SETTINGS_FILE;
}
File globalSettingsFile;
@ -402,23 +438,92 @@ public class MavenCli
}
else
{
globalSettingsFile = MavenEmbedder.DEFAULT_GLOBAL_SETTINGS_FILE;
globalSettingsFile = DEFAULT_GLOBAL_SETTINGS_FILE;
}
Configuration configuration = new DefaultConfiguration().setUserSettingsFile( userSettingsFile ).setGlobalSettingsFile( globalSettingsFile ).setClassWorld( classWorld );
Configuration configuration = new DefaultConfiguration().setUserSettingsFile( userSettingsFile ).setGlobalSettingsFile( globalSettingsFile );
if ( commandLine.hasOption( CLIManager.LOG_FILE ) )
{
File logFile = new File( commandLine.getOptionValue( CLIManager.LOG_FILE ) ).getAbsoluteFile();
configuration.setMavenEmbedderLogger( new MavenEmbedderFileLogger( logFile ) );
configuration.setMavenEmbedderLogger( new FileLogger( logFile ) );
}
else
{
configuration.setMavenEmbedderLogger( new MavenEmbedderConsoleLogger() );
configuration.setMavenEmbedderLogger( new ConsoleLogger( Logger.LEVEL_ERROR, Maven.class.getName()) );
}
return configuration;
}
// ----------------------------------------------------------------------------
// Options for settings
//
// 1. No settings
// 2. User settings only
// 3. Global settings only
// 4. Both Users settings and Global settings. In the case that both are present
// the User settings take priority.
//
// What we would like to provide is a way that the client code does not have
// to deal with settings configuration at all.
// ----------------------------------------------------------------------------
public static ConfigurationValidationResult validateConfiguration( Configuration configuration )
{
DefaultConfigurationValidationResult result = new DefaultConfigurationValidationResult();
Reader fileReader = null;
// User settings
if ( configuration.getUserSettingsFile() != null )
{
try
{
fileReader = ReaderFactory.newXmlReader( configuration.getUserSettingsFile() );
result.setUserSettings( new SettingsXpp3Reader().read( fileReader ) );
}
catch ( IOException e )
{
result.setUserSettingsException( e );
}
catch ( XmlPullParserException e )
{
result.setUserSettingsException( e );
}
finally
{
IOUtil.close( fileReader );
}
}
// Global settings
if ( configuration.getGlobalSettingsFile() != null )
{
try
{
fileReader = ReaderFactory.newXmlReader( configuration.getGlobalSettingsFile() );
result.setGlobalSettings( new SettingsXpp3Reader().read( fileReader ) );
}
catch ( IOException e )
{
result.setGlobalSettingsException( e );
}
catch ( XmlPullParserException e )
{
result.setGlobalSettingsException( e );
}
finally
{
IOUtil.close( fileReader );
}
}
return result;
}
}

View File

@ -1,4 +1,4 @@
package org.apache.maven.embedder;
package org.apache.maven.cli;
/*
* Licensed to the Apache Software Foundation (ASF) under one
@ -21,15 +21,17 @@ package org.apache.maven.embedder;
import java.io.PrintStream;
import org.apache.maven.Maven;
import org.codehaus.plexus.logging.Logger;
/**
* Logs to a user-supplied {@link PrintStream}.
*
* @author Benjamin Bentmann
*/
public class MavenEmbedderPrintStreamLogger
extends AbstractMavenEmbedderLogger
public class PrintStreamLogger
implements Logger
{
private final PrintStream out;
private static final String FATAL_ERROR = "[FATAL] ";
@ -42,7 +44,7 @@ public class MavenEmbedderPrintStreamLogger
private static final String DEBUG = "[DEBUG] ";
public MavenEmbedderPrintStreamLogger( PrintStream out )
public PrintStreamLogger( PrintStream out )
{
if ( out == null )
{
@ -52,6 +54,11 @@ public class MavenEmbedderPrintStreamLogger
this.out = out;
}
public void debug( String message )
{
debug( message, null );
}
public void debug( String message, Throwable throwable )
{
if ( isDebugEnabled() )
@ -66,6 +73,11 @@ public class MavenEmbedderPrintStreamLogger
}
}
public void info( String message )
{
info( message, null );
}
public void info( String message, Throwable throwable )
{
if ( isInfoEnabled() )
@ -80,6 +92,11 @@ public class MavenEmbedderPrintStreamLogger
}
}
public void warn( String message )
{
warn( message, null );
}
public void warn( String message, Throwable throwable )
{
if ( isWarnEnabled() )
@ -94,6 +111,11 @@ public class MavenEmbedderPrintStreamLogger
}
}
public void error( String message )
{
error( message, null );
}
public void error( String message, Throwable throwable )
{
if ( isErrorEnabled() )
@ -108,6 +130,11 @@ public class MavenEmbedderPrintStreamLogger
}
}
public void fatalError( String message )
{
fatalError( message, null );
}
public void fatalError( String message, Throwable throwable )
{
if ( isFatalErrorEnabled() )
@ -134,4 +161,47 @@ public class MavenEmbedderPrintStreamLogger
}
}
public Logger getChildLogger( String arg0 )
{
return this;
}
public String getName()
{
return Maven.class.getName();
}
public int getThreshold()
{
return 0;
}
public boolean isDebugEnabled()
{
return false;
}
public boolean isErrorEnabled()
{
return false;
}
public boolean isFatalErrorEnabled()
{
return false;
}
public boolean isInfoEnabled()
{
return false;
}
public boolean isWarnEnabled()
{
return false;
}
public void setThreshold( int arg0 )
{
}
}

View File

@ -1,126 +0,0 @@
package org.apache.maven.embedder;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
*/
public abstract class AbstractMavenEmbedderLogger
implements MavenEmbedderLogger
{
private int threshold = MavenEmbedderLogger.LEVEL_INFO;
private String name;
public int getThreshold()
{
return threshold;
}
public void setThreshold( int threshold )
{
this.threshold = threshold;
}
public String getName()
{
return name;
}
public void debug( String message )
{
debug( message, null );
}
public boolean isDebugEnabled()
{
return threshold <= LEVEL_DEBUG;
}
public void info( String message )
{
info( message, null );
}
public boolean isInfoEnabled()
{
return threshold <= LEVEL_INFO;
}
public void warn( String message )
{
warn( message, null );
}
public boolean isWarnEnabled()
{
return threshold <= LEVEL_WARN;
}
public void error( String message )
{
error( message, null );
}
public boolean isErrorEnabled()
{
return threshold <= LEVEL_ERROR;
}
public void fatalError( String message )
{
fatalError( message, null );
}
public boolean isFatalErrorEnabled()
{
return threshold <= LEVEL_FATAL;
}
protected boolean isValidThreshold( int threshold )
{
if ( threshold == LEVEL_DEBUG )
{
return true;
}
if ( threshold == LEVEL_INFO )
{
return true;
}
if ( threshold == LEVEL_WARN )
{
return true;
}
if ( threshold == LEVEL_ERROR )
{
return true;
}
if ( threshold == LEVEL_FATAL )
{
return true;
}
if ( threshold == LEVEL_DISABLED )
{
return true;
}
return false;
}
}

View File

@ -1,38 +0,0 @@
package org.apache.maven.embedder;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.codehaus.plexus.PlexusContainer;
/**
* Instances of this interface can be user upon start of the embedder to customize
* the components in the plexus container.
*
* @author mkleint
*/
public interface ContainerCustomizer
{
/**
* callback from embedder's start() method that allows to customize the components
* in the container.
*/
void customize( PlexusContainer container );
}

View File

@ -1,477 +0,0 @@
package org.apache.maven.embedder;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.File;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import org.apache.maven.Maven;
import org.apache.maven.embedder.execution.MavenExecutionRequestPopulator;
import org.apache.maven.execution.DefaultMavenExecutionResult;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResult;
import org.apache.maven.model.Model;
import org.apache.maven.model.io.ModelReader;
import org.apache.maven.model.io.ModelWriter;
import org.apache.maven.project.ProjectBuilder;
import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.settings.Settings;
import org.apache.maven.settings.SettingsConfigurationException;
import org.apache.maven.settings.io.xpp3.SettingsXpp3Reader;
import org.apache.maven.settings.io.xpp3.SettingsXpp3Writer;
import org.apache.maven.settings.validation.DefaultSettingsValidator;
import org.apache.maven.settings.validation.SettingsValidationResult;
import org.apache.maven.settings.validation.SettingsValidator;
import org.codehaus.plexus.ContainerConfiguration;
import org.codehaus.plexus.DefaultContainerConfiguration;
import org.codehaus.plexus.DefaultPlexusContainer;
import org.codehaus.plexus.MutablePlexusContainer;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.PlexusContainerException;
import org.codehaus.plexus.classworlds.ClassWorld;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.logging.LoggerManager;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.WriterFactory;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
/**
* Class intended to be used by clients who wish to embed Maven into their applications.
*
* @author Jason van Zyl
*/
//TODO: just turn this into a component
public class MavenEmbedder
{
public static final String userHome = System.getProperty( "user.home" );
public static final File userMavenConfigurationHome = new File( userHome, ".m2" );
public static final File DEFAULT_USER_SETTINGS_FILE = new File( userMavenConfigurationHome, "settings.xml" );
public static final File DEFAULT_GLOBAL_SETTINGS_FILE =
new File( System.getProperty( "maven.home", System.getProperty( "user.dir", "" ) ), "conf/settings.xml" );
public static final File DEFAULT_USER_TOOLCHAINS_FILE = new File( userMavenConfigurationHome, "toolchains.xml" );
// ----------------------------------------------------------------------------
//
// ----------------------------------------------------------------------------
//TODO: this needs to be the standard container
private MutablePlexusContainer container;
// ----------------------------------------------------------------------
// Components
// ----------------------------------------------------------------------
private Maven maven;
private ProjectBuilder projectBuilder;
private ModelReader modelReader;
private ModelWriter modelWriter;
private MavenExecutionRequestPopulator populator;
// ----------------------------------------------------------------------
// Configuration
// ----------------------------------------------------------------------
private ClassWorld classWorld;
private MavenEmbedderLogger logger;
private boolean activateSystemManager;
// ----------------------------------------------------------------------
// User options
// ----------------------------------------------------------------------
private Configuration configuration;
//private MavenExecutionRequest request;
// ----------------------------------------------------------------------------
// Constructors
// ----------------------------------------------------------------------------
public MavenEmbedder( Configuration embedderConfiguration )
throws MavenEmbedderException
{
start( embedderConfiguration );
}
/*
public MavenExecutionRequest getDefaultRequest()
{
return request;
}
*/
// ----------------------------------------------------------------------
// Accessors
// ----------------------------------------------------------------------
public ClassWorld getClassWorld()
{
return classWorld;
}
/*
public ArtifactRepository getLocalRepository()
{
return request.getLocalRepository();
}
public Settings getSettings()
{
return request.getSettings();
}
*/
public MavenEmbedderLogger getLogger()
{
return logger;
}
public void setLogger( MavenEmbedderLogger logger )
{
this.logger = logger;
}
public Model readModel( File file )
throws XmlPullParserException, IOException
{
Reader reader = ReaderFactory.newXmlReader( file );
try
{
return readModel( reader );
}
finally
{
IOUtil.close( reader );
}
}
public Model readModel( Reader reader )
throws XmlPullParserException, IOException
{
return modelReader.read( reader, null );
}
public void writeModel( Writer writer, Model model, boolean namespaceDeclaration )
throws IOException
{
modelWriter.write( writer, null, model );
}
public void writeModel( Writer writer,
Model model )
throws IOException
{
modelWriter.write( writer, null, model );
}
// ----------------------------------------------------------------------
// Settings
// ----------------------------------------------------------------------
public static void writeSettings( File file,
Settings settings )
throws IOException
{
SettingsValidator settingsValidator = new DefaultSettingsValidator();
SettingsValidationResult validationResult = settingsValidator.validate( settings );
if ( validationResult.getMessageCount() > 0 )
{
throw new IOException( "Failed to validate Settings.\n" + validationResult.render( "\n" ) );
}
SettingsXpp3Writer writer = new SettingsXpp3Writer();
Writer fileWriter = WriterFactory.newXmlWriter( file );
try
{
writer.write( fileWriter, settings );
}
finally
{
IOUtil.close( fileWriter );
}
}
public static Settings readSettings( File file )
throws IOException, SettingsConfigurationException
{
Reader fileReader = ReaderFactory.newXmlReader( file );
SettingsValidator settingsValidator = new DefaultSettingsValidator();
SettingsXpp3Reader reader = new SettingsXpp3Reader();
try
{
Settings settings = reader.read( fileReader );
SettingsValidationResult validationResult = settingsValidator.validate( settings );
if ( validationResult.getMessageCount() > 0 )
{
throw new IOException( "Failed to validate Settings.\n" + validationResult.render( "\n" ) );
}
return settings;
}
catch ( XmlPullParserException e )
{
throw new SettingsConfigurationException( "Failed to parse settings.", e );
}
finally
{
IOUtil.close( fileReader );
}
}
// ----------------------------------------------------------------------
// Lifecycle
// ----------------------------------------------------------------------
private void start( Configuration configuration )
throws MavenEmbedderException
{
classWorld = configuration.getClassWorld();
logger = configuration.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() );
}
this.configuration = configuration;
try
{
ContainerConfiguration cc = new DefaultContainerConfiguration()
.setClassWorld( classWorld )
.setName( "embedder" );
container = new DefaultPlexusContainer( cc );
}
catch ( PlexusContainerException e )
{
throw new MavenEmbedderException( "Error creating Plexus container for Maven Embedder", e );
}
if ( logger != null )
{
MavenEmbedderLoggerManager loggerManager =
new MavenEmbedderLoggerManager( new PlexusLoggerAdapter( logger ) );
container.setLoggerManager( loggerManager );
}
try
{
if ( configuration.getContainerCustomizer() != null )
{
configuration.getContainerCustomizer().customize( container );
}
// ----------------------------------------------------------------------
// Lookup each of the components we need to provide the desired
// client interface.
// ----------------------------------------------------------------------
modelReader = container.lookup( ModelReader.class );
modelWriter = container.lookup( ModelWriter.class );
maven = container.lookup( Maven.class );
projectBuilder = container.lookup( ProjectBuilder.class );
populator = container.lookup( MavenExecutionRequestPopulator.class );
container.lookup( RepositorySystem.class );
// This is temporary as we can probably cache a single request and use it for default values and
// simply cascade values in from requests used for individual executions.
//request = new DefaultMavenExecutionRequest();
//
//populator.populateDefaults( request, configuration );
}
catch ( ComponentLookupException e )
{
throw new MavenEmbedderException( "Cannot lookup required component.", e );
}
}
public void stop()
throws MavenEmbedderException
{
container.dispose();
}
// ----------------------------------------------------------------------------
// Validation
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Options for settings
//
// 1. No settings
// 2. User settings only
// 3. Global settings only
// 4. Both Users settings and Global settings. In the case that both are present
// the User settings take priority.
//
// What we would like to provide is a way that the client code does not have
// to deal with settings configuration at all.
// ----------------------------------------------------------------------------
public static ConfigurationValidationResult validateConfiguration( Configuration configuration )
{
DefaultConfigurationValidationResult result = new DefaultConfigurationValidationResult();
Reader fileReader = null;
// User settings
if ( configuration.getUserSettingsFile() != null )
{
try
{
fileReader = ReaderFactory.newXmlReader( configuration.getUserSettingsFile() );
result.setUserSettings( new SettingsXpp3Reader().read( fileReader ) );
}
catch ( IOException e )
{
result.setUserSettingsException( e );
}
catch ( XmlPullParserException e )
{
result.setUserSettingsException( e );
}
finally
{
IOUtil.close( fileReader );
}
}
// Global settings
if ( configuration.getGlobalSettingsFile() != null )
{
try
{
fileReader = ReaderFactory.newXmlReader( configuration.getGlobalSettingsFile() );
result.setGlobalSettings( new SettingsXpp3Reader().read( fileReader ) );
}
catch ( IOException e )
{
result.setGlobalSettingsException( e );
}
catch ( XmlPullParserException e )
{
result.setGlobalSettingsException( e );
}
finally
{
IOUtil.close( fileReader );
}
}
return result;
}
// ----------------------------------------------------------------------------
// Configuration
// ----------------------------------------------------------------------------
public Configuration getConfiguration()
{
return configuration;
}
public MavenExecutionResult execute( MavenExecutionRequest request )
{
LoggerManager loggerManager = container.getLoggerManager();
int oldThreshold = loggerManager.getThreshold();
try
{
loggerManager.setThresholds( request.getLoggingLevel() );
try
{
request = populator.populateDefaults( request );
}
catch ( MavenEmbedderException e )
{
MavenExecutionResult result = new DefaultMavenExecutionResult();
result.addException( e );
return result;
}
return maven.execute( request );
}
finally
{
loggerManager.setThresholds( oldThreshold );
}
}
/**
* Return the instance of the plexus container being used in the embedder.
*
* @return The plexus container used in the embedder.
*/
public PlexusContainer getPlexusContainer()
{
return container;
}
}

View File

@ -1,38 +0,0 @@
package org.apache.maven.embedder;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
/**
* Logger sending everything to the standard output streams.
* This is mainly for the cases when you have a utility that
* does not have a logger to supply.
*
* @author <a href="mailto:dev@avalon.codehaus.org">Avalon Development Team</a>
*/
public final class MavenEmbedderConsoleLogger
extends MavenEmbedderPrintStreamLogger
{
public MavenEmbedderConsoleLogger()
{
super( System.out );
}
}

View File

@ -1,79 +0,0 @@
package org.apache.maven.embedder;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 Jason van Zyl
*/
public interface MavenEmbedderLogger
{
int LEVEL_DEBUG = 0;
int LEVEL_INFO = 1;
int LEVEL_WARN = 2;
int LEVEL_ERROR = 3;
int LEVEL_FATAL = 4;
int LEVEL_DISABLED = 5;
void debug( String message );
void debug( String message,
Throwable throwable );
boolean isDebugEnabled();
void info( String message );
void info( String message,
Throwable throwable );
boolean isInfoEnabled();
void warn( String message );
void warn( String message,
Throwable throwable );
boolean isWarnEnabled();
void error( String message );
void error( String message,
Throwable throwable );
boolean isErrorEnabled();
void fatalError( String message );
void fatalError( String message,
Throwable throwable );
boolean isFatalErrorEnabled();
void setThreshold( int threshold );
int getThreshold();
void close();
}

View File

@ -1,160 +0,0 @@
package org.apache.maven.embedder;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.codehaus.plexus.logging.AbstractLoggerManager;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.logging.LoggerManager;
import org.codehaus.plexus.logging.console.ConsoleLogger;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
/**
* This is a simple logger manager that will only write the logging statements to the console.
* <p/>
* Sample configuration:
* <pre>
* <logging>
* <implementation>org.codehaus.plexus.logging.ConsoleLoggerManager</implementation>
* <logger>
* <threshold>DEBUG</threshold>
* </logger>
* </logging>
* </pre>
*
* @author Jason van Zyl
* @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
*/
public class MavenEmbedderLoggerManager
extends AbstractLoggerManager
implements LoggerManager, Initializable
{
/**
* Message of this level or higher will be logged.
* <p/>
* This field is set by the plexus container thus the name is 'threshold'. The field
* currentThreshold contains the current setting of the threshold.
*/
private String threshold = "info";
private int currentThreshold;
private Logger logger;
public MavenEmbedderLoggerManager( Logger logger )
{
this.logger = logger;
}
public void initialize()
{
debug( "Initializing ConsoleLoggerManager: " + this.hashCode() + "." );
currentThreshold = parseThreshold( threshold );
if ( currentThreshold == -1 )
{
debug( "Could not parse the threshold level: '" + threshold + "', setting to debug." );
currentThreshold = Logger.LEVEL_DEBUG;
}
}
public void setThreshold( int currentThreshold )
{
this.currentThreshold = currentThreshold;
}
public void setThresholds( int currentThreshold )
{
this.currentThreshold = currentThreshold;
logger.setThreshold( currentThreshold );
}
/** @return Returns the threshold. */
public int getThreshold()
{
return currentThreshold;
}
public void setThreshold( String role,
String roleHint,
int threshold )
{
}
public int getThreshold( String role,
String roleHint )
{
return currentThreshold;
}
public Logger getLoggerForComponent( String role,
String roleHint )
{
return logger;
}
public void returnComponentLogger( String role,
String roleHint )
{
}
public int getActiveLoggerCount()
{
return 1;
}
private int parseThreshold( String text )
{
text = text.trim().toLowerCase();
if ( text.equals( "debug" ) )
{
return ConsoleLogger.LEVEL_DEBUG;
}
else if ( text.equals( "info" ) )
{
return ConsoleLogger.LEVEL_INFO;
}
else if ( text.equals( "warn" ) )
{
return ConsoleLogger.LEVEL_WARN;
}
else if ( text.equals( "error" ) )
{
return ConsoleLogger.LEVEL_ERROR;
}
else if ( text.equals( "fatal" ) )
{
return ConsoleLogger.LEVEL_FATAL;
}
return -1;
}
/**
* Remove this method and all references when this code is verified.
*
* @param msg
*/
private void debug( String msg )
{
}
}

View File

@ -1,32 +0,0 @@
package org.apache.maven.embedder;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 Jason van Zyl */
public class MavenEmbedderSecurityManager
extends SecurityManager
{
public void checkPropertyAccess( String key )
{
super.checkPropertyAccess( key );
throw new SecurityException( "You cannot modify any System properties!" );
}
}

View File

@ -1,136 +0,0 @@
package org.apache.maven.embedder;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.codehaus.plexus.logging.Logger;
/**
* @author Jason van Zyl
*/
public class PlexusLoggerAdapter
implements Logger
{
private MavenEmbedderLogger logger;
public PlexusLoggerAdapter( MavenEmbedderLogger logger )
{
this.logger = logger;
}
public void debug( String message )
{
logger.debug( message );
}
public void debug( String message,
Throwable throwable )
{
logger.debug( message, throwable );
}
public boolean isDebugEnabled()
{
return logger.isDebugEnabled();
}
public void info( String message )
{
logger.info( message );
}
public void info( String message,
Throwable throwable )
{
logger.info( message, throwable );
}
public boolean isInfoEnabled()
{
return logger.isInfoEnabled();
}
public void warn( String message )
{
logger.warn( message );
}
public void warn( String message,
Throwable throwable )
{
logger.warn( message, throwable );
}
public boolean isWarnEnabled()
{
return logger.isWarnEnabled();
}
public void error( String message )
{
logger.error( message );
}
public void error( String message,
Throwable throwable )
{
logger.error( message, throwable );
}
public boolean isErrorEnabled()
{
return logger.isErrorEnabled();
}
public void fatalError( String message )
{
logger.fatalError( message );
}
public void fatalError( String message,
Throwable throwable )
{
logger.fatalError( message, throwable );
}
public boolean isFatalErrorEnabled()
{
return logger.isFatalErrorEnabled();
}
public void setThreshold( int i )
{
logger.setThreshold( i );
}
public int getThreshold()
{
return logger.getThreshold();
}
public String getName()
{
return toString();
}
public Logger getChildLogger( String name )
{
return this;
}
}

View File

@ -1,134 +0,0 @@
package org.apache.maven.cli;
import java.util.ArrayList;
import java.util.List;
import org.apache.maven.embedder.AbstractMavenEmbedderLogger;
public class TestEmbedderLogger
extends AbstractMavenEmbedderLogger
{
private List debugMessages = new ArrayList();
private List errorMessages = new ArrayList();
private List fatalErrorMessages = new ArrayList();
private List infoMessages = new ArrayList();
private List warnMessages = new ArrayList();
private List debugErrors = new ArrayList();
private List errors = new ArrayList();
private List fatalErrors = new ArrayList();
private List infoErrors = new ArrayList();
private List warnErrors = new ArrayList();
public void close()
{
}
public void debug( String message,
Throwable throwable )
{
log( "[debug] ", message, throwable, debugMessages, debugErrors );
}
private void log( String header,
String message, Throwable throwable,
List messages,
List errors )
{
if ( message != null )
{
messages.add( message );
System.out.println( header + message );
}
if ( throwable != null )
{
errors.add( throwable );
throwable.printStackTrace( System.out );
}
}
public void error( String message,
Throwable throwable )
{
log( "[error] ", message, throwable, errorMessages, errors );
}
public void fatalError( String message,
Throwable throwable )
{
log( "[fatal] ", message, throwable, fatalErrorMessages, fatalErrors );
}
public void info( String message,
Throwable throwable )
{
log( "[info] ", message, throwable, infoMessages, infoErrors );
}
public void warn( String message,
Throwable throwable )
{
log( "[warn] ", message, throwable, warnMessages, warnErrors );
}
public List getDebugMessages()
{
return debugMessages;
}
public List getErrorMessages()
{
return errorMessages;
}
public List getFatalErrorMessages()
{
return fatalErrorMessages;
}
public List getInfoMessages()
{
return infoMessages;
}
public List getWarnMessages()
{
return warnMessages;
}
public List getDebugErrors()
{
return debugErrors;
}
public List getErrorErrors()
{
return errors;
}
public List getFatalErrors()
{
return fatalErrors;
}
public List getInfoErrors()
{
return infoErrors;
}
public List getWarnErrors()
{
return warnErrors;
}
}

View File

@ -1,311 +0,0 @@
package org.apache.maven.embedder;
import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
import org.apache.maven.Maven;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.InvalidRepositoryException;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.DefaultMavenExecutionResult;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Build;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Exclusion;
import org.apache.maven.model.Model;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.Repository;
import org.apache.maven.project.DefaultProjectBuildingRequest;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.repository.RepositorySystem;
import org.codehaus.plexus.ContainerConfiguration;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.util.FileUtils;
public abstract class AbstractCoreMavenComponentTestCase
extends PlexusTestCase
{
@Requirement
protected RepositorySystem repositorySystem;
@Requirement
protected org.apache.maven.project.ProjectBuilder projectBuilder;
@Requirement
protected Maven maven;
protected void setUp()
throws Exception
{
repositorySystem = lookup( RepositorySystem.class );
projectBuilder = lookup( org.apache.maven.project.ProjectBuilder.class );
maven = lookup( Maven.class );
}
@Override
protected void tearDown()
throws Exception
{
repositorySystem = null;
projectBuilder = null;
super.tearDown();
}
abstract protected String getProjectsDirectory();
protected File getProject( String name )
throws Exception
{
File source = new File( new File( getBasedir(), getProjectsDirectory() ), name );
File target = new File( new File( getBasedir(), "target" ), name );
if ( !target.exists() )
{
FileUtils.copyDirectoryStructure( source, target );
}
return new File( target, "pom.xml" );
}
/**
* We need to customize the standard Plexus container with the plugin discovery listener which
* is what looks for the META-INF/maven/plugin.xml resources that enter the system when a Maven
* plugin is loaded.
*
* We also need to customize the Plexus container with a standard plugin discovery listener
* which is the MavenPluginCollector. When a Maven plugin is discovered the MavenPluginCollector
* collects the plugin descriptors which are found.
*/
protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration )
{
// containerConfiguration.addComponentDiscoverer( PluginManager.class );
// containerConfiguration.addComponentDiscoveryListener( PluginManager.class );
}
protected MavenExecutionRequest createMavenExecutionRequest( File pom )
throws Exception
{
MavenExecutionRequest request = new DefaultMavenExecutionRequest()
.setPom( pom )
.setProjectPresent( true )
.setShowErrors( true )
.setPluginGroups( Arrays.asList( new String[] { "org.apache.maven.plugins" } ) )
.setLocalRepository( getLocalRepository() )
.setRemoteRepositories( getRemoteRepositories() )
.setPluginArtifactRepositories( getPluginArtifactRepositories() )
.setGoals( Arrays.asList( new String[] { "package" } ) )
.setSystemProperties( new Properties() );
return request;
}
// layer the creation of a project builder configuration with a request, but this will need to be
// a Maven subclass because we don't want to couple maven to the project builder which we need to
// separate.
protected MavenSession createMavenSession( File pom )
throws Exception
{
return createMavenSession( pom, new Properties() );
}
protected MavenSession createMavenSession( File pom, Properties executionProperties )
throws Exception
{
MavenExecutionRequest request = createMavenExecutionRequest( pom );
ProjectBuildingRequest configuration = new DefaultProjectBuildingRequest()
.setLocalRepository( request.getLocalRepository() )
.setRemoteRepositories( request.getRemoteRepositories() )
.setPluginArtifactRepositories( request.getPluginArtifactRepositories() )
.setSystemProperties( executionProperties );
MavenProject project = null;
if ( pom != null )
{
project = projectBuilder.build( pom, configuration ).getProject();
}
else
{
project = createStubMavenProject();
}
MavenSession session = new MavenSession( getContainer(), request, new DefaultMavenExecutionResult(), project );
return session;
}
protected MavenProject createStubMavenProject()
{
Model model = new Model();
model.setGroupId( "org.apache.maven.test" );
model.setArtifactId( "maven-test" );
model.setVersion( "1.0" );
return new MavenProject( model );
}
protected List<ArtifactRepository> getRemoteRepositories()
throws InvalidRepositoryException
{
return Arrays.asList( repositorySystem.createDefaultRemoteRepository() );
}
protected List<ArtifactRepository> getPluginArtifactRepositories()
throws InvalidRepositoryException
{
Repository itRepo = new Repository();
itRepo.setId( "maven.it" );
itRepo.setUrl( "http://repository.sonatype.org/content/repositories/maven.snapshots" );
return Arrays.asList( repositorySystem.createDefaultRemoteRepository(), repositorySystem.buildArtifactRepository( itRepo ) );
}
protected ArtifactRepository getLocalRepository()
throws InvalidRepositoryException
{
return repositorySystem.createDefaultLocalRepository();
}
protected class ProjectBuilder
{
private MavenProject project;
public ProjectBuilder( String groupId, String artifactId, String version )
{
Model model = new Model();
model.setModelVersion( "4.0.0" );
model.setGroupId( groupId );
model.setArtifactId( artifactId );
model.setVersion( version );
model.setBuild( new Build() );
project = new MavenProject( model );
}
public ProjectBuilder setGroupId( String groupId )
{
project.setGroupId( groupId );
return this;
}
public ProjectBuilder setArtifactId( String artifactId )
{
project.setArtifactId( artifactId );
return this;
}
public ProjectBuilder setVersion( String version )
{
project.setVersion( version );
return this;
}
// Dependencies
//
public ProjectBuilder addDependency( String groupId, String artifactId, String version, String scope )
{
return addDependency( groupId, artifactId, version, scope, (Exclusion) null );
}
public ProjectBuilder addDependency( String groupId, String artifactId, String version, String scope, Exclusion exclusion )
{
return addDependency( groupId, artifactId, version, scope, null, exclusion );
}
public ProjectBuilder addDependency( String groupId, String artifactId, String version, String scope, String systemPath )
{
return addDependency( groupId, artifactId, version, scope, systemPath, null );
}
public ProjectBuilder addDependency( String groupId, String artifactId, String version, String scope, String systemPath, Exclusion exclusion )
{
Dependency d = new Dependency();
d.setGroupId( groupId );
d.setArtifactId( artifactId );
d.setVersion( version );
d.setScope( scope );
if ( systemPath != null && scope.equals( Artifact.SCOPE_SYSTEM ) )
{
d.setSystemPath( systemPath );
}
if ( exclusion != null )
{
d.addExclusion( exclusion );
}
project.getDependencies().add( d );
return this;
}
// Plugins
//
public ProjectBuilder addPlugin( Plugin plugin )
{
project.getBuildPlugins().add( plugin );
return this;
}
public MavenProject get()
{
return project;
}
}
protected class PluginBuilder
{
private Plugin plugin;
public PluginBuilder( String groupId, String artifactId, String version )
{
plugin = new Plugin();
plugin.setGroupId( groupId );
plugin.setArtifactId( artifactId );
plugin.setVersion( version );
}
// Dependencies
//
public PluginBuilder addDependency( String groupId, String artifactId, String version, String scope, Exclusion exclusion )
{
return addDependency( groupId, artifactId, version, scope, exclusion );
}
public PluginBuilder addDependency( String groupId, String artifactId, String version, String scope, String systemPath )
{
return addDependency( groupId, artifactId, version, scope, systemPath, null );
}
public PluginBuilder addDependency( String groupId, String artifactId, String version, String scope, String systemPath, Exclusion exclusion )
{
Dependency d = new Dependency();
d.setGroupId( groupId );
d.setArtifactId( artifactId );
d.setVersion( version );
d.setScope( scope );
if ( systemPath != null && scope.equals( Artifact.SCOPE_SYSTEM ) )
{
d.setSystemPath( systemPath );
}
if ( exclusion != null )
{
d.addExclusion( exclusion );
}
plugin.getDependencies().add( d );
return this;
}
public Plugin get()
{
return plugin;
}
}
}

View File

@ -1,33 +0,0 @@
package org.apache.maven.embedder;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.artifact.factory.DefaultArtifactFactory;
/**
*
* @author <a href="mailto:kenney@apache.org">Kenney Westerhof</a>
*
*/
public class CustomArtifactFactory
extends DefaultArtifactFactory
{
}

View File

@ -1,373 +0,0 @@
package org.apache.maven.embedder;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.File;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.util.Arrays;
import java.util.List;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResult;
import org.apache.maven.model.Build;
import org.apache.maven.model.Model;
import org.apache.maven.model.Plugin;
import org.apache.maven.project.MavenProject;
import org.apache.maven.settings.Profile;
import org.apache.maven.settings.Repository;
import org.apache.maven.settings.Settings;
import org.apache.maven.settings.SettingsConfigurationException;
import org.apache.maven.settings.io.xpp3.SettingsXpp3Reader;
import org.apache.maven.settings.io.xpp3.SettingsXpp3Writer;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.WriterFactory;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
public class MavenEmbedderTest
extends AbstractCoreMavenComponentTestCase
{
protected String basedir;
protected MavenEmbedder mavenEmbedder;
protected void setUp()
throws Exception
{
super.setUp();
basedir = System.getProperty( "basedir" );
if ( basedir == null )
{
basedir = new File( "." ).getCanonicalPath();
}
Configuration configuration = new SimpleConfiguration();
mavenEmbedder = new MavenEmbedder( configuration );
}
protected void tearDown()
throws Exception
{
mavenEmbedder.stop();
mavenEmbedder = null;
}
protected void assertNoExceptions( MavenExecutionResult result )
{
List<Exception> exceptions = result.getExceptions();
if ( ( exceptions == null ) || exceptions.isEmpty() )
{
// everything is a-ok.
return;
}
System.err.println( "Encountered " + exceptions.size() + " exception(s)." );
for ( Exception exception : exceptions )
{
exception.printStackTrace( System.err );
}
fail( "Encountered Exceptions in MavenExecutionResult during " + getName() );
}
/*MNG-3919*/
public void testWithInvalidGoal()
throws Exception
{
File testDirectory = new File( basedir, "src/test/projects/invalid-goal" );
File targetDirectory = new File( basedir, "target/projects/invalid-goal" );
FileUtils.copyDirectoryStructure( testDirectory, targetDirectory );
MavenExecutionRequest request = createMavenExecutionRequest( new File( targetDirectory, "pom.xml" ) );
request.setGoals( Arrays.asList( new String[]{"validate"} ) );
MavenExecutionResult result = mavenEmbedder.execute( request );
List<Exception> exceptions = result.getExceptions();
assertEquals( "Incorrect number of exceptions", 1, exceptions.size() );
if ( ( exceptions.get( 0 ) instanceof NullPointerException ) )
{
fail( "Null Pointer on Exception" );
}
}
//TODO: This needs to be a separate test and we can't use production plugins for the test.
/**
* Test that two executions of the embedder don't share data that has changed, see MNG-3013
*
* @throws Exception
*/
public void testTwoExecutionsDoNotCacheChangedData()
throws Exception
{
File testDirectory = new File( basedir, "src/test/embedder-test-project" );
File targetDirectory = new File( basedir, "target/embedder-test-project-caching" );
FileUtils.copyDirectoryStructure( testDirectory, targetDirectory );
File pom = new File( targetDirectory, "pom.xml" );
Model model = mavenEmbedder.readModel( pom );
Plugin plugin = new Plugin();
plugin.setArtifactId( "maven-surefire-plugin" );
plugin.setVersion( "2.4.2" );
model.setBuild( new Build() );
model.getBuild().addPlugin( plugin );
Writer writer = WriterFactory.newXmlWriter( pom );
mavenEmbedder.writeModel( writer, model );
writer.close();
MavenExecutionRequest request = createMavenExecutionRequest( pom );
MavenExecutionResult result = mavenEmbedder.execute( request );
assertNoExceptions( result );
MavenProject project = result.getProject();
Artifact p = project.getPluginArtifactMap().get( plugin.getKey() );
assertEquals( "2.4.2", p.getVersion() );
/* Add the surefire plugin 2.3 to the pom */
plugin.setVersion( "2.4.3" );
writer = WriterFactory.newXmlWriter( pom );
mavenEmbedder.writeModel( writer, model );
writer.close();
request = createMavenExecutionRequest( pom );
result = mavenEmbedder.execute( request );
assertNoExceptions( result );
project = result.getProject();
p = project.getPluginArtifactMap().get( plugin.getKey() );
assertEquals( "2.4.3", p.getVersion() );
}
public void testModelReading()
throws Exception
{
// ----------------------------------------------------------------------
// Test model reading
// ----------------------------------------------------------------------
Model model = mavenEmbedder.readModel( getPomFile() );
assertEquals( "org.apache.maven", model.getGroupId() );
}
// ----------------------------------------------------------------------------
// Model Writing
// ----------------------------------------------------------------------------
public void testModelWriting()
throws Exception
{
Model model = mavenEmbedder.readModel( getPomFile() );
model.setGroupId( "org.apache.maven.new" );
File file = new File( basedir, "target/model.xml" );
Writer writer = WriterFactory.newXmlWriter( file );
mavenEmbedder.writeModel( writer, model );
writer.close();
model = mavenEmbedder.readModel( file );
assertEquals( "org.apache.maven.new", model.getGroupId() );
}
// ----------------------------------------------------------------------
// Settings-File Handling
// ----------------------------------------------------------------------
public void testReadSettings()
throws IOException, SettingsConfigurationException, MavenEmbedderException
{
Settings s = new Settings();
s.setOffline( true );
String localRepoPath = "/path/to/local/repo";
s.setLocalRepository( localRepoPath );
File settingsFile = File.createTempFile( "embedder-test.settings.", "" );
settingsFile.deleteOnExit();
Writer writer = null;
try
{
writer = WriterFactory.newXmlWriter( settingsFile );
new SettingsXpp3Writer().write( writer, s );
}
finally
{
IOUtil.close( writer );
}
Settings result = MavenEmbedder.readSettings( settingsFile );
assertEquals( localRepoPath, result.getLocalRepository() );
assertTrue( result.isOffline() );
}
public void testReadSettings_shouldFailToValidate()
throws IOException, SettingsConfigurationException, MavenEmbedderException
{
Settings s = new Settings();
Profile p = new Profile();
Repository r = new Repository();
r.setUrl( "http://example.com" );
p.addRepository( r );
s.addProfile( p );
File settingsFile = File.createTempFile( "embedder-test.settings.", "" );
settingsFile.deleteOnExit();
Writer writer = null;
try
{
writer = WriterFactory.newXmlWriter( settingsFile );
new SettingsXpp3Writer().write( writer, s );
}
finally
{
IOUtil.close( writer );
}
try
{
MavenEmbedder.readSettings( settingsFile );
fail( "Settings should not pass validation when being read." );
}
catch ( IOException e )
{
String message = e.getMessage();
assertTrue( message.indexOf( "Failed to validate" ) > -1 );
}
}
public void testWriteSettings()
throws IOException, SettingsConfigurationException, MavenEmbedderException, XmlPullParserException
{
Settings s = new Settings();
s.setOffline( true );
String localRepoPath = "/path/to/local/repo";
s.setLocalRepository( localRepoPath );
File settingsFile = new File( System.getProperty( "basedir" ), "target/test-settings.xml" );
settingsFile.getParentFile().mkdirs();
settingsFile.deleteOnExit();
MavenEmbedder.writeSettings( settingsFile, s );
Reader reader = null;
try
{
reader = ReaderFactory.newXmlReader( settingsFile );
Settings result = new SettingsXpp3Reader().read( reader );
assertEquals( localRepoPath, result.getLocalRepository() );
assertTrue( result.isOffline() );
}
finally
{
IOUtil.close( reader );
}
}
public void testWriteSettings_shouldFailToValidate()
throws IOException, SettingsConfigurationException, MavenEmbedderException
{
Settings s = new Settings();
Profile p = new Profile();
Repository r = new Repository();
r.setUrl( "http://example.com" );
p.addRepository( r );
s.addProfile( p );
File settingsFile = File.createTempFile( "embedder-test.settings.", "" );
settingsFile.deleteOnExit();
try
{
MavenEmbedder.writeSettings( settingsFile, s );
fail( "Validation of settings should fail before settings are written." );
}
catch ( IOException e )
{
String message = e.getMessage();
assertTrue( message.indexOf( "Failed to validate" ) > -1 );
}
}
// ----------------------------------------------------------------------
// Internal Utilities
// ----------------------------------------------------------------------
protected File getPomFile()
{
return getPomFile( "pom.xml" );
}
protected File getPomFile( String name )
{
return new File( basedir, "src/test/resources/" + name );
}
@Override
protected String getProjectsDirectory()
{
return null;
}
}

View File

@ -1,43 +0,0 @@
package org.apache.maven.embedder;
import org.apache.maven.artifact.handler.ArtifactHandler;
/** @author Jason van Zyl */
public class MyArtifactHandler
implements ArtifactHandler
{
public String getExtension()
{
return "jar";
}
public String getDirectory()
{
throw new UnsupportedOperationException( "Not supported yet." );
}
public String getClassifier()
{
return null;
}
public String getPackaging()
{
return "mkleint";
}
public boolean isIncludesDependencies()
{
return false;
}
public String getLanguage()
{
return "java";
}
public boolean isAddedToClasspath()
{
return true;
}
}

View File

@ -1,40 +0,0 @@
package org.apache.maven.embedder;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
/**
* A configuration to be used for unit testing of the embedder. This basically sets some default values.
*
* @author Benjamin Bentmann
*/
public class SimpleConfiguration
extends DefaultConfiguration
{
public SimpleConfiguration()
{
setClassLoader( Thread.currentThread().getContextClassLoader() );
setMavenEmbedderLogger( new MavenEmbedderConsoleLogger() );
setUserSettingsFile( MavenEmbedder.DEFAULT_USER_SETTINGS_FILE );
}
}

View File

@ -1,65 +0,0 @@
package org.apache.maven.embedder;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.File;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
/** @author <a href="mailto:kenney@apache.org">Kenney Westerhof</a> */
public class TestComponentOverride
extends PlexusTestCase
{
private MavenEmbedder maven;
protected PlexusContainer container;
protected void setUp()
throws Exception
{
Configuration request = new SimpleConfiguration();
File extensions = new File( getBasedir(), "src/test/extensions" );
assertTrue( extensions.exists() );
request.addExtension( extensions.toURI().toURL() );
maven = new MavenEmbedder( request );
container = maven.getPlexusContainer();
}
public void testComponentOverride()
throws ComponentLookupException
{
ArtifactFactory factory = container.lookup( ArtifactFactory.class );
assertNotNull( factory );
assertTrue( "Expecting " + CustomArtifactFactory.class.getName() + " but was " + factory.getClass().getName(), CustomArtifactFactory.class.isAssignableFrom( factory.getClass() ) );
// test wheter the requirement is injected - if not, it nullpointers
factory.createArtifact( "testGroupId", "testArtifactId", "testVersion", "compile", "jar" );
}
}

View File

@ -1,73 +0,0 @@
package org.apache.maven.embedder.validation;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.File;
import org.apache.maven.embedder.AbstractCoreMavenComponentTestCase;
import org.apache.maven.embedder.Configuration;
import org.apache.maven.embedder.ConfigurationValidationResult;
import org.apache.maven.embedder.MavenEmbedder;
import org.apache.maven.embedder.SimpleConfiguration;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResult;
import org.apache.maven.project.MavenProject;
public class MavenEmbedderCrappySettingsConfigurationTest
extends AbstractCoreMavenComponentTestCase
{
public void testEmbedderWillStillStartupWhenTheSettingsConfigurationIsCrap()
throws Exception
{
File projectDirectory = getTestFile( "src/examples/simple-project" );
File user = new File( projectDirectory, "invalid-settings.xml" );
Configuration configuration = new SimpleConfiguration()
.setUserSettingsFile( user );
ConfigurationValidationResult validationResult = MavenEmbedder.validateConfiguration( configuration );
assertFalse( validationResult.isValid() );
MavenEmbedder embedder = new MavenEmbedder( configuration );
MavenExecutionRequest request = createMavenExecutionRequest( new File( projectDirectory, "pom.xml" ) );
MavenExecutionResult result = embedder.execute( request );
assertFalse( result.hasExceptions() );
assertNotNull( result.getProject() );
MavenProject project = result.getProject();
String environment = project.getProperties().getProperty( "environment" );
assertEquals( "development", environment );
}
@Override
protected String getProjectsDirectory()
{
// TODO Auto-generated method stub
return null;
}
}

View File

@ -1,104 +0,0 @@
package org.apache.maven.embedder.validation;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.File;
import org.apache.maven.embedder.Configuration;
import org.apache.maven.embedder.ConfigurationValidationResult;
import org.apache.maven.embedder.DefaultConfiguration;
import org.apache.maven.embedder.MavenEmbedder;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
/** @author Jason van Zyl */
public class ValidateConfigurationTest
extends PlexusTestCase
{
public void testConfigurationOnlyUserSettingsAreActiveAndItIsValid()
{
File user = new File( getBasedir(), "src/test/resources/settings/valid-settings.xml" );
Configuration configuration = new DefaultConfiguration()
.setUserSettingsFile( user );
ConfigurationValidationResult result = MavenEmbedder.validateConfiguration( configuration );
assertTrue( result.isUserSettingsFilePresent() );
assertTrue( result.isUserSettingsFileParses() );
assertNotNull( result.getUserSettings() );
assertNull( result.getUserSettingsException() );
assertNull( result.getGlobalSettings() );
assertNull( result.getGlobalSettingsException() );
}
public void testConfigurationOnlyUserSettingsAreActiveAndItIsInvalid()
{
File user = new File( getBasedir(), "src/test/resources/settings/invalid-settings.xml" );
Configuration configuration = new DefaultConfiguration()
.setUserSettingsFile( user );
ConfigurationValidationResult result = MavenEmbedder.validateConfiguration( configuration );
assertTrue( result.isUserSettingsFilePresent() );
assertFalse( result.isUserSettingsFileParses() );
assertNull( result.getUserSettings() );
assertNotNull( result.getUserSettingsException() );
assertTrue( result.getUserSettingsException() instanceof XmlPullParserException );
assertNull( result.getGlobalSettings() );
assertNull( result.getGlobalSettingsException() );
}
public void testConfigurationOnlyGlobalSettingsAreActiveAndItIsValid()
{
File global = new File( getBasedir(), "src/test/resources/settings/valid-settings.xml" );
Configuration configuration = new DefaultConfiguration()
.setGlobalSettingsFile( global );
ConfigurationValidationResult result = MavenEmbedder.validateConfiguration( configuration );
assertTrue( result.isGlobalSettingsFilePresent() );
assertTrue( result.isGlobalSettingsFileParses() );
assertNotNull( result.getGlobalSettings() );
assertNull( result.getGlobalSettingsException() );
assertNull( result.getUserSettings() );
assertNull( result.getUserSettingsException() );
}
public void testConfigurationOnlyGlobalSettingsAreActiveAndItIsInvalid()
{
File global = new File( getBasedir(), "src/test/resources/settings/invalid-settings.xml" );
Configuration configuration = new DefaultConfiguration()
.setGlobalSettingsFile( global );
ConfigurationValidationResult result = MavenEmbedder.validateConfiguration( configuration );
assertTrue( result.isGlobalSettingsFilePresent() );
assertFalse( result.isGlobalSettingsFileParses() );
assertNull( result.getGlobalSettings() );
assertNotNull( result.getGlobalSettingsException() );
assertTrue( result.getGlobalSettingsException() instanceof XmlPullParserException );
assertNull( result.getUserSettings() );
assertNull( result.getUserSettingsException() );
}
}

View File

@ -398,7 +398,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4</version>
<version>2.4.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>