From ed22c950e80dc0f53336a2b24b1748bbc10a80ef Mon Sep 17 00:00:00 2001 From: Brett Leslie Porter Date: Fri, 14 Oct 2005 03:32:41 +0000 Subject: [PATCH] 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 --- .../artifact/handler/ArtifactHandler.java | 4 ++ .../handler/DefaultArtifactHandler.java | 19 ++++++++++ .../resources/META-INF/plexus/components.xml | 28 ++++++++++++++ .../maven/plugin/source/JarSourceMojo.java | 38 ++++++++++--------- .../apache/maven/project/MavenProject.java | 24 ++++-------- 5 files changed, 79 insertions(+), 34 deletions(-) diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/handler/ArtifactHandler.java b/maven-artifact/src/main/java/org/apache/maven/artifact/handler/ArtifactHandler.java index ee0423036d..4c4521b5b5 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/handler/ArtifactHandler.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/handler/ArtifactHandler.java @@ -33,4 +33,8 @@ public interface ArtifactHandler String getPackaging(); boolean isIncludesDependencies(); + + String getLanguage(); + + boolean isAddedToClasspath(); } diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/handler/DefaultArtifactHandler.java b/maven-artifact/src/main/java/org/apache/maven/artifact/handler/DefaultArtifactHandler.java index f14058c8b5..311a5e969c 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/handler/DefaultArtifactHandler.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/handler/DefaultArtifactHandler.java @@ -35,6 +35,10 @@ public class DefaultArtifactHandler private boolean includesDependencies; + private String language; + + private boolean addedToClasspath; + public DefaultArtifactHandler() { } @@ -85,4 +89,19 @@ public class DefaultArtifactHandler { return includesDependencies; } + + public String getLanguage() + { + if ( language == null ) + { + language = "none"; + } + + return language; + } + + public boolean isAddedToClasspath() + { + return addedToClasspath; + } } diff --git a/maven-artifact/src/main/resources/META-INF/plexus/components.xml b/maven-artifact/src/main/resources/META-INF/plexus/components.xml index 977c4000a5..0a117a4c94 100644 --- a/maven-artifact/src/main/resources/META-INF/plexus/components.xml +++ b/maven-artifact/src/main/resources/META-INF/plexus/components.xml @@ -35,6 +35,8 @@ ejb jar + java + true @@ -44,6 +46,8 @@ org.apache.maven.artifact.handler.DefaultArtifactHandler jar + java + true @@ -56,6 +60,8 @@ jar test-jar jar + java + true @@ -66,6 +72,8 @@ maven-plugin jar + java + true @@ -85,6 +93,20 @@ java-source jar + java + false + + + + + org.apache.maven.artifact.handler.ArtifactHandler + javadoc + org.apache.maven.artifact.handler.DefaultArtifactHandler + + javadoc + jar + java + true @@ -95,6 +117,8 @@ war true + java + false @@ -105,6 +129,8 @@ ear true + java + false @@ -117,6 +143,8 @@ jar ejb client + java + true diff --git a/maven-plugins/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/JarSourceMojo.java b/maven-plugins/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/JarSourceMojo.java index e89d9ef48c..1308fc1ad5 100644 --- a/maven-plugins/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/JarSourceMojo.java +++ b/maven-plugins/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/JarSourceMojo.java @@ -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 @@ public class JarSourceMojo 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 ); + } } } diff --git a/maven-project/src/main/java/org/apache/maven/project/MavenProject.java b/maven-project/src/main/java/org/apache/maven/project/MavenProject.java index f5cb281a77..4e13a6a39e 100644 --- a/maven-project/src/main/java/org/apache/maven/project/MavenProject.java +++ b/maven-project/src/main/java/org/apache/maven/project/MavenProject.java @@ -348,7 +348,7 @@ public class MavenProject { 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 class MavenProject 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 class MavenProject { 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 class MavenProject 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 class MavenProject { 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 class MavenProject 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 class MavenProject { 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 class MavenProject 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 class MavenProject 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 // ----------------------------------------------------------------------