add new methods to type handler:

- isAddedToClassPath (default false)
- language (default "none")

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@320986 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-10-14 03:32:41 +00:00
parent c74d08fa48
commit ed22c950e8
5 changed files with 79 additions and 34 deletions

View File

@ -33,4 +33,8 @@ public interface ArtifactHandler
String getPackaging();
boolean isIncludesDependencies();
String getLanguage();
boolean isAddedToClasspath();
}

View File

@ -35,6 +35,10 @@ public class DefaultArtifactHandler
private boolean includesDependencies;
private String language;
private boolean addedToClasspath;
public DefaultArtifactHandler()
{
}
@ -85,4 +89,19 @@ public boolean isIncludesDependencies()
{
return includesDependencies;
}
public String getLanguage()
{
if ( language == null )
{
language = "none";
}
return language;
}
public boolean isAddedToClasspath()
{
return addedToClasspath;
}
}

View File

@ -35,6 +35,8 @@
<configuration>
<type>ejb</type>
<extension>jar</extension>
<language>java</language>
<addedToClasspath>true</addedToClasspath>
</configuration>
</component>
@ -44,6 +46,8 @@
<implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
<configuration>
<type>jar</type>
<language>java</language>
<addedToClasspath>true</addedToClasspath>
</configuration>
</component>
@ -56,6 +60,8 @@
<extension>jar</extension>
<type>test-jar</type>
<packaging>jar</packaging>
<language>java</language>
<addedToClasspath>true</addedToClasspath>
</configuration>
</component>
@ -66,6 +72,8 @@
<configuration>
<type>maven-plugin</type>
<extension>jar</extension>
<language>java</language>
<addedToClasspath>true</addedToClasspath>
</configuration>
</component>
@ -85,6 +93,20 @@
<configuration>
<type>java-source</type>
<extension>jar</extension>
<language>java</language>
<addedToClasspath>false</addedToClasspath>
</configuration>
</component>
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>javadoc</role-hint>
<implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
<configuration>
<type>javadoc</type>
<extension>jar</extension>
<language>java</language>
<addedToClasspath>true</addedToClasspath>
</configuration>
</component>
@ -95,6 +117,8 @@
<configuration>
<type>war</type>
<includesDependencies>true</includesDependencies>
<language>java</language>
<addedToClasspath>false</addedToClasspath>
</configuration>
</component>
@ -105,6 +129,8 @@
<configuration>
<type>ear</type>
<includesDependencies>true</includesDependencies>
<language>java</language>
<addedToClasspath>false</addedToClasspath>
</configuration>
</component>
@ -117,6 +143,8 @@
<extension>jar</extension>
<packaging>ejb</packaging>
<classifier>client</classifier>
<language>java</language>
<addedToClasspath>true</addedToClasspath>
</configuration>
</component>

View File

@ -42,13 +42,13 @@ public class JarSourceMojo
* @deprecated ICK! This needs to be generalized OUTSIDE of this mojo!
*/
private static final List BANNED_PACKAGINGS;
static
{
List banned = new ArrayList();
banned.add( "pom" );
BANNED_PACKAGINGS = banned;
}
@ -63,7 +63,7 @@ public class JarSourceMojo
* @parameter expression="${component.org.apache.maven.project.MavenProjectHelper}
*/
private MavenProjectHelper projectHelper;
/**
* @parameter expression="${project.packaging}"
* @readonly
@ -76,7 +76,7 @@ public class JarSourceMojo
* @required
*/
private String finalName;
/**
* @parameter expression="${attach}" default-value="true"
*/
@ -93,23 +93,17 @@ public class JarSourceMojo
* @required
*/
private File outputDirectory;
public void execute()
throws MojoExecutionException
{
if ( !attach )
{
getLog().info( "NOT adding java-sources to attached artifacts list." );
return;
}
else if ( BANNED_PACKAGINGS.contains( packaging ) )
if ( BANNED_PACKAGINGS.contains( packaging ) )
{
getLog().info( "NOT adding java-sources to attached artifacts for packaging: \'" + packaging + "\'." );
return;
}
// TODO: use a component lookup?
JarArchiver archiver = new JarArchiver();
@ -133,8 +127,16 @@ else if ( BANNED_PACKAGINGS.contains( packaging ) )
throw new MojoExecutionException( "Error building source JAR", e );
}
// TODO: these introduced dependencies on the project are going to become problematic - can we export it
// through metadata instead?
projectHelper.attachArtifact( project, "java-source", "sources", outputFile );
if ( !attach )
{
getLog().info( "NOT adding java-sources to attached artifacts list." );
}
else
{
// TODO: these introduced dependencies on the project are going to become problematic - can we export it
// through metadata instead?
projectHelper.attachArtifact( project, "java-source", "sources", outputFile );
}
}
}

