diff --git a/apache-maven/src/bin/mvnr.rb b/apache-maven/src/bin/mvnr.rb index cde1ef4d21..8c765b4c13 100644 --- a/apache-maven/src/bin/mvnr.rb +++ b/apache-maven/src/bin/mvnr.rb @@ -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 diff --git a/maven-embedder/src/main/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestPopulator.java b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulator.java similarity index 93% rename from maven-embedder/src/main/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestPopulator.java rename to maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulator.java index dab456aea1..bca6a4c088 100644 --- a/maven-embedder/src/main/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestPopulator.java +++ b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequestPopulator.java @@ -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 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 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 ); diff --git a/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedderException.java b/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequestPopulationException.java similarity index 77% rename from maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedderException.java rename to maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequestPopulationException.java index 924737f988..ddd6ad2266 100644 --- a/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedderException.java +++ b/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequestPopulationException.java @@ -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 ); diff --git a/maven-embedder/src/main/java/org/apache/maven/embedder/execution/MavenExecutionRequestPopulator.java b/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequestPopulator.java similarity index 83% rename from maven-embedder/src/main/java/org/apache/maven/embedder/execution/MavenExecutionRequestPopulator.java rename to maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequestPopulator.java index c185da21a6..3d0001262b 100644 --- a/maven-embedder/src/main/java/org/apache/maven/embedder/execution/MavenExecutionRequestPopulator.java +++ b/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequestPopulator.java @@ -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; } diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java b/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java index 7d114860be..9d574591bd 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java @@ -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 ) { diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/CLIRequestUtils.java b/maven-embedder/src/main/java/org/apache/maven/cli/CLIRequestUtils.java index cee166f89d..d881638793 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/CLIRequestUtils.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/CLIRequestUtils.java @@ -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 diff --git a/maven-embedder/src/main/java/org/apache/maven/embedder/Configuration.java b/maven-embedder/src/main/java/org/apache/maven/cli/Configuration.java similarity index 86% rename from maven-embedder/src/main/java/org/apache/maven/embedder/Configuration.java rename to maven-embedder/src/main/java/org/apache/maven/cli/Configuration.java index d0d3a0e066..36fdd1b61f 100644 --- a/maven-embedder/src/main/java/org/apache/maven/embedder/Configuration.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/Configuration.java @@ -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 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 getInactiveProfiles(); - // ---------------------------------------------------------------------------- - // Container Customizer - // ---------------------------------------------------------------------------- - - ContainerCustomizer getContainerCustomizer(); - // ---------------------------------------------------------------------------- // System Properties // ---------------------------------------------------------------------------- diff --git a/maven-embedder/src/main/java/org/apache/maven/embedder/ConfigurationValidationResult.java b/maven-embedder/src/main/java/org/apache/maven/cli/ConfigurationValidationResult.java similarity index 98% rename from maven-embedder/src/main/java/org/apache/maven/embedder/ConfigurationValidationResult.java rename to maven-embedder/src/main/java/org/apache/maven/cli/ConfigurationValidationResult.java index 803519e44b..454e457fcb 100644 --- a/maven-embedder/src/main/java/org/apache/maven/embedder/ConfigurationValidationResult.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/ConfigurationValidationResult.java @@ -1,4 +1,4 @@ -package org.apache.maven.embedder; +package org.apache.maven.cli; /* * Licensed to the Apache Software Foundation (ASF) under one diff --git a/maven-embedder/src/main/java/org/apache/maven/embedder/DefaultConfiguration.java b/maven-embedder/src/main/java/org/apache/maven/cli/DefaultConfiguration.java similarity index 89% rename from maven-embedder/src/main/java/org/apache/maven/embedder/DefaultConfiguration.java rename to maven-embedder/src/main/java/org/apache/maven/cli/DefaultConfiguration.java index 0f9740e5dd..571e1a5a11 100644 --- a/maven-embedder/src/main/java/org/apache/maven/embedder/DefaultConfiguration.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/DefaultConfiguration.java @@ -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 extensions = new ArrayList(); - 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; } diff --git a/maven-embedder/src/main/java/org/apache/maven/embedder/DefaultConfigurationValidationResult.java b/maven-embedder/src/main/java/org/apache/maven/cli/DefaultConfigurationValidationResult.java similarity index 98% rename from maven-embedder/src/main/java/org/apache/maven/embedder/DefaultConfigurationValidationResult.java rename to maven-embedder/src/main/java/org/apache/maven/cli/DefaultConfigurationValidationResult.java index 856cc1cc74..c96785a8ab 100644 --- a/maven-embedder/src/main/java/org/apache/maven/embedder/DefaultConfigurationValidationResult.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/DefaultConfigurationValidationResult.java @@ -1,4 +1,4 @@ -package org.apache.maven.embedder; +package org.apache.maven.cli; /* * Licensed to the Apache Software Foundation (ASF) under one diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/ExecutionEventLogger.java b/maven-embedder/src/main/java/org/apache/maven/cli/ExecutionEventLogger.java index 54bea0045b..a517e166c8 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/ExecutionEventLogger.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/ExecutionEventLogger.java @@ -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 ) { diff --git a/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedderFileLogger.java b/maven-embedder/src/main/java/org/apache/maven/cli/FileLogger.java similarity index 89% rename from maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedderFileLogger.java rename to maven-embedder/src/main/java/org/apache/maven/cli/FileLogger.java index 76cbf5c5e9..e0921a2fca 100644 --- a/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedderFileLogger.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/FileLogger.java @@ -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 ) ); } diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java index f629ac7ae5..32b67efa00 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java @@ -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; + } } diff --git a/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedderPrintStreamLogger.java b/maven-embedder/src/main/java/org/apache/maven/cli/PrintStreamLogger.java similarity index 71% rename from maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedderPrintStreamLogger.java rename to maven-embedder/src/main/java/org/apache/maven/cli/PrintStreamLogger.java index 2fdaee1ceb..054467bd0e 100644 --- a/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedderPrintStreamLogger.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/PrintStreamLogger.java @@ -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 ) + { + } } diff --git a/maven-embedder/src/main/java/org/apache/maven/embedder/AbstractMavenEmbedderLogger.java b/maven-embedder/src/main/java/org/apache/maven/embedder/AbstractMavenEmbedderLogger.java deleted file mode 100644 index 5053455711..0000000000 --- a/maven-embedder/src/main/java/org/apache/maven/embedder/AbstractMavenEmbedderLogger.java +++ /dev/null @@ -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 Trygve Laugstøl - */ -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; - } -} diff --git a/maven-embedder/src/main/java/org/apache/maven/embedder/ContainerCustomizer.java b/maven-embedder/src/main/java/org/apache/maven/embedder/ContainerCustomizer.java deleted file mode 100644 index 9c8452ec65..0000000000 --- a/maven-embedder/src/main/java/org/apache/maven/embedder/ContainerCustomizer.java +++ /dev/null @@ -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 ); - -} diff --git a/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java b/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java deleted file mode 100644 index f42d405cdd..0000000000 --- a/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java +++ /dev/null @@ -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; - } -} diff --git a/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedderConsoleLogger.java b/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedderConsoleLogger.java deleted file mode 100644 index 93fde07bcf..0000000000 --- a/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedderConsoleLogger.java +++ /dev/null @@ -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 Avalon Development Team - */ -public final class MavenEmbedderConsoleLogger - extends MavenEmbedderPrintStreamLogger -{ - - public MavenEmbedderConsoleLogger() - { - super( System.out ); - } - -} diff --git a/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedderLogger.java b/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedderLogger.java deleted file mode 100644 index 4b28765cda..0000000000 --- a/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedderLogger.java +++ /dev/null @@ -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(); -} diff --git a/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedderLoggerManager.java b/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedderLoggerManager.java deleted file mode 100644 index 09c988b957..0000000000 --- a/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedderLoggerManager.java +++ /dev/null @@ -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. - *

- * Sample configuration: - *

- * 
- *   org.codehaus.plexus.logging.ConsoleLoggerManager
- *   
- *     DEBUG
- *   
- * 
- * 
- * - * @author Jason van Zyl - * @author Trygve Laugstøl - */ -public class MavenEmbedderLoggerManager - extends AbstractLoggerManager - implements LoggerManager, Initializable -{ - /** - * Message of this level or higher will be logged. - *

- * 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 ) - { - } -} diff --git a/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedderSecurityManager.java b/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedderSecurityManager.java deleted file mode 100644 index e4d1e0d852..0000000000 --- a/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedderSecurityManager.java +++ /dev/null @@ -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!" ); - } -} diff --git a/maven-embedder/src/main/java/org/apache/maven/embedder/PlexusLoggerAdapter.java b/maven-embedder/src/main/java/org/apache/maven/embedder/PlexusLoggerAdapter.java deleted file mode 100644 index afbf683da6..0000000000 --- a/maven-embedder/src/main/java/org/apache/maven/embedder/PlexusLoggerAdapter.java +++ /dev/null @@ -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; - } -} diff --git a/maven-embedder/src/test/java/org/apache/maven/cli/TestEmbedderLogger.java b/maven-embedder/src/test/java/org/apache/maven/cli/TestEmbedderLogger.java deleted file mode 100644 index 4b50a084ca..0000000000 --- a/maven-embedder/src/test/java/org/apache/maven/cli/TestEmbedderLogger.java +++ /dev/null @@ -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; - } - -} diff --git a/maven-embedder/src/test/java/org/apache/maven/embedder/AbstractCoreMavenComponentTestCase.java b/maven-embedder/src/test/java/org/apache/maven/embedder/AbstractCoreMavenComponentTestCase.java deleted file mode 100644 index 0b2ecf75ae..0000000000 --- a/maven-embedder/src/test/java/org/apache/maven/embedder/AbstractCoreMavenComponentTestCase.java +++ /dev/null @@ -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 getRemoteRepositories() - throws InvalidRepositoryException - { - return Arrays.asList( repositorySystem.createDefaultRemoteRepository() ); - } - - protected List 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; - } - } -} diff --git a/maven-embedder/src/test/java/org/apache/maven/embedder/CustomArtifactFactory.java b/maven-embedder/src/test/java/org/apache/maven/embedder/CustomArtifactFactory.java deleted file mode 100644 index 13ea67b714..0000000000 --- a/maven-embedder/src/test/java/org/apache/maven/embedder/CustomArtifactFactory.java +++ /dev/null @@ -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 Kenney Westerhof - * - */ -public class CustomArtifactFactory - extends DefaultArtifactFactory -{ - -} diff --git a/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderTest.java b/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderTest.java deleted file mode 100644 index 5888548ce1..0000000000 --- a/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderTest.java +++ /dev/null @@ -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 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 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; - } -} diff --git a/maven-embedder/src/test/java/org/apache/maven/embedder/MyArtifactHandler.java b/maven-embedder/src/test/java/org/apache/maven/embedder/MyArtifactHandler.java deleted file mode 100644 index bf187e3761..0000000000 --- a/maven-embedder/src/test/java/org/apache/maven/embedder/MyArtifactHandler.java +++ /dev/null @@ -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; - } -} diff --git a/maven-embedder/src/test/java/org/apache/maven/embedder/SimpleConfiguration.java b/maven-embedder/src/test/java/org/apache/maven/embedder/SimpleConfiguration.java deleted file mode 100644 index c0209c9658..0000000000 --- a/maven-embedder/src/test/java/org/apache/maven/embedder/SimpleConfiguration.java +++ /dev/null @@ -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 ); - } - -} diff --git a/maven-embedder/src/test/java/org/apache/maven/embedder/TestComponentOverride.java b/maven-embedder/src/test/java/org/apache/maven/embedder/TestComponentOverride.java deleted file mode 100644 index a01e55fdf4..0000000000 --- a/maven-embedder/src/test/java/org/apache/maven/embedder/TestComponentOverride.java +++ /dev/null @@ -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 Kenney Westerhof */ -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" ); - } -} diff --git a/maven-embedder/src/test/java/org/apache/maven/embedder/validation/MavenEmbedderCrappySettingsConfigurationTest.java b/maven-embedder/src/test/java/org/apache/maven/embedder/validation/MavenEmbedderCrappySettingsConfigurationTest.java deleted file mode 100644 index 619517798c..0000000000 --- a/maven-embedder/src/test/java/org/apache/maven/embedder/validation/MavenEmbedderCrappySettingsConfigurationTest.java +++ /dev/null @@ -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; - } -} diff --git a/maven-embedder/src/test/java/org/apache/maven/embedder/validation/ValidateConfigurationTest.java b/maven-embedder/src/test/java/org/apache/maven/embedder/validation/ValidateConfigurationTest.java deleted file mode 100644 index 1e88f0eca2..0000000000 --- a/maven-embedder/src/test/java/org/apache/maven/embedder/validation/ValidateConfigurationTest.java +++ /dev/null @@ -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() ); - } -} diff --git a/pom.xml b/pom.xml index b594580410..b5b01dfcd1 100644 --- a/pom.xml +++ b/pom.xml @@ -398,7 +398,7 @@ org.apache.maven.plugins maven-resources-plugin - 2.4 + 2.4.1 org.apache.maven.plugins