Adding validation of @requiresProject and @requiresOnline to PluginManager.executeMojo(..), in order to centrally block mojos from executing under the wrong conditions.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@291422 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2005-09-25 15:03:59 +00:00
parent 410d22e73c
commit 3f3d07908d
3 changed files with 30 additions and 0 deletions

View File

@ -153,6 +153,7 @@ public class DefaultMaven
ProfileManager globalProfileManager = request.getGlobalProfileManager(); ProfileManager globalProfileManager = request.getGlobalProfileManager();
boolean foundProjects = true;
try try
{ {
loadSettingsProfiles( globalProfileManager, request.getSettings() ); loadSettingsProfiles( globalProfileManager, request.getSettings() );
@ -169,6 +170,8 @@ public class DefaultMaven
{ {
MavenProject superProject = projectBuilder.buildStandaloneSuperProject( request.getLocalRepository() ); MavenProject superProject = projectBuilder.buildStandaloneSuperProject( request.getLocalRepository() );
projects.add( superProject ); projects.add( superProject );
foundProjects = false;
} }
rm = new ReactorManager( projects ); rm = new ReactorManager( projects );
@ -205,6 +208,8 @@ public class DefaultMaven
{ {
MavenSession session = createSession( request, rm ); MavenSession session = createSession( request, rm );
session.setUsingPOMsFromFilesystem( foundProjects );
try try
{ {
MavenExecutionResponse response = lifecycleExecutor.execute( session, rm, dispatcher ); MavenExecutionResponse response = lifecycleExecutor.execute( session, rm, dispatcher );

View File

@ -46,6 +46,8 @@ public class MavenSession
private final String executionRootDir; private final String executionRootDir;
private boolean usingPOMsFromFilesystem;
public MavenSession( PlexusContainer container, Settings settings, ArtifactRepository localRepository, public MavenSession( PlexusContainer container, Settings settings, ArtifactRepository localRepository,
EventDispatcher eventDispatcher, ReactorManager rpm, List goals, String executionRootDir ) EventDispatcher eventDispatcher, ReactorManager rpm, List goals, String executionRootDir )
{ {
@ -126,4 +128,14 @@ public class MavenSession
{ {
return executionRootDir; return executionRootDir;
} }
public void setUsingPOMsFromFilesystem( boolean usingPOMsFromFilesystem )
{
this.usingPOMsFromFilesystem = usingPOMsFromFilesystem;
}
public boolean isUsingPOMsFromFilesystem()
{
return usingPOMsFromFilesystem;
}
} }

View File

@ -311,6 +311,19 @@ public class DefaultPluginManager
{ {
MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor(); 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 ) if ( mojoDescriptor.isDependencyResolutionRequired() != null )
{ {
Collection projects; Collection projects;