diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/binding/DefaultLifecycleBindingManager.java b/maven-core/src/main/java/org/apache/maven/lifecycle/binding/DefaultLifecycleBindingManager.java index cb3a725d4d..26e0f3d2f5 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/binding/DefaultLifecycleBindingManager.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/binding/DefaultLifecycleBindingManager.java @@ -248,6 +248,12 @@ public class DefaultLifecycleBindingManager } MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo( goal ); + if(mojoDescriptor == null) + { + throw new LifecycleSpecificationException( "Mojo Descriptor for goal is invalid: Plugin = " + + plugin.getKey() + ", Plugin Descriptor = " + + pluginDescriptor.getPluginLookupKey() +", Goal = " + goal); + } phase = mojoDescriptor.getPhase(); logger.debug( "Phase from plugin descriptor: " + mojoDescriptor.getFullGoalName() + " is: " + phase ); diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java b/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java index f40f1f96a3..c37be679b4 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java @@ -264,18 +264,20 @@ public final class CLIReportingUtils handleGenericException( e, showStackTraces, writer ); MavenProject project = e.getProject(); - - writer.write( NEWLINE ); - writer.write( "While building project with id: " ); - writer.write( project.getId() ); - writer.write( NEWLINE ); - if ( project.getFile() != null ) + if(project != null) { - writer.write( "Project File: " ); - writer.write( project.getFile().getAbsolutePath() ); + writer.write( NEWLINE ); + writer.write( "While building project with id: " ); + writer.write( project.getId() ); + writer.write( NEWLINE ); + if ( project.getFile() != null ) + { + writer.write( "Project File: " ); + writer.write( project.getFile().getAbsolutePath() ); + } + writer.write( NEWLINE ); } - writer.write( NEWLINE ); - + return true; } diff --git a/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderTest.java b/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderTest.java index 4c55ac3bee..64ff05fb15 100644 --- a/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderTest.java +++ b/maven-embedder/src/test/java/org/apache/maven/embedder/MavenEmbedderTest.java @@ -33,6 +33,7 @@ import org.apache.maven.settings.Settings; import org.apache.maven.settings.SettingsConfigurationException; import org.apache.maven.settings.io.xpp3.SettingsXpp3Reader; import org.apache.maven.settings.io.xpp3.SettingsXpp3Writer; +import org.apache.maven.lifecycle.LifecycleSpecificationException; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.ReaderFactory; @@ -57,6 +58,7 @@ public class MavenEmbedderTest protected MavenEmbedder maven; + protected void setUp() throws Exception { @@ -134,6 +136,30 @@ public class MavenEmbedderTest assertTrue( jar.exists() ); } + /*MNG-3919*/ + public void testWithInvalidGoal() + throws Exception + { + File testDirectory = new File( basedir, "src/test/projects/invalid-goal" ); + + File targetDirectory = new File( basedir, "target/projects/invalid-goal" ); + + FileUtils.copyDirectoryStructure( testDirectory, targetDirectory ); + + MavenExecutionRequest request = new DefaultMavenExecutionRequest().setBaseDirectory( targetDirectory ) + .setShowErrors( true ).setGoals( Arrays.asList( new String[]{"validate"} ) ); + + MavenExecutionResult result = maven.execute( request ); + List exceptions = result.getExceptions(); + assertEquals("Incorrect number of exceptions", 1, exceptions.size()); + + Iterator it = exceptions.iterator(); + if( (it.next() instanceof NullPointerException)) + { + fail("Null Pointer on Exception"); + } + } + public void testExecutionUsingAPomFile() throws Exception { diff --git a/maven-embedder/src/test/projects/invalid-goal/pom.xml b/maven-embedder/src/test/projects/invalid-goal/pom.xml new file mode 100644 index 0000000000..d72b515ad3 --- /dev/null +++ b/maven-embedder/src/test/projects/invalid-goal/pom.xml @@ -0,0 +1,49 @@ + + + + + + 4.0.0 + + org.apache.maven.its.mng + test1 + 1.0-SNAPSHOT + + jar + + + + + org.apache.maven.plugins + maven-site-plugin + 2.0-beta-7 + + + + + invalid-goal + + + + + + + +