Working on MNG-483

o Added @requiresDirectInvocation (was: @cliOnly, but this implies m2 is run from CLI...counter-intuitive for embedding)

o Added handling for new @requiresDirectInvocation (generation/parsing, MojoDescriptor support, etc.)

o Added check in DefaultLifecycleExecutor to throw a LifecycleExecutionException if a mojo specified in a lifecycle binding is marked as direct-invocation only.

o Added MavenProjectHelper/DefaultMavenProjectHelper to provide convenience methods for manipulating MavenProject instances (for example, attaching artifacts or adding resources)

o Removed maven-artifact dependency from maven-source-plugin, and added dependency on maven-plugin-api (should've been there)



git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@233021 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2005-08-16 18:03:20 +00:00
parent fe5a91b0d6
commit 9a3085813d
14 changed files with 143 additions and 16 deletions

View File

@ -86,8 +86,6 @@ public class DefaultLifecycleExecutor
private List phases;
private Map defaultPhases;
private ArtifactHandlerManager artifactHandlerManager;
// ----------------------------------------------------------------------
@ -571,6 +569,12 @@ public class DefaultLifecycleExecutor
// Not from the CLI, don't use prefix
// TODO: [MNG-608] this needs to be false
MojoDescriptor mojoDescriptor = getMojoDescriptor( goal, session, project, selectedPhase, false );
if ( mojoDescriptor.isDirectInvocationOnly() )
{
throw new LifecycleExecutionException( "Mojo: \'" + goal + "\' requires direct invocation. It cannot be used as part of lifecycle: \'" + project.getPackaging() + "\'." );
}
addToLifecycleMappings( lifecycleMappings, phase, new MojoExecution( mojoDescriptor ),
session.getSettings() );
}

View File

@ -138,6 +138,7 @@
<!-- START SNIPPET: lifecyle -->
<phases>
<phase implementation="java.lang.String">validate</phase>
<phase implementation="java.lang.String">initialize</phase>
<phase implementation="java.lang.String">generate-sources</phase>
<phase implementation="java.lang.String">process-sources</phase>
<phase implementation="java.lang.String">generate-resources</phase>
@ -158,6 +159,7 @@
</phases>
<!-- END SNIPPET: lifecycle -->
<!-- START SNIPPET: default-lifecycle -->
<!-- NOT USED, ACCORDING TO CODE.
<defaultPhases>
<process-resources>org.apache.maven.plugins:maven-resources-plugin:resources</process-resources>
<compile>org.apache.maven.plugins:maven-compiler-plugin:compile</compile>
@ -171,6 +173,7 @@
<install>org.apache.maven.plugins:maven-install-plugin:install</install>
<deploy>org.apache.maven.plugins:maven-deploy-plugin:deploy</deploy>
</defaultPhases>
-->
<!-- END SNIPPET: default-lifecycle -->
</configuration>
</component>

View File

@ -79,6 +79,8 @@ public class MojoDescriptor
private PluginDescriptor pluginDescriptor;
private boolean inheritedByDefault = true;
private boolean directInvocationOnly = false;
public MojoDescriptor()
{
@ -401,4 +403,14 @@ public class MojoDescriptor
{
return aggregator;
}
public boolean isDirectInvocationOnly()
{
return directInvocationOnly;
}
public void setDirectInvocationOnly( boolean directInvocationOnly )
{
this.directInvocationOnly = directInvocationOnly;
}
}

View File

@ -160,6 +160,13 @@ public class PluginDescriptorBuilder
mojo.setDependencyResolutionRequired( dependencyResolution );
}
String directInvocationOnly = c.getChild( "requiresDirectInvocation" ).getValue();
if ( directInvocationOnly != null )
{
mojo.setDirectInvocationOnly( Boolean.valueOf( directInvocationOnly ).booleanValue() );
}
String requiresProject = c.getChild( "requiresProject" ).getValue();
if ( requiresProject != null )
@ -187,7 +194,7 @@ public class PluginDescriptorBuilder
{
mojo.setInheritedByDefault( Boolean.valueOf( inheritedByDefault ).booleanValue() );
}
// ----------------------------------------------------------------------
// Parameters
// ----------------------------------------------------------------------

View File

@ -126,6 +126,12 @@ public class PluginDescriptorGenerator
//
// ----------------------------------------------------------------------
element( w, "requiresDirectInvocation", "" + mojoDescriptor.isDirectInvocationOnly() );
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
element( w, "requiresProject", "" + mojoDescriptor.isProjectRequired() );
// ----------------------------------------------------------------------

View File

@ -85,6 +85,8 @@ public class JavaMojoDescriptorExtractor
public static final String GOAL_INHERIT_BY_DEFAULT = "inheritByDefault";
public static final String GOAL_MULTI_EXECUTION_STRATEGY = "attainAlways";
public static final String GOAL_REQUIRES_DIRECT_INVOCATION = "requiresDirectInvocation";
protected void validateParameter( Parameter parameter, int i )
throws InvalidParameterException
@ -255,6 +257,17 @@ public class JavaMojoDescriptorExtractor
mojoDescriptor.setAggregator( true );
}
// ----------------------------------------------------------------------
// requiresDirectInvocation flag
// ----------------------------------------------------------------------
DocletTag requiresDirectInvocation = findInClassHierarchy( javaClass, GOAL_REQUIRES_DIRECT_INVOCATION );
if ( requiresDirectInvocation != null )
{
mojoDescriptor.setDirectInvocationOnly( true );
}
// ----------------------------------------------------------------------
// Online flag
// ----------------------------------------------------------------------

View File

@ -57,6 +57,7 @@ import java.util.regex.Pattern;
* @version $Id$
* @goal assembly
* @requiresDependencyResolution test
* @requiresDirectInvocation
* @execute phase="package"
*/
public class AssemblyMojo

View File

@ -28,7 +28,7 @@
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<artifactId>maven-plugin-api</artifactId>
<version>2.0-beta-1-SNAPSHOT</version>
</dependency>
</dependencies>

View File

@ -16,11 +16,10 @@ package org.apache.maven.plugin.source;
* limitations under the License.
*/
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectHelper;
import org.codehaus.plexus.archiver.jar.JarArchiver;
import java.io.File;
@ -45,9 +44,9 @@ public class JarSourceMojo
private MavenProject project;
/**
* @parameter expression="${component.org.apache.maven.artifact.factory.ArtifactFactory}
* @parameter expression="${component.org.apache.maven.project.MavenProjectHelper}
*/
private ArtifactFactory artifactFactory;
private MavenProjectHelper projectHelper;
/**
* @parameter expression="${project.build.finalName}"
@ -110,12 +109,7 @@ public class JarSourceMojo
// TODO: these introduced dependencies on the project are going to become problematic - can we export it
// through metadata instead?
Artifact artifact = artifactFactory.createArtifactWithClassifier( project.getGroupId(),
project.getArtifactId(),
project.getVersion(), null, "java-source",
"sources" );
artifact.setFile( outputFile );
project.addAttachedArtifact( artifact );
projectHelper.attachArtifact( project, "java-source", "sources", outputFile );
}
else
{

View File

@ -0,0 +1,52 @@
package org.apache.maven.project;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.model.Resource;
import java.io.File;
import java.util.List;
public class DefaultMavenProjectHelper
implements MavenProjectHelper
{
// requirement.
private ArtifactFactory artifactFactory;
public void attachArtifact( MavenProject project, String artifactType, String artifactClassifier, File artifactFile )
{
Artifact artifact = artifactFactory.createArtifactWithClassifier( project.getGroupId(),
project.getArtifactId(),
project.getVersion(),
null,
"artifactType",
"artifactClassifier" );
artifact.setFile( artifactFile );
artifact.setResolved( true );
project.addAttachedArtifact( artifact );
}
public void addResource( MavenProject project, String resourceDirectory, List includes, List excludes )
{
Resource resource = new Resource();
resource.setDirectory( resourceDirectory );
resource.setIncludes( includes );
resource.setExcludes( excludes );
project.addResource( resource );
}
public void addTestResource( MavenProject project, String resourceDirectory, List includes, List excludes )
{
Resource resource = new Resource();
resource.setDirectory( resourceDirectory );
resource.setIncludes( includes );
resource.setExcludes( excludes );
project.addTestResource( resource );
}
}

View File

@ -1337,5 +1337,9 @@ public class MavenProject
this.profileProperties = newProfilesProperties;
}
public void attachArtifact( String type, String classifier, File file )
{
}
}

View File

@ -0,0 +1,17 @@
package org.apache.maven.project;
import java.io.File;
import java.util.List;
public interface MavenProjectHelper
{
String ROLE = MavenProjectHelper.class.getName();
void attachArtifact( MavenProject project, String artifactType, String artifactClassifier, File artifactFile );
void addResource( MavenProject project, String resourceDirectory, List includes, List excludes );
void addTestResource( MavenProject project, String resourceDirectory, List includes, List excludes );
}

View File

@ -1,5 +1,19 @@
<component-set>
<components>
<!--
|
|
|
-->
<component>
<role>org.apache.maven.project.MavenProjectHelper</role>
<implementation>org.apache.maven.project.DefaultMavenProjectHelper</implementation>
<requirements>
<requirement>
<role>org.apache.maven.artifact.factory.ArtifactFactory</role>
</requirement>
</requirements>
</component>
<!--
|
|

View File

@ -60,12 +60,12 @@
<build>
<plugins>
<plugin>
<inherit>true</inherit>
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<inherit>true</inherit>
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>