From 0b0949ab868a00965de8cc87a3319bce98565932 Mon Sep 17 00:00:00 2001 From: Jason van Zyl Date: Wed, 28 Feb 2007 03:02:12 +0000 Subject: [PATCH] o make sure that even when all the configurations handed to the embedder are crap it will still start up. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@512585 13f79535-47bb-0310-9956-ffa450edef68 --- ...bedderCrappySettingsConfigurationTest.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderCrappySettingsConfigurationTest.java diff --git a/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderCrappySettingsConfigurationTest.java b/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderCrappySettingsConfigurationTest.java new file mode 100644 index 0000000000..06b536f62b --- /dev/null +++ b/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderCrappySettingsConfigurationTest.java @@ -0,0 +1,53 @@ +package org.apache.maven.embedder; + +import org.codehaus.plexus.PlexusTestCase; +import org.apache.maven.execution.MavenExecutionRequest; +import org.apache.maven.execution.DefaultMavenExecutionRequest; +import org.apache.maven.execution.MavenExecutionResult; +import org.apache.maven.project.MavenProject; + +import java.io.File; +import java.util.Arrays; +import java.util.Iterator; + +public class MavenEmbedderCrappySettingsConfigurationTest + extends PlexusTestCase +{ + public void testEmbedderWillStilStartupWhenTheSettingsConfigurationIsCrap() + throws Exception + { + // START SNIPPET: simple-embedder-example + + File projectDirectory = new File( getBasedir(), "src/examples/simple-project" ); + + File user = new File( projectDirectory, "invalid-settings.xml" ); + + Configuration configuration = new DefaultConfiguration() + .setUserSettingsFile( user ) + .setClassLoader( Thread.currentThread().getContextClassLoader() ); + + ConfigurationValidationResult validationResult = MavenEmbedder.validateConfiguration( configuration ); + + assertFalse( validationResult.isValid() ); + + MavenEmbedder embedder = new MavenEmbedder( configuration ); + + assertNotNull( embedder.getLocalRepository().getBasedir() ); + + MavenExecutionRequest request = new DefaultMavenExecutionRequest() + .setBaseDirectory( projectDirectory ) + .setGoals( Arrays.asList( new String[]{"clean", "install"} ) ); + + MavenExecutionResult result = embedder.execute( request ); + + assertNotNull( result.getMavenProject() ); + + MavenProject project = result.getMavenProject(); + + String environment = project.getProperties().getProperty( "environment" ); + + assertEquals( "development", environment ); + + // END SNIPPET: simple-embedder-example + } +}