View File

@ -348,7 +348,7 @@ public List getCompileClasspathElements()
{
Artifact a = (Artifact) i.next();
if ( isAddedToClasspath( a ) )
if ( a.getArtifactHandler().isAddedToClasspath() )
{
// TODO: let the scope handler deal with this
if ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_PROVIDED.equals( a.getScope() ) ||
@ -384,7 +384,7 @@ public List getCompileArtifacts()
Artifact a = (Artifact) i.next();
// TODO: classpath check doesn't belong here - that's the other method
if ( isAddedToClasspath( a ) )
if ( a.getArtifactHandler().isAddedToClasspath() )
{
// TODO: let the scope handler deal with this
if ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_PROVIDED.equals( a.getScope() ) ||
@ -442,7 +442,7 @@ public List getTestClasspathElements()
{
Artifact a = (Artifact) i.next();
if ( isAddedToClasspath( a ) )
if ( a.getArtifactHandler().isAddedToClasspath() )
{
// TODO: let the scope handler deal with this
// NOTE: [jc] scope == 'test' is the widest possible scope, so we don't really need to perform
@ -471,7 +471,7 @@ public List getTestArtifacts()
Artifact a = (Artifact) i.next();
// TODO: classpath check doesn't belong here - that's the other method
if ( isAddedToClasspath( a ) )
if ( a.getArtifactHandler().isAddedToClasspath() )
{
// TODO: let the scope handler deal with this
// NOTE: [jc] scope == 'test' is the widest possible scope, so we don't really need to perform
@ -536,7 +536,7 @@ public List getRuntimeClasspathElements()
{
Artifact a = (Artifact) i.next();
if ( isAddedToClasspath( a ) )
if ( a.getArtifactHandler().isAddedToClasspath() )
{
// TODO: let the scope handler deal with this
if ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_RUNTIME.equals( a.getScope() ) )
@ -562,7 +562,7 @@ public List getRuntimeArtifacts()
Artifact a = (Artifact) i.next();
// TODO: classpath check doesn't belong here - that's the other method
if ( isAddedToClasspath( a ) )
if ( a.getArtifactHandler().isAddedToClasspath() )
{
// TODO: let the scope handler deal with this
if ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_RUNTIME.equals( a.getScope() ) )
@ -618,7 +618,7 @@ public List getSystemClasspathElements()
{
Artifact a = (Artifact) i.next();
if ( isAddedToClasspath( a ) )
if ( a.getArtifactHandler().isAddedToClasspath() )
{
// TODO: let the scope handler deal with this
if ( Artifact.SCOPE_SYSTEM.equals( a.getScope() ) )
@ -653,7 +653,7 @@ public List getSystemArtifacts()
Artifact a = (Artifact) i.next();
// TODO: classpath check doesn't belong here - that's the other method
if ( isAddedToClasspath( a ) )
if ( a.getArtifactHandler().isAddedToClasspath() )
{
// TODO: let the scope handler deal with this
if ( Artifact.SCOPE_SYSTEM.equals( a.getScope() ) )
@ -698,14 +698,6 @@ public List getSystemDependencies()
return list;
}
private static boolean isAddedToClasspath( Artifact artifact )
{
String type = artifact.getType();
// TODO: utilise type handler
return "jar".equals( type ) || "ejb".equals( type ) || "ejb-client".equals( type ) || "test-jar".equals( type );
}
// ----------------------------------------------------------------------
// Delegate to the model
// ----------------------------------------------------------------------