mirror of https://github.com/apache/maven.git
MNG-2330 adding a little harness for running projects easily and testing with eclipse:eclipse
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@512844 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
fb03e03672
commit
9d1ee49281
|
@ -96,6 +96,7 @@ import java.util.HashMap;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Class intended to be used by clients who wish to embed Maven into their applications
|
||||
|
|
|
@ -0,0 +1,110 @@
|
|||
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.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;
|
||||
|
||||
public abstract class AbstractMavenEmbedderTestCase
|
||||
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();
|
||||
}
|
||||
|
||||
protected MavenExecutionRequest request( File basedir,
|
||||
List goals )
|
||||
{
|
||||
return new DefaultMavenExecutionRequest()
|
||||
.setBaseDirectory( basedir )
|
||||
.setGoals( goals );
|
||||
}
|
||||
|
||||
protected File runWithProject( String goal )
|
||||
throws Exception
|
||||
{
|
||||
return runWithProject( new String[]{goal} );
|
||||
}
|
||||
|
||||
protected File runWithProject( String[] goals )
|
||||
throws Exception
|
||||
{
|
||||
return runWithProject( Arrays.asList( goals ) );
|
||||
}
|
||||
|
||||
protected File runWithProject( List goals )
|
||||
throws Exception
|
||||
{
|
||||
/*
|
||||
if ( request.getBaseDirectory() == null || !new File( request.getBaseDirectory() ).exists() )
|
||||
{
|
||||
throw new IllegalStateException( "You must specify a valid base directory in your execution request for this test." );
|
||||
}
|
||||
*/
|
||||
|
||||
File testDirectory = new File( getBasedir(), "src/test/embedder-test-project" );
|
||||
|
||||
File targetDirectory = new File( getBasedir(), "target/" + getId() );
|
||||
|
||||
FileUtils.copyDirectoryStructure( testDirectory, targetDirectory );
|
||||
|
||||
MavenExecutionRequest request = request( targetDirectory, goals );
|
||||
|
||||
MavenExecutionResult result = maven.execute( request );
|
||||
|
||||
assertNoExceptions( result );
|
||||
|
||||
return targetDirectory;
|
||||
}
|
||||
|
||||
protected abstract String getId();
|
||||
|
||||
protected void assertNoExceptions( MavenExecutionResult result )
|
||||
{
|
||||
if ( !result.hasExceptions() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for ( Iterator i = result.getExceptions().iterator(); i.hasNext(); )
|
||||
{
|
||||
Exception exception = (Exception) i.next();
|
||||
|
||||
exception.printStackTrace( System.err );
|
||||
}
|
||||
|
||||
fail( "Encountered Exceptions in MavenExecutionResult during " + getName() );
|
||||
}
|
||||
|
||||
protected void assertFileExists( File file )
|
||||
{
|
||||
if ( !file.exists() )
|
||||
{
|
||||
fail( "The specified file '" + file + "' does not exist." );
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package org.apache.maven.embedder;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/** @author Jason van Zyl */
|
||||
public class MavenEmbedderUsingEclipsePluginTest
|
||||
extends AbstractMavenEmbedderTestCase
|
||||
{
|
||||
protected String getId()
|
||||
{
|
||||
return "eclipse-from-embedder";
|
||||
}
|
||||
|
||||
public void testRunningEclipsePlugin()
|
||||
throws Exception
|
||||
{
|
||||
File basedir = runWithProject( "eclipse:eclipse" );
|
||||
|
||||
assertFileExists( new File( basedir, ".classpath" ) );
|
||||
|
||||
assertFileExists( new File( basedir, ".project" ) );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue