diff --git a/maven-embedder/pom.xml b/maven-embedder/pom.xml index 3bfc13b89b..e26ebfdf5b 100644 --- a/maven-embedder/pom.xml +++ b/maven-embedder/pom.xml @@ -27,7 +27,7 @@ maven-embedder Maven Embedder - 2.1.0.v20070221-2149 + 2.1.0.v20070224-1541 diff --git a/maven-embedder/src/main/resources/META-INF/plexus/components.xml b/maven-embedder/src/main/resources/META-INF/plexus/components.xml index f9857461af..2a205f4ff0 100644 --- a/maven-embedder/src/main/resources/META-INF/plexus/components.xml +++ b/maven-embedder/src/main/resources/META-INF/plexus/components.xml @@ -8,9 +8,6 @@ org.apache.maven.wagon.manager.WagonManager default - - org.apache.maven.MavenTools - org.apache.maven.artifact.repository.ArtifactRepositoryFactory 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 index 03155b1823..6e042e7afb 100644 --- a/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderTest.java +++ b/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderTest.java @@ -1,6 +1,8 @@ package org.apache.maven.embedder; import org.apache.maven.SettingsConfigurationException; +import org.apache.maven.embedder.configuration.Configuration; +import org.apache.maven.embedder.configuration.DefaultConfiguration; import org.apache.maven.artifact.handler.ArtifactHandler; import org.apache.maven.execution.DefaultMavenExecutionRequest; import org.apache.maven.execution.MavenExecutionRequest; @@ -48,7 +50,11 @@ public class MavenEmbedderTest ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - maven = new MavenEmbedder( classLoader, new MavenEmbedderConsoleLogger() ); + Configuration configuration = new DefaultConfiguration() + .setClassLoader( classLoader ) + .setMavenEmbedderLogger( new MavenEmbedderConsoleLogger() ); + + maven = new MavenEmbedder( configuration ); } protected void tearDown() @@ -91,7 +97,7 @@ public class MavenEmbedderTest FileUtils.copyDirectoryStructure( testDirectory, targetDirectory ); MavenExecutionRequest request = new DefaultMavenExecutionRequest().setBaseDirectory( targetDirectory ) - .setShowErrors( true ).setGoals( Arrays.asList( new String[] { "package" } ) ); + .setShowErrors( true ).setGoals( Arrays.asList( new String[]{"package"} ) ); MavenExecutionResult result = maven.execute( request ); @@ -115,16 +121,15 @@ public class MavenEmbedderTest FileUtils.copyDirectoryStructure( testDirectory, targetDirectory ); - MavenExecutionRequest request = new DefaultMavenExecutionRequest().setPomFile( - new File( targetDirectory, - "pom.xml" ) - .getAbsolutePath() ) - .setShowErrors( true ).setGoals( Arrays.asList( new String[] { "package" } ) ); + MavenExecutionRequest request = + new DefaultMavenExecutionRequest().setPomFile( new File( targetDirectory, "pom.xml" ) + .getAbsolutePath() ) + .setShowErrors( true ).setGoals( Arrays.asList( new String[]{"package"} ) ); MavenExecutionResult result = maven.execute( request ); assertNoExceptions( result ); - + MavenProject project = result.getMavenProject(); assertEquals( "embedder-test-project", project.getArtifactId() ); @@ -147,10 +152,10 @@ public class MavenEmbedderTest MavenExecutionRequest requestWithoutProfile = new DefaultMavenExecutionRequest() .setPomFile( new File( targetDirectory, "pom.xml" ).getAbsolutePath() ).setShowErrors( true ) - .setGoals( Arrays.asList( new String[] { "validate" } ) ); + .setGoals( Arrays.asList( new String[]{"validate"} ) ); MavenExecutionResult r0 = maven.execute( requestWithoutProfile ); - + assertNoExceptions( r0 ); MavenProject p0 = r0.getMavenProject(); @@ -163,12 +168,11 @@ public class MavenEmbedderTest // Check with profile activated - MavenExecutionRequest request = new DefaultMavenExecutionRequest().setPomFile( - new File( targetDirectory, - "pom.xml" ) - .getAbsolutePath() ) - .setShowErrors( true ).setGoals( Arrays.asList( new String[] { "validate" } ) ) - .addActiveProfile( "embedderProfile" ); + MavenExecutionRequest request = + new DefaultMavenExecutionRequest().setPomFile( new File( targetDirectory, "pom.xml" ) + .getAbsolutePath() ) + .setShowErrors( true ).setGoals( Arrays.asList( new String[]{"validate"} ) ) + .addActiveProfile( "embedderProfile" ); MavenExecutionResult r1 = maven.execute( request ); @@ -230,7 +234,7 @@ public class MavenEmbedderTest .setPomFile( getPomFile().getAbsolutePath() ); MavenExecutionResult result = maven.readProjectWithDependencies( request ); - + assertNoExceptions( result ); assertEquals( "org.apache.maven", result.getMavenProject().getGroupId() ); @@ -249,8 +253,9 @@ public class MavenEmbedderTest .setPomFile( new File( basedir, "src/test/resources/pom2.xml" ).getAbsolutePath() ); ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + MavenExecutionResult result = new ExtendableMavenEmbedder( classLoader ).readProjectWithDependencies( request ); - + assertNoExceptions( result ); // Iterator it = result.getMavenProject().getTestClasspathElements().iterator(); @@ -261,7 +266,6 @@ public class MavenEmbedderTest // sources, test sources, and the junit jar.. assertEquals( 3, result.getMavenProject().getTestClasspathElements().size() ); - } // ---------------------------------------------------------------------------- @@ -287,24 +291,24 @@ public class MavenEmbedderTest 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(); - + FileWriter writer = null; try { @@ -315,9 +319,9 @@ public class MavenEmbedderTest { IOUtil.close( writer ); } - + Settings result = MavenEmbedder.readSettings( settingsFile ); - + assertEquals( localRepoPath, result.getLocalRepository() ); assertTrue( result.isOffline() ); } @@ -326,12 +330,12 @@ public class MavenEmbedderTest 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 ); @@ -355,7 +359,7 @@ public class MavenEmbedderTest fail( "Settings should not pass validation when being read." ); } - catch( IOException e ) + catch ( IOException e ) { String message = e.getMessage(); assertTrue( message.indexOf( "Failed to validate" ) > -1 ); @@ -411,7 +415,7 @@ public class MavenEmbedderTest try { MavenEmbedder.writeSettings( settingsFile, s ); - + fail( "Validation of settings should fail before settings are written." ); } catch ( IOException e ) @@ -437,7 +441,9 @@ public class MavenEmbedderTest public ExtendableMavenEmbedder( ClassLoader classLoader ) throws MavenEmbedderException { - super( classLoader, new MavenEmbedderConsoleLogger() ); + super( new DefaultConfiguration() + .setClassLoader( classLoader ) + .setMavenEmbedderLogger( new MavenEmbedderConsoleLogger() ) ); } protected Map getPluginExtensionComponents( Plugin plugin ) @@ -449,7 +455,8 @@ public class MavenEmbedderTest return toReturn; } - protected void verifyPlugin( Plugin plugin, MavenProject project ) + protected void verifyPlugin( Plugin plugin, + MavenProject project ) { //ignore don't want to actually verify in test } 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 index 586efadbb7..0f9c3bde64 100644 --- a/maven-embedder/src/test/java/org/apache/maven/embedder/TestComponentOverride.java +++ b/maven-embedder/src/test/java/org/apache/maven/embedder/TestComponentOverride.java @@ -1,6 +1,8 @@ package org.apache.maven.embedder; import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.embedder.configuration.DefaultConfiguration; +import org.apache.maven.embedder.configuration.Configuration; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; @@ -25,7 +27,7 @@ public class TestComponentOverride ClassLoader loader = Thread.currentThread().getContextClassLoader(); - MavenEmbedderConfiguration request = new DefaultMavenEmbedderConfiguration(); + Configuration request = new DefaultConfiguration(); request.setClassLoader( loader ); diff --git a/maven-embedder/src/test/java/org/apache/maven/embedder/configuration/ValidateConfigurationTest.java b/maven-embedder/src/test/java/org/apache/maven/embedder/configuration/ValidateConfigurationTest.java new file mode 100644 index 0000000000..99dd327915 --- /dev/null +++ b/maven-embedder/src/test/java/org/apache/maven/embedder/configuration/ValidateConfigurationTest.java @@ -0,0 +1,39 @@ +package org.apache.maven.embedder.configuration; + +import org.codehaus.plexus.PlexusTestCase; +import org.apache.maven.embedder.MavenEmbedder; + +import java.io.File; + +/** @author Jason van Zyl */ +public class ValidateConfigurationTest + extends PlexusTestCase +{ + public void testConfigurationOnlyUserSettingsAreActive() + { + 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.isUserSettingsFileParses() ); + + assertTrue( result.isUserSettingsFileParses() ); + } + + public void testConfigurationOnlyGlobalSettingsAreActive() + { + 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.isUserSettingsFileParses() ); + + assertTrue( result.isUserSettingsFileParses() ); + } +} diff --git a/maven-embedder/src/test/resources/settings/valid-settings.xml b/maven-embedder/src/test/resources/settings/valid-settings.xml new file mode 100644 index 0000000000..f381d8f4ed --- /dev/null +++ b/maven-embedder/src/test/resources/settings/valid-settings.xml @@ -0,0 +1,8 @@ + + + /Users/jvanzyl/maven-repo-local + + org.codehaus.tycho + org.sonatype.pwt + +