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
|
@ -311,7 +311,7 @@ public class DefaultMaven
|
||||||
lifecycleExecutor.execute( session, rm, dispatcher );
|
lifecycleExecutor.execute( session, rm, dispatcher );
|
||||||
}
|
}
|
||||||
catch ( Exception e )
|
catch ( Exception e )
|
||||||
{
|
{
|
||||||
executionExceptions.add( new BuildFailureException( e.getMessage(), e ) );
|
executionExceptions.add( new BuildFailureException( e.getMessage(), e ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -125,6 +125,11 @@ public class DefaultMavenExecutionRequest
|
||||||
|
|
||||||
public String getBaseDirectory()
|
public String getBaseDirectory()
|
||||||
{
|
{
|
||||||
|
if ( basedir == null )
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return basedir.getAbsolutePath();
|
return basedir.getAbsolutePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
<artifactId>maven-embedder</artifactId>
|
<artifactId>maven-embedder</artifactId>
|
||||||
<name>Maven Embedder</name>
|
<name>Maven Embedder</name>
|
||||||
<properties>
|
<properties>
|
||||||
<bundleVersion>2.1.0.v20061231-1908</bundleVersion>
|
<bundleVersion>2.1.0.v20061231-1929</bundleVersion>
|
||||||
</properties>
|
</properties>
|
||||||
<build>
|
<build>
|
||||||
<resources>
|
<resources>
|
||||||
|
|
|
@ -144,6 +144,13 @@ public class DefaultMavenExecutionRequestDefaultsPopulator
|
||||||
throw new MavenEmbedderException( "Unable to configure Maven for execution", e );
|
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;
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,12 +54,12 @@ public class MavenEmbedderTest
|
||||||
// Goal/Phase execution tests
|
// Goal/Phase execution tests
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
public void testPhaseExecution()
|
public void testSimplePhaseExecutionUsingABaseDirectory()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
File testDirectory = new File( basedir, "src/test/embedder-test-project" );
|
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 );
|
FileUtils.copyDirectoryStructure( testDirectory, targetDirectory );
|
||||||
|
|
||||||
|
@ -69,6 +69,34 @@ public class MavenEmbedderTest
|
||||||
|
|
||||||
MavenExecutionResult result = maven.execute( request );
|
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" );
|
File jar = new File( targetDirectory, "target/embedder-test-project-1.0-SNAPSHOT.jar" );
|
||||||
|
|
||||||
assertTrue( jar.exists() );
|
assertTrue( jar.exists() );
|
||||||
|
|
Loading…
Reference in New Issue