MNG-2733 When request.setPomFile( file ) is used, takes its basedir for the execution request so that request.getBasedir() doesn't NPE

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@491524 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2007-01-01 02:52:56 +00:00
parent cb381ffd76
commit 23e2504d23
5 changed files with 44 additions and 4 deletions

View File

@ -311,7 +311,7 @@ public class DefaultMaven
lifecycleExecutor.execute( session, rm, dispatcher );
}
catch ( Exception e )
{
{
executionExceptions.add( new BuildFailureException( e.getMessage(), e ) );
}

View File

@ -125,6 +125,11 @@ public class DefaultMavenExecutionRequest
public String getBaseDirectory()
{
if ( basedir == null )
{
return null;
}
return basedir.getAbsolutePath();
}

View File

@ -27,7 +27,7 @@
<artifactId>maven-embedder</artifactId>
<name>Maven Embedder</name>
<properties>
<bundleVersion>2.1.0.v20061231-1908</bundleVersion>
<bundleVersion>2.1.0.v20061231-1929</bundleVersion>
</properties>
<build>
<resources>

View File

@ -144,6 +144,13 @@ public class DefaultMavenExecutionRequestDefaultsPopulator
throw new MavenEmbedderException( "Unable to configure Maven for execution", e );
}
// BaseDirectory in MavenExecutionRequest
if ( request.getPomFile() != null && request.getBaseDirectory() == null )
{
request.setBasedir( new File( request.getPomFile() ) );
}
return request;
}

View File

@ -54,12 +54,12 @@ public class MavenEmbedderTest
// Goal/Phase execution tests
// ----------------------------------------------------------------------
public void testPhaseExecution()
public void testSimplePhaseExecutionUsingABaseDirectory()
throws Exception
{
File testDirectory = new File( basedir, "src/test/embedder-test-project" );
File targetDirectory = new File( basedir, "target/embedder-test-project" );
File targetDirectory = new File( basedir, "target/embedder-test-project0" );
FileUtils.copyDirectoryStructure( testDirectory, targetDirectory );
@ -69,6 +69,34 @@ public class MavenEmbedderTest
MavenExecutionResult result = maven.execute( request );
MavenProject project = result.getMavenProject();
assertEquals( "embedder-test-project", project.getArtifactId() );
File jar = new File( targetDirectory, "target/embedder-test-project-1.0-SNAPSHOT.jar" );
assertTrue( jar.exists() );
}
public void testSimplePhaseExecutionUsingAPomFile()
throws Exception
{
File testDirectory = new File( basedir, "src/test/embedder-test-project" );
File targetDirectory = new File( basedir, "target/embedder-test-project1" );
FileUtils.copyDirectoryStructure( testDirectory, targetDirectory );
MavenExecutionRequest request = new DefaultMavenExecutionRequest()
.setPomFile( new File( targetDirectory, "pom.xml" ).getAbsolutePath() )
.setGoals( Arrays.asList( new String[]{ "package" } ) );
MavenExecutionResult result = maven.execute( request );
MavenProject project = result.getMavenProject();
assertEquals( "embedder-test-project", project.getArtifactId() );
File jar = new File( targetDirectory, "target/embedder-test-project-1.0-SNAPSHOT.jar" );
assertTrue( jar.exists() );