o changed the inheritanceApplied flag to be set by default, and unset if the plugin is merged to the child without <inherit/> being specified...this makes it work with isolated POMs.

o changed the semantics of when the unsetInheritanceApplied() method is called...it's now only when <inherit/> is NOT set.
o changed the default inheritByDefault attribute on MojoDescriptor to be true
o added inheritByDefault to PluginDescriptor (even though we don't have tools supporting it yet), with semantics identical to MojoDescriptor
o added generator/builder support for the inheritByDefault attribute of PluginDescriptor
o added calculation of inheritanceApplied || inheritByDefault to lifecycle executor before allowing plugins/mojos to bind.
o Everything builds, but we need some sort of IT to test the finer points.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@178836 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2005-05-27 23:05:09 +00:00
parent 6ca4de295d
commit fda1ed95c9
7 changed files with 65 additions and 27 deletions

View File

@ -22,6 +22,7 @@ import org.apache.maven.artifact.handler.manager.ArtifactHandlerNotFoundExceptio
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.execution.MavenExecutionResponse;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Goal;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginManagement;
import org.apache.maven.plugin.MojoExecutionException;
@ -239,27 +240,42 @@ public class DefaultLifecycleExecutor
{
throw new LifecycleExecutionException( "Internal error in the plugin manager", e );
}
// ----------------------------------------------------------------------
// Look to see if the plugin configuration specifies particular mojos
// within the plugin. If this is the case then simply configure the
// mojos the user has specified and ignore the rest.
// ----------------------------------------------------------------------
for ( Iterator j = pluginDescriptor.getMojos().iterator(); j.hasNext(); )
if( plugin.isInheritanceApplied() || pluginDescriptor.isInheritedByDefault() )
{
MojoDescriptor mojoDescriptor = (MojoDescriptor) j.next();
// ----------------------------------------------------------------------
// Look to see if the plugin configuration specifies particular mojos
// within the plugin. If this is the case then simply configure the
// mojos the user has specified and ignore the rest.
// ----------------------------------------------------------------------
// TODO: remove later
if ( mojoDescriptor.getGoal() == null )
Map goalMap = plugin.getGoalsAsMap();
for ( Iterator j = pluginDescriptor.getMojos().iterator(); j.hasNext(); )
{
throw new LifecycleExecutionException(
"The plugin " + artifactId + " was built with an older version of Maven" );
}
MojoDescriptor mojoDescriptor = (MojoDescriptor) j.next();
if ( plugin.getGoals().isEmpty() || plugin.getGoalsAsMap().containsKey( mojoDescriptor.getGoal() ) )
{
configureMojoPhaseBinding( mojoDescriptor, phaseMap, session.getSettings() );
// TODO: remove later
if ( mojoDescriptor.getGoal() == null )
{
throw new LifecycleExecutionException(
"The plugin " + artifactId + " was built with an older version of Maven" );
}
Goal goal = (Goal) goalMap.get( mojoDescriptor.getGoal() );
if( goalMap.isEmpty() )
{
configureMojoPhaseBinding( mojoDescriptor, phaseMap, session.getSettings() );
}
else if ( goal != null )
{
// We have to check to see that the inheritance rules have been applied before binding this mojo.
if( goal.isInheritanceApplied() || mojoDescriptor.isInheritedByDefault() )
{
configureMojoPhaseBinding( mojoDescriptor, phaseMap, session.getSettings() );
}
}
}
}
}

View File

@ -2050,9 +2050,9 @@
<version>4.0.0</version>
<code><![CDATA[
private Map goalMap = null;
private boolean inheritanceApplied = false;
private boolean inheritanceApplied = true;
public void setInheritanceApplied()
public void unsetInheritanceApplied()
{
this.inheritanceApplied = true;
}
@ -2120,9 +2120,9 @@
<codeSegments>
<codeSegment>
<code><![CDATA[
private boolean inheritanceApplied = false;
private boolean inheritanceApplied = true;
public void setInheritanceApplied()
public void unsetInheritanceApplied()
{
this.inheritanceApplied = true;
}

View File

@ -75,7 +75,7 @@ public class MojoDescriptor
private PluginDescriptor pluginDescriptor;
private boolean inheritedByDefault = false;
private boolean inheritedByDefault = true;
public MojoDescriptor()
{

View File

@ -41,6 +41,8 @@ public class PluginDescriptor
private String source;
private boolean inheritedByDefault = true;
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
@ -178,4 +180,14 @@ public class PluginDescriptor
{
return source;
}
public boolean isInheritedByDefault()
{
return inheritedByDefault;
}
public void setInheritedByDefault( boolean inheritedByDefault )
{
this.inheritedByDefault = inheritedByDefault;
}
}

View File

@ -38,6 +38,13 @@ public class PluginDescriptorBuilder
pluginDescriptor.setVersion( c.getChild( "version" ).getValue() );
pluginDescriptor.setGoalPrefix( c.getChild( "goalPrefix" ).getValue() );
String inheritedByDefault = c.getChild( "inheritedByDefault" ).getValue();
if ( inheritedByDefault != null )
{
pluginDescriptor.setInheritedByDefault( Boolean.valueOf( inheritedByDefault ).booleanValue() );
}
// ----------------------------------------------------------------------
// Components
// ----------------------------------------------------------------------

View File

@ -70,7 +70,9 @@ public class PluginDescriptorGenerator
element( w, "goalPrefix", pluginDescriptor.getGoalPrefix() );
w.startElement( "mojos" );
element( w, "inheritedByDefault", "" + pluginDescriptor.isInheritedByDefault() );
w.startElement( "mojos" );
for ( Iterator it = pluginDescriptor.getMojos().iterator(); it.hasNext(); )
{

View File

@ -68,9 +68,9 @@ public final class ModelUtils
ModelUtils.mergePluginDefinitions( childPlugin, parentPlugin, handleAsInheritance );
}
if ( handleAsInheritance )
if ( handleAsInheritance && parentInherited == null )
{
assembledPlugin.setInheritanceApplied();
assembledPlugin.unsetInheritanceApplied();
}
assembledPlugins.put( assembledPlugin.getKey(), assembledPlugin );
@ -142,9 +142,9 @@ public final class ModelUtils
assembledGoal = childGoal;
}
if ( handleAsInheritance )
if ( handleAsInheritance && parentInherited == null )
{
assembledGoal.setInheritanceApplied();
assembledGoal.unsetInheritanceApplied();
}
assembledGoals.put( assembledGoal.getId(), assembledGoal );
@ -165,6 +165,7 @@ public final class ModelUtils
}
child.setGoals( new ArrayList( assembledGoals.values() ) );
child.flushGoalMap();
}
}