diff --git a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java index 41fddfbab8..40fbe1c2db 100644 --- a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java +++ b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java @@ -153,6 +153,7 @@ public class DefaultMaven ProfileManager globalProfileManager = request.getGlobalProfileManager(); + boolean foundProjects = true; try { loadSettingsProfiles( globalProfileManager, request.getSettings() ); @@ -169,6 +170,8 @@ public class DefaultMaven { MavenProject superProject = projectBuilder.buildStandaloneSuperProject( request.getLocalRepository() ); projects.add( superProject ); + + foundProjects = false; } rm = new ReactorManager( projects ); @@ -204,6 +207,8 @@ public class DefaultMaven try { MavenSession session = createSession( request, rm ); + + session.setUsingPOMsFromFilesystem( foundProjects ); try { diff --git a/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java b/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java index eb17b6fce3..1c230cbcd0 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java +++ b/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java @@ -46,6 +46,8 @@ public class MavenSession private final String executionRootDir; + private boolean usingPOMsFromFilesystem; + public MavenSession( PlexusContainer container, Settings settings, ArtifactRepository localRepository, EventDispatcher eventDispatcher, ReactorManager rpm, List goals, String executionRootDir ) { @@ -126,4 +128,14 @@ public class MavenSession { return executionRootDir; } + + public void setUsingPOMsFromFilesystem( boolean usingPOMsFromFilesystem ) + { + this.usingPOMsFromFilesystem = usingPOMsFromFilesystem; + } + + public boolean isUsingPOMsFromFilesystem() + { + return usingPOMsFromFilesystem; + } } \ No newline at end of file diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java index 37f5036aca..15b6f8d83f 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java @@ -310,6 +310,19 @@ public class DefaultPluginManager throws ArtifactResolutionException, PluginManagerException, MojoExecutionException { MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor(); + + // NOTE: I'm putting these checks in here, since this is the central point of access for + // anything that wants to execute a mojo. + if( mojoDescriptor.isProjectRequired() && !session.isUsingPOMsFromFilesystem() ) + { + throw new MojoExecutionException( "Cannot execute mojo: " + mojoDescriptor.getGoal() + ". It requires a project, but the build is not using one." ); + } + + if ( mojoDescriptor.isOnlineRequired() && session.getSettings().isOffline() ) + { + // TODO: Should we error out, or simply warn and skip?? + throw new MojoExecutionException( "Mojo: " + mojoDescriptor.getGoal() + " requires online mode for execution. Maven is currently offline." ); + } if ( mojoDescriptor.isDependencyResolutionRequired() != null ) {