From c9063cbb832877cf981960f6e30e155df2db4b05 Mon Sep 17 00:00:00 2001 From: Herve Boutemy Date: Sat, 12 May 2012 16:14:40 +0000 Subject: [PATCH] added DependencyScope enumeration git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/trunk@1337586 13f79535-47bb-0310-9956-ffa450edef68 --- maven-plugin-annotations/pom.xml | 7 +++ .../plugins/annotations/DependencyScope.java | 46 +++++++++++++++++++ .../maven/plugins/annotations/Mojo.java | 4 +- ...avaAnnotationsMojoDescriptorExtractor.java | 4 +- .../datamodel/MojoAnnotationContent.java | 15 +++--- .../src/site/apt/index.apt | 6 ++- 6 files changed, 69 insertions(+), 13 deletions(-) create mode 100644 maven-plugin-annotations/src/main/java/org/apache/maven/plugins/annotations/DependencyScope.java diff --git a/maven-plugin-annotations/pom.xml b/maven-plugin-annotations/pom.xml index d071f56..7a0bd1d 100644 --- a/maven-plugin-annotations/pom.xml +++ b/maven-plugin-annotations/pom.xml @@ -31,4 +31,11 @@ Maven Plugin Java 5 Annotations Java 5 annotations to use in Mojos. + + + org.apache.maven + maven-artifact + 3.0 + + diff --git a/maven-plugin-annotations/src/main/java/org/apache/maven/plugins/annotations/DependencyScope.java b/maven-plugin-annotations/src/main/java/org/apache/maven/plugins/annotations/DependencyScope.java new file mode 100644 index 0000000..b15f283 --- /dev/null +++ b/maven-plugin-annotations/src/main/java/org/apache/maven/plugins/annotations/DependencyScope.java @@ -0,0 +1,46 @@ +package org.apache.maven.plugins.annotations; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +import org.apache.maven.artifact.Artifact; + +/** + * @author Hervé Boutemy + * @since 3.0 + */ +public enum DependencyScope +{ + COMPILE( Artifact.SCOPE_COMPILE ), + COMPILE_PLUS_RUNTIME( Artifact.SCOPE_COMPILE_PLUS_RUNTIME ), + RUNTIME( Artifact.SCOPE_RUNTIME ), + TEST( Artifact.SCOPE_TEST ); + + private final String id; + + DependencyScope( String id ) + { + this.id = id; + } + + public String id() + { + return this.id; + } +} diff --git a/maven-plugin-annotations/src/main/java/org/apache/maven/plugins/annotations/Mojo.java b/maven-plugin-annotations/src/main/java/org/apache/maven/plugins/annotations/Mojo.java index 4ac2bed..b4d491d 100644 --- a/maven-plugin-annotations/src/main/java/org/apache/maven/plugins/annotations/Mojo.java +++ b/maven-plugin-annotations/src/main/java/org/apache/maven/plugins/annotations/Mojo.java @@ -40,9 +40,9 @@ public @interface Mojo LifecyclePhase defaultPhase() default LifecyclePhase.NONE; - String requiresDependencyResolution() default "runtime"; + DependencyScope requiresDependencyResolution() default DependencyScope.RUNTIME; - String requiresDependencyCollection() default ""; + DependencyScope requiresDependencyCollection() default DependencyScope.RUNTIME; String instantiationStrategy() default "per-lookup"; diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/JavaAnnotationsMojoDescriptorExtractor.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/JavaAnnotationsMojoDescriptorExtractor.java index ff40206..d75bda0 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/JavaAnnotationsMojoDescriptorExtractor.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/JavaAnnotationsMojoDescriptorExtractor.java @@ -454,8 +454,8 @@ public class JavaAnnotationsMojoDescriptorExtractor mojo.setDeprecated( mojo.getDeprecated() ); mojoDescriptor.setAggregator( mojo.aggregator() ); - mojoDescriptor.setDependencyResolutionRequired( mojo.requiresDependencyResolution() ); - mojoDescriptor.setDependencyCollectionRequired( mojo.requiresDependencyCollection() ); + mojoDescriptor.setDependencyResolutionRequired( mojo.requiresDependencyResolution().toString() ); + mojoDescriptor.setDependencyCollectionRequired( mojo.requiresDependencyCollection().toString() ); mojoDescriptor.setDirectInvocationOnly( mojo.requiresDirectInvocation() ); mojoDescriptor.setDeprecated( mojo.getDeprecated() ); diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/MojoAnnotationContent.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/MojoAnnotationContent.java index 8a1fe1e..1f49c3d 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/MojoAnnotationContent.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/MojoAnnotationContent.java @@ -19,6 +19,7 @@ package org.apache.maven.tools.plugin.annotations.datamodel; * under the License. */ +import org.apache.maven.plugins.annotations.DependencyScope; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; @@ -36,9 +37,9 @@ public class MojoAnnotationContent private LifecyclePhase defaultPhase = LifecyclePhase.NONE; - private String requiresDependencyResolution = "runtime"; + private DependencyScope requiresDependencyResolution = DependencyScope.RUNTIME; - private String requiresDependencyCollection; + private DependencyScope requiresDependencyCollection = DependencyScope.RUNTIME; private String instantiationStrategy = "per-lookup"; @@ -75,22 +76,22 @@ public class MojoAnnotationContent this.defaultPhase = LifecyclePhase.valueOf( phase ); } - public String requiresDependencyResolution() + public DependencyScope requiresDependencyResolution() { return requiresDependencyResolution; } - public void requiresDependencyResolution( String requiresDependencyResolution ) + public void requiresDependencyResolution( DependencyScope requiresDependencyResolution ) { this.requiresDependencyResolution = requiresDependencyResolution; } - public String requiresDependencyCollection() + public DependencyScope requiresDependencyCollection() { - return requiresDependencyCollection == null ? "" : requiresDependencyCollection; + return requiresDependencyCollection; } - public void requiresDependencyCollection( String requiresDependencyCollection ) + public void requiresDependencyCollection( DependencyScope requiresDependencyCollection ) { this.requiresDependencyCollection = requiresDependencyCollection; } diff --git a/maven-plugin-tools-annotations/src/site/apt/index.apt b/maven-plugin-tools-annotations/src/site/apt/index.apt index ef7a20c..1d3c441 100644 --- a/maven-plugin-tools-annotations/src/site/apt/index.apt +++ b/maven-plugin-tools-annotations/src/site/apt/index.apt @@ -36,6 +36,8 @@ Maven Plugin Tool for Annotations +---------+ import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugins.annotations.DependencyScope; +import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Execute; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; @@ -53,8 +55,8 @@ import org.apache.maven.plugins.annotations.Parameter; inheritByDefault = , instantiationStrategy = "", defaultPhase = "", - requiresDependencyResolution = "", - requiresDependencyCollection = "", // (since Maven 3.0) + requiresDependencyResolution = DependencyScope., + requiresDependencyCollection = DependencyScope., // (since Maven 3.0) requiresDirectInvocation = , requiresOnline = , requiresProject = ,