From a396a42d68dc58b764912a83c23e66c639e057d0 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Sat, 28 Apr 2012 08:35:48 +0000 Subject: [PATCH 01/48] bump version to 3.0-SNAPSHOT git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1331709 13f79535-47bb-0310-9956-ffa450edef68 --- maven-plugin-plugin/pom.xml | 4 ++-- maven-plugin-tools-ant/pom.xml | 2 +- maven-plugin-tools-api/pom.xml | 2 +- maven-plugin-tools-beanshell/pom.xml | 2 +- maven-plugin-tools-java/pom.xml | 2 +- maven-plugin-tools-javadoc/pom.xml | 2 +- maven-plugin-tools-model/pom.xml | 2 +- pom.xml | 4 ++-- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/maven-plugin-plugin/pom.xml b/maven-plugin-plugin/pom.xml index 9fb212a..d662d56 100644 --- a/maven-plugin-plugin/pom.xml +++ b/maven-plugin-plugin/pom.xml @@ -28,7 +28,7 @@ maven-plugin-plugin - 2.10-SNAPSHOT + 3.0-SNAPSHOT maven-plugin Maven Plugin Plugin @@ -60,7 +60,7 @@ 2.0.6 - 2.10-SNAPSHOT + 3.0-SNAPSHOT 1.2 1.2 diff --git a/maven-plugin-tools-ant/pom.xml b/maven-plugin-tools-ant/pom.xml index ac1ef38..fb44f78 100644 --- a/maven-plugin-tools-ant/pom.xml +++ b/maven-plugin-tools-ant/pom.xml @@ -25,7 +25,7 @@ org.apache.maven.plugin-tools maven-plugin-tools - 2.10-SNAPSHOT + 3.0-SNAPSHOT maven-plugin-tools-ant diff --git a/maven-plugin-tools-api/pom.xml b/maven-plugin-tools-api/pom.xml index 62e9700..bf66edb 100644 --- a/maven-plugin-tools-api/pom.xml +++ b/maven-plugin-tools-api/pom.xml @@ -25,7 +25,7 @@ org.apache.maven.plugin-tools maven-plugin-tools - 2.10-SNAPSHOT + 3.0-SNAPSHOT maven-plugin-tools-api diff --git a/maven-plugin-tools-beanshell/pom.xml b/maven-plugin-tools-beanshell/pom.xml index 27e3e0e..ebb2863 100644 --- a/maven-plugin-tools-beanshell/pom.xml +++ b/maven-plugin-tools-beanshell/pom.xml @@ -25,7 +25,7 @@ org.apache.maven.plugin-tools maven-plugin-tools - 2.10-SNAPSHOT + 3.0-SNAPSHOT maven-plugin-tools-beanshell diff --git a/maven-plugin-tools-java/pom.xml b/maven-plugin-tools-java/pom.xml index 1afba00..91196ab 100644 --- a/maven-plugin-tools-java/pom.xml +++ b/maven-plugin-tools-java/pom.xml @@ -25,7 +25,7 @@ org.apache.maven.plugin-tools maven-plugin-tools - 2.10-SNAPSHOT + 3.0-SNAPSHOT maven-plugin-tools-java diff --git a/maven-plugin-tools-javadoc/pom.xml b/maven-plugin-tools-javadoc/pom.xml index 5609dca..80413ba 100644 --- a/maven-plugin-tools-javadoc/pom.xml +++ b/maven-plugin-tools-javadoc/pom.xml @@ -25,7 +25,7 @@ org.apache.maven.plugin-tools maven-plugin-tools - 2.10-SNAPSHOT + 3.0-SNAPSHOT maven-plugin-tools-javadoc diff --git a/maven-plugin-tools-model/pom.xml b/maven-plugin-tools-model/pom.xml index e42e38e..641ccdf 100644 --- a/maven-plugin-tools-model/pom.xml +++ b/maven-plugin-tools-model/pom.xml @@ -25,7 +25,7 @@ org.apache.maven.plugin-tools maven-plugin-tools - 2.10-SNAPSHOT + 3.0-SNAPSHOT maven-plugin-tools-model diff --git a/pom.xml b/pom.xml index 79b6cd0..9c28544 100644 --- a/pom.xml +++ b/pom.xml @@ -31,7 +31,7 @@ org.apache.maven.plugin-tools maven-plugin-tools - 2.10-SNAPSHOT + 3.0-SNAPSHOT pom Maven Plugin Tools @@ -155,7 +155,7 @@ - 2.10-SNAPSHOT + ${project.version} 1.2 From 6a4e7387fc615068ec0c35085bd869d3acab9f66 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Sat, 28 Apr 2012 08:41:46 +0000 Subject: [PATCH 02/48] simplify properties with using ${project.version} git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1331711 13f79535-47bb-0310-9956-ffa450edef68 --- maven-plugin-plugin/pom.xml | 9 ++++----- pom.xml | 9 ++++----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/maven-plugin-plugin/pom.xml b/maven-plugin-plugin/pom.xml index d662d56..9c47c73 100644 --- a/maven-plugin-plugin/pom.xml +++ b/maven-plugin-plugin/pom.xml @@ -60,7 +60,6 @@ 2.0.6 - 3.0-SNAPSHOT 1.2 1.2 @@ -72,22 +71,22 @@ org.apache.maven.plugin-tools maven-plugin-tools-api - ${pluginToolsVersion} + ${project.version} org.apache.maven.plugin-tools maven-plugin-tools-model - ${pluginToolsVersion} + ${project.version} org.apache.maven.plugin-tools maven-plugin-tools-java - ${pluginToolsVersion} + ${project.version} org.apache.maven.plugin-tools maven-plugin-tools-beanshell - ${pluginToolsVersion} + ${project.version} org.apache.maven diff --git a/pom.xml b/pom.xml index 9c28544..743b330 100644 --- a/pom.xml +++ b/pom.xml @@ -155,7 +155,6 @@ - ${project.version} 1.2 @@ -165,22 +164,22 @@ org.apache.maven.plugin-tools maven-plugin-tools-api - ${pluginToolsVersion} + ${project.version} org.apache.maven.plugin-tools maven-plugin-tools-model - ${pluginToolsVersion} + ${project.version} org.apache.maven.plugin-tools maven-plugin-tools-java - ${pluginToolsVersion} + ${project.version} org.apache.maven.plugin-tools maven-plugin-tools-beanshell - ${pluginToolsVersion} + ${project.version} org.apache.maven From 587879842ddb3e0ba689ebe35f14062cb091da3e Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Sat, 28 Apr 2012 09:35:36 +0000 Subject: [PATCH 03/48] gitignore .idea git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1331730 13f79535-47bb-0310-9956-ffa450edef68 --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 59aa359..46a4b43 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ target #idea *.iml +.idea #eclipse .classpath From f4945e157a992f33d1570ad7bd33b9b6446b4a26 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Sat, 28 Apr 2012 21:23:10 +0000 Subject: [PATCH 04/48] [MPLUGIN-189] add java 5 annotations support to mark Mojo sources git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1331837 13f79535-47bb-0310-9956-ffa450edef68 --- maven-plugin-tools-annotations/pom.xml | 14 ++++ .../tools/plugin/annotations/Component.java | 40 ++++++++++ .../tools/plugin/annotations/Execute.java | 31 ++++++++ .../maven/tools/plugin/annotations/Goal.java | 63 ++++++++++++++++ .../plugin/annotations/LifecyclePhase.java | 74 +++++++++++++++++++ .../tools/plugin/annotations/Parameter.java | 35 +++++++++ .../tools/plugin/annotations/ThreadSafe.java | 18 +++++ pom.xml | 12 ++- 8 files changed, 283 insertions(+), 4 deletions(-) create mode 100644 maven-plugin-tools-annotations/pom.xml create mode 100644 maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/Component.java create mode 100644 maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/Execute.java create mode 100644 maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/Goal.java create mode 100644 maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/LifecyclePhase.java create mode 100644 maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/Parameter.java create mode 100644 maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/ThreadSafe.java diff --git a/maven-plugin-tools-annotations/pom.xml b/maven-plugin-tools-annotations/pom.xml new file mode 100644 index 0000000..e9575bc --- /dev/null +++ b/maven-plugin-tools-annotations/pom.xml @@ -0,0 +1,14 @@ + + + 4.0.0 + + org.apache.maven.plugin-tools + maven-plugin-tools + 3.0-SNAPSHOT + + + maven-plugin-tools-annotations + + Maven Plugin Tools Annotations + + diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/Component.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/Component.java new file mode 100644 index 0000000..bc6240b --- /dev/null +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/Component.java @@ -0,0 +1,40 @@ +package org.apache.maven.tools.plugin.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 java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * @author Olivier Lamy + */ +@Documented +@Retention( RetentionPolicy.RUNTIME ) +@Target( { ElementType.FIELD, ElementType.METHOD } ) +@Inherited +public @interface Component +{ + String role() default ""; + + String roleHint() default ""; +} diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/Execute.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/Execute.java new file mode 100644 index 0000000..6fd8e0f --- /dev/null +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/Execute.java @@ -0,0 +1,31 @@ +package org.apache.maven.tools.plugin.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. + */ + +/** + * @author Olivier Lamy + */ +public @interface Execute +{ + LifecyclePhase phase() default LifecyclePhase.NONE; + + String goal() default ""; + + String lifecycle() default ""; +} diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/Goal.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/Goal.java new file mode 100644 index 0000000..784fd63 --- /dev/null +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/Goal.java @@ -0,0 +1,63 @@ +package org.apache.maven.tools.plugin.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 java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * @author Olivier Lamy + */ +@Documented +@Retention( RetentionPolicy.RUNTIME ) +@Target( ElementType.TYPE ) +@Inherited +public @interface Goal +{ + String name(); + + LifecyclePhase defaultPhase() default LifecyclePhase.NONE; + + String requiresDependencyResolution() default "runtime"; + + String requiresDependencyCollection() default "runtime"; + + String instantiationStrategy() default "per-lookup"; + + String executionStrategy() default "once-per-session"; + + boolean requiresProject() default true; + + boolean requiresReports() default false; + + boolean aggregator() default false; + + boolean requiresDirectInvocation() default false; + + boolean requiresOnline() default false; + + boolean inheritByDefault() default true; + + String configurator() default ""; +} diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/LifecyclePhase.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/LifecyclePhase.java new file mode 100644 index 0000000..ab01368 --- /dev/null +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/LifecyclePhase.java @@ -0,0 +1,74 @@ +package org.apache.maven.tools.plugin.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. + */ + +/** + * @author Olivier Lamy + */ +public enum LifecyclePhase +{ + + VALIDATE( "validate" ), + INITIALIZE( "initialize" ), + GENERATE_SOURCES( "generate-sources" ), + PROCESS_SOURCES( "process-sources" ), + GENERATE_RESOURCES( "generate-resources" ), + PROCESS_RESOURCES( "process-resources" ), + COMPILE( "compile" ), + PROCESS_CLASSES( "process-classes" ), + GENERATE_TEST_SOURCES( "generate-test-sources" ), + PROCESS_TEST_SOURCES( "process-test-sources" ), + GENERATE_TEST_RESOURCES( "generate-test-resources" ), + PROCESS_TEST_RESOURCES( "process-test-resources" ), + TEST_COMPILE( "test-compile" ), + PROCESS_TEST_CLASSES( "process-test-classes" ), + TEST( "test" ), + PREPARE_PACKAGE( "prepare-package" ), + PACKAGE( "package" ), + PRE_INTEGRATION_TEST( "pre-integration-test" ), + INTEGRATION_TEST( "integration-test" ), + POST_INTEGRATION_TEST( "post-integration-test" ), + VERIFY( "verify" ), + INSTALL( "install" ), + DEPLOY( "deploy" ), + + PRE_CLEAN( "pre-clean" ), + CLEAN( "clean" ), + POST_CLEAN( "post-clean" ), + + PRE_SITE( "pre-site" ), + SITE( "site" ), + POST_SITE( "post-site" ), + SITE_DEPLOY( "site-deploy" ), + + NONE( "" ); + + private final String id; + + LifecyclePhase( String id ) + { + this.id = id; + } + + public String id() + { + return this.id; + } + +} diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/Parameter.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/Parameter.java new file mode 100644 index 0000000..7a0dac9 --- /dev/null +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/Parameter.java @@ -0,0 +1,35 @@ +package org.apache.maven.tools.plugin.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. + */ + +/** + * @author Olivier Lamy + */ +public @interface Parameter +{ + String alias() default ""; + + String expression() default ""; + + String defaultValue() default ""; + + boolean required() default false; + + boolean readonly() default false; +} diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/ThreadSafe.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/ThreadSafe.java new file mode 100644 index 0000000..c0f9f41 --- /dev/null +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/ThreadSafe.java @@ -0,0 +1,18 @@ +package org.apache.maven.tools.plugin.annotations; + +import java.lang.annotation.Documented; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +@Documented +@Inherited +@Retention( RUNTIME ) +@Target( { TYPE } ) +public @interface ThreadSafe +{ + boolean value() default true; +} diff --git a/pom.xml b/pom.xml index 743b330..e76fd51 100644 --- a/pom.xml +++ b/pom.xml @@ -1,5 +1,4 @@ - - + - 4.0.0 @@ -132,6 +130,7 @@ maven-plugin-plugin maven-plugin-tools-model maven-plugin-tools-javadoc + maven-plugin-tools-annotations @@ -176,6 +175,11 @@ maven-plugin-tools-java ${project.version} + + org.apache.maven.plugin-tools + maven-plugin-tools-annotations + ${project.version} + org.apache.maven.plugin-tools maven-plugin-tools-beanshell @@ -309,4 +313,4 @@ - + \ No newline at end of file From 8f804a31b5b47817f8239d96a56de156d6effabb Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Sat, 28 Apr 2012 21:23:35 +0000 Subject: [PATCH 05/48] add missing annotation parameters git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1331838 13f79535-47bb-0310-9956-ffa450edef68 --- .../tools/plugin/annotations/Component.java | 1 + .../tools/plugin/annotations/Execute.java | 12 +++++++ .../maven/tools/plugin/annotations/Goal.java | 1 + .../plugin/annotations/LifecyclePhase.java | 1 + .../tools/plugin/annotations/Parameter.java | 12 +++++++ .../tools/plugin/annotations/ThreadSafe.java | 33 ++++++++++++++++--- 6 files changed, 56 insertions(+), 4 deletions(-) diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/Component.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/Component.java index bc6240b..95b1e83 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/Component.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/Component.java @@ -27,6 +27,7 @@ import java.lang.annotation.Target; /** * @author Olivier Lamy + * @since 3.0 */ @Documented @Retention( RetentionPolicy.RUNTIME ) diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/Execute.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/Execute.java index 6fd8e0f..3b13bfb 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/Execute.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/Execute.java @@ -18,9 +18,21 @@ package org.apache.maven.tools.plugin.annotations; * under the License. */ +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + /** * @author Olivier Lamy + * @since 3.0 */ +@Documented +@Retention( RetentionPolicy.RUNTIME ) +@Target( ElementType.TYPE ) +@Inherited public @interface Execute { LifecyclePhase phase() default LifecyclePhase.NONE; diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/Goal.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/Goal.java index 784fd63..b56bd1f 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/Goal.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/Goal.java @@ -28,6 +28,7 @@ import java.lang.annotation.Target; /** * @author Olivier Lamy + * @since 3.0 */ @Documented @Retention( RetentionPolicy.RUNTIME ) diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/LifecyclePhase.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/LifecyclePhase.java index ab01368..3db6bf1 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/LifecyclePhase.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/LifecyclePhase.java @@ -20,6 +20,7 @@ package org.apache.maven.tools.plugin.annotations; /** * @author Olivier Lamy + * @since 3.0 */ public enum LifecyclePhase { diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/Parameter.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/Parameter.java index 7a0dac9..4db182a 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/Parameter.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/Parameter.java @@ -18,9 +18,21 @@ package org.apache.maven.tools.plugin.annotations; * under the License. */ +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + /** * @author Olivier Lamy + * @since 3.0 */ +@Documented +@Retention( RetentionPolicy.RUNTIME ) +@Target( { ElementType.FIELD, ElementType.METHOD } ) +@Inherited public @interface Parameter { String alias() default ""; diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/ThreadSafe.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/ThreadSafe.java index c0f9f41..4ad2389 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/ThreadSafe.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/ThreadSafe.java @@ -1,17 +1,42 @@ package org.apache.maven.tools.plugin.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 java.lang.annotation.Documented; +import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * @author Olivier Lamy + * @since 3.0 + */ @Documented @Inherited -@Retention( RUNTIME ) -@Target( { TYPE } ) +@Retention( RetentionPolicy.RUNTIME ) +@Target( { ElementType.TYPE } ) public @interface ThreadSafe { boolean value() default true; From 8c108af423aeecc7c408066cd391711f1f37b902 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Sun, 29 Apr 2012 22:00:20 +0000 Subject: [PATCH 06/48] Goal annotation renamed to Mojo, ThreadSafe moved to an attribute in Mojo annotation git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1332010 13f79535-47bb-0310-9956-ffa450edef68 --- .../annotations/{Goal.java => Mojo.java} | 4 +- .../tools/plugin/annotations/ThreadSafe.java | 43 ------------------- 2 files changed, 3 insertions(+), 44 deletions(-) rename maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/{Goal.java => Mojo.java} (96%) delete mode 100644 maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/ThreadSafe.java diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/Goal.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/Mojo.java similarity index 96% rename from maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/Goal.java rename to maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/Mojo.java index b56bd1f..2e1099f 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/Goal.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/Mojo.java @@ -34,7 +34,7 @@ import java.lang.annotation.Target; @Retention( RetentionPolicy.RUNTIME ) @Target( ElementType.TYPE ) @Inherited -public @interface Goal +public @interface Mojo { String name(); @@ -61,4 +61,6 @@ public @interface Goal boolean inheritByDefault() default true; String configurator() default ""; + + boolean threadSafe() default false; } diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/ThreadSafe.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/ThreadSafe.java deleted file mode 100644 index 4ad2389..0000000 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/ThreadSafe.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.apache.maven.tools.plugin.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 java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Inherited; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - - -/** - * @author Olivier Lamy - * @since 3.0 - */ - -@Documented -@Inherited -@Retention( RetentionPolicy.RUNTIME ) -@Target( { ElementType.TYPE } ) -public @interface ThreadSafe -{ - boolean value() default true; -} From 7e10f5b09f3b6bd6c326672f1c31598cdd665b43 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 4 May 2012 09:59:49 +0000 Subject: [PATCH 07/48] [MPLUGIN-189] commit some stuff on annotation scanning git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1333835 13f79535-47bb-0310-9956-ffa450edef68 --- maven-plugin-tools-annotations/pom.xml | 40 ++ ...avaAnnotationsMojoDescriptorExtractor.java | 61 ++ .../annotations/scanner/AnnotatedField.java | 52 ++ .../scanner/ComponentAnnotationContent.java | 84 +++ .../DefaultMojoAnnotationsScanner.java | 204 +++++++ .../scanner/MojoAnnotatedClass.java | 138 +++++ .../scanner/MojoAnnotationsScanner.java | 45 ++ .../MojoAnnotationsScannerRequest.java | 71 +++ .../annotations/scanner/MojoClassVisitor.java | 524 ++++++++++++++++++ .../scanner/ParameterAnnotationContent.java | 184 ++++++ .../resources/META-INF/plexus/components.xml | 42 ++ .../tools/plugin/annotations/FooMojo.java | 50 ++ .../annotations/TestAnnotationsReader.java | 78 +++ pom.xml | 8 +- 14 files changed, 1580 insertions(+), 1 deletion(-) create mode 100644 maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/JavaAnnotationsMojoDescriptorExtractor.java create mode 100644 maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/AnnotatedField.java create mode 100644 maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/ComponentAnnotationContent.java create mode 100644 maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java create mode 100644 maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotatedClass.java create mode 100644 maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotationsScanner.java create mode 100644 maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotationsScannerRequest.java create mode 100644 maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoClassVisitor.java create mode 100644 maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/ParameterAnnotationContent.java create mode 100644 maven-plugin-tools-annotations/src/main/resources/META-INF/plexus/components.xml create mode 100644 maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/FooMojo.java create mode 100644 maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/TestAnnotationsReader.java diff --git a/maven-plugin-tools-annotations/pom.xml b/maven-plugin-tools-annotations/pom.xml index e9575bc..56eb0f3 100644 --- a/maven-plugin-tools-annotations/pom.xml +++ b/maven-plugin-tools-annotations/pom.xml @@ -11,4 +11,44 @@ Maven Plugin Tools Annotations + + + + + org.apache.maven + maven-project + + + org.apache.maven + maven-model + + + org.apache.maven + maven-plugin-descriptor + + + org.apache.maven.plugin-tools + maven-plugin-tools-api + + + + org.codehaus.plexus + plexus-utils + + + org.codehaus.plexus + plexus-container-default + + + asm + asm + 3.3.1 + + + asm + asm-commons + 3.3.1 + + + 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 new file mode 100644 index 0000000..9f1a05f --- /dev/null +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/JavaAnnotationsMojoDescriptorExtractor.java @@ -0,0 +1,61 @@ +package org.apache.maven.tools.plugin.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.DependencyResolutionRequiredException; +import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException; +import org.apache.maven.plugin.descriptor.MojoDescriptor; +import org.apache.maven.plugin.descriptor.PluginDescriptor; +import org.apache.maven.project.MavenProject; +import org.apache.maven.tools.plugin.DefaultPluginToolsRequest; +import org.apache.maven.tools.plugin.PluginToolsRequest; +import org.apache.maven.tools.plugin.extractor.ExtractionException; +import org.apache.maven.tools.plugin.extractor.MojoDescriptorExtractor; +import org.codehaus.plexus.logging.AbstractLogEnabled; + +import java.util.List; + +/** + * @author Olivier Lamy + */ +public class JavaAnnotationsMojoDescriptorExtractor + extends AbstractLogEnabled + implements MojoDescriptorExtractor +{ + + public List execute( MavenProject project, PluginDescriptor pluginDescriptor ) + throws ExtractionException, InvalidPluginDescriptorException + { + return execute( new DefaultPluginToolsRequest( project, pluginDescriptor ) ); + } + + public List execute( PluginToolsRequest request ) + throws ExtractionException, InvalidPluginDescriptorException + { + try + { + List classpathElements = request.getProject().getCompileClasspathElements(); + return null; //To change body of implemented methods use File | Settings | File Templates. + } + catch ( DependencyResolutionRequiredException e ) + { + throw new ExtractionException( e.getMessage(), e ); + } + } +} diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/AnnotatedField.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/AnnotatedField.java new file mode 100644 index 0000000..7bf891a --- /dev/null +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/AnnotatedField.java @@ -0,0 +1,52 @@ +package org.apache.maven.tools.plugin.annotations.scanner; +/* + * 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. + */ + +/** + * @author Olivier Lamy + */ +public class AnnotatedField +{ + private String fieldName; + + public AnnotatedField( String fieldName ) + { + this.fieldName = fieldName; + } + + public String getFieldName() + { + return fieldName; + } + + public void setFieldName( String name ) + { + this.fieldName = name; + } + + @Override + public String toString() + { + final StringBuilder sb = new StringBuilder(); + sb.append( "AnnotatedField" ); + sb.append( "{fieldName='" ).append( fieldName ).append( '\'' ); + sb.append( '}' ); + return sb.toString(); + } +} diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/ComponentAnnotationContent.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/ComponentAnnotationContent.java new file mode 100644 index 0000000..60e3f72 --- /dev/null +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/ComponentAnnotationContent.java @@ -0,0 +1,84 @@ +package org.apache.maven.tools.plugin.annotations.scanner; +/* + * 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.tools.plugin.annotations.Component; + +import java.lang.annotation.Annotation; + +/** + * @author Olivier Lamy + */ +public class ComponentAnnotationContent + extends AnnotatedField + implements Component +{ + private String role; + + private String roleHint; + + public ComponentAnnotationContent( String fieldName ) + { + super( fieldName ); + } + + public ComponentAnnotationContent( String fieldName, String role, String roleHint ) + { + this( fieldName ); + this.role = role; + this.roleHint = roleHint; + } + + public String role() + { + return role; + } + + public void role( String role ) + { + this.role = role; + } + + public String roleHint() + { + return roleHint; + } + + public void roleHint( String roleHint ) + { + this.roleHint = roleHint; + } + + public Class annotationType() + { + return null; + } + + @Override + public String toString() + { + final StringBuilder sb = new StringBuilder(); + sb.append( super.toString() ); + sb.append( "ComponentAnnotationContent" ); + sb.append( "{role='" ).append( role ).append( '\'' ); + sb.append( ", roleHint='" ).append( roleHint ).append( '\'' ); + sb.append( '}' ); + return sb.toString(); + } +} diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java new file mode 100644 index 0000000..cbe9b88 --- /dev/null +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java @@ -0,0 +1,204 @@ +package org.apache.maven.tools.plugin.annotations.scanner; +/* + * 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.tools.plugin.annotations.Component; +import org.apache.maven.tools.plugin.annotations.Execute; +import org.apache.maven.tools.plugin.annotations.Mojo; +import org.apache.maven.tools.plugin.annotations.Parameter; +import org.apache.maven.tools.plugin.extractor.ExtractionException; +import org.codehaus.plexus.logging.AbstractLogEnabled; +import org.codehaus.plexus.util.DirectoryScanner; +import org.codehaus.plexus.util.IOUtil; +import org.codehaus.plexus.util.reflection.Reflector; +import org.objectweb.asm.ClassReader; + +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * @author Olivier Lamy + */ +public class DefaultMojoAnnotationsScanner + extends AbstractLogEnabled + implements MojoAnnotationsScanner +{ + private Reflector reflector = new Reflector(); + + public List scan( MojoAnnotationsScannerRequest request ) + throws ExtractionException + { + List mojoAnnotatedClasses = new ArrayList(); + try + { + for ( File classDirectory : request.getClassesDirectories() ) + { + mojoAnnotatedClasses.addAll( scanDirectory( classDirectory, request.getIncludePatterns() ) ); + } + return mojoAnnotatedClasses; + } + catch ( IOException e ) + { + throw new ExtractionException( e.getMessage(), e ); + } + } + + protected List scanDirectory( File classDirectory, List includePatterns ) + throws IOException, ExtractionException + { + List mojoAnnotatedClasses = new ArrayList(); + DirectoryScanner scanner = new DirectoryScanner(); + scanner.setBasedir( classDirectory ); + scanner.addDefaultExcludes(); + if ( includePatterns != null ) + { + scanner.setIncludes( includePatterns.toArray( new String[includePatterns.size()] ) ); + } + scanner.scan(); + String[] classFiles = scanner.getIncludedFiles(); + + for ( String classFile : classFiles ) + { + InputStream is = new BufferedInputStream( new FileInputStream( new File( classDirectory, classFile ) ) ); + try + { + + if ( classFile.endsWith( ".class" ) ) + { + MojoClassVisitor mojoClassVisitor = new MojoClassVisitor( getLogger() ); + ClassReader rdr = new ClassReader( is ); + rdr.accept( mojoClassVisitor, + ClassReader.SKIP_FRAMES | ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG ); + analyzeVisitors( mojoClassVisitor ); + if ( isMojoAnnnotatedClassCandidate( mojoClassVisitor.getMojoAnnotatedClass() ) != null ) + { + mojoAnnotatedClasses.add( mojoClassVisitor.getMojoAnnotatedClass() ); + } + + } + } + finally + { + IOUtil.close( is ); + } + + } + return mojoAnnotatedClasses; + } + + private MojoAnnotatedClass isMojoAnnnotatedClassCandidate( MojoAnnotatedClass mojoAnnotatedClass ) + { + if ( mojoAnnotatedClass == null ) + { + return null; + } + if ( !mojoAnnotatedClass.getComponents().isEmpty() || !mojoAnnotatedClass.getParameters().isEmpty() + || mojoAnnotatedClass.getExecute() != null || mojoAnnotatedClass.getMojo() != null ) + { + return mojoAnnotatedClass; + } + return null; + } + + protected void analyzeVisitors( MojoClassVisitor mojoClassVisitor ) + throws ExtractionException + { + + try + { + MojoClassVisitor.MojoAnnotationVisitor mojoAnnotationVisitor = + mojoClassVisitor.getAnnotationVisitorMap().get( Mojo.class.getName() ); + if ( mojoAnnotationVisitor != null ) + { + MojoClassVisitor.MojoAnnotationContent mojoAnnotationContent = + new MojoClassVisitor.MojoAnnotationContent(); + Class clazz = Thread.currentThread().getContextClassLoader().loadClass( + MojoClassVisitor.MojoAnnotationContent.class.getName() ); + for ( Map.Entry entry : mojoAnnotationVisitor.getAnnotationValues().entrySet() ) + { + reflector.invoke( mojoAnnotationContent, entry.getKey(), new Object[]{ entry.getValue() } ); + } + mojoClassVisitor.getMojoAnnotatedClass().setMojo( mojoAnnotationContent ); + } + + mojoAnnotationVisitor = mojoClassVisitor.getAnnotationVisitorMap().get( Execute.class.getName() ); + if ( mojoAnnotationVisitor != null ) + { + MojoClassVisitor.ExecuteAnnotationContent executeAnnotationContent = + new MojoClassVisitor.ExecuteAnnotationContent(); + Class clazz = Thread.currentThread().getContextClassLoader().loadClass( + MojoClassVisitor.MojoAnnotationContent.class.getName() ); + for ( Map.Entry entry : mojoAnnotationVisitor.getAnnotationValues().entrySet() ) + { + reflector.invoke( executeAnnotationContent, entry.getKey(), new Object[]{ entry.getValue() } ); + } + mojoClassVisitor.getMojoAnnotatedClass().setExecute( executeAnnotationContent ); + } + + List mojoFieldVisitors = + mojoClassVisitor.findFieldWithAnnotationClass( Parameter.class.getName() ); + + for ( MojoClassVisitor.MojoFieldVisitor mojoFieldVisitor : mojoFieldVisitors ) + { + ParameterAnnotationContent parameterAnnotationContent = + new ParameterAnnotationContent( mojoFieldVisitor.getFieldName() ); + if ( mojoFieldVisitor.getMojoAnnotationVisitor() != null ) + { + for ( Map.Entry entry : mojoFieldVisitor.getMojoAnnotationVisitor().getAnnotationValues().entrySet() ) + { + reflector.invoke( parameterAnnotationContent, entry.getKey(), + new Object[]{ entry.getValue() } ); + } + + } + mojoClassVisitor.getMojoAnnotatedClass().getParameters().add( parameterAnnotationContent ); + } + + mojoFieldVisitors = mojoClassVisitor.findFieldWithAnnotationClass( Component.class.getName() ); + + for ( MojoClassVisitor.MojoFieldVisitor mojoFieldVisitor : mojoFieldVisitors ) + { + ComponentAnnotationContent componentAnnotationContent = + new ComponentAnnotationContent( mojoFieldVisitor.getFieldName() ); + + if ( mojoFieldVisitor.getMojoAnnotationVisitor() != null ) + { + for ( Map.Entry entry : mojoFieldVisitor.getMojoAnnotationVisitor().getAnnotationValues().entrySet() ) + { + reflector.invoke( componentAnnotationContent, entry.getKey(), + new Object[]{ entry.getValue() } ); + } + + } + mojoClassVisitor.getMojoAnnotatedClass().getComponents().add( componentAnnotationContent ); + } + + } + catch ( Exception e ) + { + throw new ExtractionException( e.getMessage(), e ); + } + } +} diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotatedClass.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotatedClass.java new file mode 100644 index 0000000..2721c18 --- /dev/null +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotatedClass.java @@ -0,0 +1,138 @@ +package org.apache.maven.tools.plugin.annotations.scanner; +/* + * 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.tools.plugin.annotations.Execute; +import org.apache.maven.tools.plugin.annotations.Mojo; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Olivier Lamy + */ +public class MojoAnnotatedClass +{ + private String className; + + private String parentClassName; + + private Mojo mojo; + + private Execute execute; + + private List parameters; + + private List components; + + public MojoAnnotatedClass() + { + // no op + } + + public String getClassName() + { + return className; + } + + public MojoAnnotatedClass setClassName( String className ) + { + this.className = className; + return this; + } + + public Mojo getMojo() + { + return mojo; + } + + public MojoAnnotatedClass setMojo( Mojo mojo ) + { + this.mojo = mojo; + return this; + } + + public Execute getExecute() + { + return execute; + } + + public MojoAnnotatedClass setExecute( Execute execute ) + { + this.execute = execute; + return this; + } + + public List getParameters() + { + if ( this.parameters == null ) + { + this.parameters = new ArrayList(); + } + return parameters; + } + + public MojoAnnotatedClass setParameters( List parameters ) + { + this.parameters = parameters; + return this; + } + + public List getComponents() + { + if ( this.components == null ) + { + this.components = new ArrayList(); + } + return components; + } + + public MojoAnnotatedClass setComponents( List components ) + { + this.components = components; + return this; + } + + public String getParentClassName() + { + return parentClassName; + } + + public MojoAnnotatedClass setParentClassName( String parentClassName ) + { + this.parentClassName = parentClassName; + return this; + } + + + @Override + public String toString() + { + final StringBuilder sb = new StringBuilder(); + sb.append( "MojoAnnotatedClass" ); + sb.append( "{className='" ).append( className ).append( '\'' ); + sb.append( ", parentClassName='" ).append( parentClassName ).append( '\'' ); + sb.append( ", mojo=" ).append( mojo ); + sb.append( ", execute=" ).append( execute ); + sb.append( ", parameters=" ).append( parameters ); + sb.append( ", components=" ).append( components ); + sb.append( '}' ); + return sb.toString(); + } +} diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotationsScanner.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotationsScanner.java new file mode 100644 index 0000000..9a0a4b0 --- /dev/null +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotationsScanner.java @@ -0,0 +1,45 @@ +package org.apache.maven.tools.plugin.annotations.scanner; +/* + * 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.tools.plugin.annotations.Component; +import org.apache.maven.tools.plugin.annotations.Execute; +import org.apache.maven.tools.plugin.annotations.Mojo; +import org.apache.maven.tools.plugin.annotations.Parameter; +import org.apache.maven.tools.plugin.extractor.ExtractionException; + +import java.util.Arrays; +import java.util.List; + +/** + * @author Olivier Lamy + */ +public interface MojoAnnotationsScanner +{ + String ROLE = MojoAnnotationsScanner.class.getName(); + + static final List acceptedClassLevelAnnotationClasses = + Arrays.asList( Mojo.class.getName(), Execute.class.getName() ); + + static final List acceptedFieldLevelAnnotationClasses = + Arrays.asList( Parameter.class.getName(), Component.class.getName() ); + + List scan( MojoAnnotationsScannerRequest request ) + throws ExtractionException; +} diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotationsScannerRequest.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotationsScannerRequest.java new file mode 100644 index 0000000..7534b88 --- /dev/null +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotationsScannerRequest.java @@ -0,0 +1,71 @@ +package org.apache.maven.tools.plugin.annotations.scanner; +/* + * 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 java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * @author Olivier Lamy + */ +public class MojoAnnotationsScannerRequest +{ + private List classesDirectories = new ArrayList(); + + private List dependencies = new ArrayList(); + + private List includePatterns = Arrays.asList( "**/*.class" ); + + public MojoAnnotationsScannerRequest() + { + // no o + } + + public List getClassesDirectories() + { + return classesDirectories; + } + + public void setClassesDirectories( List classesDirectories ) + { + this.classesDirectories = classesDirectories; + } + + public List getDependencies() + { + return dependencies; + } + + public void setDependencies( List dependencies ) + { + this.dependencies = dependencies; + } + + public List getIncludePatterns() + { + return includePatterns; + } + + public void setIncludePatterns( List includePatterns ) + { + this.includePatterns = includePatterns; + } +} diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoClassVisitor.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoClassVisitor.java new file mode 100644 index 0000000..53e9cac --- /dev/null +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoClassVisitor.java @@ -0,0 +1,524 @@ +package org.apache.maven.tools.plugin.annotations.scanner; +/* + * 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.tools.plugin.annotations.Execute; +import org.apache.maven.tools.plugin.annotations.LifecyclePhase; +import org.apache.maven.tools.plugin.annotations.Mojo; +import org.codehaus.plexus.logging.Logger; +import org.codehaus.plexus.util.StringUtils; +import org.objectweb.asm.AnnotationVisitor; +import org.objectweb.asm.Attribute; +import org.objectweb.asm.ClassVisitor; +import org.objectweb.asm.FieldVisitor; +import org.objectweb.asm.MethodVisitor; +import org.objectweb.asm.Type; + +import java.lang.annotation.Annotation; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author Olivier Lamy + */ +public class MojoClassVisitor + implements ClassVisitor +{ + private Logger logger; + + private MojoAnnotatedClass mojoAnnotatedClass; + + private Map annotationVisitorMap = new HashMap(); + + private List fieldVisitors = new ArrayList(); + + public MojoClassVisitor( Logger logger ) + { + this.logger = logger; + } + + public MojoAnnotatedClass getMojoAnnotatedClass() + { + return mojoAnnotatedClass; + } + + public void setMojoAnnotatedClass( MojoAnnotatedClass mojoAnnotatedClass ) + { + this.mojoAnnotatedClass = mojoAnnotatedClass; + } + + public Map getAnnotationVisitorMap() + { + return annotationVisitorMap; + } + + public void setAnnotationVisitorMap( Map annotationVisitorMap ) + { + this.annotationVisitorMap = annotationVisitorMap; + } + + public List getFieldVisitors() + { + return fieldVisitors; + } + + public void setFieldVisitors( List fieldVisitors ) + { + this.fieldVisitors = fieldVisitors; + } + + public List findFieldWithAnnotationClass( String annotationClassName ) + { + List mojoFieldVisitors = new ArrayList(); + + for ( MojoFieldVisitor mojoFieldVisitor : this.fieldVisitors ) + { + MojoAnnotationVisitor mojoAnnotationVisitor = mojoFieldVisitor.getMojoAnnotationVisitor(); + if ( mojoAnnotationVisitor != null && StringUtils.equals( annotationClassName, + mojoAnnotationVisitor.annotationClassName ) ) + { + mojoFieldVisitors.add( mojoFieldVisitor ); + } + } + + return mojoFieldVisitors; + } + + public void visit( int version, int access, String name, String signature, String superName, String[] interfaces ) + { + mojoAnnotatedClass = new MojoAnnotatedClass(); + mojoAnnotatedClass.setClassName( Type.getObjectType( name ).getClassName() ).setParentClassName( + Type.getObjectType( superName ).getClassName() ); + logger.debug( "MojoClassVisitor#visit" ); + } + + public AnnotationVisitor visitAnnotation( String desc, boolean visible ) + { + logger.debug( "MojoClassVisitor#visitAnnotation" ); + String annotationClassName = Type.getType( desc ).getClassName(); + if ( !MojoAnnotationsScanner.acceptedClassLevelAnnotationClasses.contains( annotationClassName ) ) + { + return null; + } + MojoAnnotationVisitor mojoAnnotationVisitor = new MojoAnnotationVisitor( logger, annotationClassName ); + annotationVisitorMap.put( annotationClassName, mojoAnnotationVisitor ); + return mojoAnnotationVisitor; + } + + public FieldVisitor visitField( int access, String name, String desc, String signature, Object value ) + { + // Type.getType( desc ).getClassName() + logger.debug( "MojoClassVisitor#visitField" ); + MojoFieldVisitor mojoFieldVisitor = new MojoFieldVisitor( logger, name ); + fieldVisitors.add( mojoFieldVisitor ); + return mojoFieldVisitor; + } + + public MethodVisitor visitMethod( int access, String name, String desc, String signature, String[] exceptions ) + { + // we don't need methods informations + return null; + } + + public void visitAttribute( Attribute attr ) + { + } + + public void visitSource( String source, String debug ) + { + } + + public void visitOuterClass( String owner, String name, String desc ) + { + } + + public void visitInnerClass( String name, String outerName, String innerName, int access ) + { + } + + public void visitEnd() + { + logger.debug( "MojoClassVisitor#visitEnd" ); + } + + public static class MojoAnnotationContent + implements Mojo + { + + private String name; + + private LifecyclePhase defaultPhase = LifecyclePhase.NONE; + + private String requiresDependencyResolution = "runtime"; + + private String requiresDependencyCollection = "runtime"; + + private String instantiationStrategy = "per-lookup"; + + private String executionStrategy = "once-per-session"; + + private boolean requiresProject = true; + + private boolean requiresReports = false; + + private boolean aggregator = false; + + private boolean requiresDirectInvocation = false; + + private boolean requiresOnline = false; + + private boolean inheritByDefault = true; + + private String configurator; + + private boolean threadSafe = false; + + public Class annotationType() + { + return null; + } + + public LifecyclePhase defaultPhase() + { + return defaultPhase; + } + + public void defaultPhase( String phase ) + { + this.defaultPhase = LifecyclePhase.valueOf( phase ); + } + + public String requiresDependencyResolution() + { + return requiresDependencyResolution; + } + + public void requiresDependencyResolution( String requiresDependencyResolution ) + { + this.requiresDependencyResolution = requiresDependencyResolution; + } + + public String requiresDependencyCollection() + { + return requiresDependencyCollection; + } + + public void requiresDependencyCollection( String requiresDependencyCollection ) + { + this.requiresDependencyCollection = requiresDependencyCollection; + } + + public String instantiationStrategy() + { + return instantiationStrategy; + } + + public void instantiationStrategy( String instantiationStrategy ) + { + this.instantiationStrategy = instantiationStrategy; + } + + public String executionStrategy() + { + return executionStrategy; + } + + public void executionStrategy( String executionStrategy ) + { + this.executionStrategy = executionStrategy; + } + + public boolean requiresProject() + { + return requiresProject; + } + + public void requiresProject( boolean requiresProject ) + { + this.requiresProject = requiresProject; + } + + public boolean requiresReports() + { + return requiresReports; + } + + public void requiresReports( boolean requiresReports ) + { + this.requiresReports = requiresReports; + } + + public boolean aggregator() + { + return aggregator; + } + + public void aggregator( boolean aggregator ) + { + this.aggregator = aggregator; + } + + public boolean requiresDirectInvocation() + { + return requiresDirectInvocation; + } + + public void requiresDirectInvocation( boolean requiresDirectInvocation ) + { + this.requiresDirectInvocation = requiresDirectInvocation; + } + + public boolean requiresOnline() + { + return requiresOnline; + } + + public void requiresOnline( boolean requiresOnline ) + { + this.requiresOnline = requiresOnline; + } + + public boolean inheritByDefault() + { + return inheritByDefault; + } + + public void inheritByDefault( boolean inheritByDefault ) + { + this.inheritByDefault = inheritByDefault; + } + + public String configurator() + { + return configurator; + } + + public void configurator( String configurator ) + { + this.configurator = configurator; + } + + public boolean threadSafe() + { + return threadSafe; + } + + public void threadSafe( boolean threadSafe ) + { + this.threadSafe = threadSafe; + } + + public String name() + { + return this.name; + } + + public void name( String name ) + { + this.name = name; + } + + @Override + public String toString() + { + final StringBuilder sb = new StringBuilder(); + sb.append( "MojoAnnotationContent" ); + sb.append( "{name='" ).append( name ).append( '\'' ); + sb.append( ", defaultPhase=" ).append( defaultPhase ); + sb.append( ", requiresDependencyResolution='" ).append( requiresDependencyResolution ).append( '\'' ); + sb.append( ", requiresDependencyCollection='" ).append( requiresDependencyCollection ).append( '\'' ); + sb.append( ", instantiationStrategy='" ).append( instantiationStrategy ).append( '\'' ); + sb.append( ", executionStrategy='" ).append( executionStrategy ).append( '\'' ); + sb.append( ", requiresProject=" ).append( requiresProject ); + sb.append( ", requiresReports=" ).append( requiresReports ); + sb.append( ", aggregator=" ).append( aggregator ); + sb.append( ", requiresDirectInvocation=" ).append( requiresDirectInvocation ); + sb.append( ", requiresOnline=" ).append( requiresOnline ); + sb.append( ", inheritByDefault=" ).append( inheritByDefault ); + sb.append( ", configurator='" ).append( configurator ).append( '\'' ); + sb.append( ", threadSafe=" ).append( threadSafe ); + sb.append( '}' ); + return sb.toString(); + } + } + + public static class ExecuteAnnotationContent + implements Execute + { + + private String goal; + + private String lifecycle; + + private LifecyclePhase phase; + + public LifecyclePhase phase() + { + return this.phase; + } + + public String goal() + { + return this.goal; + } + + public String lifecycle() + { + return this.lifecycle; + } + + + public void phase( String phase ) + { + this.phase = LifecyclePhase.valueOf( phase ); + } + + public void goal( String goal ) + { + this.goal = goal; + } + + public void lifecycle( String lifecycle ) + { + this.lifecycle = lifecycle; + } + + + public Class annotationType() + { + return null; + } + + @Override + public String toString() + { + final StringBuilder sb = new StringBuilder(); + sb.append( "ExecuteAnnotationContent" ); + sb.append( "{goal='" ).append( goal ).append( '\'' ); + sb.append( ", lifecycle='" ).append( lifecycle ).append( '\'' ); + sb.append( ", phase=" ).append( phase ); + sb.append( '}' ); + return sb.toString(); + } + } + + //------------------------------------- + // internal classes + //------------------------------------- + static class MojoAnnotationVisitor + implements AnnotationVisitor + { + + private Logger logger; + + private String annotationClassName; + + private Map annotationValues = new HashMap(); + + MojoAnnotationVisitor( Logger logger, String annotationClassName ) + { + this.logger = logger; + this.annotationClassName = annotationClassName; + } + + public Map getAnnotationValues() + { + return annotationValues; + } + + public void visit( String name, Object value ) + { + annotationValues.put( name, value ); + logger.debug( "MojoAnnotationVisitor#visit:" + name + ":" + value ); + } + + public void visitEnum( String name, String desc, String value ) + { + annotationValues.put( name, value ); + logger.debug( "MojoAnnotationVisitor#visitEnum:" + name + ":" + desc + ":" + value ); + } + + public AnnotationVisitor visitAnnotation( String name, String desc ) + { + logger.debug( "MojoAnnotationVisitor#visitAnnotation:" + name + ":" + desc ); + return new MojoAnnotationVisitor( logger, this.annotationClassName ); + } + + public AnnotationVisitor visitArray( String s ) + { + logger.debug( "MojoAnnotationVisitor#visitArray" ); + return new MojoAnnotationVisitor( logger, this.annotationClassName ); + } + + public void visitEnd() + { + logger.debug( "MojoAnnotationVisitor#visitEnd" ); + } + } + + static class MojoFieldVisitor + implements FieldVisitor + { + private Logger logger; + + private String fieldName; + + private MojoAnnotationVisitor mojoAnnotationVisitor; + + MojoFieldVisitor( Logger logger, String fieldName ) + { + this.logger = logger; + this.fieldName = fieldName; + } + + public MojoAnnotationVisitor getMojoAnnotationVisitor() + { + return mojoAnnotationVisitor; + } + + public String getFieldName() + { + return fieldName; + } + + public AnnotationVisitor visitAnnotation( String desc, boolean visible ) + { + logger.debug( "MojoFieldVisitor#visitAnnotation:" + desc ); + String annotationClassName = Type.getType( desc ).getClassName(); + if ( !MojoAnnotationsScanner.acceptedFieldLevelAnnotationClasses.contains( annotationClassName ) ) + { + return null; + } + mojoAnnotationVisitor = new MojoAnnotationVisitor( logger, annotationClassName ); + return mojoAnnotationVisitor; + } + + public void visitAttribute( Attribute attribute ) + { + logger.debug( "MojoFieldVisitor#visitAttribute" ); + } + + public void visitEnd() + { + logger.debug( "MojoFieldVisitor#visitEnd" ); + } + } +} diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/ParameterAnnotationContent.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/ParameterAnnotationContent.java new file mode 100644 index 0000000..bf20605 --- /dev/null +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/ParameterAnnotationContent.java @@ -0,0 +1,184 @@ +package org.apache.maven.tools.plugin.annotations.scanner; +/* + * 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.tools.plugin.annotations.Parameter; + +import java.lang.annotation.Annotation; + +/** + * @author Olivier Lamy + */ +public class ParameterAnnotationContent + extends AnnotatedField + implements Parameter +{ + + private String alias; + + private String expression; + + private String defaultValue; + + private boolean required = false; + + private boolean readonly = false; + + public ParameterAnnotationContent( String fieldName ) + { + super( fieldName ); + } + + public ParameterAnnotationContent( String fieldName, String alias, String expression, String defaultValue, + boolean required, boolean readonly ) + { + this( fieldName ); + this.alias = alias; + this.expression = expression; + this.defaultValue = defaultValue; + this.required = required; + this.readonly = readonly; + } + + public String alias() + { + return alias; + } + + public void alias( String alias ) + { + this.alias = alias; + } + + public String expression() + { + return expression; + } + + public void expression( String expression ) + { + this.expression = expression; + } + + public String defaultValue() + { + return defaultValue; + } + + public void defaultValue( String defaultValue ) + { + this.defaultValue = defaultValue; + } + + public boolean required() + { + return required; + } + + public void required( boolean required ) + { + this.required = required; + } + + public boolean readonly() + { + return readonly; + } + + public void readonly( boolean readonly ) + { + this.readonly = readonly; + } + + public Class annotationType() + { + return null; + } + + @Override + public String toString() + { + final StringBuilder sb = new StringBuilder(); + sb.append( super.toString() ); + sb.append( "ParameterAnnotationContent" ); + sb.append( "{alias='" ).append( alias ).append( '\'' ); + sb.append( ", expression='" ).append( expression ).append( '\'' ); + sb.append( ", defaultValue='" ).append( defaultValue ).append( '\'' ); + sb.append( ", required=" ).append( required ); + sb.append( ", readonly=" ).append( readonly ); + sb.append( '}' ); + return sb.toString(); + } + + @Override + public boolean equals( Object o ) + { + if ( this == o ) + { + return true; + } + if ( !( o instanceof ParameterAnnotationContent ) ) + { + return false; + } + + ParameterAnnotationContent that = (ParameterAnnotationContent) o; + + if ( readonly != that.readonly ) + { + return false; + } + if ( required != that.required ) + { + return false; + } + + if ( getFieldName() != null ? !getFieldName().equals( that.getFieldName() ) : that.getFieldName() != null ) + { + return false; + } + + if ( alias != null ? !alias.equals( that.alias ) : that.alias != null ) + { + return false; + } + if ( defaultValue != null ? !defaultValue.equals( that.defaultValue ) : that.defaultValue != null ) + { + return false; + } + if ( expression != null ? !expression.equals( that.expression ) : that.expression != null ) + { + return false; + } + + return true; + } + + @Override + public int hashCode() + { + int result = alias != null ? alias.hashCode() : 0; + result = 31 * result + ( getFieldName() != null ? getFieldName().hashCode() : 0 ); + result = 31 * result + ( expression != null ? expression.hashCode() : 0 ); + result = 31 * result + ( defaultValue != null ? defaultValue.hashCode() : 0 ); + result = 31 * result + ( required ? 1 : 0 ); + result = 31 * result + ( readonly ? 1 : 0 ); + return result; + } +} diff --git a/maven-plugin-tools-annotations/src/main/resources/META-INF/plexus/components.xml b/maven-plugin-tools-annotations/src/main/resources/META-INF/plexus/components.xml new file mode 100644 index 0000000..d7b2dbe --- /dev/null +++ b/maven-plugin-tools-annotations/src/main/resources/META-INF/plexus/components.xml @@ -0,0 +1,42 @@ + + + + + + + + org.apache.maven.tools.plugin.extractor.MojoDescriptorExtractor + java-annotations + org.apache.maven.tools.plugin.annotations.JavaAnnotationsMojoDescriptorExtractor + + + + org.apache.maven.tools.plugin.annotations.scanner.MojoAnnotationsScanner + default + org.apache.maven.tools.plugin.annotations.scanner.DefaultMojoAnnotationsScanner + + + + \ No newline at end of file diff --git a/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/FooMojo.java b/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/FooMojo.java new file mode 100644 index 0000000..9bf0d8e --- /dev/null +++ b/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/FooMojo.java @@ -0,0 +1,50 @@ +package org.apache.maven.tools.plugin.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.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; + +/** + * @author Olivier Lamy + */ +@Mojo( name = "foo", defaultPhase = LifecyclePhase.COMPILE, threadSafe = true ) +@Execute( goal = "compiler", lifecycle = "my-lifecycle", phase = LifecyclePhase.PACKAGE ) +public class FooMojo + extends AbstractMojo +{ + @Parameter( expression = "${thebar}" ) + private String bar; + + @Parameter( expression = "${thebeer}" ) + private String beer; + + @Component( role = "wine", roleHint = "bordeaux" ) + private Mojo wine; + + @Component( role = "wine", roleHint = "foo" ) + private Mojo foo; + + public void execute() + throws MojoExecutionException, MojoFailureException + { + // nothing + } +} diff --git a/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/TestAnnotationsReader.java b/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/TestAnnotationsReader.java new file mode 100644 index 0000000..586ba5f --- /dev/null +++ b/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/TestAnnotationsReader.java @@ -0,0 +1,78 @@ +package org.apache.maven.tools.plugin.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.tools.plugin.annotations.scanner.ComponentAnnotationContent; +import org.apache.maven.tools.plugin.annotations.scanner.MojoAnnotatedClass; +import org.apache.maven.tools.plugin.annotations.scanner.MojoAnnotationsScanner; +import org.apache.maven.tools.plugin.annotations.scanner.MojoAnnotationsScannerRequest; +import org.apache.maven.tools.plugin.annotations.scanner.ParameterAnnotationContent; +import org.codehaus.plexus.PlexusTestCase; +import org.fest.assertions.Assertions; + +import java.io.File; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +/** + * @author Olivier Lamy + */ +public class TestAnnotationsReader + extends PlexusTestCase +{ + public void testReadMojoClass() + throws Exception + { + MojoAnnotationsScanner mojoAnnotationsScanner = (MojoAnnotationsScanner) lookup( MojoAnnotationsScanner.ROLE ); + + MojoAnnotationsScannerRequest request = new MojoAnnotationsScannerRequest(); + request.setClassesDirectories( Collections.singletonList( new File( "target/test-classes" ) ) ); + request.setIncludePatterns( Arrays.asList( "**/FooMojo.class" ) ); + + List mojoAnnotatedClasses = mojoAnnotationsScanner.scan( request ); + + System.out.println( "mojoAnnotatedClasses:" + mojoAnnotatedClasses ); + + Assertions.assertThat( mojoAnnotatedClasses ).isNotNull().isNotEmpty().hasSize( 1 ); + + MojoAnnotatedClass mojoAnnotatedClass = mojoAnnotatedClasses.get( 0 ); + + Mojo mojo = mojoAnnotatedClass.getMojo(); + + assertEquals( "foo", mojo.name() ); + assertEquals( true, mojo.threadSafe() ); + assertEquals( false, mojo.aggregator() ); + assertEquals( LifecyclePhase.COMPILE, mojo.defaultPhase() ); + + Execute execute = mojoAnnotatedClass.getExecute(); + + assertEquals( "compiler", execute.goal() ); + assertEquals( "my-lifecycle", execute.lifecycle() ); + assertEquals( LifecyclePhase.PACKAGE, execute.phase() ); + + List components = mojoAnnotatedClass.getComponents(); + Assertions.assertThat( components ).isNotNull().isNotEmpty().hasSize( 2 ); + + List parameters = mojoAnnotatedClass.getParameters(); + Assertions.assertThat( parameters ).isNotNull().isNotEmpty().hasSize( 2 ).contains( + new ParameterAnnotationContent( "bar", null, "${thebar}", null, false, false ), + new ParameterAnnotationContent( "beer", null, "${thebeer}", null, false, false ) ); + } +} diff --git a/pom.xml b/pom.xml index e76fd51..cb73ded 100644 --- a/pom.xml +++ b/pom.xml @@ -215,7 +215,7 @@ org.codehaus.plexus plexus-utils - 2.0.5 + 3.0 org.codehaus.plexus @@ -239,6 +239,12 @@ 3.8.2 test + + org.easytesting + fest-assert + 1.4 + test + From dfec22a65ede8a0cc490499c384d12263f17ab70 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 4 May 2012 10:00:19 +0000 Subject: [PATCH 08/48] [MPLUGIN-189] cleanup with moving some classes to separate packages git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1333836 13f79535-47bb-0310-9956-ffa450edef68 --- .../AnnotatedField.java | 2 +- .../ComponentAnnotationContent.java | 2 +- .../datamodel/ExecuteAnnotationContent.java | 86 +++ .../datamodel/MojoAnnotationContent.java | 227 ++++++++ .../ParameterAnnotationContent.java | 2 +- .../DefaultMojoAnnotationsScanner.java | 26 +- .../scanner/MojoAnnotatedClass.java | 2 + .../annotations/scanner/MojoClassVisitor.java | 524 ------------------ .../visitors/MojoAnnotationVisitor.java | 83 +++ .../scanner/visitors/MojoClassVisitor.java | 160 ++++++ .../scanner/visitors/MojoFieldVisitor.java | 77 +++ .../annotations/TestAnnotationsReader.java | 4 +- 12 files changed, 654 insertions(+), 541 deletions(-) rename maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/{scanner => datamodel}/AnnotatedField.java (95%) rename maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/{scanner => datamodel}/ComponentAnnotationContent.java (97%) create mode 100644 maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/ExecuteAnnotationContent.java create mode 100644 maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/MojoAnnotationContent.java rename maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/{scanner => datamodel}/ParameterAnnotationContent.java (98%) delete mode 100644 maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoClassVisitor.java create mode 100644 maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/visitors/MojoAnnotationVisitor.java create mode 100644 maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/visitors/MojoClassVisitor.java create mode 100644 maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/visitors/MojoFieldVisitor.java diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/AnnotatedField.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/AnnotatedField.java similarity index 95% rename from maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/AnnotatedField.java rename to maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/AnnotatedField.java index 7bf891a..cc9bf6d 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/AnnotatedField.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/AnnotatedField.java @@ -1,4 +1,4 @@ -package org.apache.maven.tools.plugin.annotations.scanner; +package org.apache.maven.tools.plugin.annotations.datamodel; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/ComponentAnnotationContent.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/ComponentAnnotationContent.java similarity index 97% rename from maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/ComponentAnnotationContent.java rename to maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/ComponentAnnotationContent.java index 60e3f72..b7214cc 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/ComponentAnnotationContent.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/ComponentAnnotationContent.java @@ -1,4 +1,4 @@ -package org.apache.maven.tools.plugin.annotations.scanner; +package org.apache.maven.tools.plugin.annotations.datamodel; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/ExecuteAnnotationContent.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/ExecuteAnnotationContent.java new file mode 100644 index 0000000..3c597c6 --- /dev/null +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/ExecuteAnnotationContent.java @@ -0,0 +1,86 @@ +package org.apache.maven.tools.plugin.annotations.datamodel; +/* + * 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.tools.plugin.annotations.Execute; +import org.apache.maven.tools.plugin.annotations.LifecyclePhase; + +import java.lang.annotation.Annotation; + +/** + * @author Olivier Lamy + */ +public class ExecuteAnnotationContent + implements Execute +{ + private String goal; + + private String lifecycle; + + private LifecyclePhase phase; + + public LifecyclePhase phase() + { + return this.phase; + } + + public String goal() + { + return this.goal; + } + + public String lifecycle() + { + return this.lifecycle; + } + + + public void phase( String phase ) + { + this.phase = LifecyclePhase.valueOf( phase ); + } + + public void goal( String goal ) + { + this.goal = goal; + } + + public void lifecycle( String lifecycle ) + { + this.lifecycle = lifecycle; + } + + + public Class annotationType() + { + return null; + } + + @Override + public String toString() + { + final StringBuilder sb = new StringBuilder(); + sb.append( "ExecuteAnnotationContent" ); + sb.append( "{goal='" ).append( goal ).append( '\'' ); + sb.append( ", lifecycle='" ).append( lifecycle ).append( '\'' ); + sb.append( ", phase=" ).append( phase ); + sb.append( '}' ); + return sb.toString(); + } +} 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 new file mode 100644 index 0000000..8986633 --- /dev/null +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/MojoAnnotationContent.java @@ -0,0 +1,227 @@ +package org.apache.maven.tools.plugin.annotations.datamodel; +/* + * 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.tools.plugin.annotations.LifecyclePhase; +import org.apache.maven.tools.plugin.annotations.Mojo; + +import java.lang.annotation.Annotation; + +/** + * @author Olivier Lamy + */ +public class MojoAnnotationContent + implements Mojo +{ + private String name; + + private LifecyclePhase defaultPhase = LifecyclePhase.NONE; + + private String requiresDependencyResolution = "runtime"; + + private String requiresDependencyCollection = "runtime"; + + private String instantiationStrategy = "per-lookup"; + + private String executionStrategy = "once-per-session"; + + private boolean requiresProject = true; + + private boolean requiresReports = false; + + private boolean aggregator = false; + + private boolean requiresDirectInvocation = false; + + private boolean requiresOnline = false; + + private boolean inheritByDefault = true; + + private String configurator; + + private boolean threadSafe = false; + + public Class annotationType() + { + return null; + } + + public LifecyclePhase defaultPhase() + { + return defaultPhase; + } + + public void defaultPhase( String phase ) + { + this.defaultPhase = LifecyclePhase.valueOf( phase ); + } + + public String requiresDependencyResolution() + { + return requiresDependencyResolution; + } + + public void requiresDependencyResolution( String requiresDependencyResolution ) + { + this.requiresDependencyResolution = requiresDependencyResolution; + } + + public String requiresDependencyCollection() + { + return requiresDependencyCollection; + } + + public void requiresDependencyCollection( String requiresDependencyCollection ) + { + this.requiresDependencyCollection = requiresDependencyCollection; + } + + public String instantiationStrategy() + { + return instantiationStrategy; + } + + public void instantiationStrategy( String instantiationStrategy ) + { + this.instantiationStrategy = instantiationStrategy; + } + + public String executionStrategy() + { + return executionStrategy; + } + + public void executionStrategy( String executionStrategy ) + { + this.executionStrategy = executionStrategy; + } + + public boolean requiresProject() + { + return requiresProject; + } + + public void requiresProject( boolean requiresProject ) + { + this.requiresProject = requiresProject; + } + + public boolean requiresReports() + { + return requiresReports; + } + + public void requiresReports( boolean requiresReports ) + { + this.requiresReports = requiresReports; + } + + public boolean aggregator() + { + return aggregator; + } + + public void aggregator( boolean aggregator ) + { + this.aggregator = aggregator; + } + + public boolean requiresDirectInvocation() + { + return requiresDirectInvocation; + } + + public void requiresDirectInvocation( boolean requiresDirectInvocation ) + { + this.requiresDirectInvocation = requiresDirectInvocation; + } + + public boolean requiresOnline() + { + return requiresOnline; + } + + public void requiresOnline( boolean requiresOnline ) + { + this.requiresOnline = requiresOnline; + } + + public boolean inheritByDefault() + { + return inheritByDefault; + } + + public void inheritByDefault( boolean inheritByDefault ) + { + this.inheritByDefault = inheritByDefault; + } + + public String configurator() + { + return configurator; + } + + public void configurator( String configurator ) + { + this.configurator = configurator; + } + + public boolean threadSafe() + { + return threadSafe; + } + + public void threadSafe( boolean threadSafe ) + { + this.threadSafe = threadSafe; + } + + public String name() + { + return this.name; + } + + public void name( String name ) + { + this.name = name; + } + + @Override + public String toString() + { + final StringBuilder sb = new StringBuilder(); + sb.append( "MojoAnnotationContent" ); + sb.append( "{name='" ).append( name ).append( '\'' ); + sb.append( ", defaultPhase=" ).append( defaultPhase ); + sb.append( ", requiresDependencyResolution='" ).append( requiresDependencyResolution ).append( '\'' ); + sb.append( ", requiresDependencyCollection='" ).append( requiresDependencyCollection ).append( '\'' ); + sb.append( ", instantiationStrategy='" ).append( instantiationStrategy ).append( '\'' ); + sb.append( ", executionStrategy='" ).append( executionStrategy ).append( '\'' ); + sb.append( ", requiresProject=" ).append( requiresProject ); + sb.append( ", requiresReports=" ).append( requiresReports ); + sb.append( ", aggregator=" ).append( aggregator ); + sb.append( ", requiresDirectInvocation=" ).append( requiresDirectInvocation ); + sb.append( ", requiresOnline=" ).append( requiresOnline ); + sb.append( ", inheritByDefault=" ).append( inheritByDefault ); + sb.append( ", configurator='" ).append( configurator ).append( '\'' ); + sb.append( ", threadSafe=" ).append( threadSafe ); + sb.append( '}' ); + return sb.toString(); + } +} \ No newline at end of file diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/ParameterAnnotationContent.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/ParameterAnnotationContent.java similarity index 98% rename from maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/ParameterAnnotationContent.java rename to maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/ParameterAnnotationContent.java index bf20605..556ddbc 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/ParameterAnnotationContent.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/ParameterAnnotationContent.java @@ -1,4 +1,4 @@ -package org.apache.maven.tools.plugin.annotations.scanner; +package org.apache.maven.tools.plugin.annotations.datamodel; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java index cbe9b88..e02658a 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java @@ -22,6 +22,13 @@ import org.apache.maven.tools.plugin.annotations.Component; import org.apache.maven.tools.plugin.annotations.Execute; import org.apache.maven.tools.plugin.annotations.Mojo; import org.apache.maven.tools.plugin.annotations.Parameter; +import org.apache.maven.tools.plugin.annotations.datamodel.ComponentAnnotationContent; +import org.apache.maven.tools.plugin.annotations.datamodel.ExecuteAnnotationContent; +import org.apache.maven.tools.plugin.annotations.datamodel.MojoAnnotationContent; +import org.apache.maven.tools.plugin.annotations.datamodel.ParameterAnnotationContent; +import org.apache.maven.tools.plugin.annotations.scanner.visitors.MojoAnnotationVisitor; +import org.apache.maven.tools.plugin.annotations.scanner.visitors.MojoClassVisitor; +import org.apache.maven.tools.plugin.annotations.scanner.visitors.MojoFieldVisitor; import org.apache.maven.tools.plugin.extractor.ExtractionException; import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.util.DirectoryScanner; @@ -128,14 +135,11 @@ public class DefaultMojoAnnotationsScanner try { - MojoClassVisitor.MojoAnnotationVisitor mojoAnnotationVisitor = + MojoAnnotationVisitor mojoAnnotationVisitor = mojoClassVisitor.getAnnotationVisitorMap().get( Mojo.class.getName() ); if ( mojoAnnotationVisitor != null ) { - MojoClassVisitor.MojoAnnotationContent mojoAnnotationContent = - new MojoClassVisitor.MojoAnnotationContent(); - Class clazz = Thread.currentThread().getContextClassLoader().loadClass( - MojoClassVisitor.MojoAnnotationContent.class.getName() ); + MojoAnnotationContent mojoAnnotationContent = new MojoAnnotationContent(); for ( Map.Entry entry : mojoAnnotationVisitor.getAnnotationValues().entrySet() ) { reflector.invoke( mojoAnnotationContent, entry.getKey(), new Object[]{ entry.getValue() } ); @@ -146,10 +150,8 @@ public class DefaultMojoAnnotationsScanner mojoAnnotationVisitor = mojoClassVisitor.getAnnotationVisitorMap().get( Execute.class.getName() ); if ( mojoAnnotationVisitor != null ) { - MojoClassVisitor.ExecuteAnnotationContent executeAnnotationContent = - new MojoClassVisitor.ExecuteAnnotationContent(); - Class clazz = Thread.currentThread().getContextClassLoader().loadClass( - MojoClassVisitor.MojoAnnotationContent.class.getName() ); + ExecuteAnnotationContent executeAnnotationContent = new ExecuteAnnotationContent(); + for ( Map.Entry entry : mojoAnnotationVisitor.getAnnotationValues().entrySet() ) { reflector.invoke( executeAnnotationContent, entry.getKey(), new Object[]{ entry.getValue() } ); @@ -157,10 +159,10 @@ public class DefaultMojoAnnotationsScanner mojoClassVisitor.getMojoAnnotatedClass().setExecute( executeAnnotationContent ); } - List mojoFieldVisitors = + List mojoFieldVisitors = mojoClassVisitor.findFieldWithAnnotationClass( Parameter.class.getName() ); - for ( MojoClassVisitor.MojoFieldVisitor mojoFieldVisitor : mojoFieldVisitors ) + for ( MojoFieldVisitor mojoFieldVisitor : mojoFieldVisitors ) { ParameterAnnotationContent parameterAnnotationContent = new ParameterAnnotationContent( mojoFieldVisitor.getFieldName() ); @@ -178,7 +180,7 @@ public class DefaultMojoAnnotationsScanner mojoFieldVisitors = mojoClassVisitor.findFieldWithAnnotationClass( Component.class.getName() ); - for ( MojoClassVisitor.MojoFieldVisitor mojoFieldVisitor : mojoFieldVisitors ) + for ( MojoFieldVisitor mojoFieldVisitor : mojoFieldVisitors ) { ComponentAnnotationContent componentAnnotationContent = new ComponentAnnotationContent( mojoFieldVisitor.getFieldName() ); diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotatedClass.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotatedClass.java index 2721c18..91e63f5 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotatedClass.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotatedClass.java @@ -20,6 +20,8 @@ package org.apache.maven.tools.plugin.annotations.scanner; import org.apache.maven.tools.plugin.annotations.Execute; import org.apache.maven.tools.plugin.annotations.Mojo; +import org.apache.maven.tools.plugin.annotations.datamodel.ComponentAnnotationContent; +import org.apache.maven.tools.plugin.annotations.datamodel.ParameterAnnotationContent; import java.util.ArrayList; import java.util.List; diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoClassVisitor.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoClassVisitor.java deleted file mode 100644 index 53e9cac..0000000 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoClassVisitor.java +++ /dev/null @@ -1,524 +0,0 @@ -package org.apache.maven.tools.plugin.annotations.scanner; -/* - * 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.tools.plugin.annotations.Execute; -import org.apache.maven.tools.plugin.annotations.LifecyclePhase; -import org.apache.maven.tools.plugin.annotations.Mojo; -import org.codehaus.plexus.logging.Logger; -import org.codehaus.plexus.util.StringUtils; -import org.objectweb.asm.AnnotationVisitor; -import org.objectweb.asm.Attribute; -import org.objectweb.asm.ClassVisitor; -import org.objectweb.asm.FieldVisitor; -import org.objectweb.asm.MethodVisitor; -import org.objectweb.asm.Type; - -import java.lang.annotation.Annotation; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * @author Olivier Lamy - */ -public class MojoClassVisitor - implements ClassVisitor -{ - private Logger logger; - - private MojoAnnotatedClass mojoAnnotatedClass; - - private Map annotationVisitorMap = new HashMap(); - - private List fieldVisitors = new ArrayList(); - - public MojoClassVisitor( Logger logger ) - { - this.logger = logger; - } - - public MojoAnnotatedClass getMojoAnnotatedClass() - { - return mojoAnnotatedClass; - } - - public void setMojoAnnotatedClass( MojoAnnotatedClass mojoAnnotatedClass ) - { - this.mojoAnnotatedClass = mojoAnnotatedClass; - } - - public Map getAnnotationVisitorMap() - { - return annotationVisitorMap; - } - - public void setAnnotationVisitorMap( Map annotationVisitorMap ) - { - this.annotationVisitorMap = annotationVisitorMap; - } - - public List getFieldVisitors() - { - return fieldVisitors; - } - - public void setFieldVisitors( List fieldVisitors ) - { - this.fieldVisitors = fieldVisitors; - } - - public List findFieldWithAnnotationClass( String annotationClassName ) - { - List mojoFieldVisitors = new ArrayList(); - - for ( MojoFieldVisitor mojoFieldVisitor : this.fieldVisitors ) - { - MojoAnnotationVisitor mojoAnnotationVisitor = mojoFieldVisitor.getMojoAnnotationVisitor(); - if ( mojoAnnotationVisitor != null && StringUtils.equals( annotationClassName, - mojoAnnotationVisitor.annotationClassName ) ) - { - mojoFieldVisitors.add( mojoFieldVisitor ); - } - } - - return mojoFieldVisitors; - } - - public void visit( int version, int access, String name, String signature, String superName, String[] interfaces ) - { - mojoAnnotatedClass = new MojoAnnotatedClass(); - mojoAnnotatedClass.setClassName( Type.getObjectType( name ).getClassName() ).setParentClassName( - Type.getObjectType( superName ).getClassName() ); - logger.debug( "MojoClassVisitor#visit" ); - } - - public AnnotationVisitor visitAnnotation( String desc, boolean visible ) - { - logger.debug( "MojoClassVisitor#visitAnnotation" ); - String annotationClassName = Type.getType( desc ).getClassName(); - if ( !MojoAnnotationsScanner.acceptedClassLevelAnnotationClasses.contains( annotationClassName ) ) - { - return null; - } - MojoAnnotationVisitor mojoAnnotationVisitor = new MojoAnnotationVisitor( logger, annotationClassName ); - annotationVisitorMap.put( annotationClassName, mojoAnnotationVisitor ); - return mojoAnnotationVisitor; - } - - public FieldVisitor visitField( int access, String name, String desc, String signature, Object value ) - { - // Type.getType( desc ).getClassName() - logger.debug( "MojoClassVisitor#visitField" ); - MojoFieldVisitor mojoFieldVisitor = new MojoFieldVisitor( logger, name ); - fieldVisitors.add( mojoFieldVisitor ); - return mojoFieldVisitor; - } - - public MethodVisitor visitMethod( int access, String name, String desc, String signature, String[] exceptions ) - { - // we don't need methods informations - return null; - } - - public void visitAttribute( Attribute attr ) - { - } - - public void visitSource( String source, String debug ) - { - } - - public void visitOuterClass( String owner, String name, String desc ) - { - } - - public void visitInnerClass( String name, String outerName, String innerName, int access ) - { - } - - public void visitEnd() - { - logger.debug( "MojoClassVisitor#visitEnd" ); - } - - public static class MojoAnnotationContent - implements Mojo - { - - private String name; - - private LifecyclePhase defaultPhase = LifecyclePhase.NONE; - - private String requiresDependencyResolution = "runtime"; - - private String requiresDependencyCollection = "runtime"; - - private String instantiationStrategy = "per-lookup"; - - private String executionStrategy = "once-per-session"; - - private boolean requiresProject = true; - - private boolean requiresReports = false; - - private boolean aggregator = false; - - private boolean requiresDirectInvocation = false; - - private boolean requiresOnline = false; - - private boolean inheritByDefault = true; - - private String configurator; - - private boolean threadSafe = false; - - public Class annotationType() - { - return null; - } - - public LifecyclePhase defaultPhase() - { - return defaultPhase; - } - - public void defaultPhase( String phase ) - { - this.defaultPhase = LifecyclePhase.valueOf( phase ); - } - - public String requiresDependencyResolution() - { - return requiresDependencyResolution; - } - - public void requiresDependencyResolution( String requiresDependencyResolution ) - { - this.requiresDependencyResolution = requiresDependencyResolution; - } - - public String requiresDependencyCollection() - { - return requiresDependencyCollection; - } - - public void requiresDependencyCollection( String requiresDependencyCollection ) - { - this.requiresDependencyCollection = requiresDependencyCollection; - } - - public String instantiationStrategy() - { - return instantiationStrategy; - } - - public void instantiationStrategy( String instantiationStrategy ) - { - this.instantiationStrategy = instantiationStrategy; - } - - public String executionStrategy() - { - return executionStrategy; - } - - public void executionStrategy( String executionStrategy ) - { - this.executionStrategy = executionStrategy; - } - - public boolean requiresProject() - { - return requiresProject; - } - - public void requiresProject( boolean requiresProject ) - { - this.requiresProject = requiresProject; - } - - public boolean requiresReports() - { - return requiresReports; - } - - public void requiresReports( boolean requiresReports ) - { - this.requiresReports = requiresReports; - } - - public boolean aggregator() - { - return aggregator; - } - - public void aggregator( boolean aggregator ) - { - this.aggregator = aggregator; - } - - public boolean requiresDirectInvocation() - { - return requiresDirectInvocation; - } - - public void requiresDirectInvocation( boolean requiresDirectInvocation ) - { - this.requiresDirectInvocation = requiresDirectInvocation; - } - - public boolean requiresOnline() - { - return requiresOnline; - } - - public void requiresOnline( boolean requiresOnline ) - { - this.requiresOnline = requiresOnline; - } - - public boolean inheritByDefault() - { - return inheritByDefault; - } - - public void inheritByDefault( boolean inheritByDefault ) - { - this.inheritByDefault = inheritByDefault; - } - - public String configurator() - { - return configurator; - } - - public void configurator( String configurator ) - { - this.configurator = configurator; - } - - public boolean threadSafe() - { - return threadSafe; - } - - public void threadSafe( boolean threadSafe ) - { - this.threadSafe = threadSafe; - } - - public String name() - { - return this.name; - } - - public void name( String name ) - { - this.name = name; - } - - @Override - public String toString() - { - final StringBuilder sb = new StringBuilder(); - sb.append( "MojoAnnotationContent" ); - sb.append( "{name='" ).append( name ).append( '\'' ); - sb.append( ", defaultPhase=" ).append( defaultPhase ); - sb.append( ", requiresDependencyResolution='" ).append( requiresDependencyResolution ).append( '\'' ); - sb.append( ", requiresDependencyCollection='" ).append( requiresDependencyCollection ).append( '\'' ); - sb.append( ", instantiationStrategy='" ).append( instantiationStrategy ).append( '\'' ); - sb.append( ", executionStrategy='" ).append( executionStrategy ).append( '\'' ); - sb.append( ", requiresProject=" ).append( requiresProject ); - sb.append( ", requiresReports=" ).append( requiresReports ); - sb.append( ", aggregator=" ).append( aggregator ); - sb.append( ", requiresDirectInvocation=" ).append( requiresDirectInvocation ); - sb.append( ", requiresOnline=" ).append( requiresOnline ); - sb.append( ", inheritByDefault=" ).append( inheritByDefault ); - sb.append( ", configurator='" ).append( configurator ).append( '\'' ); - sb.append( ", threadSafe=" ).append( threadSafe ); - sb.append( '}' ); - return sb.toString(); - } - } - - public static class ExecuteAnnotationContent - implements Execute - { - - private String goal; - - private String lifecycle; - - private LifecyclePhase phase; - - public LifecyclePhase phase() - { - return this.phase; - } - - public String goal() - { - return this.goal; - } - - public String lifecycle() - { - return this.lifecycle; - } - - - public void phase( String phase ) - { - this.phase = LifecyclePhase.valueOf( phase ); - } - - public void goal( String goal ) - { - this.goal = goal; - } - - public void lifecycle( String lifecycle ) - { - this.lifecycle = lifecycle; - } - - - public Class annotationType() - { - return null; - } - - @Override - public String toString() - { - final StringBuilder sb = new StringBuilder(); - sb.append( "ExecuteAnnotationContent" ); - sb.append( "{goal='" ).append( goal ).append( '\'' ); - sb.append( ", lifecycle='" ).append( lifecycle ).append( '\'' ); - sb.append( ", phase=" ).append( phase ); - sb.append( '}' ); - return sb.toString(); - } - } - - //------------------------------------- - // internal classes - //------------------------------------- - static class MojoAnnotationVisitor - implements AnnotationVisitor - { - - private Logger logger; - - private String annotationClassName; - - private Map annotationValues = new HashMap(); - - MojoAnnotationVisitor( Logger logger, String annotationClassName ) - { - this.logger = logger; - this.annotationClassName = annotationClassName; - } - - public Map getAnnotationValues() - { - return annotationValues; - } - - public void visit( String name, Object value ) - { - annotationValues.put( name, value ); - logger.debug( "MojoAnnotationVisitor#visit:" + name + ":" + value ); - } - - public void visitEnum( String name, String desc, String value ) - { - annotationValues.put( name, value ); - logger.debug( "MojoAnnotationVisitor#visitEnum:" + name + ":" + desc + ":" + value ); - } - - public AnnotationVisitor visitAnnotation( String name, String desc ) - { - logger.debug( "MojoAnnotationVisitor#visitAnnotation:" + name + ":" + desc ); - return new MojoAnnotationVisitor( logger, this.annotationClassName ); - } - - public AnnotationVisitor visitArray( String s ) - { - logger.debug( "MojoAnnotationVisitor#visitArray" ); - return new MojoAnnotationVisitor( logger, this.annotationClassName ); - } - - public void visitEnd() - { - logger.debug( "MojoAnnotationVisitor#visitEnd" ); - } - } - - static class MojoFieldVisitor - implements FieldVisitor - { - private Logger logger; - - private String fieldName; - - private MojoAnnotationVisitor mojoAnnotationVisitor; - - MojoFieldVisitor( Logger logger, String fieldName ) - { - this.logger = logger; - this.fieldName = fieldName; - } - - public MojoAnnotationVisitor getMojoAnnotationVisitor() - { - return mojoAnnotationVisitor; - } - - public String getFieldName() - { - return fieldName; - } - - public AnnotationVisitor visitAnnotation( String desc, boolean visible ) - { - logger.debug( "MojoFieldVisitor#visitAnnotation:" + desc ); - String annotationClassName = Type.getType( desc ).getClassName(); - if ( !MojoAnnotationsScanner.acceptedFieldLevelAnnotationClasses.contains( annotationClassName ) ) - { - return null; - } - mojoAnnotationVisitor = new MojoAnnotationVisitor( logger, annotationClassName ); - return mojoAnnotationVisitor; - } - - public void visitAttribute( Attribute attribute ) - { - logger.debug( "MojoFieldVisitor#visitAttribute" ); - } - - public void visitEnd() - { - logger.debug( "MojoFieldVisitor#visitEnd" ); - } - } -} diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/visitors/MojoAnnotationVisitor.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/visitors/MojoAnnotationVisitor.java new file mode 100644 index 0000000..175803a --- /dev/null +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/visitors/MojoAnnotationVisitor.java @@ -0,0 +1,83 @@ +package org.apache.maven.tools.plugin.annotations.scanner.visitors; +/* + * 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.codehaus.plexus.logging.Logger; +import org.objectweb.asm.AnnotationVisitor; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author Olivier Lamy + */ +public class MojoAnnotationVisitor + implements AnnotationVisitor +{ + private Logger logger; + + private String annotationClassName; + + private Map annotationValues = new HashMap(); + + MojoAnnotationVisitor( Logger logger, String annotationClassName ) + { + this.logger = logger; + this.annotationClassName = annotationClassName; + } + + public Map getAnnotationValues() + { + return annotationValues; + } + + public void visit( String name, Object value ) + { + annotationValues.put( name, value ); + logger.debug( "MojoAnnotationVisitor#visit:" + name + ":" + value ); + } + + public void visitEnum( String name, String desc, String value ) + { + annotationValues.put( name, value ); + logger.debug( "MojoAnnotationVisitor#visitEnum:" + name + ":" + desc + ":" + value ); + } + + public AnnotationVisitor visitAnnotation( String name, String desc ) + { + logger.debug( "MojoAnnotationVisitor#visitAnnotation:" + name + ":" + desc ); + return new MojoAnnotationVisitor( logger, this.annotationClassName ); + } + + public AnnotationVisitor visitArray( String s ) + { + logger.debug( "MojoAnnotationVisitor#visitArray" ); + return new MojoAnnotationVisitor( logger, this.annotationClassName ); + } + + public void visitEnd() + { + logger.debug( "MojoAnnotationVisitor#visitEnd" ); + } + + public String getAnnotationClassName() + { + return annotationClassName; + } +} diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/visitors/MojoClassVisitor.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/visitors/MojoClassVisitor.java new file mode 100644 index 0000000..673ba9f --- /dev/null +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/visitors/MojoClassVisitor.java @@ -0,0 +1,160 @@ +package org.apache.maven.tools.plugin.annotations.scanner.visitors; +/* + * 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.tools.plugin.annotations.scanner.MojoAnnotatedClass; +import org.apache.maven.tools.plugin.annotations.scanner.MojoAnnotationsScanner; +import org.codehaus.plexus.logging.Logger; +import org.codehaus.plexus.util.StringUtils; +import org.objectweb.asm.AnnotationVisitor; +import org.objectweb.asm.Attribute; +import org.objectweb.asm.ClassVisitor; +import org.objectweb.asm.FieldVisitor; +import org.objectweb.asm.MethodVisitor; +import org.objectweb.asm.Type; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author Olivier Lamy + */ +public class MojoClassVisitor + implements ClassVisitor +{ + private Logger logger; + + private MojoAnnotatedClass mojoAnnotatedClass; + + private Map annotationVisitorMap = new HashMap(); + + private List fieldVisitors = new ArrayList(); + + public MojoClassVisitor( Logger logger ) + { + this.logger = logger; + } + + public MojoAnnotatedClass getMojoAnnotatedClass() + { + return mojoAnnotatedClass; + } + + public void setMojoAnnotatedClass( MojoAnnotatedClass mojoAnnotatedClass ) + { + this.mojoAnnotatedClass = mojoAnnotatedClass; + } + + public Map getAnnotationVisitorMap() + { + return annotationVisitorMap; + } + + public void setAnnotationVisitorMap( Map annotationVisitorMap ) + { + this.annotationVisitorMap = annotationVisitorMap; + } + + public List getFieldVisitors() + { + return fieldVisitors; + } + + public void setFieldVisitors( List fieldVisitors ) + { + this.fieldVisitors = fieldVisitors; + } + + public List findFieldWithAnnotationClass( String annotationClassName ) + { + List mojoFieldVisitors = new ArrayList(); + + for ( MojoFieldVisitor mojoFieldVisitor : this.fieldVisitors ) + { + MojoAnnotationVisitor mojoAnnotationVisitor = mojoFieldVisitor.getMojoAnnotationVisitor(); + if ( mojoAnnotationVisitor != null && StringUtils.equals( annotationClassName, + mojoAnnotationVisitor.getAnnotationClassName() ) ) + { + mojoFieldVisitors.add( mojoFieldVisitor ); + } + } + + return mojoFieldVisitors; + } + + public void visit( int version, int access, String name, String signature, String superName, String[] interfaces ) + { + mojoAnnotatedClass = new MojoAnnotatedClass(); + mojoAnnotatedClass.setClassName( Type.getObjectType( name ).getClassName() ).setParentClassName( + Type.getObjectType( superName ).getClassName() ); + logger.debug( "MojoClassVisitor#visit" ); + } + + public AnnotationVisitor visitAnnotation( String desc, boolean visible ) + { + logger.debug( "MojoClassVisitor#visitAnnotation" ); + String annotationClassName = Type.getType( desc ).getClassName(); + if ( !MojoAnnotationsScanner.acceptedClassLevelAnnotationClasses.contains( annotationClassName ) ) + { + return null; + } + MojoAnnotationVisitor mojoAnnotationVisitor = new MojoAnnotationVisitor( logger, annotationClassName ); + annotationVisitorMap.put( annotationClassName, mojoAnnotationVisitor ); + return mojoAnnotationVisitor; + } + + public FieldVisitor visitField( int access, String name, String desc, String signature, Object value ) + { + // Type.getType( desc ).getClassName() + logger.debug( "MojoClassVisitor#visitField" ); + MojoFieldVisitor mojoFieldVisitor = new MojoFieldVisitor( logger, name ); + fieldVisitors.add( mojoFieldVisitor ); + return mojoFieldVisitor; + } + + public MethodVisitor visitMethod( int access, String name, String desc, String signature, String[] exceptions ) + { + // we don't need methods informations + return null; + } + + public void visitAttribute( Attribute attr ) + { + } + + public void visitSource( String source, String debug ) + { + } + + public void visitOuterClass( String owner, String name, String desc ) + { + } + + public void visitInnerClass( String name, String outerName, String innerName, int access ) + { + } + + public void visitEnd() + { + logger.debug( "MojoClassVisitor#visitEnd" ); + } + +} diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/visitors/MojoFieldVisitor.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/visitors/MojoFieldVisitor.java new file mode 100644 index 0000000..77fde45 --- /dev/null +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/visitors/MojoFieldVisitor.java @@ -0,0 +1,77 @@ +package org.apache.maven.tools.plugin.annotations.scanner.visitors; +/* + * 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.tools.plugin.annotations.scanner.MojoAnnotationsScanner; +import org.codehaus.plexus.logging.Logger; +import org.objectweb.asm.AnnotationVisitor; +import org.objectweb.asm.Attribute; +import org.objectweb.asm.FieldVisitor; +import org.objectweb.asm.Type; + +/** + * @author Olivier Lamy + */ +public class MojoFieldVisitor + implements FieldVisitor +{ + private Logger logger; + + private String fieldName; + + private MojoAnnotationVisitor mojoAnnotationVisitor; + + MojoFieldVisitor( Logger logger, String fieldName ) + { + this.logger = logger; + this.fieldName = fieldName; + } + + public MojoAnnotationVisitor getMojoAnnotationVisitor() + { + return mojoAnnotationVisitor; + } + + public String getFieldName() + { + return fieldName; + } + + public AnnotationVisitor visitAnnotation( String desc, boolean visible ) + { + logger.debug( "MojoFieldVisitor#visitAnnotation:" + desc ); + String annotationClassName = Type.getType( desc ).getClassName(); + if ( !MojoAnnotationsScanner.acceptedFieldLevelAnnotationClasses.contains( annotationClassName ) ) + { + return null; + } + mojoAnnotationVisitor = new MojoAnnotationVisitor( logger, annotationClassName ); + return mojoAnnotationVisitor; + } + + public void visitAttribute( Attribute attribute ) + { + logger.debug( "MojoFieldVisitor#visitAttribute" ); + } + + public void visitEnd() + { + logger.debug( "MojoFieldVisitor#visitEnd" ); + } +} diff --git a/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/TestAnnotationsReader.java b/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/TestAnnotationsReader.java index 586ba5f..70d2145 100644 --- a/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/TestAnnotationsReader.java +++ b/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/TestAnnotationsReader.java @@ -18,11 +18,11 @@ package org.apache.maven.tools.plugin.annotations; * under the License. */ -import org.apache.maven.tools.plugin.annotations.scanner.ComponentAnnotationContent; +import org.apache.maven.tools.plugin.annotations.datamodel.ComponentAnnotationContent; import org.apache.maven.tools.plugin.annotations.scanner.MojoAnnotatedClass; import org.apache.maven.tools.plugin.annotations.scanner.MojoAnnotationsScanner; import org.apache.maven.tools.plugin.annotations.scanner.MojoAnnotationsScannerRequest; -import org.apache.maven.tools.plugin.annotations.scanner.ParameterAnnotationContent; +import org.apache.maven.tools.plugin.annotations.datamodel.ParameterAnnotationContent; import org.codehaus.plexus.PlexusTestCase; import org.fest.assertions.Assertions; From 7575a489618e481a0f219fc0a08a1d31be641006 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 4 May 2012 10:00:32 +0000 Subject: [PATCH 09/48] test we have className and parentClassName after scanning git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1333837 13f79535-47bb-0310-9956-ffa450edef68 --- .../tools/plugin/annotations/TestAnnotationsReader.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/TestAnnotationsReader.java b/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/TestAnnotationsReader.java index 70d2145..e49b38f 100644 --- a/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/TestAnnotationsReader.java +++ b/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/TestAnnotationsReader.java @@ -18,11 +18,12 @@ package org.apache.maven.tools.plugin.annotations; * under the License. */ +import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.tools.plugin.annotations.datamodel.ComponentAnnotationContent; +import org.apache.maven.tools.plugin.annotations.datamodel.ParameterAnnotationContent; import org.apache.maven.tools.plugin.annotations.scanner.MojoAnnotatedClass; import org.apache.maven.tools.plugin.annotations.scanner.MojoAnnotationsScanner; import org.apache.maven.tools.plugin.annotations.scanner.MojoAnnotationsScannerRequest; -import org.apache.maven.tools.plugin.annotations.datamodel.ParameterAnnotationContent; import org.codehaus.plexus.PlexusTestCase; import org.fest.assertions.Assertions; @@ -54,6 +55,9 @@ public class TestAnnotationsReader MojoAnnotatedClass mojoAnnotatedClass = mojoAnnotatedClasses.get( 0 ); + assertEquals( FooMojo.class.getName(), mojoAnnotatedClass.getClassName() ); + assertEquals( AbstractMojo.class.getName(), mojoAnnotatedClass.getParentClassName() ); + Mojo mojo = mojoAnnotatedClass.getMojo(); assertEquals( "foo", mojo.name() ); From e2512e18592833604d307ff6fb4838b95f09c057 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 4 May 2012 10:00:53 +0000 Subject: [PATCH 10/48] [MPLUGIN-189] add a datamodel parent class with description,since and deprecated which need to parse with qdox git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1333839 13f79535-47bb-0310-9956-ffa450edef68 --- ...avaAnnotationsMojoDescriptorExtractor.java | 53 +++++++++++++++- .../datamodel/AnnotatedContent.java | 61 +++++++++++++++++++ .../annotations/datamodel/AnnotatedField.java | 1 + .../datamodel/MojoAnnotationContent.java | 1 + .../resources/META-INF/plexus/components.xml | 6 ++ 5 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/AnnotatedContent.java 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 9f1a05f..5de46e5 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 @@ -25,10 +25,16 @@ import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.project.MavenProject; import org.apache.maven.tools.plugin.DefaultPluginToolsRequest; import org.apache.maven.tools.plugin.PluginToolsRequest; +import org.apache.maven.tools.plugin.annotations.scanner.MojoAnnotatedClass; +import org.apache.maven.tools.plugin.annotations.scanner.MojoAnnotationsScanner; +import org.apache.maven.tools.plugin.annotations.scanner.MojoAnnotationsScannerRequest; import org.apache.maven.tools.plugin.extractor.ExtractionException; import org.apache.maven.tools.plugin.extractor.MojoDescriptorExtractor; import org.codehaus.plexus.logging.AbstractLogEnabled; +import java.io.File; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; /** @@ -39,6 +45,11 @@ public class JavaAnnotationsMojoDescriptorExtractor implements MojoDescriptorExtractor { + /** + * @requirement + */ + MojoAnnotationsScanner mojoAnnotationsScanner; + public List execute( MavenProject project, PluginDescriptor pluginDescriptor ) throws ExtractionException, InvalidPluginDescriptorException { @@ -50,12 +61,50 @@ public class JavaAnnotationsMojoDescriptorExtractor { try { - List classpathElements = request.getProject().getCompileClasspathElements(); - return null; //To change body of implemented methods use File | Settings | File Templates. + MojoAnnotationsScannerRequest mojoAnnotationsScannerRequest = new MojoAnnotationsScannerRequest(); + List classesDirectories = toFiles( request.getProject().getCompileClasspathElements() ); + mojoAnnotationsScannerRequest.setClassesDirectories( classesDirectories ); + + List mojoAnnotatedClasses = + mojoAnnotationsScanner.scan( mojoAnnotationsScannerRequest ); + + return toMojoDescriptors( mojoAnnotatedClasses ); } catch ( DependencyResolutionRequiredException e ) { throw new ExtractionException( e.getMessage(), e ); } } + + private List toFiles( List directories ) + { + if ( directories == null ) + { + return Collections.emptyList(); + } + List files = new ArrayList( directories.size() ); + for ( String directory : directories ) + { + files.add( new File( directory ) ); + } + return files; + } + + private List toMojoDescriptors( List mojoAnnotatedClasses ) + { + List mojoDescriptors = new ArrayList( mojoAnnotatedClasses.size() ); + for ( MojoAnnotatedClass mojoAnnotatedClass : mojoAnnotatedClasses ) + { + MojoDescriptor mojoDescriptor = new MojoDescriptor(); + + Mojo mojo = mojoAnnotatedClass.getMojo(); + + mojoDescriptor.setAggregator( mojo.aggregator() ); + mojoDescriptor.setDependencyResolutionRequired( mojo.requiresDependencyResolution() ); + mojoDescriptor.setDirectInvocationOnly( mojo.requiresDirectInvocation() ); + + mojoDescriptors.add( mojoDescriptor ); + } + return mojoDescriptors; + } } diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/AnnotatedContent.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/AnnotatedContent.java new file mode 100644 index 0000000..5f3cb55 --- /dev/null +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/AnnotatedContent.java @@ -0,0 +1,61 @@ +package org.apache.maven.tools.plugin.annotations.datamodel; +/* + * 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. + */ + +/** + * @author Olivier Lamy + */ +public class AnnotatedContent +{ + private String description; + + private String since; + + private String deprecated; + + public String getDescription() + { + return description; + } + + public void setDescription( String description ) + { + this.description = description; + } + + public String getSince() + { + return since; + } + + public void setSince( String since ) + { + this.since = since; + } + + public String getDeprecated() + { + return deprecated; + } + + public void setDeprecated( String deprecated ) + { + this.deprecated = deprecated; + } +} diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/AnnotatedField.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/AnnotatedField.java index cc9bf6d..0169206 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/AnnotatedField.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/AnnotatedField.java @@ -22,6 +22,7 @@ package org.apache.maven.tools.plugin.annotations.datamodel; * @author Olivier Lamy */ public class AnnotatedField + extends AnnotatedContent { private String fieldName; 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 8986633..fdbf6ae 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 @@ -27,6 +27,7 @@ import java.lang.annotation.Annotation; * @author Olivier Lamy */ public class MojoAnnotationContent + extends AnnotatedContent implements Mojo { private String name; diff --git a/maven-plugin-tools-annotations/src/main/resources/META-INF/plexus/components.xml b/maven-plugin-tools-annotations/src/main/resources/META-INF/plexus/components.xml index d7b2dbe..91df740 100644 --- a/maven-plugin-tools-annotations/src/main/resources/META-INF/plexus/components.xml +++ b/maven-plugin-tools-annotations/src/main/resources/META-INF/plexus/components.xml @@ -30,6 +30,12 @@ org.apache.maven.tools.plugin.extractor.MojoDescriptorExtractor java-annotations org.apache.maven.tools.plugin.annotations.JavaAnnotationsMojoDescriptorExtractor + + + org.apache.maven.tools.plugin.annotations.scanner.MojoAnnotationsScanner + default + + From ef09ac0dcb76efd161a5459891d5353a6a262797 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 4 May 2012 10:01:14 +0000 Subject: [PATCH 11/48] add missing @since 3.0 git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1333840 13f79535-47bb-0310-9956-ffa450edef68 --- .../annotations/JavaAnnotationsMojoDescriptorExtractor.java | 1 + .../tools/plugin/annotations/datamodel/AnnotatedContent.java | 1 + .../maven/tools/plugin/annotations/datamodel/AnnotatedField.java | 1 + .../plugin/annotations/datamodel/ComponentAnnotationContent.java | 1 + .../plugin/annotations/datamodel/ExecuteAnnotationContent.java | 1 + .../plugin/annotations/datamodel/MojoAnnotationContent.java | 1 + .../plugin/annotations/datamodel/ParameterAnnotationContent.java | 1 + .../annotations/scanner/DefaultMojoAnnotationsScanner.java | 1 + .../tools/plugin/annotations/scanner/MojoAnnotatedClass.java | 1 + .../tools/plugin/annotations/scanner/MojoAnnotationsScanner.java | 1 + .../annotations/scanner/MojoAnnotationsScannerRequest.java | 1 + .../annotations/scanner/visitors/MojoAnnotationVisitor.java | 1 + .../plugin/annotations/scanner/visitors/MojoClassVisitor.java | 1 + .../plugin/annotations/scanner/visitors/MojoFieldVisitor.java | 1 + 14 files changed, 14 insertions(+) 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 5de46e5..0d0843c 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 @@ -39,6 +39,7 @@ import java.util.List; /** * @author Olivier Lamy + * @since 3.0 */ public class JavaAnnotationsMojoDescriptorExtractor extends AbstractLogEnabled diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/AnnotatedContent.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/AnnotatedContent.java index 5f3cb55..fb687ca 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/AnnotatedContent.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/AnnotatedContent.java @@ -20,6 +20,7 @@ package org.apache.maven.tools.plugin.annotations.datamodel; /** * @author Olivier Lamy + * @since 3.0 */ public class AnnotatedContent { diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/AnnotatedField.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/AnnotatedField.java index 0169206..271e29e 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/AnnotatedField.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/AnnotatedField.java @@ -20,6 +20,7 @@ package org.apache.maven.tools.plugin.annotations.datamodel; /** * @author Olivier Lamy + * @since 3.0 */ public class AnnotatedField extends AnnotatedContent diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/ComponentAnnotationContent.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/ComponentAnnotationContent.java index b7214cc..bd7aad4 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/ComponentAnnotationContent.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/ComponentAnnotationContent.java @@ -24,6 +24,7 @@ import java.lang.annotation.Annotation; /** * @author Olivier Lamy + * @since 3.0 */ public class ComponentAnnotationContent extends AnnotatedField diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/ExecuteAnnotationContent.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/ExecuteAnnotationContent.java index 3c597c6..270960d 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/ExecuteAnnotationContent.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/ExecuteAnnotationContent.java @@ -25,6 +25,7 @@ import java.lang.annotation.Annotation; /** * @author Olivier Lamy + * @since 3.0 */ public class ExecuteAnnotationContent implements Execute 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 fdbf6ae..691f701 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 @@ -25,6 +25,7 @@ import java.lang.annotation.Annotation; /** * @author Olivier Lamy + * @since 3.0 */ public class MojoAnnotationContent extends AnnotatedContent diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/ParameterAnnotationContent.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/ParameterAnnotationContent.java index 556ddbc..e3212ba 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/ParameterAnnotationContent.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/ParameterAnnotationContent.java @@ -24,6 +24,7 @@ import java.lang.annotation.Annotation; /** * @author Olivier Lamy + * @since 3.0 */ public class ParameterAnnotationContent extends AnnotatedField diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java index e02658a..f33b92e 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java @@ -47,6 +47,7 @@ import java.util.Map; /** * @author Olivier Lamy + * @since 3.0 */ public class DefaultMojoAnnotationsScanner extends AbstractLogEnabled diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotatedClass.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotatedClass.java index 91e63f5..6c1dc16 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotatedClass.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotatedClass.java @@ -28,6 +28,7 @@ import java.util.List; /** * @author Olivier Lamy + * @since 3.0 */ public class MojoAnnotatedClass { diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotationsScanner.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotationsScanner.java index 9a0a4b0..9561755 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotationsScanner.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotationsScanner.java @@ -29,6 +29,7 @@ import java.util.List; /** * @author Olivier Lamy + * @since 3.0 */ public interface MojoAnnotationsScanner { diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotationsScannerRequest.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotationsScannerRequest.java index 7534b88..343a571 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotationsScannerRequest.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotationsScannerRequest.java @@ -25,6 +25,7 @@ import java.util.List; /** * @author Olivier Lamy + * @since 3.0 */ public class MojoAnnotationsScannerRequest { diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/visitors/MojoAnnotationVisitor.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/visitors/MojoAnnotationVisitor.java index 175803a..1367107 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/visitors/MojoAnnotationVisitor.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/visitors/MojoAnnotationVisitor.java @@ -26,6 +26,7 @@ import java.util.Map; /** * @author Olivier Lamy + * @since 3.0 */ public class MojoAnnotationVisitor implements AnnotationVisitor diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/visitors/MojoClassVisitor.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/visitors/MojoClassVisitor.java index 673ba9f..fe2178a 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/visitors/MojoClassVisitor.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/visitors/MojoClassVisitor.java @@ -36,6 +36,7 @@ import java.util.Map; /** * @author Olivier Lamy + * @since 3.0 */ public class MojoClassVisitor implements ClassVisitor diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/visitors/MojoFieldVisitor.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/visitors/MojoFieldVisitor.java index 77fde45..2b704a0 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/visitors/MojoFieldVisitor.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/visitors/MojoFieldVisitor.java @@ -27,6 +27,7 @@ import org.objectweb.asm.Type; /** * @author Olivier Lamy + * @since 3.0 */ public class MojoFieldVisitor implements FieldVisitor From 58fd60087197f87ed066b7b4aa1e27926ee0d85e Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 4 May 2012 10:01:23 +0000 Subject: [PATCH 12/48] missing license header in pom git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1333841 13f79535-47bb-0310-9956-ffa450edef68 --- maven-plugin-tools-annotations/pom.xml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/maven-plugin-tools-annotations/pom.xml b/maven-plugin-tools-annotations/pom.xml index 56eb0f3..32ca3e8 100644 --- a/maven-plugin-tools-annotations/pom.xml +++ b/maven-plugin-tools-annotations/pom.xml @@ -1,4 +1,22 @@ + 4.0.0 From 193f03e40434c6ebfb9fe861969a47ba80f06325 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 4 May 2012 10:01:39 +0000 Subject: [PATCH 13/48] expose datamodel classes for Mojo and Execute annotations git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1333842 13f79535-47bb-0310-9956-ffa450edef68 --- .../JavaAnnotationsMojoDescriptorExtractor.java | 5 +++-- .../annotations/scanner/MojoAnnotatedClass.java | 16 ++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) 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 0d0843c..c6e2a29 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 @@ -25,6 +25,7 @@ import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.project.MavenProject; import org.apache.maven.tools.plugin.DefaultPluginToolsRequest; import org.apache.maven.tools.plugin.PluginToolsRequest; +import org.apache.maven.tools.plugin.annotations.datamodel.MojoAnnotationContent; import org.apache.maven.tools.plugin.annotations.scanner.MojoAnnotatedClass; import org.apache.maven.tools.plugin.annotations.scanner.MojoAnnotationsScanner; import org.apache.maven.tools.plugin.annotations.scanner.MojoAnnotationsScannerRequest; @@ -98,12 +99,12 @@ public class JavaAnnotationsMojoDescriptorExtractor { MojoDescriptor mojoDescriptor = new MojoDescriptor(); - Mojo mojo = mojoAnnotatedClass.getMojo(); + MojoAnnotationContent mojo = mojoAnnotatedClass.getMojo(); mojoDescriptor.setAggregator( mojo.aggregator() ); mojoDescriptor.setDependencyResolutionRequired( mojo.requiresDependencyResolution() ); mojoDescriptor.setDirectInvocationOnly( mojo.requiresDirectInvocation() ); - + mojoDescriptor.setDeprecated( mojo.getDeprecated() ); mojoDescriptors.add( mojoDescriptor ); } return mojoDescriptors; diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotatedClass.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotatedClass.java index 6c1dc16..6ac7872 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotatedClass.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotatedClass.java @@ -18,9 +18,9 @@ package org.apache.maven.tools.plugin.annotations.scanner; * under the License. */ -import org.apache.maven.tools.plugin.annotations.Execute; -import org.apache.maven.tools.plugin.annotations.Mojo; import org.apache.maven.tools.plugin.annotations.datamodel.ComponentAnnotationContent; +import org.apache.maven.tools.plugin.annotations.datamodel.ExecuteAnnotationContent; +import org.apache.maven.tools.plugin.annotations.datamodel.MojoAnnotationContent; import org.apache.maven.tools.plugin.annotations.datamodel.ParameterAnnotationContent; import java.util.ArrayList; @@ -36,9 +36,9 @@ public class MojoAnnotatedClass private String parentClassName; - private Mojo mojo; + private MojoAnnotationContent mojo; - private Execute execute; + private ExecuteAnnotationContent execute; private List parameters; @@ -60,23 +60,23 @@ public class MojoAnnotatedClass return this; } - public Mojo getMojo() + public MojoAnnotationContent getMojo() { return mojo; } - public MojoAnnotatedClass setMojo( Mojo mojo ) + public MojoAnnotatedClass setMojo( MojoAnnotationContent mojo ) { this.mojo = mojo; return this; } - public Execute getExecute() + public ExecuteAnnotationContent getExecute() { return execute; } - public MojoAnnotatedClass setExecute( Execute execute ) + public MojoAnnotatedClass setExecute( ExecuteAnnotationContent execute ) { this.execute = execute; return this; From bd7823e5394e9e424eb1548d60c949ee88f20624 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 4 May 2012 10:01:52 +0000 Subject: [PATCH 14/48] [MPLUGIN-189] datamodel to MojoDescriptor git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1333843 13f79535-47bb-0310-9956-ffa450edef68 --- ...avaAnnotationsMojoDescriptorExtractor.java | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) 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 c6e2a29..9b7e1b8 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 @@ -19,13 +19,18 @@ package org.apache.maven.tools.plugin.annotations; */ import org.apache.maven.artifact.DependencyResolutionRequiredException; +import org.apache.maven.plugin.descriptor.DuplicateParameterException; import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException; import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.PluginDescriptor; +import org.apache.maven.plugin.descriptor.Requirement; import org.apache.maven.project.MavenProject; import org.apache.maven.tools.plugin.DefaultPluginToolsRequest; import org.apache.maven.tools.plugin.PluginToolsRequest; +import org.apache.maven.tools.plugin.annotations.datamodel.ComponentAnnotationContent; +import org.apache.maven.tools.plugin.annotations.datamodel.ExecuteAnnotationContent; import org.apache.maven.tools.plugin.annotations.datamodel.MojoAnnotationContent; +import org.apache.maven.tools.plugin.annotations.datamodel.ParameterAnnotationContent; import org.apache.maven.tools.plugin.annotations.scanner.MojoAnnotatedClass; import org.apache.maven.tools.plugin.annotations.scanner.MojoAnnotationsScanner; import org.apache.maven.tools.plugin.annotations.scanner.MojoAnnotationsScannerRequest; @@ -93,6 +98,7 @@ public class JavaAnnotationsMojoDescriptorExtractor } private List toMojoDescriptors( List mojoAnnotatedClasses ) + throws DuplicateParameterException { List mojoDescriptors = new ArrayList( mojoAnnotatedClasses.size() ); for ( MojoAnnotatedClass mojoAnnotatedClass : mojoAnnotatedClasses ) @@ -100,11 +106,53 @@ public class JavaAnnotationsMojoDescriptorExtractor MojoDescriptor mojoDescriptor = new MojoDescriptor(); MojoAnnotationContent mojo = mojoAnnotatedClass.getMojo(); + ExecuteAnnotationContent execute = mojoAnnotatedClass.getExecute(); mojoDescriptor.setAggregator( mojo.aggregator() ); mojoDescriptor.setDependencyResolutionRequired( mojo.requiresDependencyResolution() ); mojoDescriptor.setDirectInvocationOnly( mojo.requiresDirectInvocation() ); mojoDescriptor.setDeprecated( mojo.getDeprecated() ); + + mojoDescriptor.setExecuteGoal( execute.goal() ); + mojoDescriptor.setExecuteLifecycle( execute.lifecycle() ); + mojoDescriptor.setExecutePhase( execute.phase().id() ); + + mojoDescriptor.setExecutionStrategy( mojo.executionStrategy() ); + // FIXME olamy wtf ? + //mojoDescriptor.alwaysExecute(mojo.a) + + mojoDescriptor.setGoal( mojo.name() ); + mojoDescriptor.setOnlineRequired( mojo.requiresOnline() ); + + mojoDescriptor.setPhase( mojo.defaultPhase().id() ); + mojoDescriptor.setLanguage( "java" ); + + for ( ParameterAnnotationContent parameterAnnotationContent : mojoAnnotatedClass.getParameters() ) + { + org.apache.maven.plugin.descriptor.Parameter parameter = + new org.apache.maven.plugin.descriptor.Parameter(); + parameter.setName( parameterAnnotationContent.getFieldName() ); + parameter.setAlias( parameterAnnotationContent.alias() ); + parameter.setDefaultValue( parameterAnnotationContent.defaultValue() ); + parameter.setDeprecated( parameterAnnotationContent.getDeprecated() ); + parameter.setDescription( parameterAnnotationContent.getDescription() ); + // FIXME olamy wtf ? + parameter.setEditable( !parameterAnnotationContent.readonly() ); + parameter.setExpression( parameterAnnotationContent.expression() ); + mojoDescriptor.addParameter( parameter ); + } + + for ( ComponentAnnotationContent componentAnnotationContent : mojoAnnotatedClass.getComponents() ) + { + org.apache.maven.plugin.descriptor.Parameter parameter = + new org.apache.maven.plugin.descriptor.Parameter(); + parameter.setName( componentAnnotationContent.getFieldName() ); + parameter.setRequirement( + new Requirement( componentAnnotationContent.role(), componentAnnotationContent.roleHint() ) ); + parameter.setEditable( false ); + mojoDescriptor.addParameter( parameter ); + } + mojoDescriptors.add( mojoDescriptor ); } return mojoDescriptors; From 581a5da6417803610c628b6dc79d0ca057279f69 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 4 May 2012 10:02:40 +0000 Subject: [PATCH 15/48] move annotations to an other artifacts: users only need annotations and the whole content of the scan tooling git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1333844 13f79535-47bb-0310-9956-ffa450edef68 --- maven-plugin-annotations/pom.xml | 13 +++++++++++++ .../maven/plugins}/annotations/Component.java | 2 +- .../apache/maven/plugins}/annotations/Execute.java | 2 +- .../maven/plugins}/annotations/LifecyclePhase.java | 2 +- .../org/apache/maven/plugins}/annotations/Mojo.java | 2 +- .../maven/plugins}/annotations/Parameter.java | 2 +- maven-plugin-plugin/pom.xml | 12 ++++++++++++ maven-plugin-tools-annotations/pom.xml | 4 ++++ .../datamodel/ComponentAnnotationContent.java | 3 ++- .../datamodel/ExecuteAnnotationContent.java | 4 ++-- .../datamodel/MojoAnnotationContent.java | 4 ++-- .../datamodel/ParameterAnnotationContent.java | 2 +- .../scanner/DefaultMojoAnnotationsScanner.java | 8 ++++---- .../annotations/scanner/MojoAnnotationsScanner.java | 8 ++++---- .../maven/tools/plugin/annotations/FooMojo.java | 5 +++++ .../plugin/annotations/TestAnnotationsReader.java | 3 +++ pom.xml | 6 ++++++ 17 files changed, 63 insertions(+), 19 deletions(-) create mode 100644 maven-plugin-annotations/pom.xml rename {maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin => maven-plugin-annotations/src/main/java/org/apache/maven/plugins}/annotations/Component.java (96%) rename {maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin => maven-plugin-annotations/src/main/java/org/apache/maven/plugins}/annotations/Execute.java (96%) rename {maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin => maven-plugin-annotations/src/main/java/org/apache/maven/plugins}/annotations/LifecyclePhase.java (97%) rename {maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin => maven-plugin-annotations/src/main/java/org/apache/maven/plugins}/annotations/Mojo.java (97%) rename {maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin => maven-plugin-annotations/src/main/java/org/apache/maven/plugins}/annotations/Parameter.java (96%) diff --git a/maven-plugin-annotations/pom.xml b/maven-plugin-annotations/pom.xml new file mode 100644 index 0000000..4f0975f --- /dev/null +++ b/maven-plugin-annotations/pom.xml @@ -0,0 +1,13 @@ + + + 4.0.0 + + maven-plugin-tools + org.apache.maven.plugin-tools + 3.0-SNAPSHOT + + + + maven-plugin-annotations + + diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/Component.java b/maven-plugin-annotations/src/main/java/org/apache/maven/plugins/annotations/Component.java similarity index 96% rename from maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/Component.java rename to maven-plugin-annotations/src/main/java/org/apache/maven/plugins/annotations/Component.java index 95b1e83..f1607f1 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/Component.java +++ b/maven-plugin-annotations/src/main/java/org/apache/maven/plugins/annotations/Component.java @@ -1,4 +1,4 @@ -package org.apache.maven.tools.plugin.annotations; +package org.apache.maven.plugins.annotations; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/Execute.java b/maven-plugin-annotations/src/main/java/org/apache/maven/plugins/annotations/Execute.java similarity index 96% rename from maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/Execute.java rename to maven-plugin-annotations/src/main/java/org/apache/maven/plugins/annotations/Execute.java index 3b13bfb..3d6cca4 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/Execute.java +++ b/maven-plugin-annotations/src/main/java/org/apache/maven/plugins/annotations/Execute.java @@ -1,4 +1,4 @@ -package org.apache.maven.tools.plugin.annotations; +package org.apache.maven.plugins.annotations; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/LifecyclePhase.java b/maven-plugin-annotations/src/main/java/org/apache/maven/plugins/annotations/LifecyclePhase.java similarity index 97% rename from maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/LifecyclePhase.java rename to maven-plugin-annotations/src/main/java/org/apache/maven/plugins/annotations/LifecyclePhase.java index 3db6bf1..75bb163 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/LifecyclePhase.java +++ b/maven-plugin-annotations/src/main/java/org/apache/maven/plugins/annotations/LifecyclePhase.java @@ -1,4 +1,4 @@ -package org.apache.maven.tools.plugin.annotations; +package org.apache.maven.plugins.annotations; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/Mojo.java b/maven-plugin-annotations/src/main/java/org/apache/maven/plugins/annotations/Mojo.java similarity index 97% rename from maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/Mojo.java rename to maven-plugin-annotations/src/main/java/org/apache/maven/plugins/annotations/Mojo.java index 2e1099f..c102b29 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/Mojo.java +++ b/maven-plugin-annotations/src/main/java/org/apache/maven/plugins/annotations/Mojo.java @@ -1,4 +1,4 @@ -package org.apache.maven.tools.plugin.annotations; +package org.apache.maven.plugins.annotations; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/Parameter.java b/maven-plugin-annotations/src/main/java/org/apache/maven/plugins/annotations/Parameter.java similarity index 96% rename from maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/Parameter.java rename to maven-plugin-annotations/src/main/java/org/apache/maven/plugins/annotations/Parameter.java index 4db182a..ae1cc0a 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/Parameter.java +++ b/maven-plugin-annotations/src/main/java/org/apache/maven/plugins/annotations/Parameter.java @@ -1,4 +1,4 @@ -package org.apache.maven.tools.plugin.annotations; +package org.apache.maven.plugins.annotations; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file diff --git a/maven-plugin-plugin/pom.xml b/maven-plugin-plugin/pom.xml index 9c47c73..1475eb7 100644 --- a/maven-plugin-plugin/pom.xml +++ b/maven-plugin-plugin/pom.xml @@ -83,6 +83,11 @@ maven-plugin-tools-java ${project.version} + + org.apache.maven.plugin-tools + maven-plugin-tools-annotations + ${project.version} + org.apache.maven.plugin-tools maven-plugin-tools-beanshell @@ -160,6 +165,7 @@ org.apache.maven.plugin-tools maven-plugin-tools-api + org.apache.maven maven-artifact-manager @@ -195,6 +201,12 @@ runtime + + org.apache.maven.plugin-tools + maven-plugin-tools-annotations + runtime + + org.codehaus.plexus diff --git a/maven-plugin-tools-annotations/pom.xml b/maven-plugin-tools-annotations/pom.xml index 32ca3e8..5ac0ecc 100644 --- a/maven-plugin-tools-annotations/pom.xml +++ b/maven-plugin-tools-annotations/pom.xml @@ -48,6 +48,10 @@ org.apache.maven.plugin-tools maven-plugin-tools-api + + org.apache.maven.plugin-tools + maven-plugin-annotations + org.codehaus.plexus diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/ComponentAnnotationContent.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/ComponentAnnotationContent.java index bd7aad4..18aeecc 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/ComponentAnnotationContent.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/ComponentAnnotationContent.java @@ -18,7 +18,8 @@ package org.apache.maven.tools.plugin.annotations.datamodel; * under the License. */ -import org.apache.maven.tools.plugin.annotations.Component; + +import org.apache.maven.plugins.annotations.Component; import java.lang.annotation.Annotation; diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/ExecuteAnnotationContent.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/ExecuteAnnotationContent.java index 270960d..c680f3b 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/ExecuteAnnotationContent.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/ExecuteAnnotationContent.java @@ -18,8 +18,8 @@ package org.apache.maven.tools.plugin.annotations.datamodel; * under the License. */ -import org.apache.maven.tools.plugin.annotations.Execute; -import org.apache.maven.tools.plugin.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Execute; +import org.apache.maven.plugins.annotations.LifecyclePhase; import java.lang.annotation.Annotation; 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 691f701..f01e7ec 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 @@ -18,8 +18,8 @@ package org.apache.maven.tools.plugin.annotations.datamodel; * under the License. */ -import org.apache.maven.tools.plugin.annotations.LifecyclePhase; -import org.apache.maven.tools.plugin.annotations.Mojo; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; import java.lang.annotation.Annotation; diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/ParameterAnnotationContent.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/ParameterAnnotationContent.java index e3212ba..0f6062f 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/ParameterAnnotationContent.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/ParameterAnnotationContent.java @@ -18,7 +18,7 @@ package org.apache.maven.tools.plugin.annotations.datamodel; * under the License. */ -import org.apache.maven.tools.plugin.annotations.Parameter; +import org.apache.maven.plugins.annotations.Parameter; import java.lang.annotation.Annotation; diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java index f33b92e..87ad59d 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java @@ -18,10 +18,10 @@ package org.apache.maven.tools.plugin.annotations.scanner; * under the License. */ -import org.apache.maven.tools.plugin.annotations.Component; -import org.apache.maven.tools.plugin.annotations.Execute; -import org.apache.maven.tools.plugin.annotations.Mojo; -import org.apache.maven.tools.plugin.annotations.Parameter; +import org.apache.maven.plugins.annotations.Component; +import org.apache.maven.plugins.annotations.Execute; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.tools.plugin.annotations.datamodel.ComponentAnnotationContent; import org.apache.maven.tools.plugin.annotations.datamodel.ExecuteAnnotationContent; import org.apache.maven.tools.plugin.annotations.datamodel.MojoAnnotationContent; diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotationsScanner.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotationsScanner.java index 9561755..c3a6179 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotationsScanner.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotationsScanner.java @@ -18,10 +18,10 @@ package org.apache.maven.tools.plugin.annotations.scanner; * under the License. */ -import org.apache.maven.tools.plugin.annotations.Component; -import org.apache.maven.tools.plugin.annotations.Execute; -import org.apache.maven.tools.plugin.annotations.Mojo; -import org.apache.maven.tools.plugin.annotations.Parameter; +import org.apache.maven.plugins.annotations.Component; +import org.apache.maven.plugins.annotations.Execute; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.tools.plugin.extractor.ExtractionException; import java.util.Arrays; diff --git a/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/FooMojo.java b/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/FooMojo.java index 9bf0d8e..765cc53 100644 --- a/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/FooMojo.java +++ b/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/FooMojo.java @@ -21,6 +21,11 @@ package org.apache.maven.tools.plugin.annotations; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; +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; +import org.apache.maven.plugins.annotations.Parameter; /** * @author Olivier Lamy diff --git a/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/TestAnnotationsReader.java b/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/TestAnnotationsReader.java index e49b38f..1bc5e7d 100644 --- a/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/TestAnnotationsReader.java +++ b/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/TestAnnotationsReader.java @@ -19,6 +19,9 @@ package org.apache.maven.tools.plugin.annotations; */ import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugins.annotations.Execute; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.tools.plugin.annotations.datamodel.ComponentAnnotationContent; import org.apache.maven.tools.plugin.annotations.datamodel.ParameterAnnotationContent; import org.apache.maven.tools.plugin.annotations.scanner.MojoAnnotatedClass; diff --git a/pom.xml b/pom.xml index cb73ded..e9934a6 100644 --- a/pom.xml +++ b/pom.xml @@ -131,6 +131,7 @@ maven-plugin-tools-model maven-plugin-tools-javadoc maven-plugin-tools-annotations + maven-plugin-annotations @@ -180,6 +181,11 @@ maven-plugin-tools-annotations ${project.version} + + org.apache.maven.plugin-tools + maven-plugin-annotations + ${project.version} + org.apache.maven.plugin-tools maven-plugin-tools-beanshell From ceb02db5b84a81e7619fd3e8a959b8d9c1639737 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 4 May 2012 10:02:49 +0000 Subject: [PATCH 16/48] missing ASF license header git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1333845 13f79535-47bb-0310-9956-ffa450edef68 --- maven-plugin-annotations/pom.xml | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/maven-plugin-annotations/pom.xml b/maven-plugin-annotations/pom.xml index 4f0975f..c794392 100644 --- a/maven-plugin-annotations/pom.xml +++ b/maven-plugin-annotations/pom.xml @@ -1,4 +1,22 @@ - + + 4.0.0 From 5e3bc49bf16f0637d302d2102035e0d0a7ea36d3 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 4 May 2012 10:03:05 +0000 Subject: [PATCH 17/48] add TODO for scanning dependencies and sources too for javadoc @since, @deprecated and comments git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1333846 13f79535-47bb-0310-9956-ffa450edef68 --- .../JavaAnnotationsMojoDescriptorExtractor.java | 8 ++++++-- .../scanner/DefaultMojoAnnotationsScanner.java | 10 +++++++++- .../scanner/MojoAnnotationsScannerRequest.java | 12 ++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) 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 9b7e1b8..b9cf49e 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 @@ -40,6 +40,7 @@ import org.codehaus.plexus.logging.AbstractLogEnabled; import java.io.File; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -69,8 +70,11 @@ public class JavaAnnotationsMojoDescriptorExtractor try { MojoAnnotationsScannerRequest mojoAnnotationsScannerRequest = new MojoAnnotationsScannerRequest(); - List classesDirectories = toFiles( request.getProject().getCompileClasspathElements() ); - mojoAnnotationsScannerRequest.setClassesDirectories( classesDirectories ); + + mojoAnnotationsScannerRequest.setClassesDirectories( + Arrays.asList( new File( request.getProject().getBuild().getOutputDirectory() ) ) ); + + mojoAnnotationsScannerRequest.setDependencies( request.getProject().getCompileClasspathElements() ); List mojoAnnotatedClasses = mojoAnnotationsScanner.scan( mojoAnnotationsScannerRequest ); diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java index 87ad59d..0a861aa 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java @@ -63,8 +63,16 @@ public class DefaultMojoAnnotationsScanner { for ( File classDirectory : request.getClassesDirectories() ) { - mojoAnnotatedClasses.addAll( scanDirectory( classDirectory, request.getIncludePatterns() ) ); + if ( classDirectory.exists() && classDirectory.isDirectory() ) + { + mojoAnnotatedClasses.addAll( scanDirectory( classDirectory, request.getIncludePatterns() ) ); + // TODO scan sources to get @since and @deprecated and description of classes and fields. + } } + + + //TODO scan dependencies to get super class annotations if exist request.getDependencies() + return mojoAnnotatedClasses; } catch ( IOException e ) diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotationsScannerRequest.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotationsScannerRequest.java index 343a571..faf1bb7 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotationsScannerRequest.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotationsScannerRequest.java @@ -35,6 +35,8 @@ public class MojoAnnotationsScannerRequest private List includePatterns = Arrays.asList( "**/*.class" ); + private List sourceDirectories = new ArrayList(); + public MojoAnnotationsScannerRequest() { // no o @@ -69,4 +71,14 @@ public class MojoAnnotationsScannerRequest { this.includePatterns = includePatterns; } + + public List getSourceDirectories() + { + return sourceDirectories; + } + + public void setSourceDirectories( List sourceDirectories ) + { + this.sourceDirectories = sourceDirectories; + } } From 5da55eb1be04d2637be00084286b41609c853638 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 4 May 2012 10:03:54 +0000 Subject: [PATCH 18/48] add an it test. add a flag to prevent error when using only annotations: no descriptors found extraction is bind to generate-sources in maven core for maven-plugin packaging so at this stage no classes available for scanning annotations git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1333847 13f79535-47bb-0310-9956-ffa450edef68 --- maven-plugin-plugin/pom.xml | 2 + .../java-basic-annotations/invoker.properties | 2 + .../src/it/java-basic-annotations/pom.xml | 75 +++++++++++++++++++ .../maven/plugin/coreit/CoreIt0014Mojo.java | 66 ++++++++++++++++ .../apache/maven/plugin/coreit/FirstMojo.java | 66 ++++++++++++++++ .../maven/plugin/coreit/SecondMojo.java | 38 ++++++++++ .../it/java-basic-annotations/verify.groovy | 72 ++++++++++++++++++ .../plugin/plugin/AbstractGeneratorMojo.java | 10 +++ .../plugin/DescriptorGeneratorMojo.java | 2 +- .../plugin/plugin/HelpGeneratorMojo.java | 2 +- ...avaAnnotationsMojoDescriptorExtractor.java | 23 ++++-- .../datamodel/ComponentAnnotationContent.java | 4 +- .../plugin/DefaultPluginToolsRequest.java | 18 +++++ .../tools/plugin/PluginToolsRequest.java | 32 ++++++-- .../plugin/scanner/DefaultMojoScanner.java | 29 ++++--- 15 files changed, 411 insertions(+), 30 deletions(-) create mode 100644 maven-plugin-plugin/src/it/java-basic-annotations/invoker.properties create mode 100644 maven-plugin-plugin/src/it/java-basic-annotations/pom.xml create mode 100644 maven-plugin-plugin/src/it/java-basic-annotations/src/main/java/org/apache/maven/plugin/coreit/CoreIt0014Mojo.java create mode 100644 maven-plugin-plugin/src/it/java-basic-annotations/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java create mode 100644 maven-plugin-plugin/src/it/java-basic-annotations/src/main/java/org/apache/maven/plugin/coreit/SecondMojo.java create mode 100644 maven-plugin-plugin/src/it/java-basic-annotations/verify.groovy diff --git a/maven-plugin-plugin/pom.xml b/maven-plugin-plugin/pom.xml index 1475eb7..c8c0300 100644 --- a/maven-plugin-plugin/pom.xml +++ b/maven-plugin-plugin/pom.xml @@ -62,6 +62,7 @@ 2.0.6 1.2 1.2 + true @@ -292,6 +293,7 @@ ${project.build.directory}/it ${project.build.directory}/local-repo + ${it.debug} 3.0 diff --git a/maven-plugin-plugin/src/it/java-basic-annotations/invoker.properties b/maven-plugin-plugin/src/it/java-basic-annotations/invoker.properties new file mode 100644 index 0000000..e8db4c3 --- /dev/null +++ b/maven-plugin-plugin/src/it/java-basic-annotations/invoker.properties @@ -0,0 +1,2 @@ +invoker.goals.1 = install +invoker.goals.2 = org.apache.maven.its.basic-java-annotations:maven-it-basic-java-annotations:1.0:it0014 diff --git a/maven-plugin-plugin/src/it/java-basic-annotations/pom.xml b/maven-plugin-plugin/src/it/java-basic-annotations/pom.xml new file mode 100644 index 0000000..6a95441 --- /dev/null +++ b/maven-plugin-plugin/src/it/java-basic-annotations/pom.xml @@ -0,0 +1,75 @@ + + + + + + 4.0.0 + + org.apache.maven.its.basic-java-annotations + maven-it-basic-java-annotations + 1.0 + maven-plugin + + Maven Integration Test :: basic-java-annotations + + Test plugin-plugin, which tests maven-plugin-tools-api and + maven-plugin-tools-java. This will generate a plugin descriptor from + java-based mojo sources, install the plugin, and then use it. + + + + UTF-8 + + + + + org.apache.maven + maven-plugin-api + 2.0 + + + org.apache.maven.plugin-tools + maven-plugin-annotations + @project.version@ + + + + + + + org.apache.maven.plugins + maven-plugin-plugin + @project.version@ + + true + + + + + descriptor + + mojo-descriptor + process-classes + + + + + + diff --git a/maven-plugin-plugin/src/it/java-basic-annotations/src/main/java/org/apache/maven/plugin/coreit/CoreIt0014Mojo.java b/maven-plugin-plugin/src/it/java-basic-annotations/src/main/java/org/apache/maven/plugin/coreit/CoreIt0014Mojo.java new file mode 100644 index 0000000..b6dc2fa --- /dev/null +++ b/maven-plugin-plugin/src/it/java-basic-annotations/src/main/java/org/apache/maven/plugin/coreit/CoreIt0014Mojo.java @@ -0,0 +1,66 @@ +package org.apache.maven.plugin.coreit; + +/* + * 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.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; + +import java.io.File; +import java.io.IOException; + +/** + * Touches a test file. + * + */ +@Mojo( name = "it0014") +public class CoreIt0014Mojo + extends AbstractMojo +{ + + @Parameter(expression ="${project.build.directory}", required = true) + private String outputDirectory; + + public void execute() + throws MojoExecutionException + { + getLog().info( "outputDirectory = " + outputDirectory ); + + File f = new File( outputDirectory ); + + if ( !f.exists() ) + { + f.mkdirs(); + } + + File touch = new File( f, "touch.txt" ); + + try + { + touch.createNewFile(); + } + catch ( IOException e ) + { + throw new MojoExecutionException( "Error writing verification file.", e ); + } + } + +} diff --git a/maven-plugin-plugin/src/it/java-basic-annotations/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java b/maven-plugin-plugin/src/it/java-basic-annotations/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java new file mode 100644 index 0000000..cee401d --- /dev/null +++ b/maven-plugin-plugin/src/it/java-basic-annotations/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java @@ -0,0 +1,66 @@ +package org.apache.maven.plugin.coreit; + +/* + * 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.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +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; +import org.apache.maven.plugins.annotations.Parameter; + +import java.io.File; + +/** + * Touches a test file. + * + * @since 1.2 + * @deprecated Don't use! + */ +@Mojo( name = "first", requiresDependencyResolution = "test", defaultPhase = LifecyclePhase.INTEGRATION_TEST ) +@Execute( phase = LifecyclePhase.GENERATE_SOURCES, lifecycle = "cobertura" ) +public class FirstMojo + extends AbstractMojo +{ + + @Parameter( defaultValue = "${basedir}", readonly = true ) + private File basedir; + + @Parameter( expression = "${first.touchFile}", defaultValue = "${project.build.directory}/touch.txt", + required = true ) + private File touchFile; + + /** + * @since 0.1 + * @deprecated As of 0.2 + */ + @Parameter( alias = "alias" ) + private String aliasedParam; + + @Component( role = "org.apache.maven.project.MavenProjectHelper", roleHint = "test" ) + private Object projectHelper; + + public void execute() + throws MojoExecutionException + { + } + +} diff --git a/maven-plugin-plugin/src/it/java-basic-annotations/src/main/java/org/apache/maven/plugin/coreit/SecondMojo.java b/maven-plugin-plugin/src/it/java-basic-annotations/src/main/java/org/apache/maven/plugin/coreit/SecondMojo.java new file mode 100644 index 0000000..8e28eba --- /dev/null +++ b/maven-plugin-plugin/src/it/java-basic-annotations/src/main/java/org/apache/maven/plugin/coreit/SecondMojo.java @@ -0,0 +1,38 @@ +package org.apache.maven.plugin.coreit; + +/* + * 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.plugin.AbstractMojo; +import org.apache.maven.plugins.annotations.Mojo; + +/** + * Does nothing special. + * + */ +@Mojo( name = "second",requiresDependencyCollection = "compile", threadSafe = true) +public class SecondMojo + extends AbstractMojo +{ + + public void execute() + { + } + +} diff --git a/maven-plugin-plugin/src/it/java-basic-annotations/verify.groovy b/maven-plugin-plugin/src/it/java-basic-annotations/verify.groovy new file mode 100644 index 0000000..3d274c5 --- /dev/null +++ b/maven-plugin-plugin/src/it/java-basic-annotations/verify.groovy @@ -0,0 +1,72 @@ +File touchFile = new File( basedir, "target/touch.txt" ) +assert touchFile.isFile() + +File descriptorFile = new File( basedir, "target/classes/META-INF/maven/plugin.xml" ); +assert descriptorFile.isFile() + +def pluginDescriptor = new XmlParser().parse( descriptorFile ); + +def mojo = pluginDescriptor.mojos.mojo.findAll{ it.goal.text() == "first"}[0] + +assert mojo.goal.text() == 'first' +assert mojo.implementation.text() == 'org.apache.maven.plugin.coreit.FirstMojo' +assert mojo.language.text() == 'java' +assert mojo.description.text() == 'Touches a test file.' +assert mojo.deprecated.text() == "Don't use!" +assert mojo.requiresDependencyResolution.text() == 'test' +assert mojo.requiresDependencyCollection.text() == '' +assert mojo.requiresProject.text() == 'true' +assert mojo.requiresOnline.text() == 'false' +assert mojo.requiresDirectInvocation.text() == 'false' +assert mojo.aggregator.text() == 'false' +assert mojo.threadSafe.text() == 'false' +assert mojo.phase.text() == 'integration-test' +assert mojo.executePhase.text() == 'generate-sources' +assert mojo.executeLifecycle.text() == 'cobertura' + +assert mojo.configuration.basedir[0].text() == '' +assert mojo.configuration.basedir[0].'@implementation' == 'java.io.File' +assert mojo.configuration.basedir[0].'@default-value' == '${basedir}' + +assert mojo.configuration.touchFile[0].text() == '${first.touchFile}' +assert mojo.configuration.touchFile[0].'@implementation' == 'java.io.File' +assert mojo.configuration.touchFile[0].'@default-value' == '${project.build.directory}/touch.txt' + +assert mojo.requirements.requirement.size() == 1 + +assert mojo.requirements.requirement[0].role.text() == 'org.apache.maven.project.MavenProjectHelper' +assert mojo.requirements.requirement[0].'role-hint'.text() == 'test' +assert mojo.requirements.requirement[0].'field-name'.text() == 'projectHelper' + +assert mojo.parameters.parameter.size() == 3 + +assert mojo.parameters.parameter[0].name.text() == 'aliasedParam' +assert mojo.parameters.parameter[0].alias.text() == 'alias' +assert mojo.parameters.parameter[0].type.text() == 'java.lang.String' +assert mojo.parameters.parameter[0].deprecated.text() == 'As of 0.2' +assert mojo.parameters.parameter[0].required.text() == 'false' +assert mojo.parameters.parameter[0].editable.text() == 'true' +assert mojo.parameters.parameter[0].description.text() == '' + +assert mojo.parameters.parameter[1].name.text() == 'basedir' +assert mojo.parameters.parameter[1].alias.isEmpty() +assert mojo.parameters.parameter[1].type.text() == 'java.io.File' +assert mojo.parameters.parameter[1].deprecated.isEmpty() +assert mojo.parameters.parameter[1].required.text() == 'false' +assert mojo.parameters.parameter[1].editable.text() == 'false' +assert mojo.parameters.parameter[1].description.text() == 'Project directory.' + +assert mojo.parameters.parameter[2].name.text() == 'touchFile' +assert mojo.parameters.parameter[2].alias.isEmpty() +assert mojo.parameters.parameter[2].type.text() == 'java.io.File' +assert mojo.parameters.parameter[2].deprecated.isEmpty() +assert mojo.parameters.parameter[2].required.text() == 'true' +assert mojo.parameters.parameter[2].editable.text() == 'true' +assert mojo.parameters.parameter[2].description.text() == '' + +mojo = pluginDescriptor.mojos.mojo.findAll{ it.goal.text() == "second"}[0] + +assert mojo.requiresDependencyCollection.text() == 'compile' +assert mojo.threadSafe.text() == 'true' + +return true; diff --git a/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/AbstractGeneratorMojo.java b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/AbstractGeneratorMojo.java index 13d1704..00702a6 100644 --- a/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/AbstractGeneratorMojo.java +++ b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/AbstractGeneratorMojo.java @@ -79,6 +79,15 @@ public abstract class AbstractGeneratorMojo */ protected String goalPrefix; + /** + * By default an exception is throw if no mojo descriptor is found. As the maven-plugin is defined in core, the + * descriptor generator mojo is bound to generate-resources phase. + * But for annotations, the compiled classes are needed, so skip error + * @parameter expression="${maven.plugin.skipErrorNoDescriptorsFound}" default-value="false" + * @since 3.0 + */ + protected boolean skipErrorNoDescriptorsFound; + /** * The role names of mojo extractors to use. *

@@ -193,6 +202,7 @@ public abstract class AbstractGeneratorMojo PluginToolsRequest request = new DefaultPluginToolsRequest( project, pluginDescriptor ); request.setEncoding( encoding ); + request.setSkipErrorNoDescriptorsFound( skipErrorNoDescriptorsFound ); mojoScanner.populatePluginDescriptor( request ); diff --git a/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/DescriptorGeneratorMojo.java b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/DescriptorGeneratorMojo.java index 9c63dd3..a125363 100644 --- a/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/DescriptorGeneratorMojo.java +++ b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/DescriptorGeneratorMojo.java @@ -34,7 +34,7 @@ import java.io.File; * @version $Id$ * @since 2.0 * @goal descriptor - * @phase generate-resources + * @phase process-classes * @requiresDependencyResolution runtime */ public class DescriptorGeneratorMojo diff --git a/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/HelpGeneratorMojo.java b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/HelpGeneratorMojo.java index 1bac881..bf20432 100644 --- a/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/HelpGeneratorMojo.java +++ b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/HelpGeneratorMojo.java @@ -32,7 +32,7 @@ import org.apache.maven.tools.plugin.generator.PluginHelpGenerator; * @version $Id$ * @since 2.4 * @goal helpmojo - * @phase generate-sources + * @phase process-classes */ public class HelpGeneratorMojo extends AbstractGeneratorMojo 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 b9cf49e..0fa534c 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 @@ -79,7 +79,7 @@ public class JavaAnnotationsMojoDescriptorExtractor List mojoAnnotatedClasses = mojoAnnotationsScanner.scan( mojoAnnotationsScannerRequest ); - return toMojoDescriptors( mojoAnnotatedClasses ); + return toMojoDescriptors( mojoAnnotatedClasses, request ); } catch ( DependencyResolutionRequiredException e ) { @@ -101,7 +101,8 @@ public class JavaAnnotationsMojoDescriptorExtractor return files; } - private List toMojoDescriptors( List mojoAnnotatedClasses ) + private List toMojoDescriptors( List mojoAnnotatedClasses, + PluginToolsRequest request ) throws DuplicateParameterException { List mojoDescriptors = new ArrayList( mojoAnnotatedClasses.size() ); @@ -109,17 +110,25 @@ public class JavaAnnotationsMojoDescriptorExtractor { MojoDescriptor mojoDescriptor = new MojoDescriptor(); + //mojoDescriptor.setRole( mojoAnnotatedClass.getClassName() ); + //mojoDescriptor.setRoleHint( "default" ); + mojoDescriptor.setImplementation( mojoAnnotatedClass.getClassName() ); + MojoAnnotationContent mojo = mojoAnnotatedClass.getMojo(); - ExecuteAnnotationContent execute = mojoAnnotatedClass.getExecute(); mojoDescriptor.setAggregator( mojo.aggregator() ); mojoDescriptor.setDependencyResolutionRequired( mojo.requiresDependencyResolution() ); mojoDescriptor.setDirectInvocationOnly( mojo.requiresDirectInvocation() ); mojoDescriptor.setDeprecated( mojo.getDeprecated() ); - mojoDescriptor.setExecuteGoal( execute.goal() ); - mojoDescriptor.setExecuteLifecycle( execute.lifecycle() ); - mojoDescriptor.setExecutePhase( execute.phase().id() ); + ExecuteAnnotationContent execute = mojoAnnotatedClass.getExecute(); + + if ( execute != null ) + { + mojoDescriptor.setExecuteGoal( execute.goal() ); + mojoDescriptor.setExecuteLifecycle( execute.lifecycle() ); + mojoDescriptor.setExecutePhase( execute.phase().id() ); + } mojoDescriptor.setExecutionStrategy( mojo.executionStrategy() ); // FIXME olamy wtf ? @@ -157,6 +166,8 @@ public class JavaAnnotationsMojoDescriptorExtractor mojoDescriptor.addParameter( parameter ); } + mojoDescriptor.setPluginDescriptor( request.getPluginDescriptor() ); + mojoDescriptors.add( mojoDescriptor ); } return mojoDescriptors; diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/ComponentAnnotationContent.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/ComponentAnnotationContent.java index 18aeecc..5fee961 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/ComponentAnnotationContent.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/ComponentAnnotationContent.java @@ -49,7 +49,7 @@ public class ComponentAnnotationContent public String role() { - return role; + return role == null ? "" : role; } public void role( String role ) @@ -59,7 +59,7 @@ public class ComponentAnnotationContent public String roleHint() { - return roleHint; + return roleHint == null ? "" : roleHint; } public void roleHint( String roleHint ) diff --git a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/DefaultPluginToolsRequest.java b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/DefaultPluginToolsRequest.java index fdbaa7f..fd6a60e 100644 --- a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/DefaultPluginToolsRequest.java +++ b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/DefaultPluginToolsRequest.java @@ -44,6 +44,8 @@ public class DefaultPluginToolsRequest private String encoding = DEFAULT_ENCODING; + private boolean skipErrorNoDescriptorsFound; + public DefaultPluginToolsRequest( MavenProject project, PluginDescriptor pluginDescriptor ) { this.project = project; @@ -109,4 +111,20 @@ public class DefaultPluginToolsRequest return this; } + /** + * {@inheritDoc} + */ + public boolean isSkipErrorNoDescriptorsFound() + { + return skipErrorNoDescriptorsFound; + } + + /** + * {@inheritDoc} + */ + public PluginToolsRequest setSkipErrorNoDescriptorsFound( boolean skipErrorNoDescriptorsFound ) + { + this.skipErrorNoDescriptorsFound = skipErrorNoDescriptorsFound; + return this; + } } diff --git a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/PluginToolsRequest.java b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/PluginToolsRequest.java index d670f12..531ad83 100644 --- a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/PluginToolsRequest.java +++ b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/PluginToolsRequest.java @@ -26,23 +26,23 @@ import org.apache.maven.project.MavenProject; /** * Request that encapsulates all information relevant to the process of extracting {@link MojoDescriptor} * instances from metadata for a certain type of mojo. - * + * * @author jdcasey * @since 2.5 */ public interface PluginToolsRequest { - + /** * Return the current {@link MavenProject} instance in use. */ MavenProject getProject(); - + /** * @see PluginToolsRequest#getProject() */ PluginToolsRequest setProject( MavenProject project ); - + /** * Return the {@link PluginDescriptor} currently being populated as part of the build of the * current plugin project. @@ -53,21 +53,37 @@ public interface PluginToolsRequest * @see PluginToolsRequest#getPluginDescriptor() */ PluginToolsRequest setPluginDescriptor( PluginDescriptor pluginDescriptor ); - + /** * Gets the file encoding of the source files. - * + * * @return The file encoding of the source files, never null. */ String getEncoding(); /** * Sets the file encoding of the source files. - * + * * @param encoding The file encoding of the source files, may be empty or null to use the platform's - * default encoding. + * default encoding. * @return This request. */ PluginToolsRequest setEncoding( String encoding ); + /** + * By default an exception is throw if no mojo descriptor is found. As the maven-plugin is defined in core, the + * descriptor generator mojo is bound to generate-resources phase. + * But for annotations, the compiled classes are needed, so skip error + * @since 3.0 + */ + PluginToolsRequest setSkipErrorNoDescriptorsFound( boolean skipErrorNoDescriptorsFound ); + + /** + * @since 3.0 + * @return + */ + boolean isSkipErrorNoDescriptorsFound(); + + + } diff --git a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/scanner/DefaultMojoScanner.java b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/scanner/DefaultMojoScanner.java index 1d5d8a2..05a2b1c 100644 --- a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/scanner/DefaultMojoScanner.java +++ b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/scanner/DefaultMojoScanner.java @@ -19,11 +19,6 @@ package org.apache.maven.tools.plugin.scanner; * under the License. */ -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException; import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.PluginDescriptor; @@ -36,6 +31,11 @@ import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.logging.console.ConsoleLogger; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + /** * @author jdcasey */ @@ -71,14 +71,18 @@ public class DefaultMojoScanner // nop } - /** {@inheritDoc} */ + /** + * {@inheritDoc} + */ public void populatePluginDescriptor( MavenProject project, PluginDescriptor pluginDescriptor ) throws ExtractionException, InvalidPluginDescriptorException { populatePluginDescriptor( new DefaultPluginToolsRequest( project, pluginDescriptor ) ); } - - /** {@inheritDoc} */ + + /** + * {@inheritDoc} + */ public void populatePluginDescriptor( PluginToolsRequest request ) throws ExtractionException, InvalidPluginDescriptorException { @@ -103,7 +107,7 @@ public class DefaultMojoScanner List extractorDescriptors = extractor.execute( request ); logger.info( "Mojo extractor for language: " + language + " found " + extractorDescriptors.size() - + " mojo descriptors." ); + + " mojo descriptors." ); numMojoDescriptors += extractorDescriptors.size(); for ( MojoDescriptor descriptor : extractorDescriptors ) @@ -116,10 +120,11 @@ public class DefaultMojoScanner } } - if ( numMojoDescriptors == 0 ) + if ( numMojoDescriptors == 0 && !request.isSkipErrorNoDescriptorsFound() ) { - throw new InvalidPluginDescriptorException( "No mojo definitions were found for plugin: " - + request.getPluginDescriptor().getPluginLookupKey() + "." ); + throw new InvalidPluginDescriptorException( + "No mojo definitions were found for plugin: " + request.getPluginDescriptor().getPluginLookupKey() + + "." ); } } From 06470fdc2a02f3fbd2631606bbea85294e3e69eb Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 4 May 2012 10:04:16 +0000 Subject: [PATCH 19/48] move to a Map with className as key to merge with javadoc scan git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1333848 13f79535-47bb-0310-9956-ffa450edef68 --- maven-plugin-tools-annotations/pom.xml | 6 ++++ ...avaAnnotationsMojoDescriptorExtractor.java | 35 ++++++++++++++++--- .../DefaultMojoAnnotationsScanner.java | 16 ++++----- .../scanner/MojoAnnotationsScanner.java | 3 +- .../annotations/TestAnnotationsReader.java | 5 +-- maven-plugin-tools-java/pom.xml | 1 - pom.xml | 6 ++++ 7 files changed, 56 insertions(+), 16 deletions(-) diff --git a/maven-plugin-tools-annotations/pom.xml b/maven-plugin-tools-annotations/pom.xml index 5ac0ecc..0c832fb 100644 --- a/maven-plugin-tools-annotations/pom.xml +++ b/maven-plugin-tools-annotations/pom.xml @@ -71,6 +71,12 @@ asm-commons 3.3.1 + + + com.thoughtworks.qdox + qdox + + 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 0fa534c..235e0d9 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 @@ -18,6 +18,8 @@ package org.apache.maven.tools.plugin.annotations; * under the License. */ +import com.thoughtworks.qdox.JavaDocBuilder; +import com.thoughtworks.qdox.model.JavaClass; import org.apache.maven.artifact.DependencyResolutionRequiredException; import org.apache.maven.plugin.descriptor.DuplicateParameterException; import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException; @@ -43,6 +45,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.Map; /** * @author Olivier Lamy @@ -76,9 +79,11 @@ public class JavaAnnotationsMojoDescriptorExtractor mojoAnnotationsScannerRequest.setDependencies( request.getProject().getCompileClasspathElements() ); - List mojoAnnotatedClasses = + Map mojoAnnotatedClasses = mojoAnnotationsScanner.scan( mojoAnnotationsScannerRequest ); + JavaClass[] javaClasses = discoverClasses( request ); + return toMojoDescriptors( mojoAnnotatedClasses, request ); } catch ( DependencyResolutionRequiredException e ) @@ -87,6 +92,28 @@ public class JavaAnnotationsMojoDescriptorExtractor } } + protected JavaClass[] discoverClasses( final PluginToolsRequest request ) + { + JavaDocBuilder builder = new JavaDocBuilder(); + builder.setEncoding( request.getEncoding() ); + + MavenProject project = request.getProject(); + + for ( String source : (List) project.getCompileSourceRoots() ) + { + builder.addSourceTree( new File( source ) ); + } + + // TODO be more dynamic + File generatedPlugin = new File( project.getBasedir(), "target/generated-sources/plugin" ); + if ( !project.getCompileSourceRoots().contains( generatedPlugin.getAbsolutePath() ) ) + { + builder.addSourceTree( generatedPlugin ); + } + + return builder.getClasses(); + } + private List toFiles( List directories ) { if ( directories == null ) @@ -101,18 +128,19 @@ public class JavaAnnotationsMojoDescriptorExtractor return files; } - private List toMojoDescriptors( List mojoAnnotatedClasses, + private List toMojoDescriptors( Map mojoAnnotatedClasses, PluginToolsRequest request ) throws DuplicateParameterException { List mojoDescriptors = new ArrayList( mojoAnnotatedClasses.size() ); - for ( MojoAnnotatedClass mojoAnnotatedClass : mojoAnnotatedClasses ) + for ( MojoAnnotatedClass mojoAnnotatedClass : mojoAnnotatedClasses.values() ) { MojoDescriptor mojoDescriptor = new MojoDescriptor(); //mojoDescriptor.setRole( mojoAnnotatedClass.getClassName() ); //mojoDescriptor.setRoleHint( "default" ); mojoDescriptor.setImplementation( mojoAnnotatedClass.getClassName() ); + mojoDescriptor.setLanguage( "java" ); MojoAnnotationContent mojo = mojoAnnotatedClass.getMojo(); @@ -138,7 +166,6 @@ public class JavaAnnotationsMojoDescriptorExtractor mojoDescriptor.setOnlineRequired( mojo.requiresOnline() ); mojoDescriptor.setPhase( mojo.defaultPhase().id() ); - mojoDescriptor.setLanguage( "java" ); for ( ParameterAnnotationContent parameterAnnotationContent : mojoAnnotatedClass.getParameters() ) { diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java index 0a861aa..ee53ffe 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java @@ -41,7 +41,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; -import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -55,22 +55,21 @@ public class DefaultMojoAnnotationsScanner { private Reflector reflector = new Reflector(); - public List scan( MojoAnnotationsScannerRequest request ) + public Map scan( MojoAnnotationsScannerRequest request ) throws ExtractionException { - List mojoAnnotatedClasses = new ArrayList(); + Map mojoAnnotatedClasses = new HashMap(); try { for ( File classDirectory : request.getClassesDirectories() ) { if ( classDirectory.exists() && classDirectory.isDirectory() ) { - mojoAnnotatedClasses.addAll( scanDirectory( classDirectory, request.getIncludePatterns() ) ); + mojoAnnotatedClasses.putAll( scanDirectory( classDirectory, request.getIncludePatterns() ) ); // TODO scan sources to get @since and @deprecated and description of classes and fields. } } - //TODO scan dependencies to get super class annotations if exist request.getDependencies() return mojoAnnotatedClasses; @@ -81,10 +80,10 @@ public class DefaultMojoAnnotationsScanner } } - protected List scanDirectory( File classDirectory, List includePatterns ) + protected Map scanDirectory( File classDirectory, List includePatterns ) throws IOException, ExtractionException { - List mojoAnnotatedClasses = new ArrayList(); + Map mojoAnnotatedClasses = new HashMap(); DirectoryScanner scanner = new DirectoryScanner(); scanner.setBasedir( classDirectory ); scanner.addDefaultExcludes(); @@ -110,7 +109,8 @@ public class DefaultMojoAnnotationsScanner analyzeVisitors( mojoClassVisitor ); if ( isMojoAnnnotatedClassCandidate( mojoClassVisitor.getMojoAnnotatedClass() ) != null ) { - mojoAnnotatedClasses.add( mojoClassVisitor.getMojoAnnotatedClass() ); + mojoAnnotatedClasses.put( mojoClassVisitor.getMojoAnnotatedClass().getClassName(), + mojoClassVisitor.getMojoAnnotatedClass() ); } } diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotationsScanner.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotationsScanner.java index c3a6179..2bf9d9a 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotationsScanner.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotationsScanner.java @@ -26,6 +26,7 @@ import org.apache.maven.tools.plugin.extractor.ExtractionException; import java.util.Arrays; import java.util.List; +import java.util.Map; /** * @author Olivier Lamy @@ -41,6 +42,6 @@ public interface MojoAnnotationsScanner static final List acceptedFieldLevelAnnotationClasses = Arrays.asList( Parameter.class.getName(), Component.class.getName() ); - List scan( MojoAnnotationsScannerRequest request ) + Map scan( MojoAnnotationsScannerRequest request ) throws ExtractionException; } diff --git a/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/TestAnnotationsReader.java b/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/TestAnnotationsReader.java index 1bc5e7d..12b0a15 100644 --- a/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/TestAnnotationsReader.java +++ b/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/TestAnnotationsReader.java @@ -34,6 +34,7 @@ import java.io.File; import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.Map; /** * @author Olivier Lamy @@ -50,13 +51,13 @@ public class TestAnnotationsReader request.setClassesDirectories( Collections.singletonList( new File( "target/test-classes" ) ) ); request.setIncludePatterns( Arrays.asList( "**/FooMojo.class" ) ); - List mojoAnnotatedClasses = mojoAnnotationsScanner.scan( request ); + Map mojoAnnotatedClasses = mojoAnnotationsScanner.scan( request ); System.out.println( "mojoAnnotatedClasses:" + mojoAnnotatedClasses ); Assertions.assertThat( mojoAnnotatedClasses ).isNotNull().isNotEmpty().hasSize( 1 ); - MojoAnnotatedClass mojoAnnotatedClass = mojoAnnotatedClasses.get( 0 ); + MojoAnnotatedClass mojoAnnotatedClass = mojoAnnotatedClasses.values().iterator().next(); assertEquals( FooMojo.class.getName(), mojoAnnotatedClass.getClassName() ); assertEquals( AbstractMojo.class.getName(), mojoAnnotatedClass.getParentClassName() ); diff --git a/maven-plugin-tools-java/pom.xml b/maven-plugin-tools-java/pom.xml index 91196ab..4eb2d67 100644 --- a/maven-plugin-tools-java/pom.xml +++ b/maven-plugin-tools-java/pom.xml @@ -66,7 +66,6 @@ com.thoughtworks.qdox qdox - 1.11 diff --git a/pom.xml b/pom.xml index e9934a6..6dec851 100644 --- a/pom.xml +++ b/pom.xml @@ -229,6 +229,12 @@ 1.0-alpha-9-stable-1 + + com.thoughtworks.qdox + qdox + 1.11 + + org.apache.maven.plugin-testing maven-plugin-testing-harness From ddebc219e5439b5c9e60b4c89f39e6379ef89b0f Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 4 May 2012 10:04:31 +0000 Subject: [PATCH 20/48] support @since @deprecated and description at class level git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1333849 13f79535-47bb-0310-9956-ffa450edef68 --- ...avaAnnotationsMojoDescriptorExtractor.java | 88 +++++++++++++++++-- .../DefaultMojoAnnotationsScanner.java | 1 - 2 files changed, 83 insertions(+), 6 deletions(-) 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 235e0d9..d53ee08 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 @@ -19,6 +19,7 @@ package org.apache.maven.tools.plugin.annotations; */ import com.thoughtworks.qdox.JavaDocBuilder; +import com.thoughtworks.qdox.model.DocletTag; import com.thoughtworks.qdox.model.JavaClass; import org.apache.maven.artifact.DependencyResolutionRequiredException; import org.apache.maven.plugin.descriptor.DuplicateParameterException; @@ -28,6 +29,7 @@ import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.plugin.descriptor.Requirement; import org.apache.maven.project.MavenProject; import org.apache.maven.tools.plugin.DefaultPluginToolsRequest; +import org.apache.maven.tools.plugin.ExtendedMojoDescriptor; import org.apache.maven.tools.plugin.PluginToolsRequest; import org.apache.maven.tools.plugin.annotations.datamodel.ComponentAnnotationContent; import org.apache.maven.tools.plugin.annotations.datamodel.ExecuteAnnotationContent; @@ -44,6 +46,7 @@ import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -82,7 +85,9 @@ public class JavaAnnotationsMojoDescriptorExtractor Map mojoAnnotatedClasses = mojoAnnotationsScanner.scan( mojoAnnotationsScannerRequest ); - JavaClass[] javaClasses = discoverClasses( request ); + Map javaClassesMap = discoverClasses( request ); + + populateDataFromJavadoc( mojoAnnotatedClasses, javaClassesMap ); return toMojoDescriptors( mojoAnnotatedClasses, request ); } @@ -92,7 +97,61 @@ public class JavaAnnotationsMojoDescriptorExtractor } } - protected JavaClass[] discoverClasses( final PluginToolsRequest request ) + /** + * from sources scan to get @since and @deprecated and description of classes and fields. + * + * @param mojoAnnotatedClasses + * @param javaClassesMap + */ + protected void populateDataFromJavadoc( Map mojoAnnotatedClasses, + Map javaClassesMap ) + { + + for ( Map.Entry entry : mojoAnnotatedClasses.entrySet() ) + { + JavaClass javaClass = javaClassesMap.get( entry.getKey() ); + if ( javaClass != null ) + { + entry.getValue().getMojo().setDescription( javaClass.getComment() ); + DocletTag since = findInClassHierarchy( javaClass, "since" ); + if ( since != null ) + { + entry.getValue().getMojo().setSince( since.getValue() ); + } + + DocletTag deprecated = findInClassHierarchy( javaClass, "deprecated" ); + if ( deprecated != null ) + { + entry.getValue().getMojo().setDeprecated( deprecated.getValue() ); + } + } + } + + } + + /** + * @param javaClass not null + * @param tagName not null + * @return docletTag instance + */ + private static DocletTag findInClassHierarchy( JavaClass javaClass, String tagName ) + { + DocletTag tag = javaClass.getTagByName( tagName ); + + if ( tag == null ) + { + JavaClass superClass = javaClass.getSuperJavaClass(); + + if ( superClass != null ) + { + tag = findInClassHierarchy( superClass, tagName ); + } + } + + return tag; + } + + protected Map discoverClasses( final PluginToolsRequest request ) { JavaDocBuilder builder = new JavaDocBuilder(); builder.setEncoding( request.getEncoding() ); @@ -111,7 +170,21 @@ public class JavaAnnotationsMojoDescriptorExtractor builder.addSourceTree( generatedPlugin ); } - return builder.getClasses(); + JavaClass[] javaClasses = builder.getClasses(); + + if ( javaClasses == null || javaClasses.length < 1 ) + { + return Collections.emptyMap(); + } + + Map javaClassMap = new HashMap( javaClasses.length ); + + for ( JavaClass javaClass : javaClasses ) + { + javaClassMap.put( javaClass.getFullyQualifiedName(), javaClass ); + } + + return javaClassMap; } private List toFiles( List directories ) @@ -135,7 +208,7 @@ public class JavaAnnotationsMojoDescriptorExtractor List mojoDescriptors = new ArrayList( mojoAnnotatedClasses.size() ); for ( MojoAnnotatedClass mojoAnnotatedClass : mojoAnnotatedClasses.values() ) { - MojoDescriptor mojoDescriptor = new MojoDescriptor(); + ExtendedMojoDescriptor mojoDescriptor = new ExtendedMojoDescriptor(); //mojoDescriptor.setRole( mojoAnnotatedClass.getClassName() ); //mojoDescriptor.setRoleHint( "default" ); @@ -144,10 +217,15 @@ public class JavaAnnotationsMojoDescriptorExtractor MojoAnnotationContent mojo = mojoAnnotatedClass.getMojo(); + mojoDescriptor.setDescription( mojo.getDescription() ); + mojoDescriptor.setSince( mojo.getSince() ); + mojo.setDeprecated( mojo.getDeprecated() ); + mojoDescriptor.setAggregator( mojo.aggregator() ); mojoDescriptor.setDependencyResolutionRequired( mojo.requiresDependencyResolution() ); mojoDescriptor.setDirectInvocationOnly( mojo.requiresDirectInvocation() ); mojoDescriptor.setDeprecated( mojo.getDeprecated() ); + mojoDescriptor.setThreadSafe( mojo.threadSafe() ); ExecuteAnnotationContent execute = mojoAnnotatedClass.getExecute(); @@ -176,7 +254,6 @@ public class JavaAnnotationsMojoDescriptorExtractor parameter.setDefaultValue( parameterAnnotationContent.defaultValue() ); parameter.setDeprecated( parameterAnnotationContent.getDeprecated() ); parameter.setDescription( parameterAnnotationContent.getDescription() ); - // FIXME olamy wtf ? parameter.setEditable( !parameterAnnotationContent.readonly() ); parameter.setExpression( parameterAnnotationContent.expression() ); mojoDescriptor.addParameter( parameter ); @@ -190,6 +267,7 @@ public class JavaAnnotationsMojoDescriptorExtractor parameter.setRequirement( new Requirement( componentAnnotationContent.role(), componentAnnotationContent.roleHint() ) ); parameter.setEditable( false ); + mojoDescriptor.addParameter( parameter ); } diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java index ee53ffe..71bbd39 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java @@ -66,7 +66,6 @@ public class DefaultMojoAnnotationsScanner if ( classDirectory.exists() && classDirectory.isDirectory() ) { mojoAnnotatedClasses.putAll( scanDirectory( classDirectory, request.getIncludePatterns() ) ); - // TODO scan sources to get @since and @deprecated and description of classes and fields. } } From 28a6f546434645271d970736154c328d910a9e50 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 4 May 2012 10:05:16 +0000 Subject: [PATCH 21/48] revert back phase change help generation with doclet must continue to work git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1333850 13f79535-47bb-0310-9956-ffa450edef68 --- .../maven/plugins/annotations/Mojo.java | 2 +- .../src/it/help-basic/invoker.properties | 2 +- .../apache/maven/plugin/coreit/FirstMojo.java | 3 + .../it/java-basic-annotations/verify.groovy | 48 +++++----- .../plugin/DescriptorGeneratorMojo.java | 2 +- .../plugin/plugin/HelpGeneratorMojo.java | 2 +- ...avaAnnotationsMojoDescriptorExtractor.java | 94 ++++++++++++++++++- .../datamodel/MojoAnnotationContent.java | 4 +- .../datamodel/ParameterAnnotationContent.java | 19 +++- .../DefaultMojoAnnotationsScanner.java | 8 +- .../scanner/MojoAnnotatedClass.java | 26 +++-- .../scanner/visitors/MojoClassVisitor.java | 3 +- .../scanner/visitors/MojoFieldVisitor.java | 15 ++- .../tools/plugin/annotations/FooMojo.java | 2 +- .../annotations/TestAnnotationsReader.java | 10 +- 15 files changed, 186 insertions(+), 54 deletions(-) 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 c102b29..3eef3c8 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 @@ -42,7 +42,7 @@ public @interface Mojo String requiresDependencyResolution() default "runtime"; - String requiresDependencyCollection() default "runtime"; + String requiresDependencyCollection() default ""; String instantiationStrategy() default "per-lookup"; diff --git a/maven-plugin-plugin/src/it/help-basic/invoker.properties b/maven-plugin-plugin/src/it/help-basic/invoker.properties index 5b282bb..241f018 100644 --- a/maven-plugin-plugin/src/it/help-basic/invoker.properties +++ b/maven-plugin-plugin/src/it/help-basic/invoker.properties @@ -1,2 +1,2 @@ -invoker.goals.1 = install +invoker.goals.1 = install -DskipTests invoker.goals.2 = org.apache.maven.its.plugin:help:1.0:help diff --git a/maven-plugin-plugin/src/it/java-basic-annotations/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java b/maven-plugin-plugin/src/it/java-basic-annotations/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java index cee401d..f7c64fd 100644 --- a/maven-plugin-plugin/src/it/java-basic-annotations/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java +++ b/maven-plugin-plugin/src/it/java-basic-annotations/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java @@ -41,6 +41,9 @@ public class FirstMojo extends AbstractMojo { + /** + * Project directory. + */ @Parameter( defaultValue = "${basedir}", readonly = true ) private File basedir; diff --git a/maven-plugin-plugin/src/it/java-basic-annotations/verify.groovy b/maven-plugin-plugin/src/it/java-basic-annotations/verify.groovy index 3d274c5..ef33aa5 100644 --- a/maven-plugin-plugin/src/it/java-basic-annotations/verify.groovy +++ b/maven-plugin-plugin/src/it/java-basic-annotations/verify.groovy @@ -40,29 +40,35 @@ assert mojo.requirements.requirement[0].'field-name'.text() == 'projectHelper' assert mojo.parameters.parameter.size() == 3 -assert mojo.parameters.parameter[0].name.text() == 'aliasedParam' -assert mojo.parameters.parameter[0].alias.text() == 'alias' -assert mojo.parameters.parameter[0].type.text() == 'java.lang.String' -assert mojo.parameters.parameter[0].deprecated.text() == 'As of 0.2' -assert mojo.parameters.parameter[0].required.text() == 'false' -assert mojo.parameters.parameter[0].editable.text() == 'true' -assert mojo.parameters.parameter[0].description.text() == '' +def parameter = mojo.parameters.parameter.findAll{ it.name.text() == "aliasedParam"}[0] -assert mojo.parameters.parameter[1].name.text() == 'basedir' -assert mojo.parameters.parameter[1].alias.isEmpty() -assert mojo.parameters.parameter[1].type.text() == 'java.io.File' -assert mojo.parameters.parameter[1].deprecated.isEmpty() -assert mojo.parameters.parameter[1].required.text() == 'false' -assert mojo.parameters.parameter[1].editable.text() == 'false' -assert mojo.parameters.parameter[1].description.text() == 'Project directory.' +assert parameter.name.text() == 'aliasedParam' +assert parameter.alias.text() == 'alias' +assert parameter.type.text() == 'java.lang.String' +assert parameter.deprecated.text() == 'As of 0.2' +assert parameter.required.text() == 'false' +assert parameter.editable.text() == 'true' +assert parameter.description.text() == '' -assert mojo.parameters.parameter[2].name.text() == 'touchFile' -assert mojo.parameters.parameter[2].alias.isEmpty() -assert mojo.parameters.parameter[2].type.text() == 'java.io.File' -assert mojo.parameters.parameter[2].deprecated.isEmpty() -assert mojo.parameters.parameter[2].required.text() == 'true' -assert mojo.parameters.parameter[2].editable.text() == 'true' -assert mojo.parameters.parameter[2].description.text() == '' +parameter = mojo.parameters.parameter.findAll{ it.name.text() == "touchFile"}[0] + +assert parameter.name.text() == 'touchFile' +assert parameter.alias.isEmpty() +assert parameter.type.text() == 'java.io.File' +assert parameter.deprecated.isEmpty() +assert parameter.required.text() == 'true' +assert parameter.editable.text() == 'true' +assert parameter.description.text() == '' + +parameter = mojo.parameters.parameter.findAll{ it.name.text() == "basedir"}[0] + +assert parameter.name.text() == 'basedir' +assert parameter.alias.isEmpty() +assert parameter.type.text() == 'java.io.File' +assert parameter.deprecated.isEmpty() +assert parameter.required.text() == 'false' +assert parameter.editable.text() == 'false' +assert parameter.description.text() == 'Project directory.' mojo = pluginDescriptor.mojos.mojo.findAll{ it.goal.text() == "second"}[0] diff --git a/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/DescriptorGeneratorMojo.java b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/DescriptorGeneratorMojo.java index a125363..9c63dd3 100644 --- a/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/DescriptorGeneratorMojo.java +++ b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/DescriptorGeneratorMojo.java @@ -34,7 +34,7 @@ import java.io.File; * @version $Id$ * @since 2.0 * @goal descriptor - * @phase process-classes + * @phase generate-resources * @requiresDependencyResolution runtime */ public class DescriptorGeneratorMojo diff --git a/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/HelpGeneratorMojo.java b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/HelpGeneratorMojo.java index bf20432..1bac881 100644 --- a/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/HelpGeneratorMojo.java +++ b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/HelpGeneratorMojo.java @@ -32,7 +32,7 @@ import org.apache.maven.tools.plugin.generator.PluginHelpGenerator; * @version $Id$ * @since 2.4 * @goal helpmojo - * @phase process-classes + * @phase generate-sources */ public class HelpGeneratorMojo extends AbstractGeneratorMojo 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 d53ee08..8a35a0f 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 @@ -21,6 +21,7 @@ package org.apache.maven.tools.plugin.annotations; import com.thoughtworks.qdox.JavaDocBuilder; import com.thoughtworks.qdox.model.DocletTag; import com.thoughtworks.qdox.model.JavaClass; +import com.thoughtworks.qdox.model.JavaField; import org.apache.maven.artifact.DependencyResolutionRequiredException; import org.apache.maven.plugin.descriptor.DuplicateParameterException; import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException; @@ -49,6 +50,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.TreeMap; /** * @author Olivier Lamy @@ -124,6 +126,48 @@ public class JavaAnnotationsMojoDescriptorExtractor { entry.getValue().getMojo().setDeprecated( deprecated.getValue() ); } + + Map fieldsMap = extractFieldParameterTags( javaClass ); + for ( Map.Entry parameter : entry.getValue().getParameters().entrySet() ) + { + JavaField javaField = fieldsMap.get( parameter.getKey() ); + if ( javaField != null ) + { + ParameterAnnotationContent parameterAnnotationContent = parameter.getValue(); + deprecated = javaField.getTagByName( "deprecated" ); + if ( deprecated != null ) + { + parameterAnnotationContent.setDeprecated( deprecated.getValue() ); + } + since = javaField.getTagByName( "since" ); + if ( since != null ) + { + parameterAnnotationContent.setSince( since.getValue() ); + } + parameterAnnotationContent.setDescription( javaField.getComment() ); + } + } + + for ( Map.Entry component : entry.getValue().getComponents().entrySet() ) + { + JavaField javaField = fieldsMap.get( component.getKey() ); + if ( javaField != null ) + { + ComponentAnnotationContent componentAnnotationContent = component.getValue(); + deprecated = javaField.getTagByName( "deprecated" ); + if ( deprecated != null ) + { + componentAnnotationContent.setDeprecated( deprecated.getValue() ); + } + since = javaField.getTagByName( "since" ); + if ( since != null ) + { + componentAnnotationContent.setSince( since.getValue() ); + } + componentAnnotationContent.setDescription( javaField.getComment() ); + } + } + } } @@ -151,6 +195,41 @@ public class JavaAnnotationsMojoDescriptorExtractor return tag; } + /** + * extract fields that are either parameters or components. + * + * @param javaClass not null + * @return map with Mojo parameters names as keys + */ + private Map extractFieldParameterTags( JavaClass javaClass ) + { + Map rawParams; + + // we have to add the parent fields first, so that they will be overwritten by the local fields if + // that actually happens... + JavaClass superClass = javaClass.getSuperJavaClass(); + + if ( superClass != null ) + { + rawParams = extractFieldParameterTags( superClass ); + } + else + { + rawParams = new TreeMap(); + } + + JavaField[] classFields = javaClass.getFields(); + + if ( classFields != null ) + { + for ( JavaField field : classFields ) + { + rawParams.put( field.getName(), field ); + } + } + return rawParams; + } + protected Map discoverClasses( final PluginToolsRequest request ) { JavaDocBuilder builder = new JavaDocBuilder(); @@ -208,6 +287,12 @@ public class JavaAnnotationsMojoDescriptorExtractor List mojoDescriptors = new ArrayList( mojoAnnotatedClasses.size() ); for ( MojoAnnotatedClass mojoAnnotatedClass : mojoAnnotatedClasses.values() ) { + // no mojo so skip it + if ( mojoAnnotatedClass.getMojo() == null ) + { + continue; + } + ExtendedMojoDescriptor mojoDescriptor = new ExtendedMojoDescriptor(); //mojoDescriptor.setRole( mojoAnnotatedClass.getClassName() ); @@ -223,6 +308,8 @@ public class JavaAnnotationsMojoDescriptorExtractor mojoDescriptor.setAggregator( mojo.aggregator() ); mojoDescriptor.setDependencyResolutionRequired( mojo.requiresDependencyResolution() ); + mojoDescriptor.setDependencyCollectionRequired( mojo.requiresDependencyCollection() ); + mojoDescriptor.setDirectInvocationOnly( mojo.requiresDirectInvocation() ); mojoDescriptor.setDeprecated( mojo.getDeprecated() ); mojoDescriptor.setThreadSafe( mojo.threadSafe() ); @@ -245,7 +332,7 @@ public class JavaAnnotationsMojoDescriptorExtractor mojoDescriptor.setPhase( mojo.defaultPhase().id() ); - for ( ParameterAnnotationContent parameterAnnotationContent : mojoAnnotatedClass.getParameters() ) + for ( ParameterAnnotationContent parameterAnnotationContent : mojoAnnotatedClass.getParameters().values() ) { org.apache.maven.plugin.descriptor.Parameter parameter = new org.apache.maven.plugin.descriptor.Parameter(); @@ -256,10 +343,13 @@ public class JavaAnnotationsMojoDescriptorExtractor parameter.setDescription( parameterAnnotationContent.getDescription() ); parameter.setEditable( !parameterAnnotationContent.readonly() ); parameter.setExpression( parameterAnnotationContent.expression() ); + parameter.setType( parameterAnnotationContent.getClassName() ); + parameter.setRequired( parameterAnnotationContent.required() ); + mojoDescriptor.addParameter( parameter ); } - for ( ComponentAnnotationContent componentAnnotationContent : mojoAnnotatedClass.getComponents() ) + for ( ComponentAnnotationContent componentAnnotationContent : mojoAnnotatedClass.getComponents().values() ) { org.apache.maven.plugin.descriptor.Parameter parameter = new org.apache.maven.plugin.descriptor.Parameter(); 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 f01e7ec..ea70331 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 @@ -37,7 +37,7 @@ public class MojoAnnotationContent private String requiresDependencyResolution = "runtime"; - private String requiresDependencyCollection = "runtime"; + private String requiresDependencyCollection; private String instantiationStrategy = "per-lookup"; @@ -86,7 +86,7 @@ public class MojoAnnotationContent public String requiresDependencyCollection() { - return requiresDependencyCollection; + return requiresDependencyCollection == null ? "" : requiresDependencyCollection; } public void requiresDependencyCollection( String requiresDependencyCollection ) diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/ParameterAnnotationContent.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/ParameterAnnotationContent.java index 0f6062f..82a82bd 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/ParameterAnnotationContent.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/ParameterAnnotationContent.java @@ -41,15 +41,18 @@ public class ParameterAnnotationContent private boolean readonly = false; - public ParameterAnnotationContent( String fieldName ) + private String className; + + public ParameterAnnotationContent( String fieldName, String className ) { super( fieldName ); + this.className = className; } public ParameterAnnotationContent( String fieldName, String alias, String expression, String defaultValue, - boolean required, boolean readonly ) + boolean required, boolean readonly, String className ) { - this( fieldName ); + this( fieldName, className ); this.alias = alias; this.expression = expression; this.defaultValue = defaultValue; @@ -112,6 +115,16 @@ public class ParameterAnnotationContent return null; } + public String getClassName() + { + return className; + } + + public void setClassName( String className ) + { + this.className = className; + } + @Override public String toString() { diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java index 71bbd39..e3301d1 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java @@ -173,7 +173,7 @@ public class DefaultMojoAnnotationsScanner for ( MojoFieldVisitor mojoFieldVisitor : mojoFieldVisitors ) { ParameterAnnotationContent parameterAnnotationContent = - new ParameterAnnotationContent( mojoFieldVisitor.getFieldName() ); + new ParameterAnnotationContent( mojoFieldVisitor.getFieldName(), mojoFieldVisitor.getClassName() ); if ( mojoFieldVisitor.getMojoAnnotationVisitor() != null ) { for ( Map.Entry entry : mojoFieldVisitor.getMojoAnnotationVisitor().getAnnotationValues().entrySet() ) @@ -183,7 +183,8 @@ public class DefaultMojoAnnotationsScanner } } - mojoClassVisitor.getMojoAnnotatedClass().getParameters().add( parameterAnnotationContent ); + mojoClassVisitor.getMojoAnnotatedClass().getParameters().put( parameterAnnotationContent.getFieldName(), + parameterAnnotationContent ); } mojoFieldVisitors = mojoClassVisitor.findFieldWithAnnotationClass( Component.class.getName() ); @@ -202,7 +203,8 @@ public class DefaultMojoAnnotationsScanner } } - mojoClassVisitor.getMojoAnnotatedClass().getComponents().add( componentAnnotationContent ); + mojoClassVisitor.getMojoAnnotatedClass().getComponents().put( componentAnnotationContent.getFieldName(), + componentAnnotationContent ); } } diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotatedClass.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotatedClass.java index 6ac7872..2cc65d2 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotatedClass.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotatedClass.java @@ -23,8 +23,8 @@ import org.apache.maven.tools.plugin.annotations.datamodel.ExecuteAnnotationCont import org.apache.maven.tools.plugin.annotations.datamodel.MojoAnnotationContent; import org.apache.maven.tools.plugin.annotations.datamodel.ParameterAnnotationContent; -import java.util.ArrayList; -import java.util.List; +import java.util.HashMap; +import java.util.Map; /** * @author Olivier Lamy @@ -40,9 +40,15 @@ public class MojoAnnotatedClass private ExecuteAnnotationContent execute; - private List parameters; + /** + * key is field name + */ + private Map parameters; - private List components; + /** + * key is field name + */ + private Map components; public MojoAnnotatedClass() { @@ -82,31 +88,31 @@ public class MojoAnnotatedClass return this; } - public List getParameters() + public Map getParameters() { if ( this.parameters == null ) { - this.parameters = new ArrayList(); + this.parameters = new HashMap(); } return parameters; } - public MojoAnnotatedClass setParameters( List parameters ) + public MojoAnnotatedClass setParameters( Map parameters ) { this.parameters = parameters; return this; } - public List getComponents() + public Map getComponents() { if ( this.components == null ) { - this.components = new ArrayList(); + this.components = new HashMap(); } return components; } - public MojoAnnotatedClass setComponents( List components ) + public MojoAnnotatedClass setComponents( Map components ) { this.components = components; return this; diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/visitors/MojoClassVisitor.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/visitors/MojoClassVisitor.java index fe2178a..5cec4b0 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/visitors/MojoClassVisitor.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/visitors/MojoClassVisitor.java @@ -124,9 +124,8 @@ public class MojoClassVisitor public FieldVisitor visitField( int access, String name, String desc, String signature, Object value ) { - // Type.getType( desc ).getClassName() logger.debug( "MojoClassVisitor#visitField" ); - MojoFieldVisitor mojoFieldVisitor = new MojoFieldVisitor( logger, name ); + MojoFieldVisitor mojoFieldVisitor = new MojoFieldVisitor( logger, name, Type.getType( desc ).getClassName() ); fieldVisitors.add( mojoFieldVisitor ); return mojoFieldVisitor; } diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/visitors/MojoFieldVisitor.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/visitors/MojoFieldVisitor.java index 2b704a0..2b82907 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/visitors/MojoFieldVisitor.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/visitors/MojoFieldVisitor.java @@ -38,10 +38,13 @@ public class MojoFieldVisitor private MojoAnnotationVisitor mojoAnnotationVisitor; - MojoFieldVisitor( Logger logger, String fieldName ) + private String className; + + MojoFieldVisitor( Logger logger, String fieldName, String className ) { this.logger = logger; this.fieldName = fieldName; + this.className = className; } public MojoAnnotationVisitor getMojoAnnotationVisitor() @@ -75,4 +78,14 @@ public class MojoFieldVisitor { logger.debug( "MojoFieldVisitor#visitEnd" ); } + + public String getClassName() + { + return className; + } + + public void setClassName( String className ) + { + this.className = className; + } } diff --git a/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/FooMojo.java b/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/FooMojo.java index 765cc53..a10181c 100644 --- a/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/FooMojo.java +++ b/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/FooMojo.java @@ -35,7 +35,7 @@ import org.apache.maven.plugins.annotations.Parameter; public class FooMojo extends AbstractMojo { - @Parameter( expression = "${thebar}" ) + @Parameter( expression = "${thebar}", required = true) private String bar; @Parameter( expression = "${thebeer}" ) diff --git a/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/TestAnnotationsReader.java b/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/TestAnnotationsReader.java index 12b0a15..8856e90 100644 --- a/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/TestAnnotationsReader.java +++ b/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/TestAnnotationsReader.java @@ -32,8 +32,8 @@ import org.fest.assertions.Assertions; import java.io.File; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; -import java.util.List; import java.util.Map; /** @@ -75,12 +75,12 @@ public class TestAnnotationsReader assertEquals( "my-lifecycle", execute.lifecycle() ); assertEquals( LifecyclePhase.PACKAGE, execute.phase() ); - List components = mojoAnnotatedClass.getComponents(); + Collection components = mojoAnnotatedClass.getComponents().values(); Assertions.assertThat( components ).isNotNull().isNotEmpty().hasSize( 2 ); - List parameters = mojoAnnotatedClass.getParameters(); + Collection parameters = mojoAnnotatedClass.getParameters().values(); Assertions.assertThat( parameters ).isNotNull().isNotEmpty().hasSize( 2 ).contains( - new ParameterAnnotationContent( "bar", null, "${thebar}", null, false, false ), - new ParameterAnnotationContent( "beer", null, "${thebeer}", null, false, false ) ); + new ParameterAnnotationContent( "bar", null, "${thebar}", null, true, false, String.class.getName() ), + new ParameterAnnotationContent( "beer", null, "${thebeer}", null, false, false, String.class.getName() ) ); } } From 32975142d56ceecd21f094b36d6891a965eed65b Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 4 May 2012 10:05:28 +0000 Subject: [PATCH 22/48] comment test for help generation with annotations due to chicken and eggs trouble git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1333851 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/it/java-basic-annotations/invoker.properties | 3 +++ .../src/it/java-basic-annotations/pom.xml | 9 ++++++++- maven-plugin-plugin/src/it/java-basic/invoker.properties | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/maven-plugin-plugin/src/it/java-basic-annotations/invoker.properties b/maven-plugin-plugin/src/it/java-basic-annotations/invoker.properties index e8db4c3..81563cc 100644 --- a/maven-plugin-plugin/src/it/java-basic-annotations/invoker.properties +++ b/maven-plugin-plugin/src/it/java-basic-annotations/invoker.properties @@ -1,2 +1,5 @@ invoker.goals.1 = install invoker.goals.2 = org.apache.maven.its.basic-java-annotations:maven-it-basic-java-annotations:1.0:it0014 +#FIXME disabled need to find a solution for the chicken and eggs issue. +#help sources are generated @generated-sources but need descriptor which need compile phase first for classes scanning +#invoker.goals.3 = org.apache.maven.its.basic-java-annotations:maven-it-basic-java-annotations:1.0::help diff --git a/maven-plugin-plugin/src/it/java-basic-annotations/pom.xml b/maven-plugin-plugin/src/it/java-basic-annotations/pom.xml index 6a95441..8716b8b 100644 --- a/maven-plugin-plugin/src/it/java-basic-annotations/pom.xml +++ b/maven-plugin-plugin/src/it/java-basic-annotations/pom.xml @@ -62,11 +62,18 @@ under the License. + mojo-descriptor + process-classes descriptor - mojo-descriptor + + + help-goal process-classes + + helpmojo + diff --git a/maven-plugin-plugin/src/it/java-basic/invoker.properties b/maven-plugin-plugin/src/it/java-basic/invoker.properties index 71c2d75..caedd63 100644 --- a/maven-plugin-plugin/src/it/java-basic/invoker.properties +++ b/maven-plugin-plugin/src/it/java-basic/invoker.properties @@ -1,2 +1,3 @@ invoker.goals.1 = install invoker.goals.2 = org.apache.maven.its.it0013:maven-it-it0013:1.0:it0013 + From ccc0c36afefa680074ad2f60902f29ec69623d57 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Mon, 7 May 2012 15:39:56 +0000 Subject: [PATCH 24/48] [MPLUGIN-189] support parameter field inheritance git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1335069 13f79535-47bb-0310-9956-ffa450edef68 --- maven-plugin-plugin/pom.xml | 11 +++ .../invoker.properties | 5 ++ .../it/annotation-with-inheritance/pom.xml | 75 ++++++++++++++++++ .../plugin/coreit/AbstractFirstMojo.java | 52 ++++++++++++ .../maven/plugin/coreit/CoreIt0014Mojo.java | 66 ++++++++++++++++ .../apache/maven/plugin/coreit/FirstMojo.java | 59 ++++++++++++++ .../maven/plugin/coreit/SecondMojo.java | 38 +++++++++ .../annotation-with-inheritance/verify.groovy | 78 ++++++++++++++++++ maven-plugin-plugin/src/it/settings.xml | 7 ++ ...avaAnnotationsMojoDescriptorExtractor.java | 79 +++++++++++++++---- .../DefaultMojoAnnotationsScanner.java | 59 +++++++++++++- 11 files changed, 511 insertions(+), 18 deletions(-) create mode 100644 maven-plugin-plugin/src/it/annotation-with-inheritance/invoker.properties create mode 100644 maven-plugin-plugin/src/it/annotation-with-inheritance/pom.xml create mode 100644 maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/AbstractFirstMojo.java create mode 100644 maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/CoreIt0014Mojo.java create mode 100644 maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java create mode 100644 maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/SecondMojo.java create mode 100644 maven-plugin-plugin/src/it/annotation-with-inheritance/verify.groovy diff --git a/maven-plugin-plugin/pom.xml b/maven-plugin-plugin/pom.xml index c8c0300..b16b644 100644 --- a/maven-plugin-plugin/pom.xml +++ b/maven-plugin-plugin/pom.xml @@ -241,6 +241,15 @@ + + + + org.apache.maven.plugins + maven-plugin-plugin + 2.9 + + + @@ -289,7 +298,9 @@ + org.apache.maven.plugins maven-invoker-plugin + 1.6-SNAPSHOT ${project.build.directory}/it ${project.build.directory}/local-repo diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance/invoker.properties b/maven-plugin-plugin/src/it/annotation-with-inheritance/invoker.properties new file mode 100644 index 0000000..26b6a75 --- /dev/null +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance/invoker.properties @@ -0,0 +1,5 @@ +invoker.goals.1 = install +invoker.goals.2 = org.apache.maven.its.annotation-with-inheritance:annotation-with-inheritance:1.0:it0014 +#FIXME disabled need to find a solution for the chicken and eggs issue. +#help sources are generated @generated-sources but need descriptor which need compile phase first for classes scanning +#invoker.goals.3 = org.apache.maven.its.basic-java-annotations:maven-it-basic-java-annotations:1.0::help diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance/pom.xml b/maven-plugin-plugin/src/it/annotation-with-inheritance/pom.xml new file mode 100644 index 0000000..9901100 --- /dev/null +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance/pom.xml @@ -0,0 +1,75 @@ + + + + + + 4.0.0 + + org.apache.maven.its.annotation-with-inheritance + annotation-with-inheritance + 1.0 + maven-plugin + + Maven Integration Test :: annotation-with-inheritance + + Test plugin-plugin, which tests maven-plugin-tools-api and + maven-plugin-tools-java. This will generate a plugin descriptor from + java-based mojo sources, install the plugin, and then use it. + + + + UTF-8 + + + + + org.apache.maven + maven-plugin-api + 2.0 + + + org.apache.maven.plugin-tools + maven-plugin-annotations + @project.version@ + + + + + + + org.apache.maven.plugins + maven-plugin-plugin + @project.version@ + + true + + + + mojo-descriptor + process-classes + + descriptor + + + + + + + diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/AbstractFirstMojo.java b/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/AbstractFirstMojo.java new file mode 100644 index 0000000..89545f9 --- /dev/null +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/AbstractFirstMojo.java @@ -0,0 +1,52 @@ +package org.apache.maven.plugin.coreit; + +/* + * 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.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +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; +import org.apache.maven.plugins.annotations.Parameter; + +import java.io.File; + +/** + * Touches a test file. + * + */ +public abstract class AbstractFirstMojo + extends AbstractMojo +{ + + /** + * Project directory. + */ + @Parameter( defaultValue = "${basedir}", readonly = true ) + protected File basedir; + + @Parameter( expression = "${first.touchFile}", defaultValue = "${project.build.directory}/touch.txt", + required = true ) + protected File touchFile; + + + +} diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/CoreIt0014Mojo.java b/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/CoreIt0014Mojo.java new file mode 100644 index 0000000..b6dc2fa --- /dev/null +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/CoreIt0014Mojo.java @@ -0,0 +1,66 @@ +package org.apache.maven.plugin.coreit; + +/* + * 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.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; + +import java.io.File; +import java.io.IOException; + +/** + * Touches a test file. + * + */ +@Mojo( name = "it0014") +public class CoreIt0014Mojo + extends AbstractMojo +{ + + @Parameter(expression ="${project.build.directory}", required = true) + private String outputDirectory; + + public void execute() + throws MojoExecutionException + { + getLog().info( "outputDirectory = " + outputDirectory ); + + File f = new File( outputDirectory ); + + if ( !f.exists() ) + { + f.mkdirs(); + } + + File touch = new File( f, "touch.txt" ); + + try + { + touch.createNewFile(); + } + catch ( IOException e ) + { + throw new MojoExecutionException( "Error writing verification file.", e ); + } + } + +} diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java b/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java new file mode 100644 index 0000000..564b97a --- /dev/null +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java @@ -0,0 +1,59 @@ +package org.apache.maven.plugin.coreit; + +/* + * 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.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +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; +import org.apache.maven.plugins.annotations.Parameter; + +import java.io.File; + +/** + * Touches a test file. + * + * @since 1.2 + * @deprecated Don't use! + */ +@Mojo( name = "first", requiresDependencyResolution = "test", defaultPhase = LifecyclePhase.INTEGRATION_TEST ) +@Execute( phase = LifecyclePhase.GENERATE_SOURCES, lifecycle = "cobertura" ) +public class FirstMojo + extends AbstractFirstMojo +{ + + /** + * @since 0.1 + * @deprecated As of 0.2 + */ + @Parameter( alias = "alias" ) + private String aliasedParam; + + @Component( role = "org.apache.maven.project.MavenProjectHelper", roleHint = "test" ) + private Object projectHelper; + + public void execute() + throws MojoExecutionException + { + } + +} diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/SecondMojo.java b/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/SecondMojo.java new file mode 100644 index 0000000..8e28eba --- /dev/null +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/SecondMojo.java @@ -0,0 +1,38 @@ +package org.apache.maven.plugin.coreit; + +/* + * 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.plugin.AbstractMojo; +import org.apache.maven.plugins.annotations.Mojo; + +/** + * Does nothing special. + * + */ +@Mojo( name = "second",requiresDependencyCollection = "compile", threadSafe = true) +public class SecondMojo + extends AbstractMojo +{ + + public void execute() + { + } + +} diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance/verify.groovy b/maven-plugin-plugin/src/it/annotation-with-inheritance/verify.groovy new file mode 100644 index 0000000..ef33aa5 --- /dev/null +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance/verify.groovy @@ -0,0 +1,78 @@ +File touchFile = new File( basedir, "target/touch.txt" ) +assert touchFile.isFile() + +File descriptorFile = new File( basedir, "target/classes/META-INF/maven/plugin.xml" ); +assert descriptorFile.isFile() + +def pluginDescriptor = new XmlParser().parse( descriptorFile ); + +def mojo = pluginDescriptor.mojos.mojo.findAll{ it.goal.text() == "first"}[0] + +assert mojo.goal.text() == 'first' +assert mojo.implementation.text() == 'org.apache.maven.plugin.coreit.FirstMojo' +assert mojo.language.text() == 'java' +assert mojo.description.text() == 'Touches a test file.' +assert mojo.deprecated.text() == "Don't use!" +assert mojo.requiresDependencyResolution.text() == 'test' +assert mojo.requiresDependencyCollection.text() == '' +assert mojo.requiresProject.text() == 'true' +assert mojo.requiresOnline.text() == 'false' +assert mojo.requiresDirectInvocation.text() == 'false' +assert mojo.aggregator.text() == 'false' +assert mojo.threadSafe.text() == 'false' +assert mojo.phase.text() == 'integration-test' +assert mojo.executePhase.text() == 'generate-sources' +assert mojo.executeLifecycle.text() == 'cobertura' + +assert mojo.configuration.basedir[0].text() == '' +assert mojo.configuration.basedir[0].'@implementation' == 'java.io.File' +assert mojo.configuration.basedir[0].'@default-value' == '${basedir}' + +assert mojo.configuration.touchFile[0].text() == '${first.touchFile}' +assert mojo.configuration.touchFile[0].'@implementation' == 'java.io.File' +assert mojo.configuration.touchFile[0].'@default-value' == '${project.build.directory}/touch.txt' + +assert mojo.requirements.requirement.size() == 1 + +assert mojo.requirements.requirement[0].role.text() == 'org.apache.maven.project.MavenProjectHelper' +assert mojo.requirements.requirement[0].'role-hint'.text() == 'test' +assert mojo.requirements.requirement[0].'field-name'.text() == 'projectHelper' + +assert mojo.parameters.parameter.size() == 3 + +def parameter = mojo.parameters.parameter.findAll{ it.name.text() == "aliasedParam"}[0] + +assert parameter.name.text() == 'aliasedParam' +assert parameter.alias.text() == 'alias' +assert parameter.type.text() == 'java.lang.String' +assert parameter.deprecated.text() == 'As of 0.2' +assert parameter.required.text() == 'false' +assert parameter.editable.text() == 'true' +assert parameter.description.text() == '' + +parameter = mojo.parameters.parameter.findAll{ it.name.text() == "touchFile"}[0] + +assert parameter.name.text() == 'touchFile' +assert parameter.alias.isEmpty() +assert parameter.type.text() == 'java.io.File' +assert parameter.deprecated.isEmpty() +assert parameter.required.text() == 'true' +assert parameter.editable.text() == 'true' +assert parameter.description.text() == '' + +parameter = mojo.parameters.parameter.findAll{ it.name.text() == "basedir"}[0] + +assert parameter.name.text() == 'basedir' +assert parameter.alias.isEmpty() +assert parameter.type.text() == 'java.io.File' +assert parameter.deprecated.isEmpty() +assert parameter.required.text() == 'false' +assert parameter.editable.text() == 'false' +assert parameter.description.text() == 'Project directory.' + +mojo = pluginDescriptor.mojos.mojo.findAll{ it.goal.text() == "second"}[0] + +assert mojo.requiresDependencyCollection.text() == 'compile' +assert mojo.threadSafe.text() == 'true' + +return true; diff --git a/maven-plugin-plugin/src/it/settings.xml b/maven-plugin-plugin/src/it/settings.xml index c8f77f0..44480e3 100644 --- a/maven-plugin-plugin/src/it/settings.xml +++ b/maven-plugin-plugin/src/it/settings.xml @@ -20,6 +20,13 @@ under the License. --> + it-repo 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 8a35a0f..cb7fed6 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 @@ -82,7 +82,8 @@ public class JavaAnnotationsMojoDescriptorExtractor mojoAnnotationsScannerRequest.setClassesDirectories( Arrays.asList( new File( request.getProject().getBuild().getOutputDirectory() ) ) ); - mojoAnnotationsScannerRequest.setDependencies( request.getProject().getCompileClasspathElements() ); + mojoAnnotationsScannerRequest.setDependencies( + toFiles( request.getProject().getCompileClasspathElements() ) ); Map mojoAnnotatedClasses = mojoAnnotationsScanner.scan( mojoAnnotationsScannerRequest ); @@ -114,19 +115,22 @@ public class JavaAnnotationsMojoDescriptorExtractor JavaClass javaClass = javaClassesMap.get( entry.getKey() ); if ( javaClass != null ) { - entry.getValue().getMojo().setDescription( javaClass.getComment() ); - DocletTag since = findInClassHierarchy( javaClass, "since" ); - if ( since != null ) + MojoAnnotationContent mojoAnnotationContent = entry.getValue().getMojo(); + if ( mojoAnnotationContent != null ) { - entry.getValue().getMojo().setSince( since.getValue() ); - } + mojoAnnotationContent.setDescription( javaClass.getComment() ); + DocletTag since = findInClassHierarchy( javaClass, "since" ); + if ( since != null ) + { + mojoAnnotationContent.setSince( since.getValue() ); + } - DocletTag deprecated = findInClassHierarchy( javaClass, "deprecated" ); - if ( deprecated != null ) - { - entry.getValue().getMojo().setDeprecated( deprecated.getValue() ); + DocletTag deprecated = findInClassHierarchy( javaClass, "deprecated" ); + if ( deprecated != null ) + { + mojoAnnotationContent.setDeprecated( deprecated.getValue() ); + } } - Map fieldsMap = extractFieldParameterTags( javaClass ); for ( Map.Entry parameter : entry.getValue().getParameters().entrySet() ) { @@ -134,12 +138,12 @@ public class JavaAnnotationsMojoDescriptorExtractor if ( javaField != null ) { ParameterAnnotationContent parameterAnnotationContent = parameter.getValue(); - deprecated = javaField.getTagByName( "deprecated" ); + DocletTag deprecated = javaField.getTagByName( "deprecated" ); if ( deprecated != null ) { parameterAnnotationContent.setDeprecated( deprecated.getValue() ); } - since = javaField.getTagByName( "since" ); + DocletTag since = javaField.getTagByName( "since" ); if ( since != null ) { parameterAnnotationContent.setSince( since.getValue() ); @@ -154,12 +158,12 @@ public class JavaAnnotationsMojoDescriptorExtractor if ( javaField != null ) { ComponentAnnotationContent componentAnnotationContent = component.getValue(); - deprecated = javaField.getTagByName( "deprecated" ); + DocletTag deprecated = javaField.getTagByName( "deprecated" ); if ( deprecated != null ) { componentAnnotationContent.setDeprecated( deprecated.getValue() ); } - since = javaField.getTagByName( "since" ); + DocletTag since = javaField.getTagByName( "since" ); if ( since != null ) { componentAnnotationContent.setSince( since.getValue() ); @@ -332,7 +336,11 @@ public class JavaAnnotationsMojoDescriptorExtractor mojoDescriptor.setPhase( mojo.defaultPhase().id() ); - for ( ParameterAnnotationContent parameterAnnotationContent : mojoAnnotatedClass.getParameters().values() ) + Map parameters = + getParametersParentHierarchy( mojoAnnotatedClass, new HashMap(), + mojoAnnotatedClasses ); + + for ( ParameterAnnotationContent parameterAnnotationContent : parameters.values() ) { org.apache.maven.plugin.descriptor.Parameter parameter = new org.apache.maven.plugin.descriptor.Parameter(); @@ -367,4 +375,43 @@ public class JavaAnnotationsMojoDescriptorExtractor } return mojoDescriptors; } + + protected Map getParametersParentHierarchy( + MojoAnnotatedClass mojoAnnotatedClass, Map parameters, + Map mojoAnnotatedClasses ) + { + List parameterAnnotationContents = new ArrayList(); + + parameterAnnotationContents = + getParent( mojoAnnotatedClass, parameterAnnotationContents, mojoAnnotatedClasses ); + + // move to parent first to build the Map + Collections.reverse( parameterAnnotationContents ); + + Map map = + new HashMap( parameterAnnotationContents.size() ); + + for ( ParameterAnnotationContent parameterAnnotationContent : parameterAnnotationContents ) + { + map.put( parameterAnnotationContent.getFieldName(), parameterAnnotationContent ); + } + return map; + } + + protected List getParent( MojoAnnotatedClass mojoAnnotatedClass, + List parameterAnnotationContents, + Map mojoAnnotatedClasses ) + { + parameterAnnotationContents.addAll( mojoAnnotatedClass.getParameters().values() ); + String parentClassName = mojoAnnotatedClass.getParentClassName(); + if ( parentClassName != null ) + { + MojoAnnotatedClass parent = mojoAnnotatedClasses.get( parentClassName ); + if ( parent != null ) + { + return getParent( parent, parameterAnnotationContents, mojoAnnotatedClasses ); + } + } + return parameterAnnotationContents; + } } diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java index e3301d1..a654199 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java @@ -44,6 +44,8 @@ import java.io.InputStream; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; /** * @author Olivier Lamy @@ -61,6 +63,21 @@ public class DefaultMojoAnnotationsScanner Map mojoAnnotatedClasses = new HashMap(); try { + + //TODO scan dependencies to get super class annotations if exist request.getDependencies() + /*for ( File dependency : request.getDependencies() ) + { + if ( dependency.isDirectory() ) + { + mojoAnnotatedClasses.putAll( scanDirectory( dependency, request.getIncludePatterns() ) ); + } + else + { + mojoAnnotatedClasses.putAll( scanFile( dependency, request.getIncludePatterns() ) ); + } + + }*/ + for ( File classDirectory : request.getClassesDirectories() ) { if ( classDirectory.exists() && classDirectory.isDirectory() ) @@ -69,8 +86,6 @@ public class DefaultMojoAnnotationsScanner } } - //TODO scan dependencies to get super class annotations if exist request.getDependencies() - return mojoAnnotatedClasses; } catch ( IOException e ) @@ -79,6 +94,43 @@ public class DefaultMojoAnnotationsScanner } } + protected Map scanFile( File archiveFile, List includePatterns ) + throws IOException, ExtractionException + { + Map mojoAnnotatedClasses = new HashMap(); + ZipInputStream archiveStream = new ZipInputStream( new FileInputStream( archiveFile ) ); + + try + { + for ( ZipEntry zipEntry = archiveStream.getNextEntry(); zipEntry != null; + zipEntry = archiveStream.getNextEntry() ) + { + if ( zipEntry.getName().endsWith( ".class" ) ) + { + MojoClassVisitor mojoClassVisitor = new MojoClassVisitor( getLogger() ); + + ClassReader rdr = new ClassReader( archiveStream ); + rdr.accept( mojoClassVisitor, + ClassReader.SKIP_FRAMES | ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG ); + analyzeVisitors( mojoClassVisitor ); + if ( isMojoAnnnotatedClassCandidate( mojoClassVisitor.getMojoAnnotatedClass() ) != null ) + { + getLogger().debug( + "found MojoAnnotatedClass:" + mojoClassVisitor.getMojoAnnotatedClass().getClassName() + ":" + + mojoClassVisitor.getMojoAnnotatedClass() ); + mojoAnnotatedClasses.put( mojoClassVisitor.getMojoAnnotatedClass().getClassName(), + mojoClassVisitor.getMojoAnnotatedClass() ); + } + } + } + } + finally + { + IOUtil.close( archiveStream ); + } + return mojoAnnotatedClasses; + } + protected Map scanDirectory( File classDirectory, List includePatterns ) throws IOException, ExtractionException { @@ -108,6 +160,9 @@ public class DefaultMojoAnnotationsScanner analyzeVisitors( mojoClassVisitor ); if ( isMojoAnnnotatedClassCandidate( mojoClassVisitor.getMojoAnnotatedClass() ) != null ) { + getLogger().debug( + "found MojoAnnotatedClass:" + mojoClassVisitor.getMojoAnnotatedClass().getClassName() + ":" + + mojoClassVisitor.getMojoAnnotatedClass() ); mojoAnnotatedClasses.put( mojoClassVisitor.getMojoAnnotatedClass().getClassName(), mojoClassVisitor.getMojoAnnotatedClass() ); } From a4ba9593bb39f783d12f25f363f2534fc8aa8feb Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Mon, 7 May 2012 15:40:20 +0000 Subject: [PATCH 25/48] improve it git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1335070 13f79535-47bb-0310-9956-ffa450edef68 --- maven-plugin-plugin/pom.xml | 2 +- .../invoker.properties | 1 + .../src/it/annotation-with-inheritance/pom.xml | 5 +++++ .../apache/maven/plugin/coreit/FirstMojo.java | 13 +++++++++---- .../main/resources/META-INF/maven/lifecycle.xml | 17 +++++++++++++++++ .../annotation-with-inheritance/verify.groovy | 2 +- 6 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/resources/META-INF/maven/lifecycle.xml diff --git a/maven-plugin-plugin/pom.xml b/maven-plugin-plugin/pom.xml index b16b644..6a4111a 100644 --- a/maven-plugin-plugin/pom.xml +++ b/maven-plugin-plugin/pom.xml @@ -59,9 +59,9 @@ - 2.0.6 1.2 1.2 + 2.0.6 true diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance/invoker.properties b/maven-plugin-plugin/src/it/annotation-with-inheritance/invoker.properties index 26b6a75..71b5b1c 100644 --- a/maven-plugin-plugin/src/it/annotation-with-inheritance/invoker.properties +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance/invoker.properties @@ -1,5 +1,6 @@ invoker.goals.1 = install invoker.goals.2 = org.apache.maven.its.annotation-with-inheritance:annotation-with-inheritance:1.0:it0014 +invoker.goals.3 = org.apache.maven.its.annotation-with-inheritance:annotation-with-inheritance:1.0:first #FIXME disabled need to find a solution for the chicken and eggs issue. #help sources are generated @generated-sources but need descriptor which need compile phase first for classes scanning #invoker.goals.3 = org.apache.maven.its.basic-java-annotations:maven-it-basic-java-annotations:1.0::help diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance/pom.xml b/maven-plugin-plugin/src/it/annotation-with-inheritance/pom.xml index 9901100..d14442c 100644 --- a/maven-plugin-plugin/src/it/annotation-with-inheritance/pom.xml +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance/pom.xml @@ -44,6 +44,11 @@ under the License. maven-plugin-api 2.0 + + org.apache.maven + maven-project + @mavenVersion@ + org.apache.maven.plugin-tools maven-plugin-annotations diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java b/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java index 564b97a..dde40db 100644 --- a/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java @@ -19,7 +19,6 @@ package org.apache.maven.plugin.coreit; * under the License. */ -import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Execute; @@ -27,8 +26,6 @@ import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; -import java.io.File; - /** * Touches a test file. * @@ -48,12 +45,20 @@ public class FirstMojo @Parameter( alias = "alias" ) private String aliasedParam; - @Component( role = "org.apache.maven.project.MavenProjectHelper", roleHint = "test" ) + @Component( role = "org.apache.maven.project.MavenProjectHelper", roleHint = "default" ) private Object projectHelper; public void execute() throws MojoExecutionException { + if ( projectHelper == null ) + { + throw new MojoExecutionException( "projectHelper == null" ); + } + if (basedir == null || touchFile == null) + { + throw new MojoExecutionException( "basedir == null || touchFile == null" ); + } } } diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/resources/META-INF/maven/lifecycle.xml b/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/resources/META-INF/maven/lifecycle.xml new file mode 100644 index 0000000..62d944b --- /dev/null +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/resources/META-INF/maven/lifecycle.xml @@ -0,0 +1,17 @@ + + + cobertura + + + process-classes + + + test + + ${project.build.directory}/generated-classes/cobertura + true + + + + + \ No newline at end of file diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance/verify.groovy b/maven-plugin-plugin/src/it/annotation-with-inheritance/verify.groovy index ef33aa5..32a3d3b 100644 --- a/maven-plugin-plugin/src/it/annotation-with-inheritance/verify.groovy +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance/verify.groovy @@ -35,7 +35,7 @@ assert mojo.configuration.touchFile[0].'@default-value' == '${project.build.dire assert mojo.requirements.requirement.size() == 1 assert mojo.requirements.requirement[0].role.text() == 'org.apache.maven.project.MavenProjectHelper' -assert mojo.requirements.requirement[0].'role-hint'.text() == 'test' +assert mojo.requirements.requirement[0].'role-hint'.text() == 'default' assert mojo.requirements.requirement[0].'field-name'.text() == 'projectHelper' assert mojo.parameters.parameter.size() == 3 From 1a12b4417817bb62ec8284196b728e0d93150fe8 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Mon, 7 May 2012 15:40:34 +0000 Subject: [PATCH 26/48] private field git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1335071 13f79535-47bb-0310-9956-ffa450edef68 --- .../annotations/JavaAnnotationsMojoDescriptorExtractor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 cb7fed6..b81ab5c 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 @@ -64,7 +64,7 @@ public class JavaAnnotationsMojoDescriptorExtractor /** * @requirement */ - MojoAnnotationsScanner mojoAnnotationsScanner; + private MojoAnnotationsScanner mojoAnnotationsScanner; public List execute( MavenProject project, PluginDescriptor pluginDescriptor ) throws ExtractionException, InvalidPluginDescriptorException From e008c8012c69502c76762e7071de1b73226e6b36 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Mon, 7 May 2012 16:15:12 +0000 Subject: [PATCH 27/48] [MPLUGIN-189] support components field inheritance git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1335091 13f79535-47bb-0310-9956-ffa450edef68 --- .../it/annotation-with-inheritance/pom.xml | 23 ++++++++ .../plugin/coreit/AbstractFirstMojo.java | 14 +++++ .../apache/maven/plugin/coreit/FirstMojo.java | 13 ++++- .../annotation-with-inheritance/verify.groovy | 8 +-- ...avaAnnotationsMojoDescriptorExtractor.java | 56 +++++++++++++++++-- 5 files changed, 102 insertions(+), 12 deletions(-) diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance/pom.xml b/maven-plugin-plugin/src/it/annotation-with-inheritance/pom.xml index d14442c..5db6488 100644 --- a/maven-plugin-plugin/src/it/annotation-with-inheritance/pom.xml +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance/pom.xml @@ -36,6 +36,7 @@ under the License. UTF-8 + 1.8.6 @@ -54,6 +55,28 @@ under the License. maven-plugin-annotations @project.version@ + + org.codehaus.plexus + plexus-compiler-manager + ${plexusCompilerVersion} + + + org.codehaus.plexus + plexus-component-api + + + + + org.codehaus.plexus + plexus-compiler-javac + ${plexusCompilerVersion} + + + org.codehaus.plexus + plexus-component-api + + + diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/AbstractFirstMojo.java b/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/AbstractFirstMojo.java index 89545f9..cdcc6a6 100644 --- a/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/AbstractFirstMojo.java +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/AbstractFirstMojo.java @@ -26,6 +26,8 @@ import org.apache.maven.plugins.annotations.Execute; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; +import org.codehaus.plexus.compiler.manager.CompilerManager; +import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import java.io.File; @@ -47,6 +49,18 @@ public abstract class AbstractFirstMojo required = true ) protected File touchFile; + /** + * Plexus compiler manager. + */ + @Component(role = "org.codehaus.plexus.compiler.manager.CompilerManager") + protected CompilerManager compilerManager; + + /** + * + */ + @Component(role = "org.apache.maven.artifact.metadata.ArtifactMetadataSource", roleHint = "maven") + protected ArtifactMetadataSource artifactMetadataSource; + } diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java b/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java index dde40db..ec56ff6 100644 --- a/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java @@ -51,14 +51,23 @@ public class FirstMojo public void execute() throws MojoExecutionException { + if (basedir == null) + { + throw new MojoExecutionException( "basedir == null" ); + } + if (touchFile == null) + { + throw new MojoExecutionException( "touchFile == null" ); + } if ( projectHelper == null ) { throw new MojoExecutionException( "projectHelper == null" ); } - if (basedir == null || touchFile == null) + if ( compilerManager == null ) { - throw new MojoExecutionException( "basedir == null || touchFile == null" ); + throw new MojoExecutionException( "compilerManager == null" ); } + } } diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance/verify.groovy b/maven-plugin-plugin/src/it/annotation-with-inheritance/verify.groovy index 32a3d3b..6c0a341 100644 --- a/maven-plugin-plugin/src/it/annotation-with-inheritance/verify.groovy +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance/verify.groovy @@ -32,11 +32,11 @@ assert mojo.configuration.touchFile[0].text() == '${first.touchFile}' assert mojo.configuration.touchFile[0].'@implementation' == 'java.io.File' assert mojo.configuration.touchFile[0].'@default-value' == '${project.build.directory}/touch.txt' -assert mojo.requirements.requirement.size() == 1 +assert mojo.requirements.requirement.size() == 3 -assert mojo.requirements.requirement[0].role.text() == 'org.apache.maven.project.MavenProjectHelper' -assert mojo.requirements.requirement[0].'role-hint'.text() == 'default' -assert mojo.requirements.requirement[0].'field-name'.text() == 'projectHelper' +assert mojo.requirements.requirement[1].role.text() == 'org.apache.maven.project.MavenProjectHelper' +assert mojo.requirements.requirement[1].'role-hint'.text() == 'default' +assert mojo.requirements.requirement[1].'field-name'.text() == 'projectHelper' assert mojo.parameters.parameter.size() == 3 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 b81ab5c..8b3b17a 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 @@ -357,7 +357,11 @@ public class JavaAnnotationsMojoDescriptorExtractor mojoDescriptor.addParameter( parameter ); } - for ( ComponentAnnotationContent componentAnnotationContent : mojoAnnotatedClass.getComponents().values() ) + Map components = + getComponentsParentHierarchy( mojoAnnotatedClass, new HashMap(), + mojoAnnotatedClasses ); + + for ( ComponentAnnotationContent componentAnnotationContent : components.values() ) { org.apache.maven.plugin.descriptor.Parameter parameter = new org.apache.maven.plugin.descriptor.Parameter(); @@ -383,7 +387,7 @@ public class JavaAnnotationsMojoDescriptorExtractor List parameterAnnotationContents = new ArrayList(); parameterAnnotationContents = - getParent( mojoAnnotatedClass, parameterAnnotationContents, mojoAnnotatedClasses ); + getParametersParent( mojoAnnotatedClass, parameterAnnotationContents, mojoAnnotatedClasses ); // move to parent first to build the Map Collections.reverse( parameterAnnotationContents ); @@ -398,9 +402,9 @@ public class JavaAnnotationsMojoDescriptorExtractor return map; } - protected List getParent( MojoAnnotatedClass mojoAnnotatedClass, - List parameterAnnotationContents, - Map mojoAnnotatedClasses ) + protected List getParametersParent( MojoAnnotatedClass mojoAnnotatedClass, + List parameterAnnotationContents, + Map mojoAnnotatedClasses ) { parameterAnnotationContents.addAll( mojoAnnotatedClass.getParameters().values() ); String parentClassName = mojoAnnotatedClass.getParentClassName(); @@ -409,9 +413,49 @@ public class JavaAnnotationsMojoDescriptorExtractor MojoAnnotatedClass parent = mojoAnnotatedClasses.get( parentClassName ); if ( parent != null ) { - return getParent( parent, parameterAnnotationContents, mojoAnnotatedClasses ); + return getParametersParent( parent, parameterAnnotationContents, mojoAnnotatedClasses ); } } return parameterAnnotationContents; } + + + protected Map getComponentsParentHierarchy( + MojoAnnotatedClass mojoAnnotatedClass, Map components, + Map mojoAnnotatedClasses ) + { + List componentAnnotationContents = new ArrayList(); + + componentAnnotationContents = + getComponentParent( mojoAnnotatedClass, componentAnnotationContents, mojoAnnotatedClasses ); + + // move to parent first to build the Map + Collections.reverse( componentAnnotationContents ); + + Map map = + new HashMap( componentAnnotationContents.size() ); + + for ( ComponentAnnotationContent componentAnnotationContent : componentAnnotationContents ) + { + map.put( componentAnnotationContent.getFieldName(), componentAnnotationContent ); + } + return map; + } + + protected List getComponentParent( MojoAnnotatedClass mojoAnnotatedClass, + List componentAnnotationContents, + Map mojoAnnotatedClasses ) + { + componentAnnotationContents.addAll( mojoAnnotatedClass.getComponents().values() ); + String parentClassName = mojoAnnotatedClass.getParentClassName(); + if ( parentClassName != null ) + { + MojoAnnotatedClass parent = mojoAnnotatedClasses.get( parentClassName ); + if ( parent != null ) + { + return getComponentParent( parent, componentAnnotationContents, mojoAnnotatedClasses ); + } + } + return componentAnnotationContents; + } } From 2373bae3191c0526860c55559f0d68c78085ab63 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Mon, 7 May 2012 16:15:35 +0000 Subject: [PATCH 28/48] [MPLUGIN-189] support components field inheritance without role defined git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1335092 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/maven/plugin/coreit/AbstractFirstMojo.java | 2 +- .../annotations/scanner/DefaultMojoAnnotationsScanner.java | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/AbstractFirstMojo.java b/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/AbstractFirstMojo.java index cdcc6a6..6dcf140 100644 --- a/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/AbstractFirstMojo.java +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/AbstractFirstMojo.java @@ -52,7 +52,7 @@ public abstract class AbstractFirstMojo /** * Plexus compiler manager. */ - @Component(role = "org.codehaus.plexus.compiler.manager.CompilerManager") + @Component protected CompilerManager compilerManager; /** diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java index a654199..70e820a 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java @@ -33,6 +33,7 @@ import org.apache.maven.tools.plugin.extractor.ExtractionException; import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.util.DirectoryScanner; import org.codehaus.plexus.util.IOUtil; +import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.reflection.Reflector; import org.objectweb.asm.ClassReader; @@ -256,7 +257,10 @@ public class DefaultMojoAnnotationsScanner reflector.invoke( componentAnnotationContent, entry.getKey(), new Object[]{ entry.getValue() } ); } - + if ( StringUtils.isEmpty( componentAnnotationContent.role() ) ) + { + componentAnnotationContent.role( mojoFieldVisitor.getClassName() ); + } } mojoClassVisitor.getMojoAnnotatedClass().getComponents().put( componentAnnotationContent.getFieldName(), componentAnnotationContent ); From 77a87b0236c1f2f39ab42b59ffcc900e0f9143d3 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Tue, 8 May 2012 21:00:16 +0000 Subject: [PATCH 29/48] [MPLUGIN-189] support inheritence from classes available in dependencies: it with annotations in parent class available in reactors git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1335763 13f79535-47bb-0310-9956-ffa450edef68 --- .../invoker.properties | 6 ++ .../module-abstract-mojo/pom.xml | 32 ++++++++ .../maven/plugins/AbstractFirstMojo.java | 66 +++++++++++++++ .../module-mojo/pom.xml | 59 ++++++++++++++ .../maven/plugin/coreit/CoreIt0014Mojo.java | 66 +++++++++++++++ .../apache/maven/plugin/coreit/FirstMojo.java | 74 +++++++++++++++++ .../maven/plugin/coreit/SecondMojo.java | 38 +++++++++ .../resources/META-INF/maven/lifecycle.xml | 17 ++++ .../pom.xml | 81 +++++++++++++++++++ .../verify.groovy | 78 ++++++++++++++++++ .../DefaultMojoAnnotationsScanner.java | 14 +++- 11 files changed, 528 insertions(+), 3 deletions(-) create mode 100644 maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/invoker.properties create mode 100644 maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/module-abstract-mojo/pom.xml create mode 100644 maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/module-abstract-mojo/src/main/java/org/apache/maven/plugins/AbstractFirstMojo.java create mode 100644 maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/module-mojo/pom.xml create mode 100644 maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/module-mojo/src/main/java/org/apache/maven/plugin/coreit/CoreIt0014Mojo.java create mode 100644 maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/module-mojo/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java create mode 100644 maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/module-mojo/src/main/java/org/apache/maven/plugin/coreit/SecondMojo.java create mode 100644 maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/module-mojo/src/main/resources/META-INF/maven/lifecycle.xml create mode 100644 maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/pom.xml create mode 100644 maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/verify.groovy diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/invoker.properties b/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/invoker.properties new file mode 100644 index 0000000..ebc1644 --- /dev/null +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/invoker.properties @@ -0,0 +1,6 @@ +invoker.goals.1 = clean install -DskipTests +invoker.goals.2 = org.apache.maven.its.annotation-with-inheritance-reactor:module-mojo:1.0-SNAPSHOT:it0014 +invoker.goals.3 = org.apache.maven.its.annotation-with-inheritance-reactor:module-mojo:1.0-SNAPSHOT:first +#FIXME disabled need to find a solution for the chicken and eggs issue. +#help sources are generated @generated-sources but need descriptor which need compile phase first for classes scanning +#invoker.goals.3 = org.apache.maven.its.basic-java-annotations:maven-it-basic-java-annotations:1.0::help diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/module-abstract-mojo/pom.xml b/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/module-abstract-mojo/pom.xml new file mode 100644 index 0000000..ab6d5ed --- /dev/null +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/module-abstract-mojo/pom.xml @@ -0,0 +1,32 @@ + + + + + + 4.0.0 + + org.apache.maven.its.annotation-with-inheritance-reactor + annotation-with-inheritance-reactor + 1.0-SNAPSHOT + + module-abstract-mojo + + + diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/module-abstract-mojo/src/main/java/org/apache/maven/plugins/AbstractFirstMojo.java b/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/module-abstract-mojo/src/main/java/org/apache/maven/plugins/AbstractFirstMojo.java new file mode 100644 index 0000000..bfc8a4e --- /dev/null +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/module-abstract-mojo/src/main/java/org/apache/maven/plugins/AbstractFirstMojo.java @@ -0,0 +1,66 @@ +package org.apache.maven.plugins; + +/* + * 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.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +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; +import org.apache.maven.plugins.annotations.Parameter; +import org.codehaus.plexus.compiler.manager.CompilerManager; +import org.apache.maven.artifact.metadata.ArtifactMetadataSource; + +import java.io.File; + +/** + * Touches a test file. + * + */ +public abstract class AbstractFirstMojo + extends AbstractMojo +{ + + /** + * Project directory. + */ + @Parameter( defaultValue = "${basedir}", readonly = true ) + protected File basedir; + + @Parameter( expression = "${first.touchFile}", defaultValue = "${project.build.directory}/touch.txt", + required = true ) + protected File touchFile; + + /** + * Plexus compiler manager. + */ + @Component + protected CompilerManager compilerManager; + + /** + * + */ + @Component(role = "org.apache.maven.artifact.metadata.ArtifactMetadataSource", roleHint = "maven") + protected ArtifactMetadataSource artifactMetadataSource; + + + +} diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/module-mojo/pom.xml b/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/module-mojo/pom.xml new file mode 100644 index 0000000..4441a23 --- /dev/null +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/module-mojo/pom.xml @@ -0,0 +1,59 @@ + + + + + + 4.0.0 + + org.apache.maven.its.annotation-with-inheritance-reactor + annotation-with-inheritance-reactor + 1.0-SNAPSHOT + + maven-plugin + module-mojo + + + org.apache.maven.its.annotation-with-inheritance-reactor + module-abstract-mojo + ${project.version} + + + + + + org.apache.maven.plugins + maven-plugin-plugin + @project.version@ + + true + + + + mojo-descriptor + process-classes + + descriptor + + + + + + + diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/module-mojo/src/main/java/org/apache/maven/plugin/coreit/CoreIt0014Mojo.java b/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/module-mojo/src/main/java/org/apache/maven/plugin/coreit/CoreIt0014Mojo.java new file mode 100644 index 0000000..b6dc2fa --- /dev/null +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/module-mojo/src/main/java/org/apache/maven/plugin/coreit/CoreIt0014Mojo.java @@ -0,0 +1,66 @@ +package org.apache.maven.plugin.coreit; + +/* + * 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.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; + +import java.io.File; +import java.io.IOException; + +/** + * Touches a test file. + * + */ +@Mojo( name = "it0014") +public class CoreIt0014Mojo + extends AbstractMojo +{ + + @Parameter(expression ="${project.build.directory}", required = true) + private String outputDirectory; + + public void execute() + throws MojoExecutionException + { + getLog().info( "outputDirectory = " + outputDirectory ); + + File f = new File( outputDirectory ); + + if ( !f.exists() ) + { + f.mkdirs(); + } + + File touch = new File( f, "touch.txt" ); + + try + { + touch.createNewFile(); + } + catch ( IOException e ) + { + throw new MojoExecutionException( "Error writing verification file.", e ); + } + } + +} diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/module-mojo/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java b/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/module-mojo/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java new file mode 100644 index 0000000..c56fcb8 --- /dev/null +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/module-mojo/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java @@ -0,0 +1,74 @@ +package org.apache.maven.plugin.coreit; + +/* + * 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.plugin.MojoExecutionException; +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; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.plugins.AbstractFirstMojo; + +/** + * Touches a test file. + * + * @since 1.2 + * @deprecated Don't use! + */ +@Mojo( name = "first", requiresDependencyResolution = "test", defaultPhase = LifecyclePhase.INTEGRATION_TEST ) +@Execute( phase = LifecyclePhase.GENERATE_SOURCES, lifecycle = "cobertura" ) +public class FirstMojo + extends AbstractFirstMojo +{ + + /** + * @since 0.1 + * @deprecated As of 0.2 + */ + @Parameter( alias = "alias" ) + private String aliasedParam; + + @Component( role = "org.apache.maven.project.MavenProjectHelper", roleHint = "default" ) + private Object projectHelper; + + public void execute() + throws MojoExecutionException + { + if (basedir == null) + { + throw new MojoExecutionException( "basedir == null" ); + } + if (touchFile == null) + { + throw new MojoExecutionException( "touchFile == null" ); + } + if ( projectHelper == null ) + { + throw new MojoExecutionException( "projectHelper == null" ); + } + if ( compilerManager == null ) + { + throw new MojoExecutionException( "compilerManager == null" ); + } + + } + +} diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/module-mojo/src/main/java/org/apache/maven/plugin/coreit/SecondMojo.java b/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/module-mojo/src/main/java/org/apache/maven/plugin/coreit/SecondMojo.java new file mode 100644 index 0000000..8e28eba --- /dev/null +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/module-mojo/src/main/java/org/apache/maven/plugin/coreit/SecondMojo.java @@ -0,0 +1,38 @@ +package org.apache.maven.plugin.coreit; + +/* + * 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.plugin.AbstractMojo; +import org.apache.maven.plugins.annotations.Mojo; + +/** + * Does nothing special. + * + */ +@Mojo( name = "second",requiresDependencyCollection = "compile", threadSafe = true) +public class SecondMojo + extends AbstractMojo +{ + + public void execute() + { + } + +} diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/module-mojo/src/main/resources/META-INF/maven/lifecycle.xml b/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/module-mojo/src/main/resources/META-INF/maven/lifecycle.xml new file mode 100644 index 0000000..62d944b --- /dev/null +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/module-mojo/src/main/resources/META-INF/maven/lifecycle.xml @@ -0,0 +1,17 @@ + + + cobertura + + + process-classes + + + test + + ${project.build.directory}/generated-classes/cobertura + true + + + + + \ No newline at end of file diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/pom.xml b/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/pom.xml new file mode 100644 index 0000000..b453941 --- /dev/null +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/pom.xml @@ -0,0 +1,81 @@ + + + + + + 4.0.0 + + org.apache.maven.its.annotation-with-inheritance-reactor + annotation-with-inheritance-reactor + 1.0-SNAPSHOT + + Maven Integration Test :: annotation-with-inheritance + pom + + module-abstract-mojo + module-mojo + + + + UTF-8 + 1.8.6 + + + + + org.apache.maven + maven-plugin-api + 2.0 + + + org.apache.maven + maven-project + @mavenVersion@ + + + org.apache.maven.plugin-tools + maven-plugin-annotations + @project.version@ + + + org.codehaus.plexus + plexus-compiler-manager + ${plexusCompilerVersion} + + + org.codehaus.plexus + plexus-component-api + + + + + org.codehaus.plexus + plexus-compiler-javac + ${plexusCompilerVersion} + + + org.codehaus.plexus + plexus-component-api + + + + + + diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/verify.groovy b/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/verify.groovy new file mode 100644 index 0000000..33505e3 --- /dev/null +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/verify.groovy @@ -0,0 +1,78 @@ +File touchFile = new File( basedir, "module-mojo/target/touch.txt" ) +assert touchFile.isFile() + +File descriptorFile = new File( basedir, "module-mojo/target/classes/META-INF/maven/plugin.xml" ); +assert descriptorFile.isFile() + +def pluginDescriptor = new XmlParser().parse( descriptorFile ); + +def mojo = pluginDescriptor.mojos.mojo.findAll{ it.goal.text() == "first"}[0] + +assert mojo.goal.text() == 'first' +assert mojo.implementation.text() == 'org.apache.maven.plugin.coreit.FirstMojo' +assert mojo.language.text() == 'java' +assert mojo.description.text() == 'Touches a test file.' +assert mojo.deprecated.text() == "Don't use!" +assert mojo.requiresDependencyResolution.text() == 'test' +assert mojo.requiresDependencyCollection.text() == '' +assert mojo.requiresProject.text() == 'true' +assert mojo.requiresOnline.text() == 'false' +assert mojo.requiresDirectInvocation.text() == 'false' +assert mojo.aggregator.text() == 'false' +assert mojo.threadSafe.text() == 'false' +assert mojo.phase.text() == 'integration-test' +assert mojo.executePhase.text() == 'generate-sources' +assert mojo.executeLifecycle.text() == 'cobertura' + +assert mojo.configuration.basedir[0].text() == '' +assert mojo.configuration.basedir[0].'@implementation' == 'java.io.File' +assert mojo.configuration.basedir[0].'@default-value' == '${basedir}' + +assert mojo.configuration.touchFile[0].text() == '${first.touchFile}' +assert mojo.configuration.touchFile[0].'@implementation' == 'java.io.File' +assert mojo.configuration.touchFile[0].'@default-value' == '${project.build.directory}/touch.txt' + +assert mojo.requirements.requirement.size() == 3 + +assert mojo.requirements.requirement[1].role.text() == 'org.apache.maven.project.MavenProjectHelper' +assert mojo.requirements.requirement[1].'role-hint'.text() == 'default' +assert mojo.requirements.requirement[1].'field-name'.text() == 'projectHelper' + +assert mojo.parameters.parameter.size() == 3 + +def parameter = mojo.parameters.parameter.findAll{ it.name.text() == "aliasedParam"}[0] + +assert parameter.name.text() == 'aliasedParam' +assert parameter.alias.text() == 'alias' +assert parameter.type.text() == 'java.lang.String' +assert parameter.deprecated.text() == 'As of 0.2' +assert parameter.required.text() == 'false' +assert parameter.editable.text() == 'true' +assert parameter.description.text() == '' + +parameter = mojo.parameters.parameter.findAll{ it.name.text() == "touchFile"}[0] + +assert parameter.name.text() == 'touchFile' +assert parameter.alias.isEmpty() +assert parameter.type.text() == 'java.io.File' +assert parameter.deprecated.isEmpty() +assert parameter.required.text() == 'true' +assert parameter.editable.text() == 'true' +assert parameter.description.text() == '' + +parameter = mojo.parameters.parameter.findAll{ it.name.text() == "basedir"}[0] + +assert parameter.name.text() == 'basedir' +assert parameter.alias.isEmpty() +assert parameter.type.text() == 'java.io.File' +assert parameter.deprecated.isEmpty() +assert parameter.required.text() == 'false' +assert parameter.editable.text() == 'false' +assert parameter.description.text() == 'Project directory.' + +mojo = pluginDescriptor.mojos.mojo.findAll{ it.goal.text() == "second"}[0] + +assert mojo.requiresDependencyCollection.text() == 'compile' +assert mojo.threadSafe.text() == 'true' + +return true; diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java index 70e820a..c21b886 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java @@ -42,6 +42,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -65,8 +66,7 @@ public class DefaultMojoAnnotationsScanner try { - //TODO scan dependencies to get super class annotations if exist request.getDependencies() - /*for ( File dependency : request.getDependencies() ) + for ( File dependency : request.getDependencies() ) { if ( dependency.isDirectory() ) { @@ -77,7 +77,7 @@ public class DefaultMojoAnnotationsScanner mojoAnnotatedClasses.putAll( scanFile( dependency, request.getIncludePatterns() ) ); } - }*/ + } for ( File classDirectory : request.getClassesDirectories() ) { @@ -98,6 +98,10 @@ public class DefaultMojoAnnotationsScanner protected Map scanFile( File archiveFile, List includePatterns ) throws IOException, ExtractionException { + if ( !archiveFile.exists() ) + { + return Collections.emptyMap(); + } Map mojoAnnotatedClasses = new HashMap(); ZipInputStream archiveStream = new ZipInputStream( new FileInputStream( archiveFile ) ); @@ -135,6 +139,10 @@ public class DefaultMojoAnnotationsScanner protected Map scanDirectory( File classDirectory, List includePatterns ) throws IOException, ExtractionException { + if ( !classDirectory.exists() ) + { + return Collections.emptyMap(); + } Map mojoAnnotatedClasses = new HashMap(); DirectoryScanner scanner = new DirectoryScanner(); scanner.setBasedir( classDirectory ); From 18e8cb4178785b72d285869e56253d7b4599a8e0 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Tue, 8 May 2012 21:00:44 +0000 Subject: [PATCH 30/48] use artifacts for scanning for future use git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1335764 13f79535-47bb-0310-9956-ffa450edef68 --- .../plugin/plugin/AbstractGeneratorMojo.java | 12 ++++++++ ...avaAnnotationsMojoDescriptorExtractor.java | 29 +++++++------------ .../DefaultMojoAnnotationsScanner.java | 20 ++++++++----- .../MojoAnnotationsScannerRequest.java | 10 +++++-- .../plugin/DefaultPluginToolsRequest.java | 29 ++++++++++++++++--- .../tools/plugin/PluginToolsRequest.java | 18 +++++++++++- 6 files changed, 84 insertions(+), 34 deletions(-) diff --git a/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/AbstractGeneratorMojo.java b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/AbstractGeneratorMojo.java index 00702a6..085bf15 100644 --- a/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/AbstractGeneratorMojo.java +++ b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/AbstractGeneratorMojo.java @@ -19,6 +19,7 @@ package org.apache.maven.plugin.plugin; * under the License. */ +import org.apache.maven.artifact.Artifact; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException; @@ -123,6 +124,16 @@ public abstract class AbstractGeneratorMojo */ protected boolean skip; + /** + * The set of dependencies for the current project + * + * @parameter default-value = "${project.artifacts}" + * @required + * @readonly + * @since 3.0 + */ + protected Set dependencies; + /** * @return the output directory where files will be generated. */ @@ -203,6 +214,7 @@ public abstract class AbstractGeneratorMojo PluginToolsRequest request = new DefaultPluginToolsRequest( project, pluginDescriptor ); request.setEncoding( encoding ); request.setSkipErrorNoDescriptorsFound( skipErrorNoDescriptorsFound ); + request.setDependencies( dependencies ); mojoScanner.populatePluginDescriptor( request ); 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 8b3b17a..194cb7d 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 @@ -22,7 +22,6 @@ import com.thoughtworks.qdox.JavaDocBuilder; import com.thoughtworks.qdox.model.DocletTag; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaField; -import org.apache.maven.artifact.DependencyResolutionRequiredException; import org.apache.maven.plugin.descriptor.DuplicateParameterException; import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException; import org.apache.maven.plugin.descriptor.MojoDescriptor; @@ -75,29 +74,23 @@ public class JavaAnnotationsMojoDescriptorExtractor public List execute( PluginToolsRequest request ) throws ExtractionException, InvalidPluginDescriptorException { - try - { - MojoAnnotationsScannerRequest mojoAnnotationsScannerRequest = new MojoAnnotationsScannerRequest(); - mojoAnnotationsScannerRequest.setClassesDirectories( - Arrays.asList( new File( request.getProject().getBuild().getOutputDirectory() ) ) ); + MojoAnnotationsScannerRequest mojoAnnotationsScannerRequest = new MojoAnnotationsScannerRequest(); - mojoAnnotationsScannerRequest.setDependencies( - toFiles( request.getProject().getCompileClasspathElements() ) ); + mojoAnnotationsScannerRequest.setClassesDirectories( + Arrays.asList( new File( request.getProject().getBuild().getOutputDirectory() ) ) ); - Map mojoAnnotatedClasses = - mojoAnnotationsScanner.scan( mojoAnnotationsScannerRequest ); + mojoAnnotationsScannerRequest.setDependencies( request.getDependencies() ); - Map javaClassesMap = discoverClasses( request ); + Map mojoAnnotatedClasses = + mojoAnnotationsScanner.scan( mojoAnnotationsScannerRequest ); - populateDataFromJavadoc( mojoAnnotatedClasses, javaClassesMap ); + Map javaClassesMap = discoverClasses( request ); + + populateDataFromJavadoc( mojoAnnotatedClasses, javaClassesMap ); + + return toMojoDescriptors( mojoAnnotatedClasses, request ); - return toMojoDescriptors( mojoAnnotatedClasses, request ); - } - catch ( DependencyResolutionRequiredException e ) - { - throw new ExtractionException( e.getMessage(), e ); - } } /** diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java index c21b886..ffc8a2c 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java @@ -18,6 +18,7 @@ package org.apache.maven.tools.plugin.annotations.scanner; * under the License. */ +import org.apache.maven.artifact.Artifact; import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Execute; import org.apache.maven.plugins.annotations.Mojo; @@ -66,17 +67,20 @@ public class DefaultMojoAnnotationsScanner try { - for ( File dependency : request.getDependencies() ) + for ( Artifact dependency : request.getDependencies() ) { - if ( dependency.isDirectory() ) + File dependencyFile = dependency.getFile(); + if ( dependencyFile != null && dependencyFile.exists() ) { - mojoAnnotatedClasses.putAll( scanDirectory( dependency, request.getIncludePatterns() ) ); + if ( dependencyFile.isDirectory() ) + { + mojoAnnotatedClasses.putAll( scanDirectory( dependencyFile, request.getIncludePatterns() ) ); + } + else + { + mojoAnnotatedClasses.putAll( scanFile( dependencyFile, request.getIncludePatterns() ) ); + } } - else - { - mojoAnnotatedClasses.putAll( scanFile( dependency, request.getIncludePatterns() ) ); - } - } for ( File classDirectory : request.getClassesDirectories() ) diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotationsScannerRequest.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotationsScannerRequest.java index faf1bb7..90d4859 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotationsScannerRequest.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotationsScannerRequest.java @@ -18,10 +18,14 @@ package org.apache.maven.tools.plugin.annotations.scanner; * under the License. */ +import org.apache.maven.artifact.Artifact; + import java.io.File; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashSet; import java.util.List; +import java.util.Set; /** * @author Olivier Lamy @@ -31,7 +35,7 @@ public class MojoAnnotationsScannerRequest { private List classesDirectories = new ArrayList(); - private List dependencies = new ArrayList(); + private Set dependencies = new HashSet(); private List includePatterns = Arrays.asList( "**/*.class" ); @@ -52,12 +56,12 @@ public class MojoAnnotationsScannerRequest this.classesDirectories = classesDirectories; } - public List getDependencies() + public Set getDependencies() { return dependencies; } - public void setDependencies( List dependencies ) + public void setDependencies( Set dependencies ) { this.dependencies = dependencies; } diff --git a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/DefaultPluginToolsRequest.java b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/DefaultPluginToolsRequest.java index fd6a60e..73ef0fc 100644 --- a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/DefaultPluginToolsRequest.java +++ b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/DefaultPluginToolsRequest.java @@ -19,23 +19,27 @@ package org.apache.maven.tools.plugin; * under the License. */ +import org.apache.maven.artifact.Artifact; import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.util.ReaderFactory; import org.codehaus.plexus.util.StringUtils; +import java.util.HashSet; +import java.util.Set; + /** * Default implementation of {@link PluginToolsRequest}, which is used to pass parameters to components used to extract * {@link MojoDescriptor} instances from different types of metadata for a given plugin. - * + * * @author jdcasey * @since 2.5 */ public class DefaultPluginToolsRequest implements PluginToolsRequest { - + private static final String DEFAULT_ENCODING = ReaderFactory.FILE_ENCODING; private PluginDescriptor pluginDescriptor; @@ -46,6 +50,8 @@ public class DefaultPluginToolsRequest private boolean skipErrorNoDescriptorsFound; + private Set dependencies; + public DefaultPluginToolsRequest( MavenProject project, PluginDescriptor pluginDescriptor ) { this.project = project; @@ -59,7 +65,7 @@ public class DefaultPluginToolsRequest { return pluginDescriptor; } - + /** * {@inheritDoc} */ @@ -76,7 +82,7 @@ public class DefaultPluginToolsRequest { return project; } - + /** * {@inheritDoc} */ @@ -127,4 +133,19 @@ public class DefaultPluginToolsRequest this.skipErrorNoDescriptorsFound = skipErrorNoDescriptorsFound; return this; } + + public Set getDependencies() + { + if ( this.dependencies == null ) + { + this.dependencies = new HashSet(); + } + return dependencies; + } + + public PluginToolsRequest setDependencies( Set dependencies ) + { + this.dependencies = dependencies; + return this; + } } diff --git a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/PluginToolsRequest.java b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/PluginToolsRequest.java index 531ad83..0cdf998 100644 --- a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/PluginToolsRequest.java +++ b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/PluginToolsRequest.java @@ -19,10 +19,13 @@ package org.apache.maven.tools.plugin; * under the License. */ +import org.apache.maven.artifact.Artifact; import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.project.MavenProject; +import java.util.Set; + /** * Request that encapsulates all information relevant to the process of extracting {@link MojoDescriptor} * instances from metadata for a certain type of mojo. @@ -74,16 +77,29 @@ public interface PluginToolsRequest * By default an exception is throw if no mojo descriptor is found. As the maven-plugin is defined in core, the * descriptor generator mojo is bound to generate-resources phase. * But for annotations, the compiled classes are needed, so skip error + * * @since 3.0 */ PluginToolsRequest setSkipErrorNoDescriptorsFound( boolean skipErrorNoDescriptorsFound ); /** - * @since 3.0 * @return + * @since 3.0 */ boolean isSkipErrorNoDescriptorsFound(); + /** + * Returns the list of {@link Artifact} used in class path scanning for annotations + * @return + * @since 3.0 + */ + Set getDependencies(); + /** + * + * @param dependencies + * @return + */ + PluginToolsRequest setDependencies( Set dependencies ); } From 3dd6a922a9fe776286ed9fca7f09be24f2ffa434 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Tue, 8 May 2012 21:01:10 +0000 Subject: [PATCH 31/48] store the origin artifact of the annotation for later use git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1335765 13f79535-47bb-0310-9956-ffa450edef68 --- .../verify.groovy | 2 ++ .../JavaAnnotationsMojoDescriptorExtractor.java | 2 ++ .../annotations/datamodel/AnnotatedContent.java | 4 ++++ .../scanner/DefaultMojoAnnotationsScanner.java | 17 ++++++++++++----- .../annotations/scanner/MojoAnnotatedClass.java | 15 +++++++++++++++ .../scanner/MojoAnnotationsScannerRequest.java | 14 ++++++++++++++ .../annotations/TestAnnotationsReader.java | 2 ++ 7 files changed, 51 insertions(+), 5 deletions(-) diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/verify.groovy b/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/verify.groovy index 33505e3..8c7c541 100644 --- a/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/verify.groovy +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/verify.groovy @@ -6,6 +6,8 @@ assert descriptorFile.isFile() def pluginDescriptor = new XmlParser().parse( descriptorFile ); +assert pluginDescriptor.mojos.mojo.size() == 3 + def mojo = pluginDescriptor.mojos.mojo.findAll{ it.goal.text() == "first"}[0] assert mojo.goal.text() == 'first' 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 194cb7d..ea470f9 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 @@ -82,6 +82,8 @@ public class JavaAnnotationsMojoDescriptorExtractor mojoAnnotationsScannerRequest.setDependencies( request.getDependencies() ); + mojoAnnotationsScannerRequest.setProject( request.getProject() ); + Map mojoAnnotatedClasses = mojoAnnotationsScanner.scan( mojoAnnotationsScannerRequest ); diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/AnnotatedContent.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/AnnotatedContent.java index fb687ca..3869117 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/AnnotatedContent.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/AnnotatedContent.java @@ -18,12 +18,15 @@ package org.apache.maven.tools.plugin.annotations.datamodel; * under the License. */ +import org.apache.maven.artifact.Artifact; + /** * @author Olivier Lamy * @since 3.0 */ public class AnnotatedContent { + private String description; private String since; @@ -59,4 +62,5 @@ public class AnnotatedContent { this.deprecated = deprecated; } + } diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java index ffc8a2c..80cbf9d 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java @@ -74,11 +74,13 @@ public class DefaultMojoAnnotationsScanner { if ( dependencyFile.isDirectory() ) { - mojoAnnotatedClasses.putAll( scanDirectory( dependencyFile, request.getIncludePatterns() ) ); + mojoAnnotatedClasses.putAll( + scanDirectory( dependencyFile, request.getIncludePatterns(), dependency ) ); } else { - mojoAnnotatedClasses.putAll( scanFile( dependencyFile, request.getIncludePatterns() ) ); + mojoAnnotatedClasses.putAll( + scanFile( dependencyFile, request.getIncludePatterns(), dependency ) ); } } } @@ -87,7 +89,8 @@ public class DefaultMojoAnnotationsScanner { if ( classDirectory.exists() && classDirectory.isDirectory() ) { - mojoAnnotatedClasses.putAll( scanDirectory( classDirectory, request.getIncludePatterns() ) ); + mojoAnnotatedClasses.putAll( scanDirectory( classDirectory, request.getIncludePatterns(), + request.getProject().getArtifact() ) ); } } @@ -99,7 +102,8 @@ public class DefaultMojoAnnotationsScanner } } - protected Map scanFile( File archiveFile, List includePatterns ) + protected Map scanFile( File archiveFile, List includePatterns, + Artifact artifact ) throws IOException, ExtractionException { if ( !archiveFile.exists() ) @@ -127,6 +131,7 @@ public class DefaultMojoAnnotationsScanner getLogger().debug( "found MojoAnnotatedClass:" + mojoClassVisitor.getMojoAnnotatedClass().getClassName() + ":" + mojoClassVisitor.getMojoAnnotatedClass() ); + mojoClassVisitor.getMojoAnnotatedClass().setArtifact( artifact ); mojoAnnotatedClasses.put( mojoClassVisitor.getMojoAnnotatedClass().getClassName(), mojoClassVisitor.getMojoAnnotatedClass() ); } @@ -140,7 +145,8 @@ public class DefaultMojoAnnotationsScanner return mojoAnnotatedClasses; } - protected Map scanDirectory( File classDirectory, List includePatterns ) + protected Map scanDirectory( File classDirectory, List includePatterns, + Artifact artifact ) throws IOException, ExtractionException { if ( !classDirectory.exists() ) @@ -176,6 +182,7 @@ public class DefaultMojoAnnotationsScanner getLogger().debug( "found MojoAnnotatedClass:" + mojoClassVisitor.getMojoAnnotatedClass().getClassName() + ":" + mojoClassVisitor.getMojoAnnotatedClass() ); + mojoClassVisitor.getMojoAnnotatedClass().setArtifact( artifact ); mojoAnnotatedClasses.put( mojoClassVisitor.getMojoAnnotatedClass().getClassName(), mojoClassVisitor.getMojoAnnotatedClass() ); } diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotatedClass.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotatedClass.java index 2cc65d2..847634e 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotatedClass.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotatedClass.java @@ -18,6 +18,7 @@ package org.apache.maven.tools.plugin.annotations.scanner; * under the License. */ +import org.apache.maven.artifact.Artifact; import org.apache.maven.tools.plugin.annotations.datamodel.ComponentAnnotationContent; import org.apache.maven.tools.plugin.annotations.datamodel.ExecuteAnnotationContent; import org.apache.maven.tools.plugin.annotations.datamodel.MojoAnnotationContent; @@ -50,6 +51,11 @@ public class MojoAnnotatedClass */ private Map components; + /** + * artifact which contains this annotation + */ + private Artifact artifact; + public MojoAnnotatedClass() { // no op @@ -129,6 +135,15 @@ public class MojoAnnotatedClass return this; } + public Artifact getArtifact() + { + return artifact; + } + + public void setArtifact( Artifact artifact ) + { + this.artifact = artifact; + } @Override public String toString() diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotationsScannerRequest.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotationsScannerRequest.java index 90d4859..af144d1 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotationsScannerRequest.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/MojoAnnotationsScannerRequest.java @@ -19,6 +19,8 @@ package org.apache.maven.tools.plugin.annotations.scanner; */ import org.apache.maven.artifact.Artifact; +import org.apache.maven.project.MavenProject; +import org.apache.maven.project.artifact.ProjectArtifactMetadata; import java.io.File; import java.util.ArrayList; @@ -41,6 +43,8 @@ public class MojoAnnotationsScannerRequest private List sourceDirectories = new ArrayList(); + private MavenProject project; + public MojoAnnotationsScannerRequest() { // no o @@ -85,4 +89,14 @@ public class MojoAnnotationsScannerRequest { this.sourceDirectories = sourceDirectories; } + + public MavenProject getProject() + { + return project; + } + + public void setProject( MavenProject project ) + { + this.project = project; + } } diff --git a/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/TestAnnotationsReader.java b/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/TestAnnotationsReader.java index 8856e90..0e13bad 100644 --- a/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/TestAnnotationsReader.java +++ b/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/TestAnnotationsReader.java @@ -22,6 +22,7 @@ import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugins.annotations.Execute; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.project.MavenProject; import org.apache.maven.tools.plugin.annotations.datamodel.ComponentAnnotationContent; import org.apache.maven.tools.plugin.annotations.datamodel.ParameterAnnotationContent; import org.apache.maven.tools.plugin.annotations.scanner.MojoAnnotatedClass; @@ -50,6 +51,7 @@ public class TestAnnotationsReader MojoAnnotationsScannerRequest request = new MojoAnnotationsScannerRequest(); request.setClassesDirectories( Collections.singletonList( new File( "target/test-classes" ) ) ); request.setIncludePatterns( Arrays.asList( "**/FooMojo.class" ) ); + request.setProject( new MavenProject( ) ); Map mojoAnnotatedClasses = mojoAnnotationsScanner.scan( request ); From 261a3cf86a08b76a2684a8dd48bda60a9832eb70 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Tue, 8 May 2012 21:01:28 +0000 Subject: [PATCH 32/48] exclude @Mojo annotation when coming from classes from dependencies git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1335766 13f79535-47bb-0310-9956-ffa450edef68 --- maven-plugin-plugin/pom.xml | 8 ++++ .../pom.xml | 6 +++ maven-plugin-tools-annotations/pom.xml | 16 ++++++++ .../DefaultMojoAnnotationsScanner.java | 39 ++++++++++++++++--- 4 files changed, 63 insertions(+), 6 deletions(-) diff --git a/maven-plugin-plugin/pom.xml b/maven-plugin-plugin/pom.xml index 6a4111a..fb90486 100644 --- a/maven-plugin-plugin/pom.xml +++ b/maven-plugin-plugin/pom.xml @@ -316,6 +316,14 @@ + + + org.apache.maven.plugin-tools + maven-plugin-tools-annotations + ${project.version} + tests + + diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/pom.xml b/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/pom.xml index b453941..5bf61cf 100644 --- a/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/pom.xml +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/pom.xml @@ -44,6 +44,12 @@ under the License. maven-plugin-api 2.0 + + org.apache.maven.plugin-tools + maven-plugin-tools-annotations + @project.version@ + tests + org.apache.maven maven-project diff --git a/maven-plugin-tools-annotations/pom.xml b/maven-plugin-tools-annotations/pom.xml index 0c832fb..cf09fba 100644 --- a/maven-plugin-tools-annotations/pom.xml +++ b/maven-plugin-tools-annotations/pom.xml @@ -79,4 +79,20 @@ + + + + org.apache.maven.plugins + maven-jar-plugin + + + + test-jar + + + + + + + diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java index 80cbf9d..44e1788 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/scanner/DefaultMojoAnnotationsScanner.java @@ -75,12 +75,12 @@ public class DefaultMojoAnnotationsScanner if ( dependencyFile.isDirectory() ) { mojoAnnotatedClasses.putAll( - scanDirectory( dependencyFile, request.getIncludePatterns(), dependency ) ); + scanDirectory( dependencyFile, request.getIncludePatterns(), dependency, true ) ); } else { mojoAnnotatedClasses.putAll( - scanFile( dependencyFile, request.getIncludePatterns(), dependency ) ); + scanFile( dependencyFile, request.getIncludePatterns(), dependency, true ) ); } } } @@ -89,8 +89,9 @@ public class DefaultMojoAnnotationsScanner { if ( classDirectory.exists() && classDirectory.isDirectory() ) { - mojoAnnotatedClasses.putAll( scanDirectory( classDirectory, request.getIncludePatterns(), - request.getProject().getArtifact() ) ); + mojoAnnotatedClasses.putAll( + scanDirectory( classDirectory, request.getIncludePatterns(), request.getProject().getArtifact(), + false ) ); } } @@ -102,8 +103,17 @@ public class DefaultMojoAnnotationsScanner } } + /** + * @param archiveFile + * @param includePatterns + * @param artifact + * @param excludeMojo for dependencies we exclude Mojo annotations found + * @return + * @throws IOException + * @throws ExtractionException + */ protected Map scanFile( File archiveFile, List includePatterns, - Artifact artifact ) + Artifact artifact, boolean excludeMojo ) throws IOException, ExtractionException { if ( !archiveFile.exists() ) @@ -126,6 +136,10 @@ public class DefaultMojoAnnotationsScanner rdr.accept( mojoClassVisitor, ClassReader.SKIP_FRAMES | ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG ); analyzeVisitors( mojoClassVisitor ); + if ( excludeMojo ) + { + mojoClassVisitor.getMojoAnnotatedClass().setMojo( null ); + } if ( isMojoAnnnotatedClassCandidate( mojoClassVisitor.getMojoAnnotatedClass() ) != null ) { getLogger().debug( @@ -145,8 +159,17 @@ public class DefaultMojoAnnotationsScanner return mojoAnnotatedClasses; } + /** + * @param classDirectory + * @param includePatterns + * @param artifact + * @param excludeMojo for dependencies we exclude Mojo annotations found + * @return + * @throws IOException + * @throws ExtractionException + */ protected Map scanDirectory( File classDirectory, List includePatterns, - Artifact artifact ) + Artifact artifact, boolean excludeMojo ) throws IOException, ExtractionException { if ( !classDirectory.exists() ) @@ -177,6 +200,10 @@ public class DefaultMojoAnnotationsScanner rdr.accept( mojoClassVisitor, ClassReader.SKIP_FRAMES | ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG ); analyzeVisitors( mojoClassVisitor ); + if ( excludeMojo ) + { + mojoClassVisitor.getMojoAnnotatedClass().setMojo( null ); + } if ( isMojoAnnnotatedClassCandidate( mojoClassVisitor.getMojoAnnotatedClass() ) != null ) { getLogger().debug( From 9badbe7f6859c7af52b7c4ba80ff6ea630abe9ed Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Tue, 8 May 2012 21:01:42 +0000 Subject: [PATCH 33/48] [MPLUGIN-189] scan sources from reactors project to get @since,@deprecated and text git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1335767 13f79535-47bb-0310-9956-ffa450edef68 --- ...avaAnnotationsMojoDescriptorExtractor.java | 57 +++++++++++++++++-- 1 file changed, 53 insertions(+), 4 deletions(-) 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 ea470f9..8982846 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 @@ -22,6 +22,7 @@ import com.thoughtworks.qdox.JavaDocBuilder; import com.thoughtworks.qdox.model.DocletTag; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaField; +import org.apache.maven.artifact.Artifact; import org.apache.maven.plugin.descriptor.DuplicateParameterException; import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException; import org.apache.maven.plugin.descriptor.MojoDescriptor; @@ -41,10 +42,12 @@ import org.apache.maven.tools.plugin.annotations.scanner.MojoAnnotationsScannerR import org.apache.maven.tools.plugin.extractor.ExtractionException; import org.apache.maven.tools.plugin.extractor.MojoDescriptorExtractor; import org.codehaus.plexus.logging.AbstractLogEnabled; +import org.codehaus.plexus.util.StringUtils; import java.io.File; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -87,7 +90,32 @@ public class JavaAnnotationsMojoDescriptorExtractor Map mojoAnnotatedClasses = mojoAnnotationsScanner.scan( mojoAnnotationsScannerRequest ); - Map javaClassesMap = discoverClasses( request ); + // found artifact from reactors to scan sources + // we currently only scan sources from reactors + List mavenProjects = new ArrayList(); + + for ( MojoAnnotatedClass mojoAnnotatedClass : mojoAnnotatedClasses.values() ) + { + if ( !StringUtils.equals( mojoAnnotatedClass.getArtifact().getArtifactId(), + request.getProject().getArtifact().getArtifactId() ) ) + { + MavenProject mavenProject = + getFromProjectReferences( mojoAnnotatedClass.getArtifact(), request.getProject() ); + if ( mavenProject != null ) + { + mavenProjects.add( mavenProject ); + } + } + } + + Map javaClassesMap = new HashMap(); + + for ( MavenProject mavenProject : mavenProjects ) + { + javaClassesMap.putAll( discoverClasses( request.getEncoding(), mavenProject ) ); + } + + javaClassesMap.putAll( discoverClasses( request ) ); populateDataFromJavadoc( mojoAnnotatedClasses, javaClassesMap ); @@ -231,10 +259,13 @@ public class JavaAnnotationsMojoDescriptorExtractor protected Map discoverClasses( final PluginToolsRequest request ) { - JavaDocBuilder builder = new JavaDocBuilder(); - builder.setEncoding( request.getEncoding() ); + return discoverClasses( request.getEncoding(), request.getProject() ); + } - MavenProject project = request.getProject(); + protected Map discoverClasses( final String encoding, MavenProject project ) + { + JavaDocBuilder builder = new JavaDocBuilder(); + builder.setEncoding( encoding ); for ( String source : (List) project.getCompileSourceRoots() ) { @@ -453,4 +484,22 @@ public class JavaAnnotationsMojoDescriptorExtractor } return componentAnnotationContents; } + + protected MavenProject getFromProjectReferences( Artifact artifact, MavenProject project ) + { + if ( project.getProjectReferences() == null || project.getProjectReferences().isEmpty() ) + { + return null; + } + Collection mavenProjects = project.getProjectReferences().values(); + for ( MavenProject mavenProject : mavenProjects ) + { + if ( StringUtils.equals( mavenProject.getId(), artifact.getId() ) ) + { + return mavenProject; + } + } + return null; + } + } From d1e2e09ba894568dfa26287d760b6ddcc9fc14e1 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Wed, 9 May 2012 16:43:10 +0000 Subject: [PATCH 34/48] add the directory only if exists git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1336288 13f79535-47bb-0310-9956-ffa450edef68 --- .../annotations/JavaAnnotationsMojoDescriptorExtractor.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 8982846..47819db 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 @@ -262,7 +262,7 @@ public class JavaAnnotationsMojoDescriptorExtractor return discoverClasses( request.getEncoding(), request.getProject() ); } - protected Map discoverClasses( final String encoding, MavenProject project ) + protected Map discoverClasses( final String encoding, final MavenProject project ) { JavaDocBuilder builder = new JavaDocBuilder(); builder.setEncoding( encoding ); @@ -274,7 +274,8 @@ public class JavaAnnotationsMojoDescriptorExtractor // TODO be more dynamic File generatedPlugin = new File( project.getBasedir(), "target/generated-sources/plugin" ); - if ( !project.getCompileSourceRoots().contains( generatedPlugin.getAbsolutePath() ) ) + if ( !project.getCompileSourceRoots().contains( generatedPlugin.getAbsolutePath() ) + && generatedPlugin.exists() ) { builder.addSourceTree( generatedPlugin ); } From ccc68be0c6a7f152ad5a7c0cf11d10ee936d4359 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Wed, 9 May 2012 16:43:54 +0000 Subject: [PATCH 35/48] @Execute can come from parent classes hierarchy order parameters/components on fieldName order to ensure stability of tests. git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1336290 13f79535-47bb-0310-9956-ffa450edef68 --- .../verify.groovy | 6 +-- .../annotation-with-inheritance/verify.groovy | 6 +-- maven-plugin-tools-annotations/pom.xml | 24 ++++++++++ ...avaAnnotationsMojoDescriptorExtractor.java | 48 ++++++++++++------- .../annotations/datamodel/AnnotatedField.java | 6 +++ .../tools/plugin/annotations/FooMojo.java | 33 +++++++++---- .../annotations/TestAnnotationsReader.java | 7 +-- 7 files changed, 95 insertions(+), 35 deletions(-) diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/verify.groovy b/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/verify.groovy index 8c7c541..6348f09 100644 --- a/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/verify.groovy +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/verify.groovy @@ -36,9 +36,9 @@ assert mojo.configuration.touchFile[0].'@default-value' == '${project.build.dire assert mojo.requirements.requirement.size() == 3 -assert mojo.requirements.requirement[1].role.text() == 'org.apache.maven.project.MavenProjectHelper' -assert mojo.requirements.requirement[1].'role-hint'.text() == 'default' -assert mojo.requirements.requirement[1].'field-name'.text() == 'projectHelper' +assert mojo.requirements.requirement[2].role.text() == 'org.apache.maven.project.MavenProjectHelper' +assert mojo.requirements.requirement[2].'role-hint'.text() == 'default' +assert mojo.requirements.requirement[2].'field-name'.text() == 'projectHelper' assert mojo.parameters.parameter.size() == 3 diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance/verify.groovy b/maven-plugin-plugin/src/it/annotation-with-inheritance/verify.groovy index 6c0a341..56fb57b 100644 --- a/maven-plugin-plugin/src/it/annotation-with-inheritance/verify.groovy +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance/verify.groovy @@ -34,9 +34,9 @@ assert mojo.configuration.touchFile[0].'@default-value' == '${project.build.dire assert mojo.requirements.requirement.size() == 3 -assert mojo.requirements.requirement[1].role.text() == 'org.apache.maven.project.MavenProjectHelper' -assert mojo.requirements.requirement[1].'role-hint'.text() == 'default' -assert mojo.requirements.requirement[1].'field-name'.text() == 'projectHelper' +assert mojo.requirements.requirement[2].role.text() == 'org.apache.maven.project.MavenProjectHelper' +assert mojo.requirements.requirement[2].'role-hint'.text() == 'default' +assert mojo.requirements.requirement[2].'field-name'.text() == 'projectHelper' assert mojo.parameters.parameter.size() == 3 diff --git a/maven-plugin-tools-annotations/pom.xml b/maven-plugin-tools-annotations/pom.xml index cf09fba..b8d8705 100644 --- a/maven-plugin-tools-annotations/pom.xml +++ b/maven-plugin-tools-annotations/pom.xml @@ -77,6 +77,19 @@ qdox + + org.codehaus.plexus + plexus-compiler-manager + 1.8.6 + + + org.codehaus.plexus + plexus-component-api + + + test + + @@ -92,6 +105,17 @@ + + org.apache.maven.plugins + maven-source-plugin + + + + test-jar-no-fork + + + + 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 47819db..48a7d1b 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 @@ -53,6 +53,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.TreeMap; +import java.util.TreeSet; /** * @author Olivier Lamy @@ -297,19 +298,6 @@ public class JavaAnnotationsMojoDescriptorExtractor return javaClassMap; } - private List toFiles( List directories ) - { - if ( directories == null ) - { - return Collections.emptyList(); - } - List files = new ArrayList( directories.size() ); - for ( String directory : directories ) - { - files.add( new File( directory ) ); - } - return files; - } private List toMojoDescriptors( Map mojoAnnotatedClasses, PluginToolsRequest request ) @@ -345,8 +333,7 @@ public class JavaAnnotationsMojoDescriptorExtractor mojoDescriptor.setDeprecated( mojo.getDeprecated() ); mojoDescriptor.setThreadSafe( mojo.threadSafe() ); - ExecuteAnnotationContent execute = mojoAnnotatedClass.getExecute(); - + ExecuteAnnotationContent execute = findExecuteInParentHierarchy( mojoAnnotatedClass, mojoAnnotatedClasses ); if ( execute != null ) { mojoDescriptor.setExecuteGoal( execute.goal() ); @@ -355,7 +342,7 @@ public class JavaAnnotationsMojoDescriptorExtractor } mojoDescriptor.setExecutionStrategy( mojo.executionStrategy() ); - // FIXME olamy wtf ? + // ??? //mojoDescriptor.alwaysExecute(mojo.a) mojoDescriptor.setGoal( mojo.name() ); @@ -367,7 +354,8 @@ public class JavaAnnotationsMojoDescriptorExtractor getParametersParentHierarchy( mojoAnnotatedClass, new HashMap(), mojoAnnotatedClasses ); - for ( ParameterAnnotationContent parameterAnnotationContent : parameters.values() ) + for ( ParameterAnnotationContent parameterAnnotationContent : new TreeSet( + parameters.values() ) ) { org.apache.maven.plugin.descriptor.Parameter parameter = new org.apache.maven.plugin.descriptor.Parameter(); @@ -388,7 +376,8 @@ public class JavaAnnotationsMojoDescriptorExtractor getComponentsParentHierarchy( mojoAnnotatedClass, new HashMap(), mojoAnnotatedClasses ); - for ( ComponentAnnotationContent componentAnnotationContent : components.values() ) + for ( ComponentAnnotationContent componentAnnotationContent : new TreeSet( + components.values() ) ) { org.apache.maven.plugin.descriptor.Parameter parameter = new org.apache.maven.plugin.descriptor.Parameter(); @@ -407,6 +396,29 @@ public class JavaAnnotationsMojoDescriptorExtractor return mojoDescriptors; } + + protected ExecuteAnnotationContent findExecuteInParentHierarchy( MojoAnnotatedClass mojoAnnotatedClass, + Map mojoAnnotatedClasses ) + { + + if ( mojoAnnotatedClass.getExecute() != null ) + { + return mojoAnnotatedClass.getExecute(); + } + String parentClassName = mojoAnnotatedClass.getParentClassName(); + if ( StringUtils.isEmpty( parentClassName ) ) + { + return null; + } + MojoAnnotatedClass parent = mojoAnnotatedClasses.get( parentClassName ); + if ( parent == null ) + { + return null; + } + return findExecuteInParentHierarchy( parent, mojoAnnotatedClasses ); + } + + protected Map getParametersParentHierarchy( MojoAnnotatedClass mojoAnnotatedClass, Map parameters, Map mojoAnnotatedClasses ) diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/AnnotatedField.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/AnnotatedField.java index 271e29e..ec69326 100644 --- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/AnnotatedField.java +++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/datamodel/AnnotatedField.java @@ -24,6 +24,7 @@ package org.apache.maven.tools.plugin.annotations.datamodel; */ public class AnnotatedField extends AnnotatedContent + implements Comparable { private String fieldName; @@ -51,4 +52,9 @@ public class AnnotatedField sb.append( '}' ); return sb.toString(); } + + public int compareTo( AnnotatedField annotatedField ) + { + return getFieldName().compareTo( annotatedField.getFieldName() ); + } } diff --git a/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/FooMojo.java b/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/FooMojo.java index a10181c..68021ae 100644 --- a/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/FooMojo.java +++ b/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/FooMojo.java @@ -18,6 +18,7 @@ package org.apache.maven.tools.plugin.annotations; * under the License. */ +import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; @@ -26,6 +27,7 @@ import org.apache.maven.plugins.annotations.Execute; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; +import org.codehaus.plexus.compiler.manager.CompilerManager; /** * @author Olivier Lamy @@ -35,17 +37,32 @@ import org.apache.maven.plugins.annotations.Parameter; public class FooMojo extends AbstractMojo { - @Parameter( expression = "${thebar}", required = true) - private String bar; + /** + * the cool bar to go + * @since 1.0 + * + */ + @Parameter( expression = "${thebar}", required = true, defaultValue = "coolbar" ) + protected String bar; - @Parameter( expression = "${thebeer}" ) - private String beer; + /** + * beer for non french folks + * @deprecated wine is better + */ + @Parameter( expression = "${thebeer}", defaultValue = "coolbeer" ) + protected String beer; - @Component( role = "wine", roleHint = "bordeaux" ) - private Mojo wine; + /** + * Plexus compiler manager. + */ + @Component + protected CompilerManager compilerManager; - @Component( role = "wine", roleHint = "foo" ) - private Mojo foo; + /** + * + */ + @Component( role = "org.apache.maven.artifact.metadata.ArtifactMetadataSource", roleHint = "maven" ) + protected ArtifactMetadataSource artifactMetadataSource; public void execute() throws MojoExecutionException, MojoFailureException diff --git a/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/TestAnnotationsReader.java b/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/TestAnnotationsReader.java index 0e13bad..f51900f 100644 --- a/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/TestAnnotationsReader.java +++ b/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/TestAnnotationsReader.java @@ -51,7 +51,7 @@ public class TestAnnotationsReader MojoAnnotationsScannerRequest request = new MojoAnnotationsScannerRequest(); request.setClassesDirectories( Collections.singletonList( new File( "target/test-classes" ) ) ); request.setIncludePatterns( Arrays.asList( "**/FooMojo.class" ) ); - request.setProject( new MavenProject( ) ); + request.setProject( new MavenProject() ); Map mojoAnnotatedClasses = mojoAnnotationsScanner.scan( request ); @@ -82,7 +82,8 @@ public class TestAnnotationsReader Collection parameters = mojoAnnotatedClass.getParameters().values(); Assertions.assertThat( parameters ).isNotNull().isNotEmpty().hasSize( 2 ).contains( - new ParameterAnnotationContent( "bar", null, "${thebar}", null, true, false, String.class.getName() ), - new ParameterAnnotationContent( "beer", null, "${thebeer}", null, false, false, String.class.getName() ) ); + new ParameterAnnotationContent( "bar", null, "${thebar}", "coolbar", true, false, String.class.getName() ), + new ParameterAnnotationContent( "beer", null, "${thebeer}", "coolbeer", false, false, + String.class.getName() ) ); } } From d85b22ec88011ad710dca34a7f7237e553a03896 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Wed, 9 May 2012 16:45:26 +0000 Subject: [PATCH 36/48] [MPLUGIN-189] scan sources from dependencies if sources classifier found to get @since,@deprecated and text git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1336291 13f79535-47bb-0310-9956-ffa450edef68 --- maven-plugin-plugin/pom.xml | 5 + .../invoker.properties | 5 + .../pom.xml | 109 +++++++++++++ .../apache/maven/plugin/coreit/FirstMojo.java | 73 +++++++++ .../resources/META-INF/maven/lifecycle.xml | 17 ++ .../verify.groovy | 75 +++++++++ .../plugin/plugin/AbstractGeneratorMojo.java | 57 +++++-- maven-plugin-tools-annotations/pom.xml | 5 + ...avaAnnotationsMojoDescriptorExtractor.java | 154 ++++++++++++++++-- .../resources/META-INF/plexus/components.xml | 12 ++ .../tools/plugin/annotations/FooMojo.java | 1 - .../plugin/DefaultPluginToolsRequest.java | 28 ++++ .../tools/plugin/PluginToolsRequest.java | 35 +++- pom.xml | 5 + 14 files changed, 550 insertions(+), 31 deletions(-) create mode 100644 maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/invoker.properties create mode 100644 maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/pom.xml create mode 100644 maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java create mode 100644 maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/src/main/resources/META-INF/maven/lifecycle.xml create mode 100644 maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/verify.groovy diff --git a/maven-plugin-plugin/pom.xml b/maven-plugin-plugin/pom.xml index fb90486..1b99f8b 100644 --- a/maven-plugin-plugin/pom.xml +++ b/maven-plugin-plugin/pom.xml @@ -106,6 +106,11 @@ plexus-utils 2.0.5 + + org.codehaus.plexus + plexus-archiver + 2.1.1 + diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/invoker.properties b/maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/invoker.properties new file mode 100644 index 0000000..98d7b19 --- /dev/null +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/invoker.properties @@ -0,0 +1,5 @@ +invoker.goals.1 = install +invoker.goals.2 = org.apache.maven.its.annotation-with-inheritance-from-deps:annotation-with-inheritance-from-deps:1.0:first +#FIXME disabled need to find a solution for the chicken and eggs issue. +#help sources are generated @generated-sources but need descriptor which need compile phase first for classes scanning +#invoker.goals.3 = org.apache.maven.its.basic-java-annotations:maven-it-basic-java-annotations:1.0::help diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/pom.xml b/maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/pom.xml new file mode 100644 index 0000000..5158139 --- /dev/null +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/pom.xml @@ -0,0 +1,109 @@ + + + + + + 4.0.0 + + org.apache.maven.its.annotation-with-inheritance-from-deps + annotation-with-inheritance-from-deps + 1.0 + maven-plugin + + Maven Integration Test :: annotation-with-inheritance-from-deps + + Test plugin-plugin, which tests maven-plugin-tools-api and + maven-plugin-tools-java. This will generate a plugin descriptor from + java-based mojo sources, install the plugin, and then use it. + + + + UTF-8 + 1.8.6 + + + + + org.apache.maven + maven-plugin-api + 2.0 + + + org.apache.maven + maven-project + @mavenVersion@ + + + org.apache.maven.plugin-tools + maven-plugin-annotations + @project.version@ + + + org.apache.maven.plugin-tools + maven-plugin-tools-annotations + @project.version@ + tests + + + org.codehaus.plexus + plexus-compiler-manager + ${plexusCompilerVersion} + + + org.codehaus.plexus + plexus-component-api + + + + + org.codehaus.plexus + plexus-compiler-javac + ${plexusCompilerVersion} + + + org.codehaus.plexus + plexus-component-api + + + + + + + + + org.apache.maven.plugins + maven-plugin-plugin + @project.version@ + + true + + + + mojo-descriptor + process-classes + + descriptor + + + + + + + diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java b/maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java new file mode 100644 index 0000000..167f30e --- /dev/null +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java @@ -0,0 +1,73 @@ +package org.apache.maven.plugin.coreit; + +/* + * 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.plugin.MojoExecutionException; +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; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.tools.plugin.annotations.FooMojo; + +/** + * Touches a test file. + * + * @since 1.2 + * @deprecated Don't use! + */ +@Mojo( name = "first", requiresDependencyResolution = "test", defaultPhase = LifecyclePhase.INTEGRATION_TEST ) +public class FirstMojo + extends FooMojo +{ + + /** + * @since 0.1 + * @deprecated As of 0.2 + */ + @Parameter( alias = "alias" ) + private String aliasedParam; + + @Component( role = "org.apache.maven.project.MavenProjectHelper", roleHint = "default" ) + private Object projectHelper; + + public void execute() + throws MojoExecutionException + { + if (bar == null) + { + throw new MojoExecutionException( "bar == null" ); + } + if (beer == null) + { + throw new MojoExecutionException( "beer == null" ); + } + if ( projectHelper == null ) + { + throw new MojoExecutionException( "projectHelper == null" ); + } + if ( compilerManager == null ) + { + throw new MojoExecutionException( "compilerManager == null" ); + } + + } + +} diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/src/main/resources/META-INF/maven/lifecycle.xml b/maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/src/main/resources/META-INF/maven/lifecycle.xml new file mode 100644 index 0000000..7b21d5a --- /dev/null +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/src/main/resources/META-INF/maven/lifecycle.xml @@ -0,0 +1,17 @@ + + + my-lifecycle + + + process-classes + + + test + + ${project.build.directory}/generated-classes/cobertura + true + + + + + \ No newline at end of file diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/verify.groovy b/maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/verify.groovy new file mode 100644 index 0000000..9e047fa --- /dev/null +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/verify.groovy @@ -0,0 +1,75 @@ + +File descriptorFile = new File( basedir, "target/classes/META-INF/maven/plugin.xml" ); +assert descriptorFile.isFile() + +def pluginDescriptor = new XmlParser().parse( descriptorFile ); + +def mojo = pluginDescriptor.mojos.mojo.findAll{ it.goal.text() == "first"}[0] + +assert mojo.goal.text() == 'first' +assert mojo.implementation.text() == 'org.apache.maven.plugin.coreit.FirstMojo' +assert mojo.language.text() == 'java' +assert mojo.description.text() == 'Touches a test file.' +assert mojo.deprecated.text() == "Don't use!" +assert mojo.requiresDependencyResolution.text() == 'test' +assert mojo.requiresDependencyCollection.text() == '' +assert mojo.requiresProject.text() == 'true' +assert mojo.requiresOnline.text() == 'false' +assert mojo.requiresDirectInvocation.text() == 'false' +assert mojo.aggregator.text() == 'false' +assert mojo.threadSafe.text() == 'false' +assert mojo.phase.text() == 'integration-test' +assert mojo.executePhase.text() == 'package' +assert mojo.executeLifecycle.text() == 'my-lifecycle' + +assert mojo.configuration.bar[0].text() == '${thebar}' +assert mojo.configuration.bar[0].'@implementation' == 'java.lang.String' +assert mojo.configuration.bar[0].'@default-value' == 'coolbar' + +assert mojo.configuration.beer[0].text() == '${thebeer}' +assert mojo.configuration.beer[0].'@implementation' == 'java.lang.String' +assert mojo.configuration.beer[0].'@default-value' == 'coolbeer' + +assert mojo.requirements.requirement.size() == 3 + +assert mojo.requirements.requirement[1].role.text() == 'org.codehaus.plexus.compiler.manager.CompilerManager' +assert mojo.requirements.requirement[1].'role-hint'.text() == '' +assert mojo.requirements.requirement[1].'field-name'.text() == 'compilerManager' + +assert mojo.requirements.requirement[2].role.text() == 'org.apache.maven.project.MavenProjectHelper' +assert mojo.requirements.requirement[2].'role-hint'.text() == 'default' +assert mojo.requirements.requirement[2].'field-name'.text() == 'projectHelper' + +assert mojo.parameters.parameter.size() == 3 + +def parameter = mojo.parameters.parameter.findAll{ it.name.text() == "aliasedParam"}[0] + +assert parameter.name.text() == 'aliasedParam' +assert parameter.alias.text() == 'alias' +assert parameter.type.text() == 'java.lang.String' +assert parameter.deprecated.text() == 'As of 0.2' +assert parameter.required.text() == 'false' +assert parameter.editable.text() == 'true' +assert parameter.description.text() == '' + +parameter = mojo.parameters.parameter.findAll{ it.name.text() == "beer"}[0] + +assert parameter.name.text() == 'beer' +assert parameter.alias.isEmpty() +assert parameter.type.text() == 'java.lang.String' +assert parameter.deprecated.text() == "wine is better" +assert parameter.required.text() == 'false' +assert parameter.editable.text() == 'true' +assert parameter.description.text() == 'beer for non french folks' + +parameter = mojo.parameters.parameter.findAll{ it.name.text() == "bar"}[0] + +assert parameter.name.text() == 'bar' +assert parameter.alias.isEmpty() +assert parameter.type.text() == 'java.lang.String' +assert parameter.deprecated.isEmpty() +assert parameter.required.text() == 'true' +assert parameter.editable.text() == 'true' +assert parameter.description.text() == 'the cool bar to go' + +return true; diff --git a/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/AbstractGeneratorMojo.java b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/AbstractGeneratorMojo.java index 085bf15..3a66ffe 100644 --- a/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/AbstractGeneratorMojo.java +++ b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/AbstractGeneratorMojo.java @@ -20,6 +20,7 @@ package org.apache.maven.plugin.plugin; */ import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException; @@ -35,6 +36,7 @@ import org.codehaus.plexus.util.ReaderFactory; import java.io.File; import java.io.IOException; +import java.util.List; import java.util.Set; /** @@ -42,7 +44,6 @@ import java.util.Set; * * @author Jason van Zyl * @version $Id$ - * * @threadSafe */ public abstract class AbstractGeneratorMojo @@ -67,7 +68,7 @@ public abstract class AbstractGeneratorMojo /** * The file encoding of the source files. - * + * * @parameter expression="${encoding}" default-value="${project.build.sourceEncoding}" * @since 2.5 */ @@ -84,6 +85,7 @@ public abstract class AbstractGeneratorMojo * By default an exception is throw if no mojo descriptor is found. As the maven-plugin is defined in core, the * descriptor generator mojo is bound to generate-resources phase. * But for annotations, the compiled classes are needed, so skip error + * * @parameter expression="${maven.plugin.skipErrorNoDescriptorsFound}" default-value="false" * @since 3.0 */ @@ -100,12 +102,12 @@ public abstract class AbstractGeneratorMojo *

      *  <!-- Use all mojo extractors -->
      *  <extractors/>
-     *  
+     *
      *  <!-- Use no mojo extractors -->
      *  <extractors>
      *      <extractor/>
      *  </extractors>
-     *  
+     *
      *  <!-- Use only bsh mojo extractor -->
      *  <extractors>
      *      <extractor>bsh</extractor>
@@ -134,6 +136,26 @@ public abstract class AbstractGeneratorMojo
      */
     protected Set dependencies;
 
+    /**
+     * List of Remote Repositories used by the resolver
+     *
+     * @parameter expression="${project.remoteArtifactRepositories}"
+     * @readonly
+     * @required
+     * @since 3.0
+     */
+    protected List remoteRepos;
+
+    /**
+     * Location of the local repository.
+     *
+     * @parameter expression="${localRepository}"
+     * @readonly
+     * @required
+     * @since 3.0
+     */
+    protected ArtifactRepository local;
+
     /**
      * @return the output directory where files will be generated.
      */
@@ -144,7 +166,9 @@ public abstract class AbstractGeneratorMojo
      */
     protected abstract Generator createGenerator();
 
-    /** {@inheritDoc} */
+    /**
+     * {@inheritDoc}
+     */
     public void execute()
         throws MojoExecutionException
     {
@@ -158,11 +182,11 @@ public abstract class AbstractGeneratorMojo
             return;
         }
 
-        if ( project.getArtifactId().toLowerCase().startsWith( "maven-" ) 
-            && project.getArtifactId().toLowerCase().endsWith( "-plugin" )
-            && !"org.apache.maven.plugins".equals( project.getGroupId() ) )
+        if ( project.getArtifactId().toLowerCase().startsWith( "maven-" )
+            && project.getArtifactId().toLowerCase().endsWith( "-plugin" ) && !"org.apache.maven.plugins".equals(
+            project.getGroupId() ) )
         {
-            getLog().error( "\n\nArtifact Ids of the format maven-___-plugin are reserved for \n" 
+            getLog().error( "\n\nArtifact Ids of the format maven-___-plugin are reserved for \n"
                                 + "plugins in the Group Id org.apache.maven.plugins\n"
                                 + "Please change your artifactId to the format ___-maven-plugin\n"
                                 + "In the future this error will break the build.\n\n" );
@@ -176,8 +200,8 @@ public abstract class AbstractGeneratorMojo
         else if ( !goalPrefix.equals( defaultGoalPrefix ) )
         {
             getLog().warn(
-                           "\n\nGoal prefix is specified as: '" + goalPrefix + "'. "
-                               + "Maven currently expects it to be '" + defaultGoalPrefix + "'.\n" );
+                "\n\nGoal prefix is specified as: '" + goalPrefix + "'. " + "Maven currently expects it to be '"
+                    + defaultGoalPrefix + "'.\n" );
         }
 
         mojoScanner.setActiveExtractors( extractors );
@@ -200,21 +224,23 @@ public abstract class AbstractGeneratorMojo
         if ( encoding == null || encoding.length() < 1 )
         {
             getLog().warn( "Using platform encoding (" + ReaderFactory.FILE_ENCODING
-                                  + " actually) to read mojo metadata, i.e. build is platform dependent!" );
+                               + " actually) to read mojo metadata, i.e. build is platform dependent!" );
         }
         else
         {
             getLog().info( "Using '" + encoding + "' encoding to read mojo metadata." );
         }
-        
+
         try
         {
             pluginDescriptor.setDependencies( PluginUtils.toComponentDependencies( project.getRuntimeDependencies() ) );
-            
+
             PluginToolsRequest request = new DefaultPluginToolsRequest( project, pluginDescriptor );
             request.setEncoding( encoding );
             request.setSkipErrorNoDescriptorsFound( skipErrorNoDescriptorsFound );
             request.setDependencies( dependencies );
+            request.setLocal( this.local );
+            request.setRemoteRepos( this.remoteRepos );
 
             mojoScanner.populatePluginDescriptor( request );
 
@@ -239,7 +265,8 @@ public abstract class AbstractGeneratorMojo
         catch ( LinkageError e )
         {
             throw new MojoExecutionException( "The API of the mojo scanner is not compatible with this plugin version."
-                + " Please check the plugin dependencies configured in the POM and ensure the versions match.", e );
+                                                  + " Please check the plugin dependencies configured in the POM and ensure the versions match.",
+                                              e );
         }
     }
 
diff --git a/maven-plugin-tools-annotations/pom.xml b/maven-plugin-tools-annotations/pom.xml
index b8d8705..c2fdcf8 100644
--- a/maven-plugin-tools-annotations/pom.xml
+++ b/maven-plugin-tools-annotations/pom.xml
@@ -72,6 +72,11 @@
       3.3.1
     
 
+    
+      org.codehaus.plexus
+      plexus-archiver
+    
+
     
       com.thoughtworks.qdox
       qdox
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 48a7d1b..3ec1c72 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
@@ -23,6 +23,10 @@ import com.thoughtworks.qdox.model.DocletTag;
 import com.thoughtworks.qdox.model.JavaClass;
 import com.thoughtworks.qdox.model.JavaField;
 import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.artifact.resolver.ArtifactResolver;
 import org.apache.maven.plugin.descriptor.DuplicateParameterException;
 import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException;
 import org.apache.maven.plugin.descriptor.MojoDescriptor;
@@ -41,6 +45,9 @@ import org.apache.maven.tools.plugin.annotations.scanner.MojoAnnotationsScanner;
 import org.apache.maven.tools.plugin.annotations.scanner.MojoAnnotationsScannerRequest;
 import org.apache.maven.tools.plugin.extractor.ExtractionException;
 import org.apache.maven.tools.plugin.extractor.MojoDescriptorExtractor;
+import org.codehaus.plexus.archiver.UnArchiver;
+import org.codehaus.plexus.archiver.manager.ArchiverManager;
+import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;
 import org.codehaus.plexus.logging.AbstractLogEnabled;
 import org.codehaus.plexus.util.StringUtils;
 
@@ -50,8 +57,10 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.TreeMap;
 import java.util.TreeSet;
 
@@ -69,6 +78,21 @@ public class JavaAnnotationsMojoDescriptorExtractor
      */
     private MojoAnnotationsScanner mojoAnnotationsScanner;
 
+    /**
+     * @requirement
+     */
+    private ArtifactResolver artifactResolver;
+
+    /**
+     * @requirement
+     */
+    private ArtifactFactory artifactFactory;
+
+    /**
+     * @requirement
+     */
+    private ArchiverManager archiverManager;
+
     public List execute( MavenProject project, PluginDescriptor pluginDescriptor )
         throws ExtractionException, InvalidPluginDescriptorException
     {
@@ -95,6 +119,9 @@ public class JavaAnnotationsMojoDescriptorExtractor
         // we currently only scan sources from reactors
         List mavenProjects = new ArrayList();
 
+        // if we need to scan sources from external artifacts
+        Set externalArtifacts = new HashSet();
+
         for ( MojoAnnotatedClass mojoAnnotatedClass : mojoAnnotatedClasses.values() )
         {
             if ( !StringUtils.equals( mojoAnnotatedClass.getArtifact().getArtifactId(),
@@ -106,11 +133,31 @@ public class JavaAnnotationsMojoDescriptorExtractor
                 {
                     mavenProjects.add( mavenProject );
                 }
+                else
+                {
+                    externalArtifacts.add( mojoAnnotatedClass.getArtifact() );
+                }
             }
         }
 
         Map javaClassesMap = new HashMap();
 
+        // try to get artifact with classifier sources
+        // extract somewhere then scan doclet for @since, @deprecated
+        for ( Artifact artifact : externalArtifacts )
+        {
+            // parameter for test-sources too ?? olamy I need that for it test only
+            if ( StringUtils.equalsIgnoreCase( "tests", artifact.getClassifier() ) )
+            {
+                javaClassesMap.putAll( discoverClassesFromSourcesJar( artifact, request, "test-sources" ) );
+            }
+            else
+            {
+                javaClassesMap.putAll( discoverClassesFromSourcesJar( artifact, request, "sources" ) );
+            }
+
+        }
+
         for ( MavenProject mavenProject : mavenProjects )
         {
             javaClassesMap.putAll( discoverClasses( request.getEncoding(), mavenProject ) );
@@ -120,10 +167,59 @@ public class JavaAnnotationsMojoDescriptorExtractor
 
         populateDataFromJavadoc( mojoAnnotatedClasses, javaClassesMap );
 
-        return toMojoDescriptors( mojoAnnotatedClasses, request );
+        return toMojoDescriptors( mojoAnnotatedClasses, request, javaClassesMap );
 
     }
 
+
+    protected Map discoverClassesFromSourcesJar( Artifact artifact, PluginToolsRequest request,
+                                                                    String classifier )
+        throws ExtractionException
+    {
+        try
+        {
+            Artifact sourcesArtifact =
+                artifactFactory.createArtifactWithClassifier( artifact.getGroupId(), artifact.getArtifactId(),
+                                                              artifact.getVersion(), artifact.getType(), classifier );
+
+            artifactResolver.resolve( sourcesArtifact, request.getRemoteRepos(), request.getLocal() );
+            if ( sourcesArtifact.getFile() != null && sourcesArtifact.getFile().exists() )
+            {
+                File extractDirectory = new File( request.getProject().getBuild().getDirectory(),
+                                                  "maven-plugin-plugin-sources/" + sourcesArtifact.getGroupId() + "/"
+                                                      + sourcesArtifact.getArtifactId() + "/"
+                                                      + sourcesArtifact.getVersion() + "/"
+                                                      + sourcesArtifact.getClassifier() );
+                if ( !extractDirectory.exists() )
+                {
+                    extractDirectory.mkdirs();
+                }
+                // extract sources in a directory
+                //target/maven-plugin-plugin/${groupId}/${artifact}/sources
+                UnArchiver unArchiver = archiverManager.getUnArchiver( "jar" );
+                unArchiver.setSourceFile( sourcesArtifact.getFile() );
+                unArchiver.setDestDirectory( extractDirectory );
+                unArchiver.extract();
+
+                return discoverClasses( request.getEncoding(), Arrays.asList( extractDirectory ) );
+            }
+        }
+        catch ( ArtifactResolutionException e )
+        {
+            throw new ExtractionException( e.getMessage(), e );
+        }
+        catch ( ArtifactNotFoundException e )
+        {
+            //throw new ExtractionException( e.getMessage(), e );
+            getLogger().debug( "skip ArtifactNotFoundException:" + e.getMessage() );
+        }
+        catch ( NoSuchArchiverException e )
+        {
+            throw new ExtractionException( e.getMessage(), e );
+        }
+        return Collections.emptyMap();
+    }
+
     /**
      * from sources scan to get @since and @deprecated and description of classes and fields.
      *
@@ -155,8 +251,13 @@ public class JavaAnnotationsMojoDescriptorExtractor
                         mojoAnnotationContent.setDeprecated( deprecated.getValue() );
                     }
                 }
-                Map fieldsMap = extractFieldParameterTags( javaClass );
-                for ( Map.Entry parameter : entry.getValue().getParameters().entrySet() )
+                Map fieldsMap =
+                    extractFieldParameterTags( javaClass, javaClassesMap, mojoAnnotatedClasses );
+                Map parameters =
+                    getParametersParentHierarchy( entry.getValue(), new HashMap(),
+                                                  mojoAnnotatedClasses );
+                for ( Map.Entry parameter : new TreeMap(
+                    parameters ).entrySet() )
                 {
                     JavaField javaField = fieldsMap.get( parameter.getKey() );
                     if ( javaField != null )
@@ -206,7 +307,7 @@ public class JavaAnnotationsMojoDescriptorExtractor
      * @param tagName   not null
      * @return docletTag instance
      */
-    private static DocletTag findInClassHierarchy( JavaClass javaClass, String tagName )
+    private DocletTag findInClassHierarchy( JavaClass javaClass, String tagName )
     {
         DocletTag tag = javaClass.getTagByName( tagName );
 
@@ -229,9 +330,11 @@ public class JavaAnnotationsMojoDescriptorExtractor
      * @param javaClass not null
      * @return map with Mojo parameters names as keys
      */
-    private Map extractFieldParameterTags( JavaClass javaClass )
+    private Map extractFieldParameterTags( JavaClass javaClass,
+                                                              Map javaClassesMap,
+                                                              Map mojoAnnotatedClasses )
     {
-        Map rawParams;
+        Map rawParams = new TreeMap();
 
         // we have to add the parent fields first, so that they will be overwritten by the local fields if
         // that actually happens...
@@ -239,10 +342,20 @@ public class JavaAnnotationsMojoDescriptorExtractor
 
         if ( superClass != null )
         {
-            rawParams = extractFieldParameterTags( superClass );
+            if ( superClass.getFields().length > 0 )
+            {
+                rawParams = extractFieldParameterTags( superClass, javaClassesMap, mojoAnnotatedClasses );
+            }
+            // maybe sources comes from scan of sources artifact
+            superClass = javaClassesMap.get( superClass.getFullyQualifiedName() );
+            if ( superClass != null )
+            {
+                rawParams = extractFieldParameterTags( superClass, javaClassesMap, mojoAnnotatedClasses );
+            }
         }
         else
         {
+
             rawParams = new TreeMap();
         }
 
@@ -265,12 +378,11 @@ public class JavaAnnotationsMojoDescriptorExtractor
 
     protected Map discoverClasses( final String encoding, final MavenProject project )
     {
-        JavaDocBuilder builder = new JavaDocBuilder();
-        builder.setEncoding( encoding );
+        List sources = new ArrayList();
 
         for ( String source : (List) project.getCompileSourceRoots() )
         {
-            builder.addSourceTree( new File( source ) );
+            sources.add( new File( source ) );
         }
 
         // TODO be more dynamic
@@ -278,7 +390,20 @@ public class JavaAnnotationsMojoDescriptorExtractor
         if ( !project.getCompileSourceRoots().contains( generatedPlugin.getAbsolutePath() )
             && generatedPlugin.exists() )
         {
-            builder.addSourceTree( generatedPlugin );
+            sources.add( generatedPlugin );
+        }
+
+        return discoverClasses( encoding, sources );
+    }
+
+    protected Map discoverClasses( final String encoding, List sourceDirectories )
+    {
+        JavaDocBuilder builder = new JavaDocBuilder();
+        builder.setEncoding( encoding );
+
+        for ( File source : sourceDirectories )
+        {
+            builder.addSourceTree( source );
         }
 
         JavaClass[] javaClasses = builder.getClasses();
@@ -298,9 +423,8 @@ public class JavaAnnotationsMojoDescriptorExtractor
         return javaClassMap;
     }
 
-
     private List toMojoDescriptors( Map mojoAnnotatedClasses,
-                                                    PluginToolsRequest request )
+                                                    PluginToolsRequest request, Map javaClassesMap )
         throws DuplicateParameterException
     {
         List mojoDescriptors = new ArrayList( mojoAnnotatedClasses.size() );
@@ -367,6 +491,7 @@ public class JavaAnnotationsMojoDescriptorExtractor
                 parameter.setEditable( !parameterAnnotationContent.readonly() );
                 parameter.setExpression( parameterAnnotationContent.expression() );
                 parameter.setType( parameterAnnotationContent.getClassName() );
+                parameter.setSince( parameterAnnotationContent.getSince() );
                 parameter.setRequired( parameterAnnotationContent.required() );
 
                 mojoDescriptor.addParameter( parameter );
@@ -385,7 +510,8 @@ public class JavaAnnotationsMojoDescriptorExtractor
                 parameter.setRequirement(
                     new Requirement( componentAnnotationContent.role(), componentAnnotationContent.roleHint() ) );
                 parameter.setEditable( false );
-
+                parameter.setDeprecated( componentAnnotationContent.getDeprecated() );
+                parameter.setSince( componentAnnotationContent.getSince() );
                 mojoDescriptor.addParameter( parameter );
             }
 
diff --git a/maven-plugin-tools-annotations/src/main/resources/META-INF/plexus/components.xml b/maven-plugin-tools-annotations/src/main/resources/META-INF/plexus/components.xml
index 91df740..18fb315 100644
--- a/maven-plugin-tools-annotations/src/main/resources/META-INF/plexus/components.xml
+++ b/maven-plugin-tools-annotations/src/main/resources/META-INF/plexus/components.xml
@@ -35,6 +35,18 @@
           org.apache.maven.tools.plugin.annotations.scanner.MojoAnnotationsScanner
           default
         
+        
+          org.apache.maven.artifact.resolver.ArtifactResolver
+          default
+        
+        
+          org.apache.maven.artifact.factory.ArtifactFactory
+          default
+        
+        
+          org.codehaus.plexus.archiver.manager.ArchiverManager
+          default
+        
       
     
 
diff --git a/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/FooMojo.java b/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/FooMojo.java
index 68021ae..1f9da50 100644
--- a/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/FooMojo.java
+++ b/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/FooMojo.java
@@ -40,7 +40,6 @@ public class FooMojo
     /**
      * the cool bar to go
      * @since 1.0
-     *
      */
     @Parameter( expression = "${thebar}", required = true, defaultValue = "coolbar" )
     protected String bar;
diff --git a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/DefaultPluginToolsRequest.java b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/DefaultPluginToolsRequest.java
index 73ef0fc..9c70400 100644
--- a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/DefaultPluginToolsRequest.java
+++ b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/DefaultPluginToolsRequest.java
@@ -20,6 +20,7 @@ package org.apache.maven.tools.plugin;
  */
 
 import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.plugin.descriptor.MojoDescriptor;
 import org.apache.maven.plugin.descriptor.PluginDescriptor;
 import org.apache.maven.project.MavenProject;
@@ -27,6 +28,7 @@ import org.codehaus.plexus.util.ReaderFactory;
 import org.codehaus.plexus.util.StringUtils;
 
 import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
 
 /**
@@ -52,6 +54,10 @@ public class DefaultPluginToolsRequest
 
     private Set dependencies;
 
+    private List remoteRepos;
+
+    private ArtifactRepository local;
+
     public DefaultPluginToolsRequest( MavenProject project, PluginDescriptor pluginDescriptor )
     {
         this.project = project;
@@ -148,4 +154,26 @@ public class DefaultPluginToolsRequest
         this.dependencies = dependencies;
         return this;
     }
+
+    public List getRemoteRepos()
+    {
+        return remoteRepos;
+    }
+
+    public PluginToolsRequest setRemoteRepos( List remoteRepos )
+    {
+        this.remoteRepos = remoteRepos;
+        return this;
+    }
+
+    public ArtifactRepository getLocal()
+    {
+        return local;
+    }
+
+    public PluginToolsRequest setLocal( ArtifactRepository local )
+    {
+        this.local = local;
+        return this;
+    }
 }
diff --git a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/PluginToolsRequest.java b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/PluginToolsRequest.java
index 0cdf998..03fe386 100644
--- a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/PluginToolsRequest.java
+++ b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/PluginToolsRequest.java
@@ -20,10 +20,12 @@ package org.apache.maven.tools.plugin;
  */
 
 import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.plugin.descriptor.MojoDescriptor;
 import org.apache.maven.plugin.descriptor.PluginDescriptor;
 import org.apache.maven.project.MavenProject;
 
+import java.util.List;
 import java.util.Set;
 
 /**
@@ -90,16 +92,47 @@ public interface PluginToolsRequest
 
     /**
      * Returns the list of {@link Artifact} used in class path scanning for annotations
+     *
      * @return
      * @since 3.0
      */
     Set getDependencies();
 
     /**
-     *
      * @param dependencies
      * @return
+     * @since 3.0
      */
     PluginToolsRequest setDependencies( Set dependencies );
 
+    /**
+     *
+     * @return
+     * @since 3.0
+     */
+    List getRemoteRepos();
+
+    /**
+     *
+     * @param remoteRepos
+     * @return
+     * @since 3.0
+     */
+    PluginToolsRequest setRemoteRepos( List remoteRepos );
+
+    /**
+     *
+     * @return
+     * @since 3.0
+     */
+    ArtifactRepository getLocal();
+
+    /**
+     *
+     * @param local
+     * @return
+     * @since 3.0
+     */
+    PluginToolsRequest setLocal( ArtifactRepository local );
+
 }
diff --git a/pom.xml b/pom.xml
index 6dec851..d603983 100644
--- a/pom.xml
+++ b/pom.xml
@@ -228,6 +228,11 @@
         plexus-container-default
         1.0-alpha-9-stable-1
       
+      
+        org.codehaus.plexus
+        plexus-archiver
+        2.1.1
+      
 
       
         com.thoughtworks.qdox

From ba66d8def760d6522f0816fb9c012c3aa3911e70 Mon Sep 17 00:00:00 2001
From: Olivier Lamy 
Date: Wed, 9 May 2012 16:45:49 +0000
Subject: [PATCH 37/48] add warning if artifact with sources classifier not
 found

git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1336293 13f79535-47bb-0310-9956-ffa450edef68
---
 .../annotations/JavaAnnotationsMojoDescriptorExtractor.java    | 3 +++
 1 file changed, 3 insertions(+)

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 3ec1c72..e24eb5e 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
@@ -212,6 +212,9 @@ public class JavaAnnotationsMojoDescriptorExtractor
         {
             //throw new ExtractionException( e.getMessage(), e );
             getLogger().debug( "skip ArtifactNotFoundException:" + e.getMessage() );
+            getLogger().warn(
+                "Impossible to get sources artifact for " + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":"
+                    + artifact.getVersion() + ". Some javadoc tags (@since, @deprecated and comments) won't be used" );
         }
         catch ( NoSuchArchiverException e )
         {

From 4ec2eaf3a5afe32f7dd504b37bdde59045c880c1 Mon Sep 17 00:00:00 2001
From: Olivier Lamy 
Date: Fri, 11 May 2012 16:44:59 +0000
Subject: [PATCH 38/48] [MPLUGIN-189] push some stuff on help for annotations
 the goal is to have a generic class which will read the descriptor. Copy of
 the descriptor with cleaning html for description fields (copy in a path
 META-INF/maven/${groupId}/${artifactId}/plugin-description.xml

git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1337273 13f79535-47bb-0310-9956-ffa450edef68
---
 maven-plugin-plugin/pom.xml                   |  35 +
 .../pom.xml                                   |   1 +
 .../pom.xml                                   |   1 +
 .../invoker.properties                        |  10 +-
 .../it/annotation-with-inheritance/pom.xml    |   9 +-
 .../apache/maven/plugin/coreit/FirstMojo.java |   2 +-
 .../src/it/help-basic/invoker.properties      |   2 +-
 maven-plugin-plugin/src/it/help-basic/pom.xml |   6 +
 .../src/it/help-package/invoker.properties    |   2 +-
 .../src/it/help-package/pom.xml               |   6 +
 .../invoker.properties                        |   2 +-
 .../java-basic-annotations/invoker.properties |   2 +-
 .../src/it/java-basic/invoker.properties      |   2 +-
 .../src/it/mplugin-187/invoker.properties     |   2 +-
 .../invoker.properties                        |   2 +-
 .../src/it/plugin-report/invoker.properties   |   2 +-
 .../src/it/skip/invoker.properties            |   2 +-
 .../plugin/plugin/AbstractGeneratorMojo.java  |   4 +-
 .../plugin/plugin/HelpGeneratorMojo.java      |  35 +-
 .../maven/plugin/plugin/PluginReport.java     | 187 +++--
 maven-plugin-tools-api/pom.xml                |  30 +
 .../tools/plugin/generator/Generator.java     |  15 +-
 .../generator/PluginDescriptorGenerator.java  | 244 +++++-
 .../plugin/generator/PluginHelpGenerator.java | 758 ++++--------------
 .../plugin/generator/PluginXdocGenerator.java | 135 ++--
 .../generator/AbstractGeneratorTestCase.java  |  31 +-
 .../generator/PluginHelpGeneratorTest.java    |  10 +
 pom.xml                                       |  18 +
 28 files changed, 716 insertions(+), 839 deletions(-)

diff --git a/maven-plugin-plugin/pom.xml b/maven-plugin-plugin/pom.xml
index 1b99f8b..262c50e 100644
--- a/maven-plugin-plugin/pom.xml
+++ b/maven-plugin-plugin/pom.xml
@@ -111,6 +111,24 @@
         plexus-archiver
         2.1.1
       
+      
+        org.codehaus.plexus
+        plexus-velocity
+        1.1.8
+        
+          
+            velocity
+            velocity
+          
+        
+      
+
+      
+      
+        org.apache.velocity
+        velocity
+        1.7
+      
     
   
 
@@ -218,6 +236,23 @@
       org.codehaus.plexus
       plexus-utils
     
+    
+      org.codehaus.plexus
+      plexus-velocity
+      
+        
+          velocity
+          velocity
+        
+      
+    
+
+    
+    
+      org.apache.velocity
+      velocity
+    
+
   
 
   
diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/pom.xml b/maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/pom.xml
index 5158139..ea74e0a 100644
--- a/maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/pom.xml
+++ b/maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/pom.xml
@@ -54,6 +54,7 @@ under the License.
       org.apache.maven.plugin-tools
       maven-plugin-annotations
       @project.version@
+      compile
     
     
       org.apache.maven.plugin-tools
diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/pom.xml b/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/pom.xml
index 5bf61cf..1a8ac83 100644
--- a/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/pom.xml
+++ b/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/pom.xml
@@ -59,6 +59,7 @@ under the License.
       org.apache.maven.plugin-tools
       maven-plugin-annotations
       @project.version@
+      compile
     
     
       org.codehaus.plexus
diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance/invoker.properties b/maven-plugin-plugin/src/it/annotation-with-inheritance/invoker.properties
index 71b5b1c..773daef 100644
--- a/maven-plugin-plugin/src/it/annotation-with-inheritance/invoker.properties
+++ b/maven-plugin-plugin/src/it/annotation-with-inheritance/invoker.properties
@@ -1,6 +1,4 @@
-invoker.goals.1 = install
-invoker.goals.2 = org.apache.maven.its.annotation-with-inheritance:annotation-with-inheritance:1.0:it0014
-invoker.goals.3 = org.apache.maven.its.annotation-with-inheritance:annotation-with-inheritance:1.0:first
-#FIXME disabled need to find a solution for the chicken and eggs issue.
-#help sources are generated @generated-sources but need descriptor which need compile phase first for classes scanning
-#invoker.goals.3 = org.apache.maven.its.basic-java-annotations:maven-it-basic-java-annotations:1.0::help
+invoker.goals.1 = clean install -DskipTests
+invoker.goals.2 = org.apache.maven.its.annotation-with-inheritance:annotation-with-inheritance:1.0-SNAPSHOT:it0014
+invoker.goals.3 = org.apache.maven.its.annotation-with-inheritance:annotation-with-inheritance:1.0-SNAPSHOT:first
+invoker.goals.4 = org.apache.maven.its.annotation-with-inheritance:annotation-with-inheritance:1.0-SNAPSHOT:help
diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance/pom.xml b/maven-plugin-plugin/src/it/annotation-with-inheritance/pom.xml
index 5db6488..6799f43 100644
--- a/maven-plugin-plugin/src/it/annotation-with-inheritance/pom.xml
+++ b/maven-plugin-plugin/src/it/annotation-with-inheritance/pom.xml
@@ -24,7 +24,7 @@ under the License.
 
   org.apache.maven.its.annotation-with-inheritance
   annotation-with-inheritance
-  1.0
+  1.0-SNAPSHOT
   maven-plugin
 
   Maven Integration Test :: annotation-with-inheritance
@@ -54,6 +54,7 @@ under the License.
       org.apache.maven.plugin-tools
       maven-plugin-annotations
       @project.version@
+      compile
     
     
       org.codehaus.plexus
@@ -96,6 +97,12 @@ under the License.
               descriptor
             
           
+          
+            help-goal
+            
+              helpmojo
+            
+          
         
       
     
diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java b/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java
index ec56ff6..e8358f7 100644
--- a/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java
+++ b/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java
@@ -32,7 +32,7 @@ import org.apache.maven.plugins.annotations.Parameter;
  * @since 1.2
  * @deprecated Don't use!
  */
-@Mojo( name = "first", requiresDependencyResolution = "test", defaultPhase = LifecyclePhase.INTEGRATION_TEST )
+@Mojo( name = "first", requiresDependencyResolution = "test", defaultPhase = LifecyclePhase.INTEGRATION_TEST)
 @Execute( phase = LifecyclePhase.GENERATE_SOURCES, lifecycle = "cobertura" )
 public class FirstMojo
     extends AbstractFirstMojo
diff --git a/maven-plugin-plugin/src/it/help-basic/invoker.properties b/maven-plugin-plugin/src/it/help-basic/invoker.properties
index 241f018..1828fac 100644
--- a/maven-plugin-plugin/src/it/help-basic/invoker.properties
+++ b/maven-plugin-plugin/src/it/help-basic/invoker.properties
@@ -1,2 +1,2 @@
-invoker.goals.1 = install -DskipTests
+invoker.goals.1 = clean install -DskipTests
 invoker.goals.2 = org.apache.maven.its.plugin:help:1.0:help
diff --git a/maven-plugin-plugin/src/it/help-basic/pom.xml b/maven-plugin-plugin/src/it/help-basic/pom.xml
index 0121194..f51bdac 100644
--- a/maven-plugin-plugin/src/it/help-basic/pom.xml
+++ b/maven-plugin-plugin/src/it/help-basic/pom.xml
@@ -41,6 +41,12 @@ under the License.
       maven-plugin-api
       2.0
     
+    
+      org.codehaus.plexus
+      plexus-utils
+      3.0.1
+      provided
+    
   
 
   
diff --git a/maven-plugin-plugin/src/it/help-package/invoker.properties b/maven-plugin-plugin/src/it/help-package/invoker.properties
index 557f44a..6e222d4 100644
--- a/maven-plugin-plugin/src/it/help-package/invoker.properties
+++ b/maven-plugin-plugin/src/it/help-package/invoker.properties
@@ -1 +1 @@
-invoker.goals = compile
+invoker.goals = clean compile
diff --git a/maven-plugin-plugin/src/it/help-package/pom.xml b/maven-plugin-plugin/src/it/help-package/pom.xml
index 3913245..d34a0e7 100644
--- a/maven-plugin-plugin/src/it/help-package/pom.xml
+++ b/maven-plugin-plugin/src/it/help-package/pom.xml
@@ -41,6 +41,12 @@ under the License.
       maven-plugin-api
       2.0
     
+    
+      org.codehaus.plexus
+      plexus-utils
+      3.0.1
+      provided
+    
   
 
   
diff --git a/maven-plugin-plugin/src/it/ignore-plugin-class-realm/invoker.properties b/maven-plugin-plugin/src/it/ignore-plugin-class-realm/invoker.properties
index 0fd616a..5270276 100644
--- a/maven-plugin-plugin/src/it/ignore-plugin-class-realm/invoker.properties
+++ b/maven-plugin-plugin/src/it/ignore-plugin-class-realm/invoker.properties
@@ -1,4 +1,4 @@
-invoker.goals.1 = clean install
+invoker.goals.1 = clean install -DskipTests
 invoker.profiles.1 = setup
 
 invoker.goals.2 = clean process-classes
diff --git a/maven-plugin-plugin/src/it/java-basic-annotations/invoker.properties b/maven-plugin-plugin/src/it/java-basic-annotations/invoker.properties
index 81563cc..a559219 100644
--- a/maven-plugin-plugin/src/it/java-basic-annotations/invoker.properties
+++ b/maven-plugin-plugin/src/it/java-basic-annotations/invoker.properties
@@ -1,4 +1,4 @@
-invoker.goals.1 = install
+invoker.goals.1 = clean install -DskipTests
 invoker.goals.2 = org.apache.maven.its.basic-java-annotations:maven-it-basic-java-annotations:1.0:it0014
 #FIXME disabled need to find a solution for the chicken and eggs issue.
 #help sources are generated @generated-sources but need descriptor which need compile phase first for classes scanning
diff --git a/maven-plugin-plugin/src/it/java-basic/invoker.properties b/maven-plugin-plugin/src/it/java-basic/invoker.properties
index caedd63..1a33a20 100644
--- a/maven-plugin-plugin/src/it/java-basic/invoker.properties
+++ b/maven-plugin-plugin/src/it/java-basic/invoker.properties
@@ -1,3 +1,3 @@
-invoker.goals.1 = install
+invoker.goals.1 = install -DskipTests
 invoker.goals.2 = org.apache.maven.its.it0013:maven-it-it0013:1.0:it0013
 
diff --git a/maven-plugin-plugin/src/it/mplugin-187/invoker.properties b/maven-plugin-plugin/src/it/mplugin-187/invoker.properties
index 8762f0e..1b50bea 100644
--- a/maven-plugin-plugin/src/it/mplugin-187/invoker.properties
+++ b/maven-plugin-plugin/src/it/mplugin-187/invoker.properties
@@ -1 +1 @@
-invoker.goals = clean plugin:report
+invoker.goals = clean plugin:report -DskipTests
diff --git a/maven-plugin-plugin/src/it/plugin-info-jdk-default-version/invoker.properties b/maven-plugin-plugin/src/it/plugin-info-jdk-default-version/invoker.properties
index 88bfb6d..8a7b3cb 100644
--- a/maven-plugin-plugin/src/it/plugin-info-jdk-default-version/invoker.properties
+++ b/maven-plugin-plugin/src/it/plugin-info-jdk-default-version/invoker.properties
@@ -1 +1 @@
-invoker.goals = clean site
+invoker.goals = clean site -DskipTests
diff --git a/maven-plugin-plugin/src/it/plugin-report/invoker.properties b/maven-plugin-plugin/src/it/plugin-report/invoker.properties
index 88bfb6d..8a7b3cb 100644
--- a/maven-plugin-plugin/src/it/plugin-report/invoker.properties
+++ b/maven-plugin-plugin/src/it/plugin-report/invoker.properties
@@ -1 +1 @@
-invoker.goals = clean site
+invoker.goals = clean site -DskipTests
diff --git a/maven-plugin-plugin/src/it/skip/invoker.properties b/maven-plugin-plugin/src/it/skip/invoker.properties
index 4c83645..06b1654 100644
--- a/maven-plugin-plugin/src/it/skip/invoker.properties
+++ b/maven-plugin-plugin/src/it/skip/invoker.properties
@@ -1,2 +1,2 @@
-invoker.goals = install
+invoker.goals = install -DskipTests
 invoker.mavenOpts = -Dmaven.plugin.skip=true
\ No newline at end of file
diff --git a/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/AbstractGeneratorMojo.java b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/AbstractGeneratorMojo.java
index 3a66ffe..fc696cf 100644
--- a/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/AbstractGeneratorMojo.java
+++ b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/AbstractGeneratorMojo.java
@@ -30,12 +30,14 @@ import org.apache.maven.tools.plugin.DefaultPluginToolsRequest;
 import org.apache.maven.tools.plugin.PluginToolsRequest;
 import org.apache.maven.tools.plugin.extractor.ExtractionException;
 import org.apache.maven.tools.plugin.generator.Generator;
+import org.apache.maven.tools.plugin.generator.GeneratorException;
 import org.apache.maven.tools.plugin.scanner.MojoScanner;
 import org.apache.maven.tools.plugin.util.PluginUtils;
 import org.codehaus.plexus.util.ReaderFactory;
 
 import java.io.File;
 import java.io.IOException;
+import java.lang.annotation.Documented;
 import java.util.List;
 import java.util.Set;
 
@@ -248,7 +250,7 @@ public abstract class AbstractGeneratorMojo
 
             createGenerator().execute( getOutputDirectory(), request );
         }
-        catch ( IOException e )
+        catch ( GeneratorException e )
         {
             throw new MojoExecutionException( "Error writing plugin descriptor", e );
         }
diff --git a/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/HelpGeneratorMojo.java b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/HelpGeneratorMojo.java
index 1bac881..ae14d31 100644
--- a/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/HelpGeneratorMojo.java
+++ b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/HelpGeneratorMojo.java
@@ -19,20 +19,21 @@ package org.apache.maven.plugin.plugin;
  * under the License.
  */
 
-import java.io.File;
-
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.tools.plugin.generator.Generator;
 import org.apache.maven.tools.plugin.generator.PluginHelpGenerator;
+import org.codehaus.plexus.velocity.VelocityComponent;
+
+import java.io.File;
 
 /**
  * Generates a HelpMojo class.
  *
  * @author Vincent Siveton
  * @version $Id$
- * @since 2.4
  * @goal helpmojo
  * @phase generate-sources
+ * @since 2.4
  */
 public class HelpGeneratorMojo
     extends AbstractGeneratorMojo
@@ -47,7 +48,7 @@ public class HelpGeneratorMojo
     /**
      * The name of the package for the generated HelpMojo. By default, the package will be calculated based
      * on the packages of the other plugin goals.
-     * 
+     *
      * @parameter
      * @since 2.6
      */
@@ -61,19 +62,35 @@ public class HelpGeneratorMojo
      */
     private boolean useJava5;
 
-    /** {@inheritDoc} */
+    /**
+     * Velocity component.
+     *
+     * @component
+     * @readonly
+     * @required
+     */
+    private VelocityComponent velocity;
+
+    /**
+     * {@inheritDoc}
+     */
     protected File getOutputDirectory()
     {
         return outputDirectory;
     }
 
-    /** {@inheritDoc} */
+    /**
+     * {@inheritDoc}
+     */
     protected Generator createGenerator()
     {
-        return new PluginHelpGenerator().setHelpPackageName( helpPackageName ).setUseJava5( useJava5 );
+        return new PluginHelpGenerator().setHelpPackageName( helpPackageName ).setUseJava5(
+            useJava5 ).setVelocityComponent( this.velocity );
     }
 
-    /** {@inheritDoc} */
+    /**
+     * {@inheritDoc}
+     */
     public void execute()
         throws MojoExecutionException
     {
@@ -83,5 +100,7 @@ public class HelpGeneratorMojo
         {
             project.addCompileSourceRoot( outputDirectory.getAbsolutePath() );
         }
+
     }
+
 }
diff --git a/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/PluginReport.java b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/PluginReport.java
index b2ee032..ec0bbf1 100644
--- a/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/PluginReport.java
+++ b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/PluginReport.java
@@ -19,15 +19,6 @@ package org.apache.maven.plugin.plugin;
  * under the License.
  */
 
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.ResourceBundle;
-
 import org.apache.maven.doxia.sink.Sink;
 import org.apache.maven.doxia.siterenderer.Renderer;
 import org.apache.maven.model.Plugin;
@@ -42,21 +33,30 @@ import org.apache.maven.reporting.MavenReportException;
 import org.apache.maven.tools.plugin.DefaultPluginToolsRequest;
 import org.apache.maven.tools.plugin.PluginToolsRequest;
 import org.apache.maven.tools.plugin.extractor.ExtractionException;
+import org.apache.maven.tools.plugin.generator.GeneratorException;
 import org.apache.maven.tools.plugin.generator.PluginXdocGenerator;
 import org.apache.maven.tools.plugin.scanner.MojoScanner;
 import org.apache.maven.tools.plugin.util.PluginUtils;
 import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.xml.Xpp3Dom;
 
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.ResourceBundle;
+
 /**
  * Generates the Plugin's documentation report.
  *
  * @author Stephane Nicoll
  * @author Vincent Siveton
  * @version $Id$
- * @since 2.0
  * @goal report
  * @execute phase="compile"
+ * @since 2.0
  */
 public class PluginReport
     extends AbstractMavenReport
@@ -91,13 +91,12 @@ public class PluginReport
      */
     protected MojoScanner mojoScanner;
 
-   /**
-    * The file encoding of the source files.
-    *
-    * @parameter expression="${encoding}" default-value="${project.build.sourceEncoding}"
-    *
-    * @since 2.7
-    */
+    /**
+     * The file encoding of the source files.
+     *
+     * @parameter expression="${encoding}" default-value="${project.build.sourceEncoding}"
+     * @since 2.7
+     */
     private String encoding;
 
 
@@ -124,10 +123,10 @@ public class PluginReport
     private Requirements requirements;
 
     /**
-     * The goal prefix that will appear before the ":". 
-     * By default, this plugin applies a heuristic to derive a heuristic from 
-     * the plugin's artifactId. 
-     * 
+     * The goal prefix that will appear before the ":".
+     * By default, this plugin applies a heuristic to derive a heuristic from
+     * the plugin's artifactId.
+     * 

* It removes any occurrences of the regular expression -?maven-?, * and then removes any occurrences of -?plugin-?. *

@@ -158,31 +157,41 @@ public class PluginReport */ private boolean skipReport; - /** {@inheritDoc} */ + /** + * {@inheritDoc} + */ protected Renderer getSiteRenderer() { return siteRenderer; } - /** {@inheritDoc} */ + /** + * {@inheritDoc} + */ protected String getOutputDirectory() { return outputDirectory.getPath(); } - /** {@inheritDoc} */ + /** + * {@inheritDoc} + */ protected MavenProject getProject() { return project; } - /** {@inheritDoc} */ + /** + * {@inheritDoc} + */ public boolean canGenerateReport() { return "maven-plugin".equals( project.getPackaging() ); } - /** {@inheritDoc} */ + /** + * {@inheritDoc} + */ @SuppressWarnings( "unchecked" ) protected void executeReport( Locale locale ) throws MavenReportException @@ -205,8 +214,7 @@ public class PluginReport } else { - getLog().warn( - "\n\nGoal prefix is specified as: '" + goalPrefix + "'. Maven currently expects it to be '" + getLog().warn( "\n\nGoal prefix is specified as: '" + goalPrefix + "'. Maven currently expects it to be '" + defaultGoalPrefix + "'.\n" ); } @@ -224,11 +232,11 @@ public class PluginReport try { pluginDescriptor.setDependencies( PluginUtils.toComponentDependencies( project.getRuntimeDependencies() ) ); - + PluginToolsRequest request = new DefaultPluginToolsRequest( project, pluginDescriptor ); request.setEncoding( encoding ); - try + try { mojoScanner.populatePluginDescriptor( request ); } @@ -243,11 +251,11 @@ public class PluginReport generatePluginDocumentation( pluginDescriptor, locale ); // Write the overview - PluginOverviewRenderer r = new PluginOverviewRenderer( project, requirements, getSink(), pluginDescriptor, - locale ); + PluginOverviewRenderer r = + new PluginOverviewRenderer( project, requirements, getSink(), pluginDescriptor, locale ); r.render(); } - + catch ( ExtractionException e ) { throw new MavenReportException( "Error extracting plugin descriptor: \'" + e.getLocalizedMessage() + "\'", @@ -255,19 +263,25 @@ public class PluginReport } } - /** {@inheritDoc} */ + /** + * {@inheritDoc} + */ public String getDescription( Locale locale ) { return getBundle( locale ).getString( "report.plugin.description" ); } - /** {@inheritDoc} */ + /** + * {@inheritDoc} + */ public String getName( Locale locale ) { return getBundle( locale ).getString( "report.plugin.name" ); } - /** {@inheritDoc} */ + /** + * {@inheritDoc} + */ public String getOutputName() { return "plugin-info"; @@ -275,7 +289,7 @@ public class PluginReport /** * @param pluginDescriptor not null - * @param locale not null + * @param locale not null * @throws MavenReportException if any */ private void generatePluginDocumentation( PluginDescriptor pluginDescriptor, Locale locale ) @@ -287,9 +301,10 @@ public class PluginReport outputDir.mkdirs(); PluginXdocGenerator generator = new PluginXdocGenerator( project, locale ); - generator.execute( outputDir, pluginDescriptor ); + PluginToolsRequest pluginToolsRequest = new DefaultPluginToolsRequest( project, pluginDescriptor ); + generator.execute( outputDir, pluginToolsRequest ); } - catch ( IOException e ) + catch ( GeneratorException e ) { throw new MavenReportException( "Error writing plugin documentation", e ); } @@ -321,11 +336,11 @@ public class PluginReport private final Locale locale; /** - * @param project not null - * @param requirements not null - * @param sink not null + * @param project not null + * @param requirements not null + * @param sink not null * @param pluginDescriptor not null - * @param locale not null + * @param locale not null */ public PluginOverviewRenderer( MavenProject project, Requirements requirements, Sink sink, PluginDescriptor pluginDescriptor, Locale locale ) @@ -341,13 +356,17 @@ public class PluginReport this.locale = locale; } - /** {@inheritDoc} */ + /** + * {@inheritDoc} + */ public String getTitle() { return getBundle( locale ).getString( "report.plugin.title" ); } - /** {@inheritDoc} */ + /** + * {@inheritDoc} + */ @SuppressWarnings( { "unchecked", "rawtypes" } ) public void renderBody() { @@ -362,7 +381,6 @@ public class PluginReport paragraph( getBundle( locale ).getString( "report.plugin.goals.intro" ) ); - boolean hasMavenReport = false; for ( Iterator i = pluginDescriptor.getMojos().iterator(); i.hasNext(); ) { @@ -381,11 +399,11 @@ public class PluginReport String descriptionColumnName = getBundle( locale ).getString( "report.plugin.goals.column.description" ); if ( hasMavenReport ) { - tableHeader( new String[] { goalColumnName, isMavenReport, descriptionColumnName } ); + tableHeader( new String[]{ goalColumnName, isMavenReport, descriptionColumnName } ); } else { - tableHeader( new String[] { goalColumnName, descriptionColumnName } ); + tableHeader( new String[]{ goalColumnName, descriptionColumnName } ); } List mojos = new ArrayList(); @@ -449,15 +467,16 @@ public class PluginReport String maven = discoverMavenRequirement( project, requirements ); sink.tableRow(); tableCell( getBundle( locale ).getString( "report.plugin.systemrequirements.maven" ) ); - tableCell( ( maven != null ? maven : getBundle( locale ) - .getString( "report.plugin.systemrequirements.nominimum" ) ) ); + tableCell( ( maven != null + ? maven + : getBundle( locale ).getString( "report.plugin.systemrequirements.nominimum" ) ) ); sink.tableRow_(); String jdk = discoverJdkRequirement( project, requirements ); sink.tableRow(); tableCell( getBundle( locale ).getString( "report.plugin.systemrequirements.jdk" ) ); - tableCell( ( jdk != null ? jdk : getBundle( locale ) - .getString( "report.plugin.systemrequirements.nominimum" ) ) ); + tableCell( + ( jdk != null ? jdk : getBundle( locale ).getString( "report.plugin.systemrequirements.nominimum" ) ) ); sink.tableRow_(); sink.tableRow(); @@ -482,9 +501,9 @@ public class PluginReport sink.tableRow(); tableCell( key ); - tableCell( ( StringUtils.isNotEmpty( requirements.getOthers().getProperty( key ) ) ? requirements - .getOthers().getProperty( key ) : getBundle( locale ) - .getString( "report.plugin.systemrequirements.nominimum" ) ) ); + tableCell( ( StringUtils.isNotEmpty( requirements.getOthers().getProperty( key ) ) + ? requirements.getOthers().getProperty( key ) + : getBundle( locale ).getString( "report.plugin.systemrequirements.nominimum" ) ) ); sink.tableRow_(); } } @@ -515,31 +534,32 @@ public class PluginReport sb.append( "" ).append( '\n' ); sb.append( " ..." ).append( '\n' ); sb.append( " " ).append( '\n' ); - sb.append( " " ) - .append( '\n' ); + sb.append( + " " ).append( + '\n' ); sb.append( " " ).append( '\n' ); sb.append( " " ).append( '\n' ); sb.append( " " ).append( '\n' ); - sb.append( " " ).append( pluginDescriptor.getGroupId() ).append( "" ) - .append( '\n' ); - sb.append( " " ).append( pluginDescriptor.getArtifactId() ).append( "" ) - .append( '\n' ); - sb.append( " " ).append( pluginDescriptor.getVersion() ).append( "" ) - .append( '\n' ); + sb.append( " " ).append( pluginDescriptor.getGroupId() ).append( "" ).append( + '\n' ); + sb.append( " " ).append( pluginDescriptor.getArtifactId() ).append( + "" ).append( '\n' ); + sb.append( " " ).append( pluginDescriptor.getVersion() ).append( "" ).append( + '\n' ); sb.append( " " ).append( '\n' ); sb.append( " ..." ).append( '\n' ); sb.append( " " ).append( '\n' ); sb.append( " " ).append( '\n' ); - sb.append( " " ) - .append( '\n' ); + sb.append( " " ).append( + '\n' ); sb.append( " " ).append( '\n' ); sb.append( " " ).append( '\n' ); - sb.append( " " ).append( pluginDescriptor.getGroupId() ).append( "" ) - .append( '\n' ); - sb.append( " " ).append( pluginDescriptor.getArtifactId() ).append( "" ) - .append( '\n' ); - sb.append( " " ).append( pluginDescriptor.getVersion() ).append( "" ) - .append( '\n' ); + sb.append( " " ).append( pluginDescriptor.getGroupId() ).append( "" ).append( + '\n' ); + sb.append( " " ).append( pluginDescriptor.getArtifactId() ).append( + "" ).append( '\n' ); + sb.append( " " ).append( pluginDescriptor.getVersion() ).append( "" ).append( + '\n' ); sb.append( " " ).append( '\n' ); sb.append( " ..." ).append( '\n' ); sb.append( " " ).append( '\n' ); @@ -548,17 +568,18 @@ public class PluginReport if ( hasMavenReport ) { sb.append( " ..." ).append( '\n' ); - sb.append( " " ) - .append( '\n' ); + sb.append( + " " ).append( + '\n' ); sb.append( " " ).append( '\n' ); sb.append( " " ).append( '\n' ); sb.append( " " ).append( '\n' ); - sb.append( " " ).append( pluginDescriptor.getGroupId() ).append( "" ) - .append( '\n' ); - sb.append( " " ).append( pluginDescriptor.getArtifactId() ).append( "" ) - .append( '\n' ); - sb.append( " " ).append( pluginDescriptor.getVersion() ).append( "" ) - .append( '\n' ); + sb.append( " " ).append( pluginDescriptor.getGroupId() ).append( "" ).append( + '\n' ); + sb.append( " " ).append( pluginDescriptor.getArtifactId() ).append( + "" ).append( '\n' ); + sb.append( " " ).append( pluginDescriptor.getVersion() ).append( "" ).append( + '\n' ); sb.append( " " ).append( '\n' ); sb.append( " ..." ).append( '\n' ); sb.append( " " ).append( '\n' ); @@ -581,7 +602,7 @@ public class PluginReport * Try to lookup on the Maven prerequisites property. * If not specified, uses the value defined by the user. * - * @param project not null + * @param project not null * @param requirements not null * @return the Maven version */ @@ -606,7 +627,7 @@ public class PluginReport * If not specified, uses the value defined by the user. * If not specified, uses the value of the system property java.specification.version. * - * @param project not null + * @param project not null * @param requirements not null * @return the JDK version */ @@ -686,11 +707,11 @@ public class PluginReport jdk = pluginConf.getChild( "target" ).getValue(); } - if ( jdk == null ) + if ( jdk == null ) { return backupJdk; } - else + else { return jdk; } diff --git a/maven-plugin-tools-api/pom.xml b/maven-plugin-tools-api/pom.xml index bf66edb..28803f5 100644 --- a/maven-plugin-tools-api/pom.xml +++ b/maven-plugin-tools-api/pom.xml @@ -71,6 +71,22 @@ org.codehaus.plexus plexus-container-default + + org.codehaus.plexus + plexus-velocity + + + velocity + velocity + + + + + + + org.apache.velocity + velocity + @@ -93,6 +109,20 @@ + + + + org.apache.maven.plugins + maven-surefire-plugin + + + ${project.build.outputDirectory} + + + + + + reporting diff --git a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/Generator.java b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/Generator.java index 344183a..388dd78 100644 --- a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/Generator.java +++ b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/Generator.java @@ -33,18 +33,7 @@ import java.io.IOException; */ public interface Generator { - /** - * Execute the generation for a given plugin descriptor. - * - * @param destinationDirectory required - * @param pluginDescriptor required - * @throws IOException if any - * - * @deprecated Use {@link Generator#execute(File, PluginToolsRequest)} instead. - */ - void execute( File destinationDirectory, PluginDescriptor pluginDescriptor ) - throws IOException; - + /** * Execute the generation for a given plugin descriptor. * @@ -55,5 +44,5 @@ public interface Generator * @since 2.5 */ void execute( File destinationDirectory, PluginToolsRequest request ) - throws IOException; + throws GeneratorException; } \ No newline at end of file diff --git a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java index d41f341..136db43 100644 --- a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java +++ b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java @@ -19,11 +19,12 @@ package org.apache.maven.tools.plugin.generator; * under the License. */ +import org.apache.maven.plugin.descriptor.DuplicateMojoDescriptorException; import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.Parameter; import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.plugin.descriptor.Requirement; -import org.apache.maven.tools.plugin.DefaultPluginToolsRequest; +import org.apache.maven.project.MavenProject; import org.apache.maven.tools.plugin.ExtendedMojoDescriptor; import org.apache.maven.tools.plugin.PluginToolsRequest; import org.apache.maven.tools.plugin.util.PluginUtils; @@ -33,53 +34,91 @@ import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter; import org.codehaus.plexus.util.xml.XMLWriter; import java.io.File; +import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.Writer; +import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; +import java.util.Properties; import java.util.Set; /** + * @version $Id$ * @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. - * - * @version $Id$ */ public class PluginDescriptorGenerator implements Generator { - /** {@inheritDoc} */ - public void execute( File destinationDirectory, PluginDescriptor pluginDescriptor ) - throws IOException - { - execute( destinationDirectory, new DefaultPluginToolsRequest( null, pluginDescriptor ) ); - } - - /** {@inheritDoc} */ + + /** + * {@inheritDoc} + */ public void execute( File destinationDirectory, PluginToolsRequest request ) - throws IOException + throws GeneratorException + { + try + { + File f = new File( destinationDirectory, "plugin.xml" ); + writeDescriptor( f, request, false ); + MavenProject mavenProject = request.getProject(); + String pluginDescriptionFilePath = + "META-INF/maven/" + mavenProject.getGroupId() + "/" + mavenProject.getArtifactId() + + "/plugin-description.xml"; + f = new File( request.getProject().getBuild().getOutputDirectory(), pluginDescriptionFilePath ); + writeDescriptor( f, request, true ); + } + catch ( IOException e ) + { + throw new GeneratorException( e.getMessage(), e ); + } + catch ( DuplicateMojoDescriptorException e ) + { + throw new GeneratorException( e.getMessage(), e ); + } + } + + public void writeDescriptor( File destinationFile, PluginToolsRequest request, boolean cleanDescription ) + throws IOException, DuplicateMojoDescriptorException { PluginDescriptor pluginDescriptor = request.getPluginDescriptor(); - - String encoding = "UTF-8"; - File f = new File( destinationDirectory, "plugin.xml" ); + File tmpPropertiesFile = + new File( request.getProject().getBuild().getDirectory(), "maven-plugin-help.properties" ); - if ( !f.getParentFile().exists() ) + if ( tmpPropertiesFile.exists() ) { - f.getParentFile().mkdirs(); + Properties properties = new Properties(); + properties.load( new FileInputStream( tmpPropertiesFile ) ); + //MojoDescriptor mojoDescriptor = + // makeHelpDescriptor( pluginDescriptor, properties.getProperty( "helpPackageName" ) ); + //pluginDescriptor.addMojo( mojoDescriptor ); } + if ( destinationFile.exists() ) + { + destinationFile.delete(); + } + else + { + if ( !destinationFile.getParentFile().exists() ) + { + destinationFile.getParentFile().mkdirs(); + } + } + + String encoding = "UTF-8"; Writer writer = null; try { - writer = new OutputStreamWriter( new FileOutputStream( f ), encoding ); + writer = new OutputStreamWriter( new FileOutputStream( destinationFile ), encoding ); XMLWriter w = new PrettyPrintXMLWriter( writer, encoding, null ); @@ -105,11 +144,11 @@ public class PluginDescriptorGenerator if ( pluginDescriptor.getMojos() != null ) { - for ( @SuppressWarnings( "unchecked" ) - Iterator it = pluginDescriptor.getMojos().iterator(); it.hasNext(); ) + for ( @SuppressWarnings( "unchecked" ) Iterator it = + pluginDescriptor.getMojos().iterator(); it.hasNext(); ) { MojoDescriptor descriptor = it.next(); - processMojoDescriptor( descriptor, w ); + processMojoDescriptor( descriptor, w, cleanDescription ); } } @@ -120,6 +159,7 @@ public class PluginDescriptorGenerator w.endElement(); writer.flush(); + } finally { @@ -128,10 +168,142 @@ public class PluginDescriptorGenerator } /** - * @param mojoDescriptor not null - * @param w not null + * Creates a minimalistic mojo descriptor for the generated help goal. + * + * @param pluginDescriptor The descriptor of the plugin for which to generate a help goal, must not be + * null. + * @return The mojo descriptor for the generated help goal, never null. */ + private MojoDescriptor makeHelpDescriptor( PluginDescriptor pluginDescriptor, String packageName ) + { + MojoDescriptor descriptor = new MojoDescriptor(); + + descriptor.setPluginDescriptor( pluginDescriptor ); + + descriptor.setLanguage( "java" ); + + descriptor.setGoal( "help" ); + + if ( StringUtils.isEmpty( packageName ) ) + { + packageName = discoverPackageName( pluginDescriptor ); + } + if ( StringUtils.isNotEmpty( packageName ) ) + { + descriptor.setImplementation( packageName + '.' + "HelpMojo" ); + } + else + { + descriptor.setImplementation( "HelpMojo" ); + } + + descriptor.setDescription( + "Display help information on " + pluginDescriptor.getArtifactId() + ".
Call

  mvn "
+                + descriptor.getFullGoalName()
+                + " -Ddetail=true -Dgoal=<goal-name>
to display parameter details." ); + + try + { + Parameter param = new Parameter(); + param.setName( "detail" ); + param.setType( "boolean" ); + param.setDescription( "If true, display all settable properties for each goal." ); + param.setDefaultValue( "false" ); + param.setExpression( "${detail}" ); + descriptor.addParameter( param ); + + param = new Parameter(); + param.setName( "goal" ); + param.setType( "java.lang.String" ); + param.setDescription( + "The name of the goal for which to show help." + " If unspecified, all goals will be displayed." ); + param.setExpression( "${goal}" ); + descriptor.addParameter( param ); + + param = new Parameter(); + param.setName( "lineLength" ); + param.setType( "int" ); + param.setDescription( "The maximum length of a display line, should be positive." ); + param.setDefaultValue( "80" ); + param.setExpression( "${lineLength}" ); + descriptor.addParameter( param ); + + param = new Parameter(); + param.setName( "indentSize" ); + param.setType( "int" ); + param.setDescription( "The number of spaces per indentation level, should be positive." ); + param.setDefaultValue( "2" ); + param.setExpression( "${indentSize}" ); + descriptor.addParameter( param ); + } + catch ( Exception e ) + { + throw new RuntimeException( "Failed to setup parameters for help goal", e ); + } + + return descriptor; + } + + /** + * Find the best package name, based on the number of hits of actual Mojo classes. + * + * @param pluginDescriptor not null + * @return the best name of the package for the generated mojo + */ + private static String discoverPackageName( PluginDescriptor pluginDescriptor ) + { + Map packageNames = new HashMap(); + for ( Iterator it = pluginDescriptor.getMojos().iterator(); it.hasNext(); ) + { + MojoDescriptor descriptor = (MojoDescriptor) it.next(); + + String impl = descriptor.getImplementation(); + if ( impl.lastIndexOf( '.' ) != -1 ) + { + String name = impl.substring( 0, impl.lastIndexOf( '.' ) ); + if ( packageNames.get( name ) != null ) + { + int next = ( (Integer) packageNames.get( name ) ).intValue() + 1; + packageNames.put( name, new Integer( next ) ); + } + else + { + packageNames.put( name, new Integer( 1 ) ); + } + } + else + { + packageNames.put( "", new Integer( 1 ) ); + } + } + + String packageName = ""; + int max = 0; + for ( Iterator it = packageNames.keySet().iterator(); it.hasNext(); ) + { + String key = it.next().toString(); + int value = ( (Integer) packageNames.get( key ) ).intValue(); + if ( value > max ) + { + max = value; + packageName = key; + } + } + + return packageName; + } + protected void processMojoDescriptor( MojoDescriptor mojoDescriptor, XMLWriter w ) + { + processMojoDescriptor( mojoDescriptor, w, false ); + } + + /** + * @param mojoDescriptor not null + * @param w not null + * @param cleanDescription will clean html content from description fields + */ + protected void processMojoDescriptor( MojoDescriptor mojoDescriptor, XMLWriter w, boolean cleanDescription ) { w.startElement( "mojo" ); @@ -152,7 +324,14 @@ public class PluginDescriptorGenerator if ( description != null ) { w.startElement( "description" ); - w.writeText( mojoDescriptor.getDescription() ); + if ( cleanDescription ) + { + w.writeText( PluginUtils.toText( mojoDescriptor.getDescription() ) ); + } + else + { + w.writeText( mojoDescriptor.getDescription() ); + } w.endElement(); } @@ -323,8 +502,7 @@ public class PluginDescriptorGenerator // Parameters // ---------------------------------------------------------------------- - @SuppressWarnings( "unchecked" ) - List parameters = mojoDescriptor.getParameters(); + @SuppressWarnings( "unchecked" ) List parameters = mojoDescriptor.getParameters(); w.startElement( "parameters" ); @@ -397,11 +575,17 @@ public class PluginDescriptorGenerator PluginUtils.element( w, "required", Boolean.toString( parameter.isRequired() ) ); PluginUtils.element( w, "editable", Boolean.toString( parameter.isEditable() ) ); + if ( cleanDescription ) + { + PluginUtils.element( w, "description", PluginUtils.toText( parameter.getDescription() ) ); + } + else + { + PluginUtils.element( w, "description", parameter.getDescription() ); + } - PluginUtils.element( w, "description", parameter.getDescription() ); - - if ( StringUtils.isNotEmpty( parameter.getDefaultValue() ) - || StringUtils.isNotEmpty( parameter.getExpression() ) ) + if ( StringUtils.isNotEmpty( parameter.getDefaultValue() ) || StringUtils.isNotEmpty( + parameter.getExpression() ) ) { configuration.add( parameter ); } diff --git a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginHelpGenerator.java b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginHelpGenerator.java index a7ab865..13d37a0 100644 --- a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginHelpGenerator.java +++ b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginHelpGenerator.java @@ -19,31 +19,31 @@ package org.apache.maven.tools.plugin.generator; * under the License. */ -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStreamWriter; -import java.io.Writer; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Properties; - import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.Parameter; import org.apache.maven.plugin.descriptor.PluginDescriptor; -import org.apache.maven.tools.plugin.DefaultPluginToolsRequest; +import org.apache.maven.project.MavenProject; import org.apache.maven.tools.plugin.PluginToolsRequest; -import org.apache.maven.tools.plugin.util.PluginUtils; +import org.apache.velocity.VelocityContext; import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.logging.console.ConsoleLogger; import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.StringUtils; +import org.codehaus.plexus.velocity.VelocityComponent; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.io.StringWriter; +import java.io.Writer; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Properties; /** * Generates an HelpMojo class. @@ -56,20 +56,30 @@ public class PluginHelpGenerator extends AbstractLogEnabled implements Generator { - /** Line separator */ + /** + * Line separator + */ private static final String LS = System.getProperty( "line.separator" ); - /** Default generated class name */ + /** + * Default generated class name + */ private static final String HELP_MOJO_CLASS_NAME = "HelpMojo"; - /** Default goal */ + /** + * Default goal + */ private static final String HELP_GOAL = "help"; private String helpPackageName; - - /** Flag to indicate if the generated help mojo should use Java 5 features */ + + /** + * Flag to indicate if the generated help mojo should use Java 5 features + */ private boolean useJava5; + private VelocityComponent velocityComponent; + /** * Default constructor */ @@ -82,39 +92,29 @@ public class PluginHelpGenerator // Public methods // ---------------------------------------------------------------------- - /** {@inheritDoc} */ - public void execute( File destinationDirectory, PluginDescriptor pluginDescriptor ) - throws IOException - { - execute( destinationDirectory, new DefaultPluginToolsRequest( null, pluginDescriptor ) ); - } - - /** {@inheritDoc} */ + + /** + * {@inheritDoc} + */ public void execute( File destinationDirectory, PluginToolsRequest request ) - throws IOException + throws GeneratorException { PluginDescriptor pluginDescriptor = request.getPluginDescriptor(); - - if ( pluginDescriptor.getMojos() == null || pluginDescriptor.getMojos().size() < 1 ) - { - return; - } MojoDescriptor helpDescriptor = makeHelpDescriptor( pluginDescriptor ); // Verify that no help goal already exists - for ( @SuppressWarnings( "unchecked" ) - Iterator it = pluginDescriptor.getMojos().iterator(); it.hasNext(); ) + for ( @SuppressWarnings( "unchecked" ) Iterator it = pluginDescriptor.getMojos().iterator(); + it.hasNext(); ) { MojoDescriptor descriptor = it.next(); - if ( descriptor.getGoal().equals( helpDescriptor.getGoal() ) - && !descriptor.getImplementation().equals( helpDescriptor.getImplementation() ) ) + if ( descriptor.getGoal().equals( helpDescriptor.getGoal() ) && !descriptor.getImplementation().equals( + helpDescriptor.getImplementation() ) ) { if ( getLogger().isWarnEnabled() ) { - getLogger().warn( - "\n\nA help goal (" + descriptor.getImplementation() + getLogger().warn( "\n\nA help goal (" + descriptor.getImplementation() + ") already exists in this plugin. SKIPPED THE " + helpDescriptor.getImplementation() + " GENERATION.\n" ); } @@ -123,6 +123,36 @@ public class PluginHelpGenerator } } + Properties properties = new Properties(); + properties.put( "helpPackageName", helpPackageName == null ? "" : helpPackageName ); + + MavenProject mavenProject = request.getProject(); + + String propertiesFilePath = "META-INF/maven/" + mavenProject.getGroupId() + "/" + mavenProject.getArtifactId(); + + File tmpPropertiesFile = + new File( request.getProject().getBuild().getDirectory(), "maven-plugin-help.properties" ); + if ( tmpPropertiesFile.exists() ) + { + tmpPropertiesFile.delete(); + } + else + { + if ( !tmpPropertiesFile.getParentFile().exists() ) + { + tmpPropertiesFile.getParentFile().mkdirs(); + } + } + + try + { + properties.store( new FileOutputStream( tmpPropertiesFile ), "maven plugin help generation informations" ); + } + catch ( IOException e ) + { + throw new GeneratorException( e.getMessage(), e ); + } + String sourcePath = helpDescriptor.getImplementation().replace( '.', File.separatorChar ) + ".java"; File helpClass = new File( destinationDirectory, sourcePath ); helpClass.getParentFile().mkdirs(); @@ -131,13 +161,19 @@ public class PluginHelpGenerator try { writer = new OutputStreamWriter( new FileOutputStream( helpClass ), request.getEncoding() ); - writeClass( writer, pluginDescriptor, helpDescriptor, useJava5 ); + writer.write( getHelpClassSources( propertiesFilePath ) ); writer.flush(); } + catch ( IOException e ) + { + throw new GeneratorException( e.getMessage(), e ); + } finally { IOUtil.close( writer ); } + + } public PluginHelpGenerator setHelpPackageName( String helpPackageName ) @@ -152,15 +188,52 @@ public class PluginHelpGenerator return this; } + public VelocityComponent getVelocityComponent() + { + return velocityComponent; + } + + public PluginHelpGenerator setVelocityComponent( VelocityComponent velocityComponent ) + { + this.velocityComponent = velocityComponent; + return this; + } + // ---------------------------------------------------------------------- // Private methods // ---------------------------------------------------------------------- + protected String getHelpClassSources( String propertiesFilePath ) + { + Properties properties = new Properties(); + VelocityContext context = new VelocityContext( properties ); + if ( this.helpPackageName != null ) + { + properties.put( "helpPackageName", this.helpPackageName ); + } + else + { + properties.put( "helpPackageName", "" ); + } + properties.put( "propertiesFilePath", propertiesFilePath + "/plugin-description.xml" ); + // FIXME encoding ! + + StringWriter stringWriter = new StringWriter(); + + InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream( "help-class-source.vm" ); + InputStreamReader isReader = new InputStreamReader( is ); + velocityComponent.getEngine().evaluate( context, stringWriter, "", isReader ); + + return stringWriter.toString(); + + } + + /** * Creates a minimalistic mojo descriptor for the generated help goal. * * @param pluginDescriptor The descriptor of the plugin for which to generate a help goal, must not be - * null. + * null. * @return The mojo descriptor for the generated help goal, never null. */ private MojoDescriptor makeHelpDescriptor( PluginDescriptor pluginDescriptor ) @@ -187,9 +260,10 @@ public class PluginHelpGenerator descriptor.setImplementation( HELP_MOJO_CLASS_NAME ); } - descriptor.setDescription( "Display help information on " + pluginDescriptor.getArtifactId() - + ".
Call
  mvn " + descriptor.getFullGoalName()
-            + " -Ddetail=true -Dgoal=<goal-name>
to display parameter details." ); + descriptor.setDescription( + "Display help information on " + pluginDescriptor.getArtifactId() + ".
Call
  mvn "
+                + descriptor.getFullGoalName()
+                + " -Ddetail=true -Dgoal=<goal-name>
to display parameter details." ); try { @@ -204,8 +278,8 @@ public class PluginHelpGenerator param = new Parameter(); param.setName( "goal" ); param.setType( "java.lang.String" ); - param.setDescription( "The name of the goal for which to show help." - + " If unspecified, all goals will be displayed." ); + param.setDescription( + "The name of the goal for which to show help." + " If unspecified, all goals will be displayed." ); param.setExpression( "${goal}" ); descriptor.addParameter( param ); @@ -241,595 +315,45 @@ public class PluginHelpGenerator */ private static String discoverPackageName( PluginDescriptor pluginDescriptor ) { - Map packageNames = new HashMap(); - for ( @SuppressWarnings( "unchecked" ) - Iterator it = pluginDescriptor.getMojos().iterator(); it.hasNext(); ) + Map packageNames = new HashMap(); + for ( Iterator it = pluginDescriptor.getMojos().iterator(); it.hasNext(); ) { - MojoDescriptor descriptor = it.next(); - - String name = ""; - int next = 1; + MojoDescriptor descriptor = (MojoDescriptor) it.next(); String impl = descriptor.getImplementation(); if ( impl.lastIndexOf( '.' ) != -1 ) { - name = impl.substring( 0, impl.lastIndexOf( '.' ) ); - Integer count = packageNames.get( name ); - - if ( count != null ) + String name = impl.substring( 0, impl.lastIndexOf( '.' ) ); + if ( packageNames.get( name ) != null ) { - next = count.intValue() + 1; + int next = ( (Integer) packageNames.get( name ) ).intValue() + 1; + packageNames.put( name, new Integer( next ) ); + } + else + { + packageNames.put( name, new Integer( 1 ) ); } } - - packageNames.put( name, next ); + else + { + packageNames.put( "", new Integer( 1 ) ); + } } String packageName = ""; int max = 0; - for ( Map.Entry entry : packageNames.entrySet() ) + for ( Iterator it = packageNames.keySet().iterator(); it.hasNext(); ) { - int value = entry.getValue().intValue(); + String key = it.next().toString(); + int value = ( (Integer) packageNames.get( key ) ).intValue(); if ( value > max ) { max = value; - packageName = entry.getKey(); + packageName = key; } } return packageName; } - /** - * Generates the HelpMojo class. - * - * @param writer not null - * @param pluginDescriptor not null - * @param helpDescriptor not null - * @param useJava5 If the generated code should use Java5 features - * @throws IOException if any - */ - private static void writeClass( Writer writer, PluginDescriptor pluginDescriptor, MojoDescriptor helpDescriptor, - boolean useJava5 ) - throws IOException - { - String packageName = ""; - String simpleName = helpDescriptor.getImplementation(); - int dot = simpleName.lastIndexOf( '.' ); - if ( dot >= 0 ) - { - packageName = simpleName.substring( 0, dot ); - simpleName = simpleName.substring( dot + 1 ); - } - - if ( packageName.length() > 0 ) - { - writer.write( "package " + packageName + ";" + LS ); - writer.write( LS ); - } - - writeImports( writer ); - writer.write( LS ); - - writeMojoJavadoc( writer, pluginDescriptor, helpDescriptor ); - - if ( useJava5 ) - { - writer.write( "@SuppressWarnings( \"all\" )" + LS ); - } - - writer.write( "public class " + simpleName + LS ); - writer.write( " extends AbstractMojo" + LS ); - writer.write( "{" + LS ); - - writeVariables( writer, helpDescriptor ); - - writer.write( LS ); - - writeExecute( writer, pluginDescriptor, helpDescriptor ); - - writer.write( LS ); - writeUtilities( writer, useJava5 ); - writer.write( "}" + LS ); - } - - /** - * @param writer not null - * @throws IOException if any - */ - private static void writeImports( Writer writer ) - throws IOException - { - writer.write( "import java.util.ArrayList;" + LS ); - writer.write( "import java.util.Iterator;" + LS ); - writer.write( "import java.util.List;" + LS ); - writer.write( LS ); - writer.write( "import org.apache.maven.plugin.AbstractMojo;" + LS ); - writer.write( "import org.apache.maven.plugin.MojoExecutionException;" + LS ); - } - - /** - * @param writer not null - * @param pluginDescriptor not null - * @param helpDescriptor not null - * @throws IOException if any - */ - private static void writeMojoJavadoc( Writer writer, PluginDescriptor pluginDescriptor, - MojoDescriptor helpDescriptor ) - throws IOException - { - StringBuffer author = new StringBuffer(); - author.append( PluginHelpGenerator.class.getName() ); - - String resource = "META-INF/maven/org.apache.maven.plugin-tools/maven-plugin-tools-api/pom.properties"; - InputStream resourceAsStream = PluginHelpGenerator.class.getClassLoader().getResourceAsStream( resource ); - - if ( resourceAsStream != null ) - { - try - { - Properties properties = new Properties(); - properties.load( resourceAsStream ); - - author.append( " (version " ).append( properties.getProperty( "version", "unknown" ) ).append( ")" ); - } - catch ( IOException e ) - { - // nope - } - finally - { - IOUtil.close( resourceAsStream ); - } - } - - writer.write( "/**" + LS ); - writer.write( " * " + helpDescriptor.getDescription() + LS ); - writer.write( " *" + LS ); - writer.write( " * @version generated on " + new Date() + LS ); - writer.write( " * @author " + author.toString() + LS ); - writer.write( " * @goal " + helpDescriptor.getGoal() + LS ); - writer.write( " * @requiresProject false" + LS ); - writer.write( " * @threadSafe" + LS ); - writer.write( " */" + LS ); - } - - /** - * @param writer not null - * @param helpDescriptor not null - * @throws IOException if any - */ - private static void writeVariables( Writer writer, MojoDescriptor helpDescriptor ) - throws IOException - { - for ( @SuppressWarnings( "unchecked" ) - Iterator it = helpDescriptor.getParameters().iterator(); it.hasNext(); ) - { - Parameter param = it.next(); - writer.write( " /**" + LS ); - writer.write( " * " + StringUtils.escape( param.getDescription() ) + LS ); - writer.write( " * " + LS ); - writer.write( " * @parameter" ); - if ( StringUtils.isNotEmpty( param.getExpression() ) ) - { - writer.write( " expression=\"" ); - writer.write( StringUtils.escape( param.getExpression() ) ); - writer.write( "\"" ); - } - if ( StringUtils.isNotEmpty( param.getDefaultValue() ) ) - { - writer.write( " default-value=\"" ); - writer.write( StringUtils.escape( param.getDefaultValue() ) ); - writer.write( "\"" ); - } - writer.write( LS ); - writer.write( " */" + LS ); - writer.write( " private " + param.getType() + " " + param.getName() + ";" + LS ); - writer.write( LS ); - } - } - - /** - * @param writer not null - * @param pluginDescriptor not null - * @param helpDescriptor not null - * @throws IOException if any - */ - private static void writeExecute( Writer writer, PluginDescriptor pluginDescriptor, MojoDescriptor helpDescriptor ) - throws IOException - { - List mojoDescriptors = new ArrayList(); - - mojoDescriptors.add( helpDescriptor ); - for ( @SuppressWarnings( "unchecked" ) - Iterator it = pluginDescriptor.getMojos().iterator(); it.hasNext(); ) - { - MojoDescriptor mojoDescriptor = it.next(); - - if ( !helpDescriptor.getGoal().equals( mojoDescriptor.getGoal() ) ) - { - mojoDescriptors.add( mojoDescriptor ); - } - } - - PluginUtils.sortMojos( mojoDescriptors ); - - writer.write( " /** {@inheritDoc} */" + LS ); - writer.write( " public void execute()" + LS ); - writer.write( " throws MojoExecutionException" + LS ); - writer.write( " {" + LS ); - - writer.write( " if ( lineLength <= 0 )" + LS ); - writer.write( " {" + LS ); - writer.write( " getLog().warn( \"The parameter 'lineLength' should be positive, using '80' as " - + "default.\" );" + LS ); - writer.write( " lineLength = 80;" + LS ); - writer.write( " }" + LS ); - writer.write( " if ( indentSize <= 0 )" + LS ); - writer.write( " {" + LS ); - writer.write( " getLog().warn( \"The parameter 'indentSize' should be positive, using '2' as " - + "default.\" );" + LS ); - writer.write( " indentSize = 2;" + LS ); - writer.write( " }" + LS ); - writer.write( LS ); - - writer.write( " StringBuffer sb = new StringBuffer();" + LS ); - writer.write( LS ); - - writer.write( " append( sb, \"" + StringUtils.escape( pluginDescriptor.getId() ) + "\", 0 );" + LS ); - writer.write( " append( sb, \"\", 0 );" + LS ); - writer.write( LS ); - - if ( StringUtils.isNotEmpty( pluginDescriptor.getName() ) - && ( pluginDescriptor.getName().indexOf( pluginDescriptor.getId() ) != -1 ) ) - { - writer.write( " append( sb, \"" - + StringUtils.escape( pluginDescriptor.getName() + " " + pluginDescriptor.getVersion() ) - + "\", 0 );" + LS ); - } - else - { - if ( StringUtils.isNotEmpty( pluginDescriptor.getName() ) ) - { - writer.write( " append( sb, \"" + StringUtils.escape( pluginDescriptor.getName() ) - + "\", 0 );" + LS ); - } - else - { - writer.write( " append( sb, \"" + StringUtils.escape( pluginDescriptor.getId() ) - + "\", 0 );" + LS ); - } - } - writer.write( " append( sb, \"" + toDescription( pluginDescriptor.getDescription() ) + "\", 1 );" - + LS ); - writer.write( " append( sb, \"\", 0 );" + LS ); - writer.write( LS ); - - writer.write( " if ( goal == null || goal.length() <= 0 )" + LS ); - writer.write( " {" + LS ); - writer.write( " append( sb, \"This plugin has " + mojoDescriptors.size() + " " - + ( mojoDescriptors.size() > 1 ? "goals" : "goal" ) + ":\", 0 );" + LS ); - writer.write( " append( sb, \"\", 0 );" + LS ); - writer.write( " }" + LS ); - - writer.write( LS ); - - for ( MojoDescriptor descriptor : mojoDescriptors ) - { - writeGoal( writer, descriptor ); - } - - writer.write( " if ( getLog().isInfoEnabled() )" + LS ); - writer.write( " {" + LS ); - writer.write( " getLog().info( sb.toString() );" + LS ); - writer.write( " }" + LS ); - writer.write( " }" + LS ); - } - - /** - * @param writer not null - * @param descriptor not null - * @throws IOException if any - */ - private static void writeGoal( Writer writer, MojoDescriptor descriptor ) - throws IOException - { - String goalDescription = toDescription( descriptor.getDescription() ); - - writer.write( " if ( goal == null || goal.length() <= 0 || \"" - + StringUtils.escape( descriptor.getGoal() ) + "\".equals( goal ) )" + LS ); - writer.write( " {" + LS ); - writer.write( " append( sb, \"" + StringUtils.escape( descriptor.getFullGoalName() ) + "\", 0 );" - + LS ); - if ( StringUtils.isNotEmpty( descriptor.getDeprecated() ) ) - { - writer.write( " append( sb, \"Deprecated. " + toDescription( descriptor.getDeprecated() ) - + "\", 1 );" + LS ); - writer.write( " if ( detail )" + LS ); - writer.write( " {" + LS ); - writer.write( " append( sb, \"\", 0 );" + LS ); - writer.write( " append( sb, \"" + goalDescription + "\", 1 );" + LS ); - writer.write( " }" + LS ); - } - else - { - writer.write( " append( sb, \"" + goalDescription + "\", 1 );" + LS ); - } - writer.write( " append( sb, \"\", 0 );" + LS ); - - if ( descriptor.getParameters() != null && descriptor.getParameters().size() > 0 ) - { - @SuppressWarnings( "unchecked" ) - List params = descriptor.getParameters(); - - PluginUtils.sortMojoParameters( params ); - - writer.write( " if ( detail )" + LS ); - writer.write( " {" + LS ); - - writer.write( " append( sb, \"Available parameters:\", 1 );" + LS ); - writer.write( " append( sb, \"\", 0 );" + LS ); - - for ( Parameter parameter : params ) - { - if ( parameter.isEditable() ) - { - writer.write( LS ); - writeParameter( writer, parameter ); - } - } - - writer.write( " }" + LS ); - } - - writer.write( " }" + LS ); - writer.write( LS ); - } - - /** - * @param writer not null - * @param parameter not null - * @throws IOException if any - */ - private static void writeParameter( Writer writer, Parameter parameter ) - throws IOException - { - String expression = parameter.getExpression(); - - if ( expression == null || !expression.startsWith( "${component." ) ) - { - String parameterName = StringUtils.escape( parameter.getName() ); - String parameterDescription = toDescription( parameter.getDescription() ); - String parameterDefaultValue = ""; - if ( StringUtils.isNotEmpty( parameter.getDefaultValue() ) ) - { - parameterDefaultValue = " (Default: " + StringUtils.escape( parameter.getDefaultValue() ) + ")"; - } - writer.write( " append( sb, \"" + parameterName + parameterDefaultValue + "\", 2 );" + LS ); - if ( StringUtils.isNotEmpty( parameter.getDeprecated() ) ) - { - writer.write( " append( sb, \"Deprecated. " + toDescription( parameter.getDeprecated() ) - + "\", 3 );" + LS ); - writer.write( " append( sb, \"\", 0 );" + LS ); - } - writer.write( " append( sb, \"" + parameterDescription + "\", 3 );" + LS ); - if ( parameter.isRequired() ) - { - writer.write( " append( sb, \"Required: Yes\", 3 );" + LS ); - } - if ( StringUtils.isNotEmpty( parameter.getExpression() ) ) - { - writer.write( " append( sb, \"Expression: " - + StringUtils.escape( parameter.getExpression() ) + "\", 3 );" + LS ); - } - writer.write( " append( sb, \"\", 0 );" + LS ); - } - } - - /** - * @param writer not null - * @param useJava5 If the generated code should use Java5 features - * @throws IOException if any - */ - private static void writeUtilities( Writer writer, boolean useJava5 ) - throws IOException - { - writer.write( " /**" + LS ); - writer.write( " *

Repeat a String n times to form a new string.

" + LS ); - writer.write( " *" + LS ); - writer.write( " * @param str String to repeat" + LS ); - writer.write( " * @param repeat number of times to repeat str" + LS ); - writer.write( " * @return String with repeated String" + LS ); - writer.write( " * @throws NegativeArraySizeException if repeat < 0" + LS ); - writer.write( " * @throws NullPointerException if str is null" + LS ); - writer.write( " */" + LS ); - writer.write( " private static String repeat( String str, int repeat )" + LS ); - writer.write( " {" + LS ); - writer.write( " StringBuffer buffer = new StringBuffer( repeat * str.length() );" + LS ); - writer.write( LS ); - writer.write( " for ( int i = 0; i < repeat; i++ )" + LS ); - writer.write( " {" + LS ); - writer.write( " buffer.append( str );" + LS ); - writer.write( " }" + LS ); - writer.write( LS ); - writer.write( " return buffer.toString();" + LS ); - writer.write( " }" + LS ); - - writer.write( LS ); - writer.write( " /** " + LS ); - writer.write( " * Append a description to the buffer by respecting the indentSize and lineLength " - + "parameters." + LS ); - writer.write( " * Note: The last character is always a new line." + LS ); - writer.write( " * " + LS ); - writer.write( " * @param sb The buffer to append the description, not null." + LS ); - writer.write( " * @param description The description, not null." + LS ); - writer.write( " * @param indent The base indentation level of each line, must not be negative." + LS ); - writer.write( " */" + LS ); - writer.write( " private void append( StringBuffer sb, String description, int indent )" + LS ); - writer.write( " {" + LS ); - writer.write( " for ( Iterator it = toLines( description, indent, indentSize, lineLength )" - + ".iterator(); it.hasNext(); )" + LS ); - writer.write( " {" + LS ); - writer.write( " sb.append( it.next().toString() ).append( '\\n' );" + LS ); - writer.write( " }" + LS ); - writer.write( " }" + LS ); - - writer.write( LS ); - writer.write( " /** " + LS ); - writer.write( " * Splits the specified text into lines of convenient display length." + LS ); - writer.write( " * " + LS ); - writer.write( " * @param text The text to split into lines, must not be null." + LS ); - writer.write( " * @param indent The base indentation level of each line, must not be negative." + LS ); - writer.write( " * @param indentSize The size of each indentation, must not be negative." + LS ); - writer.write( " * @param lineLength The length of the line, must not be negative." + LS ); - writer.write( " * @return The sequence of display lines, never null." + LS ); - writer.write( " * @throws NegativeArraySizeException if indent < 0" + LS ); - writer.write( " */" + LS ); - writer.write( " private static List toLines( String text, int indent, int indentSize, int lineLength )" - + LS ); - writer.write( " {" + LS ); - if ( useJava5 ) - { - writer.write( " List lines = new ArrayList();" + LS ); - } - else - { - writer.write( " List lines = new ArrayList();" + LS ); - } - writer.write( LS ); - writer.write( " String ind = repeat( \"\\t\", indent );" + LS ); - writer.write( " String[] plainLines = text.split( \"(\\r\\n)|(\\r)|(\\n)\" );" + LS ); - writer.write( " for ( int i = 0; i < plainLines.length; i++ )" + LS ); - writer.write( " {" + LS ); - writer.write( " toLines( lines, ind + plainLines[i], indentSize, lineLength );" + LS ); - writer.write( " }" + LS ); - writer.write( LS ); - writer.write( " return lines;" + LS ); - writer.write( " }" + LS ); - - writer.write( LS ); - writer.write( " /** " + LS ); - writer.write( " * Adds the specified line to the output sequence, performing line wrapping if necessary." - + LS ); - writer.write( " * " + LS ); - writer.write( " * @param lines The sequence of display lines, must not be null." + LS ); - writer.write( " * @param line The line to add, must not be null." + LS ); - writer.write( " * @param indentSize The size of each indentation, must not be negative." + LS ); - writer.write( " * @param lineLength The length of the line, must not be negative." + LS ); - writer.write( " */" + LS ); - if ( useJava5 ) - { - writer.write( " private static void toLines( List lines, String line, int indentSize, int lineLength )" - + LS ); - } - else - { - writer.write( " private static void toLines( List lines, String line, int indentSize, int lineLength )" - + LS ); - } - writer.write( " {" + LS ); - writer.write( " int lineIndent = getIndentLevel( line );" + LS ); - writer.write( " StringBuffer buf = new StringBuffer( 256 );" + LS ); - writer.write( " String[] tokens = line.split( \" +\" );" + LS ); - writer.write( " for ( int i = 0; i < tokens.length; i++ )" + LS ); - writer.write( " {" + LS ); - writer.write( " String token = tokens[i];" + LS ); - writer.write( " if ( i > 0 )" + LS ); - writer.write( " {" + LS ); - writer.write( " if ( buf.length() + token.length() >= lineLength )" + LS ); - writer.write( " {" + LS ); - writer.write( " lines.add( buf.toString() );" + LS ); - writer.write( " buf.setLength( 0 );" + LS ); - writer.write( " buf.append( repeat( \" \", lineIndent * indentSize ) );" + LS ); - writer.write( " }" + LS ); - writer.write( " else" + LS ); - writer.write( " {" + LS ); - writer.write( " buf.append( ' ' );" + LS ); - writer.write( " }" + LS ); - writer.write( " }" + LS ); - writer.write( " for ( int j = 0; j < token.length(); j++ )" + LS ); - writer.write( " {" + LS ); - writer.write( " char c = token.charAt( j );" + LS ); - writer.write( " if ( c == '\\t' )" + LS ); - writer.write( " {" + LS ); - writer.write( " buf.append( repeat( \" \", indentSize - buf.length() % indentSize ) );" - + LS ); - writer.write( " }" + LS ); - writer.write( " else if ( c == '\\u00A0' )" + LS ); - writer.write( " {" + LS ); - writer.write( " buf.append( ' ' );" + LS ); - writer.write( " }" + LS ); - writer.write( " else" + LS ); - writer.write( " {" + LS ); - writer.write( " buf.append( c );" + LS ); - writer.write( " }" + LS ); - writer.write( " }" + LS ); - writer.write( " }" + LS ); - writer.write( " lines.add( buf.toString() );" + LS ); - writer.write( " }" + LS ); - - writer.write( LS ); - writer.write( " /** " + LS ); - writer.write( " * Gets the indentation level of the specified line." + LS ); - writer.write( " * " + LS ); - writer.write( " * @param line The line whose indentation level should be retrieved, must not be " - + "null." + LS ); - writer.write( " * @return The indentation level of the line." + LS ); - writer.write( " */" + LS ); - writer.write( " private static int getIndentLevel( String line )" + LS ); - writer.write( " {" + LS ); - writer.write( " int level = 0;" + LS ); - writer.write( " for ( int i = 0; i < line.length() && line.charAt( i ) == '\\t'; i++ )" + LS ); - writer.write( " {" + LS ); - writer.write( " level++;" + LS ); - writer.write( " }" + LS ); - writer.write( " for ( int i = level + 1; i <= level + 4 && i < line.length(); i++ )" + LS ); - writer.write( " {" + LS ); - writer.write( " if ( line.charAt( i ) == '\\t' )" + LS ); - writer.write( " {" + LS ); - writer.write( " level++;" + LS ); - writer.write( " break;" + LS ); - writer.write( " }" + LS ); - writer.write( " }" + LS ); - writer.write( " return level;" + LS ); - writer.write( " }" + LS ); - } - - /** - * Gets the effective string to use for the plugin/mojo/parameter description. - * - * @param description The description of the element, may be null. - * @return The effective description string, never null. - */ - private static String toDescription( String description ) - { - if ( StringUtils.isNotEmpty( description ) ) - { - return StringUtils.escape( PluginUtils.toText( description ) ); - } - - return "(no description available)"; - } - - /** - * Converts a HTML fragment as extracted from a javadoc comment to a plain text string. This method tries to retain - * as much of the text formatting as possible by means of the following transformations: - *
    - *
  • List items are converted to leading tabs (U+0009), followed by the item number/bullet, another tab and - * finally the item contents. Each tab denotes an increase of indentation.
  • - *
  • Flow breaking elements as well as literal line terminators in preformatted text are converted to a newline - * (U+000A) to denote a mandatory line break.
  • - *
  • Consecutive spaces and line terminators from character data outside of preformatted text will be normalized - * to a single space. The resulting space denotes a possible point for line wrapping.
  • - *
  • Each space in preformatted text will be converted to a non-breaking space (U+00A0).
  • - *
- * - * @param html The HTML fragment to convert to plain text, may be null. - * @return A string with HTML tags converted into pure text, never null. - * @deprecated since 2.4.3, using {@link PluginUtils#toText(String)} instead of. - */ - protected static String toText( String html ) - { - return PluginUtils.toText( html ); - } } diff --git a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginXdocGenerator.java b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginXdocGenerator.java index 899d70e..fbd3a1c 100644 --- a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginXdocGenerator.java +++ b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginXdocGenerator.java @@ -19,6 +19,17 @@ package org.apache.maven.tools.plugin.generator; * under the License. */ +import org.apache.maven.plugin.descriptor.MojoDescriptor; +import org.apache.maven.plugin.descriptor.Parameter; +import org.apache.maven.project.MavenProject; +import org.apache.maven.tools.plugin.ExtendedMojoDescriptor; +import org.apache.maven.tools.plugin.PluginToolsRequest; +import org.apache.maven.tools.plugin.util.PluginUtils; +import org.codehaus.plexus.util.IOUtil; +import org.codehaus.plexus.util.StringUtils; +import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter; +import org.codehaus.plexus.util.xml.XMLWriter; + import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -32,30 +43,21 @@ import java.util.List; import java.util.Locale; import java.util.ResourceBundle; -import org.apache.maven.plugin.descriptor.MojoDescriptor; -import org.apache.maven.plugin.descriptor.Parameter; -import org.apache.maven.plugin.descriptor.PluginDescriptor; -import org.apache.maven.project.MavenProject; -import org.apache.maven.tools.plugin.DefaultPluginToolsRequest; -import org.apache.maven.tools.plugin.ExtendedMojoDescriptor; -import org.apache.maven.tools.plugin.PluginToolsRequest; -import org.apache.maven.tools.plugin.util.PluginUtils; -import org.codehaus.plexus.util.IOUtil; -import org.codehaus.plexus.util.StringUtils; -import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter; -import org.codehaus.plexus.util.xml.XMLWriter; - /** - * @todo add example usage tag that can be shown in the doco * @version $Id$ + * @todo add example usage tag that can be shown in the doco */ public class PluginXdocGenerator implements Generator { - /** locale */ + /** + * locale + */ private final Locale locale; - /** project */ + /** + * project + */ private final MavenProject project; /** @@ -81,7 +83,7 @@ public class PluginXdocGenerator /** * @param project not null. - * @param locale not null wanted locale. + * @param locale not null wanted locale. */ public PluginXdocGenerator( MavenProject project, Locale locale ) { @@ -96,31 +98,35 @@ public class PluginXdocGenerator } } - /** {@inheritDoc} */ - public void execute( File destinationDirectory, PluginDescriptor pluginDescriptor ) - throws IOException - { - execute( destinationDirectory, new DefaultPluginToolsRequest( project, pluginDescriptor ) ); - } - /** {@inheritDoc} */ + /** + * {@inheritDoc} + */ public void execute( File destinationDirectory, PluginToolsRequest request ) - throws IOException + throws GeneratorException { - if ( request.getPluginDescriptor().getMojos() != null ) + try { - for ( @SuppressWarnings( "unchecked" ) - Iterator it = request.getPluginDescriptor().getMojos().iterator(); it.hasNext(); ) + if ( request.getPluginDescriptor().getMojos() != null ) { - MojoDescriptor descriptor = it.next(); + for ( @SuppressWarnings( "unchecked" ) Iterator it = + request.getPluginDescriptor().getMojos().iterator(); it.hasNext(); ) + { + MojoDescriptor descriptor = it.next(); - processMojoDescriptor( descriptor, destinationDirectory ); + processMojoDescriptor( descriptor, destinationDirectory ); + } } } + catch ( IOException e ) + { + throw new GeneratorException( e.getMessage(), e ); + } + } /** - * @param mojoDescriptor not null + * @param mojoDescriptor not null * @param destinationDirectory not null * @throws IOException if any */ @@ -147,7 +153,7 @@ public class PluginXdocGenerator /** * @param mojo not null - * @param ext not null + * @param ext not null * @return the output file name */ private String getMojoFilename( MojoDescriptor mojo, String ext ) @@ -157,7 +163,7 @@ public class PluginXdocGenerator /** * @param mojoDescriptor not null - * @param w not null + * @param w not null */ private void writeBody( MojoDescriptor mojoDescriptor, XMLWriter w ) { @@ -196,8 +202,8 @@ public class PluginXdocGenerator w.endElement(); //p w.startElement( "p" ); w.writeMarkup( mojoDescriptor.getPluginDescriptor().getGroupId() + ":" - + mojoDescriptor.getPluginDescriptor().getArtifactId() + ":" - + mojoDescriptor.getPluginDescriptor().getVersion() + ":" + mojoDescriptor.getGoal() ); + + mojoDescriptor.getPluginDescriptor().getArtifactId() + ":" + + mojoDescriptor.getPluginDescriptor().getVersion() + ":" + mojoDescriptor.getGoal() ); w.endElement(); //p if ( StringUtils.isNotEmpty( mojoDescriptor.getDeprecated() ) ) @@ -237,7 +243,7 @@ public class PluginXdocGenerator /** * @param mojoDescriptor not null - * @param w not null + * @param w not null */ private void writeReportNotice( MojoDescriptor mojoDescriptor, XMLWriter w ) { @@ -252,7 +258,7 @@ public class PluginXdocGenerator /** * @param mojoDescriptor not null - * @param w not null + * @param w not null */ private void writeGoalAttributes( MojoDescriptor mojoDescriptor, XMLWriter w ) { @@ -273,12 +279,12 @@ public class PluginXdocGenerator w.writeMarkup( getString( "pluginxdoc.mojodescriptor.projectRequired" ) ); w.endElement(); //li } - + if ( mojoDescriptor.isRequiresReports() ) { if ( !addedUl ) { - w.startElement( "ul" ); + w.startElement( "ul" ); addedUl = true; } w.startElement( "li" ); @@ -451,12 +457,11 @@ public class PluginXdocGenerator /** * @param mojoDescriptor not null - * @param w not null + * @param w not null */ private void writeGoalParameterTable( MojoDescriptor mojoDescriptor, XMLWriter w ) { - @SuppressWarnings( "unchecked" ) - List parameterList = mojoDescriptor.getParameters(); + @SuppressWarnings( "unchecked" ) List parameterList = mojoDescriptor.getParameters(); //remove components and read-only parameters List list = filterParameters( parameterList ); @@ -490,7 +495,7 @@ public class PluginXdocGenerator if ( parameterList != null ) { - for ( Parameter parameter : parameterList ) + for ( Parameter parameter : parameterList ) { if ( parameter.isEditable() ) { @@ -509,8 +514,8 @@ public class PluginXdocGenerator /** * @param mojoDescriptor not null - * @param parameterList not null - * @param w not null + * @param parameterList not null + * @param w not null */ private void writeParameterDetails( MojoDescriptor mojoDescriptor, List parameterList, XMLWriter w ) { @@ -570,8 +575,8 @@ public class PluginXdocGenerator w.startElement( "ul" ); addedUl = true; } - writeDetail( getString( "pluginxdoc.mojodescriptor.parameter.since" ), - mojoDescriptor.getSince(), w ); + writeDetail( getString( "pluginxdoc.mojodescriptor.parameter.since" ), mojoDescriptor.getSince(), + w ); } } @@ -582,8 +587,8 @@ public class PluginXdocGenerator w.startElement( "ul" ); addedUl = true; } - writeDetail( getString( "pluginxdoc.mojodescriptor.parameter.required" ), - getString( "pluginxdoc.yes" ), w ); + writeDetail( getString( "pluginxdoc.mojodescriptor.parameter.required" ), getString( "pluginxdoc.yes" ), + w ); } else { @@ -592,8 +597,8 @@ public class PluginXdocGenerator w.startElement( "ul" ); addedUl = true; } - writeDetail( getString( "pluginxdoc.mojodescriptor.parameter.required" ), - getString( "pluginxdoc.no" ), w ); + writeDetail( getString( "pluginxdoc.mojodescriptor.parameter.required" ), getString( "pluginxdoc.no" ), + w ); } if ( !addedUl && StringUtils.isNotEmpty( parameter.getExpression() ) ) @@ -628,7 +633,7 @@ public class PluginXdocGenerator /** * @param param not null * @param value could be null - * @param w not null + * @param w not null */ private void writeDetail( String param, String value, XMLWriter w ) { @@ -642,8 +647,8 @@ public class PluginXdocGenerator /** * @param mojoDescriptor not null - * @param parameterList not null - * @param w not null + * @param parameterList not null + * @param w not null */ private void writeParameterSummary( MojoDescriptor mojoDescriptor, List parameterList, XMLWriter w ) { @@ -664,11 +669,12 @@ public class PluginXdocGenerator /** * @param mojoDescriptor not null - * @param title not null - * @param parameterList not null - * @param w not null + * @param title not null + * @param parameterList not null + * @param w not null */ - private void writeParameterList( MojoDescriptor mojoDescriptor, String title, List parameterList, XMLWriter w ) + private void writeParameterList( MojoDescriptor mojoDescriptor, String title, List parameterList, + XMLWriter w ) { w.startElement( "subsection" ); w.addAttribute( "name", title ); @@ -722,9 +728,8 @@ public class PluginXdocGenerator String description; if ( StringUtils.isNotEmpty( parameter.getDeprecated() ) ) { - description = - format( "pluginxdoc.mojodescriptor.parameter.deprecated", - PluginUtils.makeHtmlValid( parameter.getDeprecated() ) ); + description = format( "pluginxdoc.mojodescriptor.parameter.deprecated", + PluginUtils.makeHtmlValid( parameter.getDeprecated() ) ); } else if ( StringUtils.isNotEmpty( parameter.getDescription() ) ) { @@ -750,7 +755,7 @@ public class PluginXdocGenerator } /** - * @param required true for required parameters, false otherwise. + * @param required true for required parameters, false otherwise. * @param parameterList not null * @return list of parameters depending the value of required */ @@ -792,21 +797,21 @@ public class PluginXdocGenerator /** * Convenience method. * - * @param key not null + * @param key not null * @param arg1 not null * @return Localized, formatted text identified by key. * @see #format(String, Object[]) */ private String format( String key, Object arg1 ) { - return format( key, new Object[] { arg1 } ); + return format( key, new Object[]{ arg1 } ); } /** * Looks up the value for key in the ResourceBundle, * then formats that value for the specified Locale using args. * - * @param key not null + * @param key not null * @param args not null * @return Localized, formatted text identified by key. */ diff --git a/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/AbstractGeneratorTestCase.java b/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/AbstractGeneratorTestCase.java index e987068..0087e1c 100644 --- a/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/AbstractGeneratorTestCase.java +++ b/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/AbstractGeneratorTestCase.java @@ -19,11 +19,13 @@ package org.apache.maven.tools.plugin.generator; * under the License. */ -import junit.framework.TestCase; +import org.apache.maven.model.Build; import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.Parameter; import org.apache.maven.plugin.descriptor.PluginDescriptor; +import org.apache.maven.project.MavenProject; import org.apache.maven.tools.plugin.DefaultPluginToolsRequest; +import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.component.repository.ComponentDependency; import org.codehaus.plexus.util.FileUtils; @@ -38,7 +40,7 @@ import java.util.List; * jdcasey Exp $ */ public abstract class AbstractGeneratorTestCase - extends TestCase + extends PlexusTestCase { protected Generator generator; @@ -47,6 +49,7 @@ public abstract class AbstractGeneratorTestCase protected void setUp() throws Exception { + super.setUp(); basedir = System.getProperty( "basedir" ); } @@ -93,7 +96,25 @@ public abstract class AbstractGeneratorTestCase FileUtils.deleteDirectory( destinationDirectory ); destinationDirectory.mkdir(); - generator.execute( destinationDirectory, new DefaultPluginToolsRequest( null, pluginDescriptor ) ); + MavenProject mavenProject = new MavenProject(); + mavenProject.setGroupId( "foo" ); + mavenProject.setArtifactId( "bar" ); + mavenProject.setBuild( new Build() + { + @Override + public String getDirectory() + { + return basedir + "/target"; + } + + @Override + public String getOutputDirectory() + { + return basedir + "/target"; + } + } ); + + generator.execute( destinationDirectory, new DefaultPluginToolsRequest( mavenProject, pluginDescriptor ) ); validate( destinationDirectory ); @@ -120,8 +141,8 @@ 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." ); + "! Make sure your test case is named in the form ${generatorClassName}Test " + + "or override the setupPlugin() method to instantiate the mojo yourself." ); } } diff --git a/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/PluginHelpGeneratorTest.java b/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/PluginHelpGeneratorTest.java index 78565f2..725967b 100644 --- a/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/PluginHelpGeneratorTest.java +++ b/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/PluginHelpGeneratorTest.java @@ -19,6 +19,8 @@ package org.apache.maven.tools.plugin.generator; * under the License. */ +import org.codehaus.plexus.velocity.VelocityComponent; + /** * @author Vincent Siveton * @version $Id$ @@ -27,4 +29,12 @@ public class PluginHelpGeneratorTest extends AbstractGeneratorTestCase { // inherits tests from base class + protected void setupGenerator() + throws Exception + { + + generator = + new PluginHelpGenerator().setVelocityComponent( (VelocityComponent) lookup( VelocityComponent.ROLE ) ); + + } } diff --git a/pom.xml b/pom.xml index d603983..1feec30 100644 --- a/pom.xml +++ b/pom.xml @@ -233,6 +233,24 @@ plexus-archiver 2.1.1 + + org.codehaus.plexus + plexus-velocity + 1.1.8 + + + velocity + velocity + + + + + + + org.apache.velocity + velocity + 1.7 + com.thoughtworks.qdox From 0aa8ad9c050803a7285a55bd68f3b41d84996c42 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 11 May 2012 16:45:16 +0000 Subject: [PATCH 39/48] missed to add files git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1337274 13f79535-47bb-0310-9956-ffa450edef68 --- .../plugin/generator/GeneratorException.java | 32 ++ .../src/main/resources/help-class-source.vm | 311 ++++++++++++++++++ 2 files changed, 343 insertions(+) create mode 100644 maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/GeneratorException.java create mode 100644 maven-plugin-tools-api/src/main/resources/help-class-source.vm diff --git a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/GeneratorException.java b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/GeneratorException.java new file mode 100644 index 0000000..10c6473 --- /dev/null +++ b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/GeneratorException.java @@ -0,0 +1,32 @@ +package org.apache.maven.tools.plugin.generator; +/* + * 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. + */ + +/** + * @author Olivier Lamy + * @since 3.0 + */ +public class GeneratorException + extends Exception +{ + public GeneratorException( String s, Throwable throwable ) + { + super( s, throwable ); + } +} diff --git a/maven-plugin-tools-api/src/main/resources/help-class-source.vm b/maven-plugin-tools-api/src/main/resources/help-class-source.vm new file mode 100644 index 0000000..faf7beb --- /dev/null +++ b/maven-plugin-tools-api/src/main/resources/help-class-source.vm @@ -0,0 +1,311 @@ +#if ($helpPackageName.length>0) + package ${helpPackageName}; +#end + +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.codehaus.plexus.util.xml.Xpp3Dom; +import org.codehaus.plexus.util.xml.Xpp3DomBuilder; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; + +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; + +/** + * @author + * @version + */ +@Mojo( name = "help", threadSafe = true, requiresProject = false) +public class HelpMojo + extends AbstractMojo +{ + /** + * If true, display all settable properties for each goal. + * + */ + @Parameter( expression = "${detail}", defaultValue = "false" ) + private boolean detail; + + /** + * The name of the goal for which to show help. If unspecified, all goals will be displayed. + * + */ + @Parameter( expression = "${goal}" ) + private java.lang.String goal; + + /** + * The maximum length of a display line, should be positive. + * + */ + @Parameter( expression = "${lineLength}", defaultValue = "80" ) + private int lineLength; + + /** + * The number of spaces per indentation level, should be positive. + * + */ + @Parameter( expression = "${indentSize}", defaultValue = "2" ) + private int indentSize; + + // groupId/artifactId/version + private String pluginDescriptorPath = "${propertiesFilePath}"; + + private Xpp3Dom build() + throws MojoExecutionException + { + // olamy more than one pluginDescriptor in the classloader possible ? + InputStream is = getClass().getResourceAsStream( pluginDescriptorPath ); + try + { + return Xpp3DomBuilder.build( is, "ISO-8859-1" ); + } + catch ( XmlPullParserException e ) + { + throw new MojoExecutionException( e.getMessage(), e ); + } + catch ( IOException e ) + { + throw new MojoExecutionException( e.getMessage(), e ); + } + } + + /** + * {@inheritDoc} + */ + public void execute() + throws MojoExecutionException + { + if ( lineLength <= 0 ) + { + getLog().warn( "The parameter 'lineLength' should be positive, using '80' as default." ); + lineLength = 80; + } + if ( indentSize <= 0 ) + { + getLog().warn( "The parameter 'indentSize' should be positive, using '2' as default." ); + indentSize = 2; + } + + // FIXME encoding as parameter + Xpp3Dom pluginElement = build(); + + StringBuffer sb = new StringBuffer(); + /** + * org.apache.maven.plugins + * maven-plugin-plugin + * 3.0-SNAPSHOT + */ + //append( sb, "org.apache.maven.plugins:maven-plugin-plugin:3.0-SNAPSHOT", 0 ); + append( sb, + pluginElement.getChild( "groupId" ).getValue() + ":" + pluginElement.getChild( "artifactId" ).getValue() + + ":" + pluginElement.getChild( "version" ).getValue(), 0 ); + append( sb, "", 0 ); + + //append( sb, "Maven Plugin Plugin", 0 ); + append( sb, pluginElement.getChild( "name" ).getValue(), 0 ); + //append( sb, + // "The Plugin Plugin is used to create a Maven plugin descriptor for any Mojo\'s found in the source tree, to include in the JAR. It is also used to generate Xdoc files for the Mojos as well as for updating the plugin registry, the artifact metadata and a generic help goal.", + // 1 ); + append( sb, pluginElement.getChild( "description" ).getValue(), 1 ); + append( sb, "", 0 ); + + //plugin + String goalPrefix = pluginElement.getChild( "goalPrefix" ).getValue(); + + Xpp3Dom[] mojos = pluginElement.getChild( "mojos" ).getChildren( "mojo" ); + + if ( goal == null || goal.length() <= 0 ) + { + + append( sb, "This plugin has " + mojos.length + " goals:", 0 ); + append( sb, "", 0 ); + } + + for ( Xpp3Dom mojo : mojos ) + { + String mojoGoal = mojo.getChild( "goal" ).getValue(); + Xpp3Dom configurationElement = mojo.getChild( "configuration" ); + if ( goal == null || goal.length() <= 0 || mojoGoal.equals( goal ) ) + { + append( sb, goalPrefix + ":" + mojoGoal, 0 ); + append( sb, mojo.getChild( "description" ).getValue(), 1 ); + append( sb, "", 0 ); + if ( detail ) + { + Xpp3Dom[] parameters = mojo.getChild( "parameters" ).getChildren( "parameter" ); + append( sb, "Available parameters:", 1 ); + append( sb, "", 0 ); + + append( sb, "goalPrefix", 2 ); + append( sb, "The prefix for the plugin goal.", 3 ); + append( sb, "", 0 ); + + for ( Xpp3Dom parameter : parameters ) + { + Xpp3Dom name = parameter.getChild( "name" ); + Xpp3Dom fieldConfigurationElement = configurationElement.getChild( name.getValue() ); + if ( fieldConfigurationElement != null && fieldConfigurationElement.getValue() != null ) + { + append( sb, name.getValue() + "(Default: " + configurationElement.getChild( + name.getValue() ).getAttribute( "default-value" ) + ")", 2 ); + } + + append( sb, parameter.getChild( "description" ).getValue(), 3 ); + if ( fieldConfigurationElement != null && fieldConfigurationElement.getValue() != null ) + { + append( sb, fieldConfigurationElement.getValue(), 3 ); + } + append( sb, "", 0 ); + } + } + } + } + + if ( getLog().isInfoEnabled() ) + { + getLog().info( sb.toString() ); + } + } + + /** + *

Repeat a String n times to form a new string.

+ * + * @param str String to repeat + * @param repeat number of times to repeat str + * @return String with repeated String + * @throws NegativeArraySizeException if repeat < 0 + * @throws NullPointerException if str is null + */ + private static String repeat( String str, int repeat ) + { + StringBuffer buffer = new StringBuffer( repeat * str.length() ); + + for ( int i = 0; i < repeat; i++ ) + { + buffer.append( str ); + } + + return buffer.toString(); + } + + /** + * Append a description to the buffer by respecting the indentSize and lineLength parameters. + * Note: The last character is always a new line. + * + * @param sb The buffer to append the description, not null. + * @param description The description, not null. + * @param indent The base indentation level of each line, must not be negative. + */ + private void append( StringBuffer sb, String description, int indent ) + { + for ( Iterator it = toLines( description, indent, indentSize, lineLength ).iterator(); it.hasNext(); ) + { + sb.append( it.next().toString() ).append( '\n' ); + } + } + + /** + * Splits the specified text into lines of convenient display length. + * + * @param text The text to split into lines, must not be null. + * @param indent The base indentation level of each line, must not be negative. + * @param indentSize The size of each indentation, must not be negative. + * @param lineLength The length of the line, must not be negative. + * @return The sequence of display lines, never null. + * @throws NegativeArraySizeException if indent < 0 + */ + private static List toLines( String text, int indent, int indentSize, int lineLength ) + { + List lines = new ArrayList(); + + String ind = repeat( "\t", indent ); + String[] plainLines = text.split( "(\r\n)|(\r)|(\n)" ); + for ( int i = 0; i < plainLines.length; i++ ) + { + toLines( lines, ind + plainLines[i], indentSize, lineLength ); + } + + return lines; + } + + /** + * Adds the specified line to the output sequence, performing line wrapping if necessary. + * + * @param lines The sequence of display lines, must not be null. + * @param line The line to add, must not be null. + * @param indentSize The size of each indentation, must not be negative. + * @param lineLength The length of the line, must not be negative. + */ + private static void toLines( List lines, String line, int indentSize, int lineLength ) + { + int lineIndent = getIndentLevel( line ); + StringBuffer buf = new StringBuffer( 256 ); + String[] tokens = line.split( " +" ); + for ( int i = 0; i < tokens.length; i++ ) + { + String token = tokens[i]; + if ( i > 0 ) + { + if ( buf.length() + token.length() >= lineLength ) + { + lines.add( buf.toString() ); + buf.setLength( 0 ); + buf.append( repeat( " ", lineIndent * indentSize ) ); + } + else + { + buf.append( ' ' ); + } + } + for ( int j = 0; j < token.length(); j++ ) + { + char c = token.charAt( j ); + if ( c == '\t' ) + { + buf.append( repeat( " ", indentSize - buf.length() % indentSize ) ); + } + else if ( c == '\u00A0' ) + { + buf.append( ' ' ); + } + else + { + buf.append( c ); + } + } + } + lines.add( buf.toString() ); + } + + /** + * Gets the indentation level of the specified line. + * + * @param line The line whose indentation level should be retrieved, must not be null. + * @return The indentation level of the line. + */ + private static int getIndentLevel( String line ) + { + int level = 0; + for ( int i = 0; i < line.length() && line.charAt( i ) == '\t'; i++ ) + { + level++; + } + for ( int i = level + 1; i <= level + 4 && i < line.length(); i++ ) + { + if ( line.charAt( i ) == '\t' ) + { + level++; + break; + } + } + return level; + } + + +} From 2eef7a412b6a829bfaaa11400c21535b05ce1ce0 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 11 May 2012 16:45:45 +0000 Subject: [PATCH 40/48] don't test help generation in all it, use doclet for help generation to not force users to add annotations artifact as a dependency git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1337275 13f79535-47bb-0310-9956-ffa450edef68 --- .../invoker.properties | 6 +- .../pom.xml | 8 +- .../invoker.properties | 3 - .../src/it/help-basic/invoker.properties | 2 +- maven-plugin-plugin/src/it/help-basic/pom.xml | 2 +- .../src/it/help-package/pom.xml | 2 +- .../ignore-plugin-class-realm/dep-a/pom.xml | 2 +- .../ignore-plugin-class-realm/dep-b/pom.xml | 4 +- .../src/it/ignore-plugin-class-realm/pom.xml | 2 +- .../it/ignore-plugin-class-realm/test/pom.xml | 6 +- .../java-basic-annotations/invoker.properties | 6 +- .../src/it/java-basic-annotations/pom.xml | 9 +- .../src/it/java-basic/invoker.properties | 4 +- maven-plugin-plugin/src/it/java-basic/pom.xml | 2 +- .../plugin-info-jdk-default-version/pom.xml | 87 ++++++++++--------- .../src/it/plugin-report/pom.xml | 2 +- maven-plugin-plugin/src/it/skip/pom.xml | 2 +- .../src/it/source-encoding/latin-1/pom.xml | 6 +- .../src/it/source-encoding/pom.xml | 2 +- .../src/it/source-encoding/utf-8/pom.xml | 6 +- .../src/main/resources/help-class-source.vm | 51 ++++++++--- 21 files changed, 123 insertions(+), 91 deletions(-) diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/invoker.properties b/maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/invoker.properties index 98d7b19..e3434ff 100644 --- a/maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/invoker.properties +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/invoker.properties @@ -1,5 +1,3 @@ invoker.goals.1 = install -invoker.goals.2 = org.apache.maven.its.annotation-with-inheritance-from-deps:annotation-with-inheritance-from-deps:1.0:first -#FIXME disabled need to find a solution for the chicken and eggs issue. -#help sources are generated @generated-sources but need descriptor which need compile phase first for classes scanning -#invoker.goals.3 = org.apache.maven.its.basic-java-annotations:maven-it-basic-java-annotations:1.0::help +invoker.goals.2 = org.apache.maven.its.annotation-with-inheritance-from-deps:annotation-with-inheritance-from-deps:1.0-SNAPSHOT:first +invoker.goals.3 = org.apache.maven.its.annotation-with-inheritance-from-deps:annotation-with-inheritance-from-deps:1.0-SNAPSHOT:help diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/pom.xml b/maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/pom.xml index ea74e0a..370c4c6 100644 --- a/maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/pom.xml +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/pom.xml @@ -24,7 +24,7 @@ under the License. org.apache.maven.its.annotation-with-inheritance-from-deps annotation-with-inheritance-from-deps - 1.0 + 1.0-SNAPSHOT maven-plugin Maven Integration Test :: annotation-with-inheritance-from-deps @@ -103,6 +103,12 @@ under the License. descriptor + + help-goal + + helpmojo + + diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/invoker.properties b/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/invoker.properties index ebc1644..c3906a8 100644 --- a/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/invoker.properties +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/invoker.properties @@ -1,6 +1,3 @@ invoker.goals.1 = clean install -DskipTests invoker.goals.2 = org.apache.maven.its.annotation-with-inheritance-reactor:module-mojo:1.0-SNAPSHOT:it0014 invoker.goals.3 = org.apache.maven.its.annotation-with-inheritance-reactor:module-mojo:1.0-SNAPSHOT:first -#FIXME disabled need to find a solution for the chicken and eggs issue. -#help sources are generated @generated-sources but need descriptor which need compile phase first for classes scanning -#invoker.goals.3 = org.apache.maven.its.basic-java-annotations:maven-it-basic-java-annotations:1.0::help diff --git a/maven-plugin-plugin/src/it/help-basic/invoker.properties b/maven-plugin-plugin/src/it/help-basic/invoker.properties index 1828fac..e384308 100644 --- a/maven-plugin-plugin/src/it/help-basic/invoker.properties +++ b/maven-plugin-plugin/src/it/help-basic/invoker.properties @@ -1,2 +1,2 @@ invoker.goals.1 = clean install -DskipTests -invoker.goals.2 = org.apache.maven.its.plugin:help:1.0:help +invoker.goals.2 = org.apache.maven.its.plugin:help:1.0-SNAPSHOT:help diff --git a/maven-plugin-plugin/src/it/help-basic/pom.xml b/maven-plugin-plugin/src/it/help-basic/pom.xml index f51bdac..df81e40 100644 --- a/maven-plugin-plugin/src/it/help-basic/pom.xml +++ b/maven-plugin-plugin/src/it/help-basic/pom.xml @@ -24,7 +24,7 @@ under the License. org.apache.maven.its.plugin help - 1.0 + 1.0-SNAPSHOT maven-plugin diff --git a/maven-plugin-plugin/src/it/help-package/pom.xml b/maven-plugin-plugin/src/it/help-package/pom.xml index d34a0e7..842afc1 100644 --- a/maven-plugin-plugin/src/it/help-package/pom.xml +++ b/maven-plugin-plugin/src/it/help-package/pom.xml @@ -24,7 +24,7 @@ under the License. org.apache.maven.its.plugin help - 1.0 + 1.0-SNAPSHOT maven-plugin diff --git a/maven-plugin-plugin/src/it/ignore-plugin-class-realm/dep-a/pom.xml b/maven-plugin-plugin/src/it/ignore-plugin-class-realm/dep-a/pom.xml index 8c772fe..4531045 100644 --- a/maven-plugin-plugin/src/it/ignore-plugin-class-realm/dep-a/pom.xml +++ b/maven-plugin-plugin/src/it/ignore-plugin-class-realm/dep-a/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven.its.plugin ipcr - 1.0 + 1.0-SNAPSHOT ipcr-dep-a diff --git a/maven-plugin-plugin/src/it/ignore-plugin-class-realm/dep-b/pom.xml b/maven-plugin-plugin/src/it/ignore-plugin-class-realm/dep-b/pom.xml index 254d8d6..8999cc2 100644 --- a/maven-plugin-plugin/src/it/ignore-plugin-class-realm/dep-b/pom.xml +++ b/maven-plugin-plugin/src/it/ignore-plugin-class-realm/dep-b/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven.its.plugin ipcr - 1.0 + 1.0-SNAPSHOT ipcr-dep-b @@ -42,7 +42,7 @@ under the License. org.apache.maven.its.plugin ipcr-dep-a - 1.0 + ${project.version} diff --git a/maven-plugin-plugin/src/it/ignore-plugin-class-realm/pom.xml b/maven-plugin-plugin/src/it/ignore-plugin-class-realm/pom.xml index 1d9752d..7b98666 100644 --- a/maven-plugin-plugin/src/it/ignore-plugin-class-realm/pom.xml +++ b/maven-plugin-plugin/src/it/ignore-plugin-class-realm/pom.xml @@ -24,7 +24,7 @@ under the License. org.apache.maven.its.plugin ipcr - 1.0 + 1.0-SNAPSHOT pom Aggregator diff --git a/maven-plugin-plugin/src/it/ignore-plugin-class-realm/test/pom.xml b/maven-plugin-plugin/src/it/ignore-plugin-class-realm/test/pom.xml index df1dd9e..c616620 100644 --- a/maven-plugin-plugin/src/it/ignore-plugin-class-realm/test/pom.xml +++ b/maven-plugin-plugin/src/it/ignore-plugin-class-realm/test/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven.its.plugin ipcr - 1.0 + 1.0-SNAPSHOT ipcr-plugin @@ -45,7 +45,7 @@ under the License. org.apache.maven.its.plugin ipcr-dep-b - 1.0 + ${project.version} @@ -58,7 +58,7 @@ under the License. org.apache.maven.its.plugin ipcr-dep-b - 1.0 + 1.0-SNAPSHOT org.apache.maven.its.plugin diff --git a/maven-plugin-plugin/src/it/java-basic-annotations/invoker.properties b/maven-plugin-plugin/src/it/java-basic-annotations/invoker.properties index a559219..96b1dca 100644 --- a/maven-plugin-plugin/src/it/java-basic-annotations/invoker.properties +++ b/maven-plugin-plugin/src/it/java-basic-annotations/invoker.properties @@ -1,5 +1,3 @@ invoker.goals.1 = clean install -DskipTests -invoker.goals.2 = org.apache.maven.its.basic-java-annotations:maven-it-basic-java-annotations:1.0:it0014 -#FIXME disabled need to find a solution for the chicken and eggs issue. -#help sources are generated @generated-sources but need descriptor which need compile phase first for classes scanning -#invoker.goals.3 = org.apache.maven.its.basic-java-annotations:maven-it-basic-java-annotations:1.0::help +invoker.goals.2 = org.apache.maven.its.basic-java-annotations:maven-it-basic-java-annotations:1.0-SNAPSHOT:it0014 +invoker.goals.3 = org.apache.maven.its.basic-java-annotations:maven-it-basic-java-annotations:1.0-SNAPSHOT:help \ No newline at end of file diff --git a/maven-plugin-plugin/src/it/java-basic-annotations/pom.xml b/maven-plugin-plugin/src/it/java-basic-annotations/pom.xml index 8716b8b..3eb1e16 100644 --- a/maven-plugin-plugin/src/it/java-basic-annotations/pom.xml +++ b/maven-plugin-plugin/src/it/java-basic-annotations/pom.xml @@ -24,7 +24,7 @@ under the License. org.apache.maven.its.basic-java-annotations maven-it-basic-java-annotations - 1.0 + 1.0-SNAPSHOT maven-plugin Maven Integration Test :: basic-java-annotations @@ -44,6 +44,12 @@ under the License. maven-plugin-api 2.0 + + org.codehaus.plexus + plexus-utils + 3.0.1 + provided + org.apache.maven.plugin-tools maven-plugin-annotations @@ -70,7 +76,6 @@ under the License. help-goal - process-classes helpmojo diff --git a/maven-plugin-plugin/src/it/java-basic/invoker.properties b/maven-plugin-plugin/src/it/java-basic/invoker.properties index 1a33a20..f382771 100644 --- a/maven-plugin-plugin/src/it/java-basic/invoker.properties +++ b/maven-plugin-plugin/src/it/java-basic/invoker.properties @@ -1,3 +1,3 @@ -invoker.goals.1 = install -DskipTests -invoker.goals.2 = org.apache.maven.its.it0013:maven-it-it0013:1.0:it0013 +invoker.goals.1 = clean install -DskipTests +invoker.goals.2 = org.apache.maven.its.it0013:maven-it-it0013:1.0-SNAPSHOT:it0013 diff --git a/maven-plugin-plugin/src/it/java-basic/pom.xml b/maven-plugin-plugin/src/it/java-basic/pom.xml index 651823b..d96ea92 100644 --- a/maven-plugin-plugin/src/it/java-basic/pom.xml +++ b/maven-plugin-plugin/src/it/java-basic/pom.xml @@ -24,7 +24,7 @@ under the License. org.apache.maven.its.it0013 maven-it-it0013 - 1.0 + 1.0-SNAPSHOT maven-plugin Maven Integration Test :: it0013 diff --git a/maven-plugin-plugin/src/it/plugin-info-jdk-default-version/pom.xml b/maven-plugin-plugin/src/it/plugin-info-jdk-default-version/pom.xml index 18b0a36..42872ac 100644 --- a/maven-plugin-plugin/src/it/plugin-info-jdk-default-version/pom.xml +++ b/maven-plugin-plugin/src/it/plugin-info-jdk-default-version/pom.xml @@ -1,47 +1,48 @@ - - 4.0.0 - org.apache.maven.its - jdk-default-version - 1.0-SNAPSHOT - maven-plugin - - UTF-8 - - - - org.apache.maven - maven-plugin-api - 2.0 - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 2.3.2 - - - - org.apache.maven.plugins - maven-plugin-plugin - @project.version@ - - - org.apache.maven.plugins - maven-site-plugin - @sitePluginVersion@ - - - - + + 4.0.0 + org.apache.maven.its + jdk-default-version + 1.0-SNAPSHOT + maven-plugin + + UTF-8 + + + + org.apache.maven + maven-plugin-api + 2.0 + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + + + org.apache.maven.plugins + maven-plugin-plugin + @project.version@ + + + org.apache.maven.plugins + maven-site-plugin + @sitePluginVersion@ + + + + diff --git a/maven-plugin-plugin/src/it/plugin-report/pom.xml b/maven-plugin-plugin/src/it/plugin-report/pom.xml index f8f2f29..39d180f 100644 --- a/maven-plugin-plugin/src/it/plugin-report/pom.xml +++ b/maven-plugin-plugin/src/it/plugin-report/pom.xml @@ -30,7 +30,7 @@ under the License. org.apache.maven.its plugin-report - 1.0 + 1.0-SNAPSHOT maven-plugin MPLUGIN-105 diff --git a/maven-plugin-plugin/src/it/skip/pom.xml b/maven-plugin-plugin/src/it/skip/pom.xml index a54c994..40a0893 100644 --- a/maven-plugin-plugin/src/it/skip/pom.xml +++ b/maven-plugin-plugin/src/it/skip/pom.xml @@ -24,7 +24,7 @@ under the License. org.apache.maven.its.it0013 mplugin-174 - 1.0 + 1.0-SNAPSHOT maven-plugin MPLUGIN-174 diff --git a/maven-plugin-plugin/src/it/source-encoding/latin-1/pom.xml b/maven-plugin-plugin/src/it/source-encoding/latin-1/pom.xml index b9e8530..e21d6ca 100644 --- a/maven-plugin-plugin/src/it/source-encoding/latin-1/pom.xml +++ b/maven-plugin-plugin/src/it/source-encoding/latin-1/pom.xml @@ -24,7 +24,7 @@ under the License. org.apache.maven.its.plugin latin-1 - 1.0 + 1.0-SNAPSHOT maven-plugin Latin-1 @@ -49,12 +49,12 @@ under the License. org.apache.maven.plugins maven-compiler-plugin - 2.0.2 + 2.4 org.apache.maven.plugins maven-resources-plugin - 2.2 + 2.5 org.apache.maven.plugins diff --git a/maven-plugin-plugin/src/it/source-encoding/pom.xml b/maven-plugin-plugin/src/it/source-encoding/pom.xml index 4b58ca5..57cff57 100644 --- a/maven-plugin-plugin/src/it/source-encoding/pom.xml +++ b/maven-plugin-plugin/src/it/source-encoding/pom.xml @@ -24,7 +24,7 @@ under the License. org.apache.maven.its.plugin aggregator - 1.0 + 1.0-SNAPSHOT pom Aggregator diff --git a/maven-plugin-plugin/src/it/source-encoding/utf-8/pom.xml b/maven-plugin-plugin/src/it/source-encoding/utf-8/pom.xml index 4e29ebc..a8ddf7f 100644 --- a/maven-plugin-plugin/src/it/source-encoding/utf-8/pom.xml +++ b/maven-plugin-plugin/src/it/source-encoding/utf-8/pom.xml @@ -24,7 +24,7 @@ under the License. org.apache.maven.its.plugin utf-8 - 1.0 + 1.0-SNAPSHOT maven-plugin UTF-8 @@ -49,12 +49,12 @@ under the License. org.apache.maven.plugins maven-compiler-plugin - 2.0.2 + 2.4 org.apache.maven.plugins maven-resources-plugin - 2.2 + 2.5 org.apache.maven.plugins diff --git a/maven-plugin-tools-api/src/main/resources/help-class-source.vm b/maven-plugin-tools-api/src/main/resources/help-class-source.vm index faf7beb..f4e356a 100644 --- a/maven-plugin-tools-api/src/main/resources/help-class-source.vm +++ b/maven-plugin-tools-api/src/main/resources/help-class-source.vm @@ -14,14 +14,13 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; - /** * @author * @version + * @goal help + * @requiresProject false + * @threadSafe */ -@Mojo( name = "help", threadSafe = true, requiresProject = false) public class HelpMojo extends AbstractMojo { @@ -29,29 +28,57 @@ public class HelpMojo * If true, display all settable properties for each goal. * */ - @Parameter( expression = "${detail}", defaultValue = "false" ) - private boolean detail; + //@Parameter( expression = "${detail}", defaultValue = "false" ) + //private boolean detail; /** * The name of the goal for which to show help. If unspecified, all goals will be displayed. * */ - @Parameter( expression = "${goal}" ) - private java.lang.String goal; + //@Parameter( expression = "${goal}" ) + //private java.lang.String goal; /** * The maximum length of a display line, should be positive. * */ - @Parameter( expression = "${lineLength}", defaultValue = "80" ) - private int lineLength; + //@Parameter( expression = "${lineLength}", defaultValue = "80" ) + //private int lineLength; /** * The number of spaces per indentation level, should be positive. * */ - @Parameter( expression = "${indentSize}", defaultValue = "2" ) - private int indentSize; + //@Parameter( expression = "${indentSize}", defaultValue = "2" ) + //private int indentSize; + +/** + * If true, display all settable properties for each goal. + * + * @parameter expression="${detail}" default-value="false" + */ +private boolean detail; + +/** + * The name of the goal for which to show help. If unspecified, all goals will be displayed. + * + * @parameter expression="${goal}" + */ +private java.lang.String goal; + +/** + * The maximum length of a display line, should be positive. + * + * @parameter expression="${lineLength}" default-value="80" + */ +private int lineLength; + +/** + * The number of spaces per indentation level, should be positive. + * + * @parameter expression="${indentSize}" default-value="2" + */ +private int indentSize; // groupId/artifactId/version private String pluginDescriptorPath = "${propertiesFilePath}"; From 73885abdbc5a454c0ed6c8f23c453a59e0510e14 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 11 May 2012 16:46:01 +0000 Subject: [PATCH 41/48] prevent write files in scm tree during tests git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1337277 13f79535-47bb-0310-9956-ffa450edef68 --- maven-plugin-tools-java/pom.xml | 14 ++++++++++++++ .../java/JavaMojoDescriptorExtractorTest.java | 8 ++++++++ 2 files changed, 22 insertions(+) diff --git a/maven-plugin-tools-java/pom.xml b/maven-plugin-tools-java/pom.xml index 4eb2d67..e662e87 100644 --- a/maven-plugin-tools-java/pom.xml +++ b/maven-plugin-tools-java/pom.xml @@ -76,4 +76,18 @@ + + + + org.apache.maven.plugins + maven-surefire-plugin + + + ${project.build.directory} + + + + + + diff --git a/maven-plugin-tools-java/src/test/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractorTest.java b/maven-plugin-tools-java/src/test/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractorTest.java index c6e18b5..77b2359 100644 --- a/maven-plugin-tools-java/src/test/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractorTest.java +++ b/maven-plugin-tools-java/src/test/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractorTest.java @@ -20,6 +20,7 @@ package org.apache.maven.tools.plugin.extractor.java; */ import junit.framework.TestCase; +import org.apache.maven.model.Build; import org.apache.maven.model.Model; import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.Parameter; @@ -77,6 +78,13 @@ public class JavaMojoDescriptorExtractorTest model.setArtifactId( "maven-unitTesting-plugin" ); MavenProject project = new MavenProject( model ); + project.setBuild( new Build(){ + @Override + public String getOutputDirectory() + { + return System.getProperty( "filePath" ); + } + }); project.setFile( new File( root, "pom.xml" ) ); project.addCompileSourceRoot( new File( root, directory ).getPath() ); From 643c8de61cd5ff6426485be6b3fbd5d1e9b688c7 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 11 May 2012 16:46:13 +0000 Subject: [PATCH 42/48] fix package name parameter for help generation git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1337278 13f79535-47bb-0310-9956-ffa450edef68 --- maven-plugin-plugin/src/it/help-package/pom.xml | 2 +- .../src/main/resources/help-class-source.vm | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/maven-plugin-plugin/src/it/help-package/pom.xml b/maven-plugin-plugin/src/it/help-package/pom.xml index 842afc1..20b74fd 100644 --- a/maven-plugin-plugin/src/it/help-package/pom.xml +++ b/maven-plugin-plugin/src/it/help-package/pom.xml @@ -23,7 +23,7 @@ under the License. 4.0.0 org.apache.maven.its.plugin - help + help-package 1.0-SNAPSHOT maven-plugin diff --git a/maven-plugin-tools-api/src/main/resources/help-class-source.vm b/maven-plugin-tools-api/src/main/resources/help-class-source.vm index f4e356a..0df0df7 100644 --- a/maven-plugin-tools-api/src/main/resources/help-class-source.vm +++ b/maven-plugin-tools-api/src/main/resources/help-class-source.vm @@ -1,5 +1,5 @@ -#if ($helpPackageName.length>0) - package ${helpPackageName}; +#if ($helpPackageName.length()>0) +package ${helpPackageName}; #end import org.apache.maven.plugin.AbstractMojo; From 2f6eee2513d43ccbf334d69c3b48bc341f96dddb Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 11 May 2012 16:46:34 +0000 Subject: [PATCH 43/48] [MPLUGIN-189] if helpPackageName is not configured change the package of the generic class name to have a similar package as before annotations git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1337279 13f79535-47bb-0310-9956-ffa450edef68 --- .../verify.groovy | 6 + .../annotation-with-inheritance/verify.groovy | 6 + maven-plugin-tools-annotations/pom.xml | 2 - maven-plugin-tools-api/pom.xml | 9 ++ .../generator/PluginDescriptorGenerator.java | 121 ++++++++++++++++-- .../plugin/generator/PluginHelpGenerator.java | 6 +- .../src/main/resources/help-class-source.vm | 3 +- pom.xml | 11 ++ 8 files changed, 149 insertions(+), 15 deletions(-) diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/verify.groovy b/maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/verify.groovy index 9e047fa..213081a 100644 --- a/maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/verify.groovy +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/verify.groovy @@ -2,6 +2,12 @@ File descriptorFile = new File( basedir, "target/classes/META-INF/maven/plugin.xml" ); assert descriptorFile.isFile() +File oldHelpClass = new File( basedir, "target/classes/HelpMojo.class" ); +assert !oldHelpClass.exists() + +File newHelpClass = new File( basedir, "target/classes/org/apache/maven/plugin/coreit/HelpMojo.class" ); +assert newHelpClass.exists() + def pluginDescriptor = new XmlParser().parse( descriptorFile ); def mojo = pluginDescriptor.mojos.mojo.findAll{ it.goal.text() == "first"}[0] diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance/verify.groovy b/maven-plugin-plugin/src/it/annotation-with-inheritance/verify.groovy index 56fb57b..2052a1f 100644 --- a/maven-plugin-plugin/src/it/annotation-with-inheritance/verify.groovy +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance/verify.groovy @@ -4,6 +4,12 @@ assert touchFile.isFile() File descriptorFile = new File( basedir, "target/classes/META-INF/maven/plugin.xml" ); assert descriptorFile.isFile() +File oldHelpClass = new File( basedir, "target/classes/HelpMojo.class" ); +assert !oldHelpClass.exists() + +File newHelpClass = new File( basedir, "target/classes/org/apache/maven/plugin/coreit/HelpMojo.class" ); +assert newHelpClass.exists() + def pluginDescriptor = new XmlParser().parse( descriptorFile ); def mojo = pluginDescriptor.mojos.mojo.findAll{ it.goal.text() == "first"}[0] diff --git a/maven-plugin-tools-annotations/pom.xml b/maven-plugin-tools-annotations/pom.xml index c2fdcf8..bef9e8a 100644 --- a/maven-plugin-tools-annotations/pom.xml +++ b/maven-plugin-tools-annotations/pom.xml @@ -64,12 +64,10 @@ asm asm - 3.3.1 asm asm-commons - 3.3.1 diff --git a/maven-plugin-tools-api/pom.xml b/maven-plugin-tools-api/pom.xml index 28803f5..6de6aa0 100644 --- a/maven-plugin-tools-api/pom.xml +++ b/maven-plugin-tools-api/pom.xml @@ -88,6 +88,15 @@ velocity + + asm + asm + + + asm + asm-commons + + net.sf.jtidy diff --git a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java index 136db43..76e48f8 100644 --- a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java +++ b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java @@ -32,6 +32,11 @@ import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter; import org.codehaus.plexus.util.xml.XMLWriter; +import org.objectweb.asm.ClassReader; +import org.objectweb.asm.ClassVisitor; +import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.commons.RemappingClassAdapter; +import org.objectweb.asm.commons.SimpleRemapper; import java.io.File; import java.io.FileInputStream; @@ -64,6 +69,35 @@ public class PluginDescriptorGenerator public void execute( File destinationDirectory, PluginToolsRequest request ) throws GeneratorException { + + File tmpPropertiesFile = + new File( request.getProject().getBuild().getDirectory(), "maven-plugin-help.properties" ); + + if ( tmpPropertiesFile.exists() ) + { + Properties properties = new Properties(); + try + { + properties.load( new FileInputStream( tmpPropertiesFile ) ); + } + catch ( IOException e ) + { + throw new GeneratorException( e.getMessage(), e ); + } + String helpPackageName = properties.getProperty( "helpPackageName" ); + // if helpPackageName property is empty we have to rewrite the class with a better package name than empty + if ( StringUtils.isEmpty( helpPackageName ) ) + { + String helpMojoImplementation = rewriteHelpClassToMojoPackage( request ); + if ( helpMojoImplementation != null ) + { + // rewrite plugin descriptor with new HelpMojo implementation class + rewriteDescriptor( request.getPluginDescriptor(), helpMojoImplementation ); + } + + } + } + try { File f = new File( destinationDirectory, "plugin.xml" ); @@ -90,17 +124,6 @@ public class PluginDescriptorGenerator { PluginDescriptor pluginDescriptor = request.getPluginDescriptor(); - File tmpPropertiesFile = - new File( request.getProject().getBuild().getDirectory(), "maven-plugin-help.properties" ); - - if ( tmpPropertiesFile.exists() ) - { - Properties properties = new Properties(); - properties.load( new FileInputStream( tmpPropertiesFile ) ); - //MojoDescriptor mojoDescriptor = - // makeHelpDescriptor( pluginDescriptor, properties.getProperty( "helpPackageName" ) ); - //pluginDescriptor.addMojo( mojoDescriptor ); - } if ( destinationFile.exists() ) { destinationFile.delete(); @@ -664,4 +687,80 @@ public class PluginDescriptorGenerator w.endElement(); } + + protected String rewriteHelpClassToMojoPackage( PluginToolsRequest request ) + throws GeneratorException + { + String destinationPackage = PluginHelpGenerator.discoverPackageName( request.getPluginDescriptor() ); + if ( StringUtils.isEmpty( destinationPackage ) ) + { + return null; + } + File helpClassFile = new File( request.getProject().getBuild().getOutputDirectory(), "HelpMojo.class" ); + if ( !helpClassFile.exists() ) + { + return null; + } + File rewriteHelpClassFile = new File( + request.getProject().getBuild().getOutputDirectory() + "/" + StringUtils.replace( destinationPackage, ".", + "/" ), "HelpMojo.class" ); + if ( !rewriteHelpClassFile.getParentFile().exists() ) + { + rewriteHelpClassFile.getParentFile().mkdirs(); + } + + ClassReader cr = null; + try + { + cr = new ClassReader( new FileInputStream( helpClassFile ) ); + } + catch ( IOException e ) + { + throw new GeneratorException( e.getMessage(), e ); + } + + ClassWriter cw = new ClassWriter( 0 ); + + ClassVisitor cv = new RemappingClassAdapter( cw, new SimpleRemapper( "HelpMojo", + StringUtils.replace( destinationPackage, + ".", "/" ) + + "/HelpMojo" ) ); + + try + { + cr.accept( cv, ClassReader.EXPAND_FRAMES ); + } + catch ( Throwable e ) + { + throw new GeneratorException( "ASM issue processing classFile " + helpClassFile.getPath(), e ); + } + + byte[] renamedClass = cw.toByteArray(); + FileOutputStream fos = null; + try + { + fos = new FileOutputStream( rewriteHelpClassFile ); + fos.write( renamedClass ); + } + catch ( IOException e ) + { + throw new GeneratorException( "Error rewriting help class: " + e.getMessage(), e ); + } + finally + { + IOUtil.close( fos ); + } + helpClassFile.delete(); + return destinationPackage + ".HelpMojo"; + } + + + private void rewriteDescriptor( PluginDescriptor pluginDescriptor, String helpMojoImplementation ) + { + MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo( "help" ); + if ( mojoDescriptor != null ) + { + mojoDescriptor.setImplementation( helpMojoImplementation ); + } + } } diff --git a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginHelpGenerator.java b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginHelpGenerator.java index 13d37a0..6f54f51 100644 --- a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginHelpGenerator.java +++ b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginHelpGenerator.java @@ -313,7 +313,7 @@ public class PluginHelpGenerator * @param pluginDescriptor not null * @return the best name of the package for the generated mojo */ - private static String discoverPackageName( PluginDescriptor pluginDescriptor ) + protected static String discoverPackageName( PluginDescriptor pluginDescriptor ) { Map packageNames = new HashMap(); for ( Iterator it = pluginDescriptor.getMojos().iterator(); it.hasNext(); ) @@ -321,6 +321,10 @@ public class PluginHelpGenerator MojoDescriptor descriptor = (MojoDescriptor) it.next(); String impl = descriptor.getImplementation(); + if ( StringUtils.equals( descriptor.getGoal(), "help" ) && StringUtils.equals( "HelpMojo", impl ) ) + { + continue; + } if ( impl.lastIndexOf( '.' ) != -1 ) { String name = impl.substring( 0, impl.lastIndexOf( '.' ) ); diff --git a/maven-plugin-tools-api/src/main/resources/help-class-source.vm b/maven-plugin-tools-api/src/main/resources/help-class-source.vm index 0df0df7..6db6464 100644 --- a/maven-plugin-tools-api/src/main/resources/help-class-source.vm +++ b/maven-plugin-tools-api/src/main/resources/help-class-source.vm @@ -81,12 +81,13 @@ private int lineLength; private int indentSize; // groupId/artifactId/version - private String pluginDescriptorPath = "${propertiesFilePath}"; + private String pluginDescriptorPath = "/${propertiesFilePath}"; private Xpp3Dom build() throws MojoExecutionException { // olamy more than one pluginDescriptor in the classloader possible ? + getLog().debug("load pluginDescriptorPath: " + pluginDescriptorPath); InputStream is = getClass().getResourceAsStream( pluginDescriptorPath ); try { diff --git a/pom.xml b/pom.xml index 1feec30..f562ff9 100644 --- a/pom.xml +++ b/pom.xml @@ -258,6 +258,17 @@ 1.11 + + asm + asm + 3.3.1 + + + asm + asm-commons + 3.3.1 + + org.apache.maven.plugin-testing maven-plugin-testing-harness From 34ebb1721b7d384464222b5fe172070edb75e31c Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 11 May 2012 16:46:48 +0000 Subject: [PATCH 44/48] use generics git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1337280 13f79535-47bb-0310-9956-ffa450edef68 --- .../maven/tools/plugin/generator/PluginHelpGenerator.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginHelpGenerator.java b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginHelpGenerator.java index 6f54f51..9a1d1a2 100644 --- a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginHelpGenerator.java +++ b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginHelpGenerator.java @@ -315,7 +315,7 @@ public class PluginHelpGenerator */ protected static String discoverPackageName( PluginDescriptor pluginDescriptor ) { - Map packageNames = new HashMap(); + Map packageNames = new HashMap(); for ( Iterator it = pluginDescriptor.getMojos().iterator(); it.hasNext(); ) { MojoDescriptor descriptor = (MojoDescriptor) it.next(); @@ -330,7 +330,7 @@ public class PluginHelpGenerator String name = impl.substring( 0, impl.lastIndexOf( '.' ) ); if ( packageNames.get( name ) != null ) { - int next = ( (Integer) packageNames.get( name ) ).intValue() + 1; + int next = ( packageNames.get( name ) ).intValue() + 1; packageNames.put( name, new Integer( next ) ); } else @@ -349,7 +349,7 @@ public class PluginHelpGenerator for ( Iterator it = packageNames.keySet().iterator(); it.hasNext(); ) { String key = it.next().toString(); - int value = ( (Integer) packageNames.get( key ) ).intValue(); + int value = ( packageNames.get( key ) ).intValue(); if ( value > max ) { max = value; From 69afeb1a56c183ac9514528e8b3bc8e78e53a537 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 11 May 2012 20:02:08 +0000 Subject: [PATCH 45/48] fix mvn 2 compatibility git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1337351 13f79535-47bb-0310-9956-ffa450edef68 --- .../pom.xml | 9 +++++ .../apache/maven/plugin/coreit/FirstMojo.java | 2 +- .../verify.groovy | 2 +- .../apache/maven/plugin/coreit/FirstMojo.java | 2 +- .../pom.xml | 12 ++++++ .../verify.groovy | 2 +- .../it/annotation-with-inheritance/pom.xml | 9 +++++ .../apache/maven/plugin/coreit/FirstMojo.java | 2 +- .../annotation-with-inheritance/verify.groovy | 2 +- maven-plugin-plugin/src/it/help-basic/pom.xml | 9 +++++ .../src/it/help-package/pom.xml | 9 +++++ .../src/it/java-basic-annotations/pom.xml | 9 +++++ .../resources/META-INF/plexus/components.xml | 4 -- .../plugin/generator/PluginHelpGenerator.java | 38 +++++++++++-------- 14 files changed, 85 insertions(+), 26 deletions(-) diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/pom.xml b/maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/pom.xml index 370c4c6..1e71de2 100644 --- a/maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/pom.xml +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/pom.xml @@ -87,6 +87,15 @@ under the License. + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.4 + + + org.apache.maven.plugins diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java b/maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java index 167f30e..70ecea5 100644 --- a/maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java @@ -45,7 +45,7 @@ public class FirstMojo @Parameter( alias = "alias" ) private String aliasedParam; - @Component( role = "org.apache.maven.project.MavenProjectHelper", roleHint = "default" ) + @Component( role = "org.apache.maven.project.MavenProjectHelper" )// , roleHint = "default" private Object projectHelper; public void execute() diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/verify.groovy b/maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/verify.groovy index 213081a..6aefc31 100644 --- a/maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/verify.groovy +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance-from-deps/verify.groovy @@ -43,7 +43,7 @@ assert mojo.requirements.requirement[1].'role-hint'.text() == '' assert mojo.requirements.requirement[1].'field-name'.text() == 'compilerManager' assert mojo.requirements.requirement[2].role.text() == 'org.apache.maven.project.MavenProjectHelper' -assert mojo.requirements.requirement[2].'role-hint'.text() == 'default' +//assert mojo.requirements.requirement[2].'role-hint'.text() == 'default' assert mojo.requirements.requirement[2].'field-name'.text() == 'projectHelper' assert mojo.parameters.parameter.size() == 3 diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/module-mojo/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java b/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/module-mojo/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java index c56fcb8..a70cc1f 100644 --- a/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/module-mojo/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/module-mojo/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java @@ -46,7 +46,7 @@ public class FirstMojo @Parameter( alias = "alias" ) private String aliasedParam; - @Component( role = "org.apache.maven.project.MavenProjectHelper", roleHint = "default" ) + @Component( role = "org.apache.maven.project.MavenProjectHelper") private Object projectHelper; public void execute() diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/pom.xml b/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/pom.xml index 1a8ac83..838ea70 100644 --- a/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/pom.xml +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/pom.xml @@ -85,4 +85,16 @@ under the License. + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.4 + + + + + diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/verify.groovy b/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/verify.groovy index 6348f09..7659c5d 100644 --- a/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/verify.groovy +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance-reactor/verify.groovy @@ -37,7 +37,7 @@ assert mojo.configuration.touchFile[0].'@default-value' == '${project.build.dire assert mojo.requirements.requirement.size() == 3 assert mojo.requirements.requirement[2].role.text() == 'org.apache.maven.project.MavenProjectHelper' -assert mojo.requirements.requirement[2].'role-hint'.text() == 'default' +//assert mojo.requirements.requirement[2].'role-hint'.text() == 'default' assert mojo.requirements.requirement[2].'field-name'.text() == 'projectHelper' assert mojo.parameters.parameter.size() == 3 diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance/pom.xml b/maven-plugin-plugin/src/it/annotation-with-inheritance/pom.xml index 6799f43..945aaad 100644 --- a/maven-plugin-plugin/src/it/annotation-with-inheritance/pom.xml +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance/pom.xml @@ -81,6 +81,15 @@ under the License. + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.4 + + + org.apache.maven.plugins diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java b/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java index e8358f7..adcb5e3 100644 --- a/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance/src/main/java/org/apache/maven/plugin/coreit/FirstMojo.java @@ -45,7 +45,7 @@ public class FirstMojo @Parameter( alias = "alias" ) private String aliasedParam; - @Component( role = "org.apache.maven.project.MavenProjectHelper", roleHint = "default" ) + @Component( role = "org.apache.maven.project.MavenProjectHelper" )//, roleHint = "default" private Object projectHelper; public void execute() diff --git a/maven-plugin-plugin/src/it/annotation-with-inheritance/verify.groovy b/maven-plugin-plugin/src/it/annotation-with-inheritance/verify.groovy index 2052a1f..8554b25 100644 --- a/maven-plugin-plugin/src/it/annotation-with-inheritance/verify.groovy +++ b/maven-plugin-plugin/src/it/annotation-with-inheritance/verify.groovy @@ -41,7 +41,7 @@ assert mojo.configuration.touchFile[0].'@default-value' == '${project.build.dire assert mojo.requirements.requirement.size() == 3 assert mojo.requirements.requirement[2].role.text() == 'org.apache.maven.project.MavenProjectHelper' -assert mojo.requirements.requirement[2].'role-hint'.text() == 'default' +//assert mojo.requirements.requirement[2].'role-hint'.text() == 'default' assert mojo.requirements.requirement[2].'field-name'.text() == 'projectHelper' assert mojo.parameters.parameter.size() == 3 diff --git a/maven-plugin-plugin/src/it/help-basic/pom.xml b/maven-plugin-plugin/src/it/help-basic/pom.xml index df81e40..c970246 100644 --- a/maven-plugin-plugin/src/it/help-basic/pom.xml +++ b/maven-plugin-plugin/src/it/help-basic/pom.xml @@ -50,6 +50,15 @@ under the License. + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.4 + + + org.apache.maven.plugins diff --git a/maven-plugin-plugin/src/it/help-package/pom.xml b/maven-plugin-plugin/src/it/help-package/pom.xml index 20b74fd..1ae3c32 100644 --- a/maven-plugin-plugin/src/it/help-package/pom.xml +++ b/maven-plugin-plugin/src/it/help-package/pom.xml @@ -50,6 +50,15 @@ under the License. + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.4 + + + org.apache.maven.plugins diff --git a/maven-plugin-plugin/src/it/java-basic-annotations/pom.xml b/maven-plugin-plugin/src/it/java-basic-annotations/pom.xml index 3eb1e16..bec1a1f 100644 --- a/maven-plugin-plugin/src/it/java-basic-annotations/pom.xml +++ b/maven-plugin-plugin/src/it/java-basic-annotations/pom.xml @@ -58,6 +58,15 @@ under the License. + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.4 + + + org.apache.maven.plugins diff --git a/maven-plugin-tools-annotations/src/main/resources/META-INF/plexus/components.xml b/maven-plugin-tools-annotations/src/main/resources/META-INF/plexus/components.xml index 18fb315..9d6aa87 100644 --- a/maven-plugin-tools-annotations/src/main/resources/META-INF/plexus/components.xml +++ b/maven-plugin-tools-annotations/src/main/resources/META-INF/plexus/components.xml @@ -33,19 +33,15 @@ org.apache.maven.tools.plugin.annotations.scanner.MojoAnnotationsScanner - default org.apache.maven.artifact.resolver.ArtifactResolver - default org.apache.maven.artifact.factory.ArtifactFactory - default org.codehaus.plexus.archiver.manager.ArchiverManager - default diff --git a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginHelpGenerator.java b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginHelpGenerator.java index 9a1d1a2..8f48f64 100644 --- a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginHelpGenerator.java +++ b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginHelpGenerator.java @@ -42,6 +42,7 @@ import java.io.StringWriter; import java.io.Writer; import java.util.HashMap; import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.Properties; @@ -103,26 +104,27 @@ public class PluginHelpGenerator MojoDescriptor helpDescriptor = makeHelpDescriptor( pluginDescriptor ); - // Verify that no help goal already exists - for ( @SuppressWarnings( "unchecked" ) Iterator it = pluginDescriptor.getMojos().iterator(); - it.hasNext(); ) + List mojoDescriptors = pluginDescriptor.getMojos(); + + if ( mojoDescriptors != null ) { - MojoDescriptor descriptor = it.next(); - - if ( descriptor.getGoal().equals( helpDescriptor.getGoal() ) && !descriptor.getImplementation().equals( - helpDescriptor.getImplementation() ) ) + // Verify that no help goal already exists + for ( MojoDescriptor descriptor : mojoDescriptors ) { - if ( getLogger().isWarnEnabled() ) + if ( descriptor.getGoal().equals( helpDescriptor.getGoal() ) && !descriptor.getImplementation().equals( + helpDescriptor.getImplementation() ) ) { - getLogger().warn( "\n\nA help goal (" + descriptor.getImplementation() - + ") already exists in this plugin. SKIPPED THE " - + helpDescriptor.getImplementation() + " GENERATION.\n" ); - } + if ( getLogger().isWarnEnabled() ) + { + getLogger().warn( "\n\nA help goal (" + descriptor.getImplementation() + + ") already exists in this plugin. SKIPPED THE " + + helpDescriptor.getImplementation() + " GENERATION.\n" ); + } - return; + return; + } } } - Properties properties = new Properties(); properties.put( "helpPackageName", helpPackageName == null ? "" : helpPackageName ); @@ -316,9 +318,13 @@ public class PluginHelpGenerator protected static String discoverPackageName( PluginDescriptor pluginDescriptor ) { Map packageNames = new HashMap(); - for ( Iterator it = pluginDescriptor.getMojos().iterator(); it.hasNext(); ) + List mojoDescriptors = pluginDescriptor.getMojos(); + if ( mojoDescriptors == null ) + { + return ""; + } + for ( MojoDescriptor descriptor : mojoDescriptors ) { - MojoDescriptor descriptor = (MojoDescriptor) it.next(); String impl = descriptor.getImplementation(); if ( StringUtils.equals( descriptor.getGoal(), "help" ) && StringUtils.equals( "HelpMojo", impl ) ) From a9bb0f65713710c07072e308f7002608caccfcc6 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 11 May 2012 22:56:12 +0000 Subject: [PATCH 46/48] restore javadoc comment on the generated help mojo git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1337406 13f79535-47bb-0310-9956-ffa450edef68 --- maven-plugin-tools-api/src/main/resources/help-class-source.vm | 1 + 1 file changed, 1 insertion(+) diff --git a/maven-plugin-tools-api/src/main/resources/help-class-source.vm b/maven-plugin-tools-api/src/main/resources/help-class-source.vm index 6db6464..1a65a62 100644 --- a/maven-plugin-tools-api/src/main/resources/help-class-source.vm +++ b/maven-plugin-tools-api/src/main/resources/help-class-source.vm @@ -15,6 +15,7 @@ import java.util.Iterator; import java.util.List; /** + * Display help information on maven-plugin-plugin.
Call
 mvn plugin:help -Ddetail=true -Dgoal=<goal-name>
to display parameter details. * @author * @version * @goal help From 6b38de8036a57d413b47cff705344d777d15d50c Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 11 May 2012 23:06:56 +0000 Subject: [PATCH 47/48] fix help content generation from
 tag

git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1337408 13f79535-47bb-0310-9956-ffa450edef68
---
 .../plugin/generator/PluginDescriptorGenerator.java    | 10 ++++++++--
 .../apache/maven/tools/plugin/util/PluginUtils.java    |  2 +-
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java
index 76e48f8..1d3e1af 100644
--- a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java
+++ b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java
@@ -148,8 +148,14 @@ public class PluginDescriptorGenerator
             w.startElement( "plugin" );
 
             PluginUtils.element( w, "name", pluginDescriptor.getName() );
-
-            PluginUtils.element( w, "description", pluginDescriptor.getDescription() );
+            if ( cleanDescription )
+            {
+                PluginUtils.element( w, "description", PluginUtils.toText( pluginDescriptor.getDescription() ) );
+            }
+            else
+            {
+                PluginUtils.element( w, "description", pluginDescriptor.getDescription() );
+            }
 
             PluginUtils.element( w, "groupId", pluginDescriptor.getGroupId() );
 
diff --git a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/util/PluginUtils.java b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/util/PluginUtils.java
index 94f2ada..462832d 100644
--- a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/util/PluginUtils.java
+++ b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/util/PluginUtils.java
@@ -715,7 +715,7 @@ public final class PluginUtils
             String text;
             if ( preformatted > 0 )
             {
-                text = data.replace( ' ', '\u00A0' );
+                text = data;
             }
             else
             {

From a534b3d2b5b65795a9ee738f5d16749783309116 Mon Sep 17 00:00:00 2001
From: Olivier Lamy 
Date: Sat, 12 May 2012 07:16:25 +0000
Subject: [PATCH 48/48] fix ci url

git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1337460 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/pom.xml b/pom.xml
index f562ff9..f9531f2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -145,7 +145,7 @@
   
   
     Jenkins
-    https://builds.apache.org/hudson/job/maven-plugin-tools/
+    https://builds.apache.org/job/maven-plugin-tools/
   
   
     
@@ -365,4 +365,4 @@
       
     
   
-
\ No newline at end of file
+