mirror of https://github.com/apache/maven.git
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:
parent
cb381ffd76
commit
23e2504d23
|
@ -125,6 +125,11 @@ public class DefaultMavenExecutionRequest
|
|||
|
||||
public String getBaseDirectory()
|
||||
{
|
||||
if ( basedir == null )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return basedir.getAbsolutePath();
|
||||
}
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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() );
|
||||
|
|
Loading…
Reference in New Issue