mirror of https://github.com/apache/maven.git
o Tests for MNG-2835
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@512891 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
24b3c86c9b
commit
fb7988c21c
|
@ -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 )
|
||||
{
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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()
|
||||
{
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0"?>
|
||||
<settings>
|
||||
<localRepository>/Users/jvanzyl/maven-repo-local</localRepository>
|
||||
<localRepository>/global/maven/local-repository</localRepository>
|
||||
<pluginGroups>
|
||||
<pluginGroup>org.codehaus.tycho</pluginGroup>
|
||||
<pluginGroup>org.sonatype.pwt</pluginGroup>
|
||||
|
|
Loading…
Reference in New Issue