mirror of https://github.com/apache/maven.git
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:
parent
410d22e73c
commit
3f3d07908d
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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 )
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue