change @requiresDependencyResolution to take a scope (default is "runtime" if no scope specified, none if tag not specified at all).

This still means ALL tests get the test dependencies of their compile time dependencies. Check if there is really a valid use case for that.


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163780 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-04-05 08:17:28 +00:00
parent ddeee6f1d4
commit 9d6fad725a
15 changed files with 166 additions and 72 deletions

View File

@ -280,8 +280,6 @@ public class DefaultArtifactResolver
knownVersion,
newArtifact.getScope(),
knownArtifact.getType() );
// don't copy file - these aren't resolved yet
resolvedArtifacts.put( artifact.getConflictId(), artifact );
}
}

View File

@ -0,0 +1,85 @@
package org.apache.maven.artifact.resolver.filter;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DefaultArtifact;
/*
* Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Filter to only retain objects in the given scope or better.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @version $Id$
*/
public class ScopeArtifactFilter
implements ArtifactFilter
{
private final boolean compileScope;
private final boolean runtimeScope;
private final boolean testScope;
public ScopeArtifactFilter( String scope )
{
if ( DefaultArtifact.SCOPE_COMPILE.equals( scope ) )
{
compileScope = true;
runtimeScope = false;
testScope = false;
}
else if ( DefaultArtifact.SCOPE_RUNTIME.equals( scope ) )
{
compileScope = true;
runtimeScope = true;
testScope = false;
}
else if ( DefaultArtifact.SCOPE_TEST.equals( scope ) )
{
compileScope = true;
runtimeScope = true;
testScope = true;
}
else
{
compileScope = false;
runtimeScope = false;
testScope = false;
}
}
public boolean include( Artifact artifact )
{
if ( DefaultArtifact.SCOPE_COMPILE.equals( artifact.getScope() ) )
{
return compileScope;
}
else if ( DefaultArtifact.SCOPE_RUNTIME.equals( artifact.getScope() ) )
{
return runtimeScope;
}
else if ( DefaultArtifact.SCOPE_TEST.equals( artifact.getScope() ) )
{
return testScope;
}
else
{
// TODO: should this be true?
return false;
}
}
}

View File

@ -25,6 +25,7 @@ import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.artifact.resolver.filter.ExclusionSetFilter;
import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.monitor.event.EventDispatcher;
import org.apache.maven.monitor.event.MavenEvents;
@ -340,7 +341,7 @@ public class DefaultPluginManager
try
{
if ( mojoDescriptor.requiresDependencyResolution() )
if ( mojoDescriptor.getRequiresDependencyResolution() != null )
{
ArtifactResolver artifactResolver = null;
@ -351,7 +352,8 @@ public class DefaultPluginManager
artifactResolver = (ArtifactResolver) container.lookup( ArtifactResolver.ROLE );
mavenProjectBuilder = (MavenProjectBuilder) container.lookup( MavenProjectBuilder.ROLE );
resolveTransitiveDependencies( session, artifactResolver, mavenProjectBuilder );
resolveTransitiveDependencies( session, artifactResolver, mavenProjectBuilder,
mojoDescriptor.getRequiresDependencyResolution() );
downloadDependencies( session, artifactResolver );
}
finally
@ -700,10 +702,8 @@ public class DefaultPluginManager
// TODO: configure this from bootstrap or scan lib
artifactFilter = new ExclusionSetFilter( new String[]{"maven-core", "maven-artifact", "maven-model",
"maven-settings", "maven-monitor", "maven-plugin",
"plexus-container-api", "plexus-container-default",
"plexus-artifact-container", "wagon-provider-api",
"classworlds"} );
"plexus-container-default", "plexus-artifact-container",
"wagon-provider-api", "classworlds"} );
}
// ----------------------------------------------------------------------
@ -711,17 +711,19 @@ public class DefaultPluginManager
// ----------------------------------------------------------------------
private void resolveTransitiveDependencies( MavenSession context, ArtifactResolver artifactResolver,
MavenProjectBuilder mavenProjectBuilder )
MavenProjectBuilder mavenProjectBuilder, String scope )
throws ArtifactResolutionException
{
MavenProject project = context.getProject();
MavenMetadataSource sourceReader = new MavenMetadataSource( artifactResolver, mavenProjectBuilder );
ArtifactFilter filter = new ScopeArtifactFilter( scope );
ArtifactResolutionResult result = artifactResolver.resolveTransitively( project.getArtifacts(),
context.getRemoteRepositories(),
context.getLocalRepository(),
sourceReader );
sourceReader, filter );
project.addArtifacts( result.getArtifacts().values() );
}

View File

@ -32,12 +32,13 @@ import java.util.Set;
/**
* @todo add example usage tag that can be shown in the doco
* @todo need to add validation directives so that systems embedding maven2 can
* get validation directives to help users in IDEs.
* get validation directives to help users in IDEs.
*/
public class PluginDescriptorGenerator
implements Generator
{
public void execute( String destinationDirectory, Set mavenMojoDescriptors, MavenProject project ) throws Exception
public void execute( String destinationDirectory, Set mavenMojoDescriptors, MavenProject project )
throws Exception
{
File f = new File( destinationDirectory, "plugin.xml" );
@ -94,9 +95,9 @@ public class PluginDescriptorGenerator
//
// ----------------------------------------------------------------------
if ( mojoDescriptor.requiresDependencyResolution() )
if ( mojoDescriptor.getRequiresDependencyResolution() != null )
{
element( w, "requiresDependencyResolution", "true" );
element( w, "requiresDependencyResolution", mojoDescriptor.getRequiresDependencyResolution() );
}
// ----------------------------------------------------------------------

View File

@ -16,6 +16,7 @@ package org.apache.maven.tools.plugin.generator;
* limitations under the License.
*/
import junit.framework.TestCase;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Model;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
@ -28,8 +29,6 @@ import java.util.Collections;
import java.util.List;
import java.util.Set;
import junit.framework.TestCase;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
* @version $Id: AbstractGeneratorTestCase.java,v 1.1 2005/02/20 16:25:21
@ -42,12 +41,14 @@ public abstract class AbstractGeneratorTestCase
protected String basedir;
protected void setUp() throws Exception
protected void setUp()
throws Exception
{
basedir = System.getProperty( "basedir" );
}
public void testGenerator() throws Exception
public void testGenerator()
throws Exception
{
setupGenerator();
@ -61,7 +62,7 @@ public abstract class AbstractGeneratorTestCase
mojoDescriptor.setGoal( "testGoal" );
mojoDescriptor.setId( "test" );
mojoDescriptor.setImplementation( "org.apache.maven.tools.plugin.generator.TestMojo" );
mojoDescriptor.setRequiresDependencyResolution( true );
mojoDescriptor.setRequiresDependencyResolution( "compile" );
List params = new ArrayList();
@ -101,7 +102,8 @@ public abstract class AbstractGeneratorTestCase
//
// ----------------------------------------------------------------------
protected void setupGenerator() throws Exception
protected void setupGenerator()
throws Exception
{
String generatorClassName = getClass().getName();
@ -115,9 +117,9 @@ public abstract class AbstractGeneratorTestCase
}
catch ( Exception e )
{
throw new Exception( "Cannot find " + generatorClassName
+ "! Make sure your test case is named in the form ${generatorClassName}Test "
+ "or override the setupPlugin() method to instantiate the mojo yourself." );
throw new Exception( "Cannot find " + generatorClassName +
"! Make sure your test case is named in the form ${generatorClassName}Test " +
"or override the setupPlugin() method to instantiate the mojo yourself." );
}
}
@ -125,7 +127,8 @@ public abstract class AbstractGeneratorTestCase
//
// ----------------------------------------------------------------------
protected void validate() throws Exception
protected void validate()
throws Exception
{
// empty
}

View File

@ -39,7 +39,8 @@ import java.util.List;
public class PluginDescriptorGeneratorTest
extends AbstractGeneratorTestCase
{
protected void validate() throws Exception
protected void validate()
throws Exception
{
PluginDescriptorBuilder pdb = new PluginDescriptorBuilder();
@ -69,7 +70,8 @@ public class PluginDescriptorGeneratorTest
assertEquals( "0.0.0", dependency.getVersion() );
}
private String readFile( File pluginDescriptorFile ) throws IOException
private String readFile( File pluginDescriptorFile )
throws IOException
{
StringWriter sWriter = new StringWriter();
PrintWriter pWriter = new PrintWriter( sWriter );
@ -77,7 +79,7 @@ public class PluginDescriptorGeneratorTest
BufferedReader reader = new BufferedReader( new FileReader( pluginDescriptorFile ) );
String line = null;
while ( (line = reader.readLine()) != null )
while ( ( line = reader.readLine() ) != null )
{
pWriter.println( line );
}
@ -96,7 +98,7 @@ public class PluginDescriptorGeneratorTest
// The following should be defaults
assertEquals( "per-lookup", mojoDescriptor.getInstantiationStrategy() );
assertTrue( mojoDescriptor.requiresDependencyResolution() );
assertNotNull( mojoDescriptor.getRequiresDependencyResolution() );
// check the parameter.
checkParameter( (Parameter) mojoDescriptor.getParameters().get( 0 ) );

View File

@ -180,7 +180,12 @@ public class JavaMojoDescriptorExtractor
if ( requiresDependencyResolution != null )
{
mojoDescriptor.setRequiresDependencyResolution( true );
String value = requiresDependencyResolution.getValue();
if ( value == null || value.length() == 0 )
{
value = "runtime";
}
mojoDescriptor.setRequiresDependencyResolution( value );
}
// ----------------------------------------------------------------------

View File

@ -1,25 +1,20 @@
import org.apache.maven.project.MavenProject;
import org.apache.maven.plugin.AbstractPlugin;
import org.apache.maven.plugin.PluginExecutionRequest;
import org.apache.maven.plugin.PluginExecutionResponse;
/**
* @goal ideaTwo
*
* @description Create an IDEA project file from a Maven project.
*
* @requiresDependencyResolution
*
* @requiresDependencyResolution compile
* @prereq foo
* @prereq bar
*
* @parameter
* name="project"
* type="String[]"
* required="true"
* validator="org.foo.validator"
* expression="#project"
* description="Maven project used to generate IDEA project files."
* @parameter name="project"
* type="String[]"
* required="true"
* validator="org.foo.validator"
* expression="#project"
* description="Maven project used to generate IDEA project files."
*/
public class JavaExtractorTestTwo
extends AbstractPlugin

View File

@ -54,7 +54,7 @@ public class MojoDescriptor
private List prereqs;
private boolean requiresDependencyResolution = false;
private String requiresDependencyResolution = null;
private boolean requiresProject = true;
@ -150,12 +150,12 @@ public class MojoDescriptor
// Dependency requirement
// ----------------------------------------------------------------------
public void setRequiresDependencyResolution( boolean requiresDependencyResolution )
public void setRequiresDependencyResolution( String requiresDependencyResolution )
{
this.requiresDependencyResolution = requiresDependencyResolution;
}
public boolean requiresDependencyResolution()
public String getRequiresDependencyResolution()
{
return requiresDependencyResolution;
}

View File

@ -1,10 +1,10 @@
package org.apache.maven.plugin.descriptor;
import org.apache.maven.plugin.AbstractPlugin;
import org.codehaus.plexus.configuration.PlexusConfiguration;
import org.codehaus.plexus.configuration.PlexusConfigurationException;
import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
import org.apache.maven.plugin.AbstractPlugin;
import java.io.Reader;
import java.util.ArrayList;
@ -105,7 +105,7 @@ public class PluginDescriptorBuilder
if ( dependencyResolution != null )
{
mojo.setRequiresDependencyResolution( dependencyResolution.equals( "true" ) ? true : false );
mojo.setRequiresDependencyResolution( dependencyResolution );
}
// ----------------------------------------------------------------------

View File

@ -34,25 +34,25 @@ import java.util.Set;
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
* @version $Id$
* @goal compile
* @requiresDependencyResolution
* @requiresDependencyResolution compile
* @description Compiles application sources
* @parameter name="compileSourceRoots" type="java.util.List" required="true" validator=""
* expression="#project.compileSourceRoots" description=""
* expression="#project.compileSourceRoots" description=""
* @parameter name="outputDirectory" type="String" required="true" validator=""
* expression="#project.build.outputDirectory" description=""
* expression="#project.build.outputDirectory" description=""
* @parameter name="classpathElements" type="List" required="true" validator=""
* expression="#project.compileClasspathElements" description=""
* expression="#project.compileClasspathElements" description=""
* @parameter name="debug" type="boolean" required="false" validator=""
* expression="#maven.compiler.debug" description="Whether to include debugging
* information in the compiled class files; the default value is false"
* expression="#maven.compiler.debug" description="Whether to include debugging
* information in the compiled class files; the default value is false"
* @todo change debug parameter type to Boolean
* @parameter name="source" type="String" required="false" expression="#source" validator=""
* description="The -source argument for the Java compiler"
* description="The -source argument for the Java compiler"
* @parameter name="target" type="String" required="false" expression="#target" validator=""
* description="The -target argument for the Java compiler"
* description="The -target argument for the Java compiler"
* @parameter name="staleMillis" type="long" required="false" expression="#lastModGranularityMs"
* validator="" description="The granularity in milliseconds of the last modification
* date for testing whether a source needs recompilation"
* validator="" description="The granularity in milliseconds of the last modification
* date for testing whether a source needs recompilation"
* @todo change staleMillis parameter type to Long
*/
@ -167,8 +167,8 @@ public class CompilerMojo
}
catch ( NumberFormatException e )
{
throw new PluginExecutionException( "Invalid staleMillis plugin parameter value: \'" + staleMillis
+ "\'", e );
throw new PluginExecutionException( "Invalid staleMillis plugin parameter value: \'" + staleMillis +
"\'", e );
}
}
@ -194,8 +194,8 @@ public class CompilerMojo
}
catch ( InclusionScanException e )
{
throw new PluginExecutionException( "Error scanning source root: \'" + sourceRoot
+ "\' for stale files to recompile.", e );
throw new PluginExecutionException( "Error scanning source root: \'" + sourceRoot +
"\' for stale files to recompile.", e );
}
}
@ -204,7 +204,7 @@ public class CompilerMojo
/**
* @todo also in ant plugin. This should be resolved at some point so that it does not need to
* be calculated continuously - or should the plugins accept empty source roots as is?
* be calculated continuously - or should the plugins accept empty source roots as is?
*/
private static List removeEmptyCompileSourceRoots( List compileSourceRootsList )
{

View File

@ -21,7 +21,7 @@ package org.apache.maven.plugin;
* @version $Id$
* @goal testCompile
* @description Compiles test sources
* @requiresDependencyResolution
* @requiresDependencyResolution test
* @parameter name="compileSourceRoots"
* type="java.util.List"
* required="true"

View File

@ -38,7 +38,7 @@ import java.util.Iterator;
/**
* @goal idea
* @requiresDependencyResolution
* @requiresDependencyResolution test
* @description Goal for generating IDEA files from a POM
* @parameter name="project"
* type="MavenProject"

View File

@ -27,7 +27,7 @@ import java.util.List;
/**
* Aggregator tag for the actual meat of the mojo.
*
*
* @author jdcasey Created on Feb 8, 2005
*/
public class MetadataTag
@ -39,7 +39,7 @@ public class MetadataTag
private String goal;
private boolean requiresDependencyResolution = true;
private String requiresDependencyResolution = null;
private boolean requiresProject = true;
@ -58,7 +58,8 @@ public class MetadataTag
return false;
}
protected void doExecute( MarmaladeExecutionContext context ) throws MarmaladeExecutionException
protected void doExecute( MarmaladeExecutionContext context )
throws MarmaladeExecutionException
{
processChildren( context );
@ -66,7 +67,8 @@ public class MetadataTag
context.setVariable( MarmaladeMojoExecutionDirectives.METADATA_OUTVAR, descriptor, true );
}
private MojoDescriptor buildDescriptor( MarmaladeExecutionContext context ) throws MarmaladeExecutionException
private MojoDescriptor buildDescriptor( MarmaladeExecutionContext context )
throws MarmaladeExecutionException
{
MojoDescriptor descriptor = new MojoDescriptor();
@ -146,7 +148,7 @@ public class MetadataTag
this.description = description;
}
public void setRequiresDependencyResolution( boolean requiresDependencyResolution )
public void setRequiresDependencyResolution( String requiresDependencyResolution )
{
this.requiresDependencyResolution = requiresDependencyResolution;
}

View File

@ -22,13 +22,14 @@ import org.codehaus.marmalade.runtime.MarmaladeExecutionException;
* @author jdcasey Created on Feb 8, 2005
*/
public class RequiresDependencyResolutionTag
extends AbstractBooleanValuedBodyTag
extends AbstractStringValuedBodyTag
{
protected void setValue( Boolean value ) throws MarmaladeExecutionException
protected void setValue( String value )
throws MarmaladeExecutionException
{
MetadataTag metadataTag = (MetadataTag) requireParent( MetadataTag.class );
metadataTag.setRequiresDependencyResolution( value.booleanValue() );
metadataTag.setRequiresDependencyResolution( value );
}
}