diff --git a/maven-embedder/src/test/java/org/apache/maven/embedder/AbstractMavenEmbedderTestCase.java b/maven-embedder/src/test/java/org/apache/maven/embedder/AbstractEmbedderExecutionTestCase.java similarity index 78% rename from maven-embedder/src/test/java/org/apache/maven/embedder/AbstractMavenEmbedderTestCase.java rename to maven-embedder/src/test/java/org/apache/maven/embedder/AbstractEmbedderExecutionTestCase.java index 8f3b9b88e0..c4132855d1 100644 --- a/maven-embedder/src/test/java/org/apache/maven/embedder/AbstractMavenEmbedderTestCase.java +++ b/maven-embedder/src/test/java/org/apache/maven/embedder/AbstractEmbedderExecutionTestCase.java @@ -1,41 +1,18 @@ package org.apache.maven.embedder; -import org.apache.maven.execution.MavenExecutionResult; -import org.apache.maven.execution.MavenExecutionRequest; import org.apache.maven.execution.DefaultMavenExecutionRequest; +import org.apache.maven.execution.MavenExecutionRequest; +import org.apache.maven.execution.MavenExecutionResult; import org.codehaus.plexus.util.FileUtils; -import org.codehaus.plexus.PlexusTestCase; -import java.util.List; -import java.util.Iterator; -import java.util.Arrays; import java.io.File; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; -public abstract class AbstractMavenEmbedderTestCase - extends PlexusTestCase +public abstract class AbstractEmbedderExecutionTestCase + extends AbstractEmbedderTestCase { - protected MavenEmbedder maven; - - protected void setUp() - throws Exception - { - super.setUp(); - - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - - Configuration configuration = new DefaultConfiguration() - .setClassLoader( classLoader ) - .setMavenEmbedderLogger( new MavenEmbedderConsoleLogger() ); - - maven = new MavenEmbedder( configuration ); - } - - protected void tearDown() - throws Exception - { - maven.stop(); - } - protected MavenExecutionRequest request( File basedir, List goals ) { diff --git a/maven-embedder/src/test/java/org/apache/maven/embedder/AbstractEmbedderTestCase.java b/maven-embedder/src/test/java/org/apache/maven/embedder/AbstractEmbedderTestCase.java new file mode 100644 index 0000000000..52a6be8c2d --- /dev/null +++ b/maven-embedder/src/test/java/org/apache/maven/embedder/AbstractEmbedderTestCase.java @@ -0,0 +1,38 @@ +package org.apache.maven.embedder; + +import org.codehaus.plexus.PlexusTestCase; +import org.codehaus.plexus.util.FileUtils; +import org.apache.maven.execution.MavenExecutionRequest; +import org.apache.maven.execution.DefaultMavenExecutionRequest; +import org.apache.maven.execution.MavenExecutionResult; + +import java.io.File; +import java.util.List; +import java.util.Arrays; +import java.util.Iterator; + +public abstract class AbstractEmbedderTestCase + extends PlexusTestCase +{ + protected MavenEmbedder maven; + + protected void setUp() + throws Exception + { + super.setUp(); + + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + + Configuration configuration = new DefaultConfiguration() + .setClassLoader( classLoader ) + .setMavenEmbedderLogger( new MavenEmbedderConsoleLogger() ); + + maven = new MavenEmbedder( configuration ); + } + + protected void tearDown() + throws Exception + { + maven.stop(); + } +} diff --git a/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderUsingEclipsePluginTest.java b/maven-embedder/src/test/java/org/apache/maven/embedder/EmbedderUsingEclipsePluginTest.java similarity index 82% rename from maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderUsingEclipsePluginTest.java rename to maven-embedder/src/test/java/org/apache/maven/embedder/EmbedderUsingEclipsePluginTest.java index 20b964a351..083628a729 100644 --- a/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderUsingEclipsePluginTest.java +++ b/maven-embedder/src/test/java/org/apache/maven/embedder/EmbedderUsingEclipsePluginTest.java @@ -3,8 +3,8 @@ package org.apache.maven.embedder; import java.io.File; /** @author Jason van Zyl */ -public class MavenEmbedderUsingEclipsePluginTest - extends AbstractMavenEmbedderTestCase +public class EmbedderUsingEclipsePluginTest + extends AbstractEmbedderExecutionTestCase { protected String getId() { diff --git a/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderBehaviorTest.java b/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderBehaviorTest.java new file mode 100644 index 0000000000..5329fbb159 --- /dev/null +++ b/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderBehaviorTest.java @@ -0,0 +1,32 @@ +package org.apache.maven.embedder; + +import org.codehaus.plexus.PlexusTestCase; + +import java.io.File; + +/** @author Jason van Zyl */ +public class MavenEmbedderBehaviorTest + extends PlexusTestCase +{ + public void testThatTheLocalRepositoryIsTakenFromGlobalSettingsWhenUserSettingsAreNull() + throws Exception + { + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + + Configuration configuration = new DefaultConfiguration() + .setClassLoader( classLoader ) + .setMavenEmbedderLogger( new MavenEmbedderConsoleLogger() ) + .setUserSettingsFile( null ) + .setGlobalSettingsFile( new File( getBasedir(), "src/test/resources/settings/valid-settings.xml" ) ); + + ConfigurationValidationResult result = MavenEmbedder.validateConfiguration( configuration ); + + assertTrue( result.isValid() ); + + MavenEmbedder maven = new MavenEmbedder( configuration ); + + assertEquals( "/global/maven/local-repository", maven.getLocalRepository().getBasedir() ); + + maven.stop(); + } +} diff --git a/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderExampleTest.java b/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderExampleTest.java index ab45864317..01f20e6641 100644 --- a/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderExampleTest.java +++ b/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderExampleTest.java @@ -78,4 +78,23 @@ public class MavenEmbedderExampleTest // END SNIPPET: simple-embedder-example } + + public void testEmbedderExampleThatShowsHowToMimicTheMavenCLI() + throws Exception + { + + // START SNIPPET: mimic-cli + Configuration configuration = new DefaultConfiguration() + .setUserSettingsFile( MavenEmbedder.DEFAULT_USER_SETTINGS_FILE ) + .setGlobalSettingsFile( MavenEmbedder.DEFAULT_GLOBAL_SETTINGS_FILE ) + .setClassLoader( Thread.currentThread().getContextClassLoader() ); + + ConfigurationValidationResult validationResult = MavenEmbedder.validateConfiguration( configuration ); + + if ( validationResult.isValid() ) + { + // If the configuration is valid then do your thang ... + } + // END SNIPPET: mimic-cli + } } diff --git a/maven-embedder/src/test/resources/settings/valid-settings.xml b/maven-embedder/src/test/resources/settings/valid-settings.xml index f381d8f4ed..50babd6f12 100644 --- a/maven-embedder/src/test/resources/settings/valid-settings.xml +++ b/maven-embedder/src/test/resources/settings/valid-settings.xml @@ -1,6 +1,6 @@ - /Users/jvanzyl/maven-repo-local + /global/maven/local-repository org.codehaus.tycho org.sonatype.pwt