Author: gboue
Date: Wed Nov  2 00:43:39 2016
New Revision: 1767593

URL: http://svn.apache.org/viewvc?rev=1767593&view=rev
Log:
[MPH-116] Printout the information if a goal is a report goal or not

Adding the information in the describe goal: the plugin and all of its 
dependencies are resolved to determine whether the Java class of the goal 
implements MavenReport.

Added:
    maven/plugins/trunk/maven-help-plugin/src/it/describe-cmd-with-goal-report/
    
maven/plugins/trunk/maven-help-plugin/src/it/describe-cmd-with-goal-report/invoker.properties
   (with props)
    
maven/plugins/trunk/maven-help-plugin/src/it/describe-cmd-with-goal-report/pom.xml
   (with props)
    
maven/plugins/trunk/maven-help-plugin/src/it/describe-cmd-with-goal-report/verify.groovy
   (with props)
Modified:
    
maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/DescribeMojo.java

Added: 
maven/plugins/trunk/maven-help-plugin/src/it/describe-cmd-with-goal-report/invoker.properties
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-help-plugin/src/it/describe-cmd-with-goal-report/invoker.properties?rev=1767593&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-help-plugin/src/it/describe-cmd-with-goal-report/invoker.properties
 (added)
+++ 
maven/plugins/trunk/maven-help-plugin/src/it/describe-cmd-with-goal-report/invoker.properties
 Wed Nov  2 00:43:39 2016
@@ -0,0 +1,20 @@
+# 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.
+
+invoker.goals.1 = -l changes.log 
${project.groupId}:${project.artifactId}:${project.version}:describe 
-Dcmd=changes:jira-report
+invoker.goals.2 = -l javadoc.log 
${project.groupId}:${project.artifactId}:${project.version}:describe 
-Dcmd=javadoc:javadoc
+invoker.goals.3 = -l assembly.log 
${project.groupId}:${project.artifactId}:${project.version}:describe 
-Dcmd=assembly:single

Propchange: 
maven/plugins/trunk/maven-help-plugin/src/it/describe-cmd-with-goal-report/invoker.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/plugins/trunk/maven-help-plugin/src/it/describe-cmd-with-goal-report/invoker.properties
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: 
maven/plugins/trunk/maven-help-plugin/src/it/describe-cmd-with-goal-report/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-help-plugin/src/it/describe-cmd-with-goal-report/pom.xml?rev=1767593&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-help-plugin/src/it/describe-cmd-with-goal-report/pom.xml
 (added)
+++ 
maven/plugins/trunk/maven-help-plugin/src/it/describe-cmd-with-goal-report/pom.xml
 Wed Nov  2 00:43:39 2016
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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.
+-->
+
+<project>
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.its.help</groupId>
+  <artifactId>test</artifactId>
+  <version>1.0</version>
+  
+  <url>https://issues.apache.org/jira/browse/MPH-116</url>
+  <description>Tests that describe outputs whether the configured goal is a 
report goal or not</description>
+
+  <build>
+    <plugins>
+    </plugins>
+  </build>
+</project>

Propchange: 
maven/plugins/trunk/maven-help-plugin/src/it/describe-cmd-with-goal-report/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/plugins/trunk/maven-help-plugin/src/it/describe-cmd-with-goal-report/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: 
maven/plugins/trunk/maven-help-plugin/src/it/describe-cmd-with-goal-report/verify.groovy
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-help-plugin/src/it/describe-cmd-with-goal-report/verify.groovy?rev=1767593&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-help-plugin/src/it/describe-cmd-with-goal-report/verify.groovy
 (added)
+++ 
maven/plugins/trunk/maven-help-plugin/src/it/describe-cmd-with-goal-report/verify.groovy
 Wed Nov  2 00:43:39 2016
@@ -0,0 +1,29 @@
+/*
+ * 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.
+ */
+def buildLog = new File(basedir, 'changes.log'); 
+assert buildLog.exists()
+assert buildLog.text.contains('Note: This goal should be used as a Maven 
report.');
+
+buildLog = new File(basedir, 'javadoc.log'); 
+assert buildLog.exists()
+assert buildLog.text.contains('Note: This goal should be used as a Maven 
report.');
+
+buildLog = new File(basedir, 'assembly.log'); 
+assert buildLog.exists()
+assert !buildLog.text.contains('Note: This goal should be used as a Maven 
report.');

Propchange: 
maven/plugins/trunk/maven-help-plugin/src/it/describe-cmd-with-goal-report/verify.groovy
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/plugins/trunk/maven-help-plugin/src/it/describe-cmd-with-goal-report/verify.groovy
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: 
maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/DescribeMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/DescribeMojo.java?rev=1767593&r1=1767592&r2=1767593&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/DescribeMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-help-plugin/src/main/java/org/apache/maven/plugins/help/DescribeMojo.java
 Wed Nov  2 00:43:39 2016
@@ -19,9 +19,12 @@ package org.apache.maven.plugins.help;
  * under the License.
  */
 
+import java.io.File;
 import java.io.IOException;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.net.URL;
+import java.net.URLClassLoader;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
@@ -35,6 +38,7 @@ import org.apache.maven.artifact.factory
 import org.apache.maven.artifact.repository.ArtifactRepository;
 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.artifact.versioning.InvalidVersionSpecificationException;
 import org.apache.maven.artifact.versioning.VersionRange;
 import org.apache.maven.execution.MavenSession;
@@ -60,6 +64,7 @@ import org.apache.maven.plugins.annotati
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.project.MavenProjectBuilder;
 import org.apache.maven.project.ProjectBuildingException;
+import org.apache.maven.reporting.MavenReport;
 import org.apache.maven.tools.plugin.util.PluginUtils;
 import 
org.codehaus.plexus.component.repository.exception.ComponentLookupException;
 import org.codehaus.plexus.util.StringUtils;
@@ -108,6 +113,14 @@ public class DescribeMojo
      */
     @Component
     private ArtifactFactory artifactFactory;
+    
+    /**
+     * Maven Artifact Resolver component.
+     *
+     * @since 2.2.1
+     */
+    @Component
+    private ArtifactResolver artifactResolver;
 
     /**
      * The Plugin manager instance used to resolve Plugin descriptors.
@@ -656,6 +669,11 @@ public class DescribeMojo
             append( buffer, "Deprecated. " + deprecation, 1 );
         }
 
+        if ( isReportGoal( md ) )
+        {
+            append( buffer, "Note", "This goal should be used as a Maven 
report.", 1 );
+        }
+
         if ( !fullDescription )
         {
             return;
@@ -1082,6 +1100,40 @@ public class DescribeMojo
         }
     }
 
+    /**
+     * Determines if this Mojo should be used as a report or not. This 
resolves the plugin project along with all of its
+     * transitive dependencies to determine if the Java class of this goal 
implements <code>MavenReport</code>.
+     * 
+     * @param md Mojo descriptor
+     * @return Whether or not this goal should be used as a report.
+     */
+    private boolean isReportGoal( MojoDescriptor md )
+    {
+        PluginDescriptor d = md.getPluginDescriptor();
+        Artifact jar = artifactFactory.createArtifact( d.getGroupId(), 
d.getArtifactId(), d.getVersion(), "", "jar" );
+        Artifact pom = artifactFactory.createArtifact( d.getGroupId(), 
d.getArtifactId(), d.getVersion(), "", "pom" );
+        List<URL> urls = new ArrayList<URL>();
+        try
+        {
+            artifactResolver.resolve( jar, remoteRepositories, localRepository 
);
+            artifactResolver.resolve( pom, remoteRepositories, localRepository 
);
+            MavenProject project = projectBuilder.buildWithDependencies( 
pom.getFile(), localRepository, null );
+            urls.add( jar.getFile().toURI().toURL() );
+            for ( Object artifact : project.getCompileClasspathElements() )
+            {
+                urls.add( new File( (String) artifact ).toURI().toURL() );
+            }
+            ClassLoader classLoader =
+                new URLClassLoader( urls.toArray( new URL[urls.size()] ), 
getClass().getClassLoader() );
+            return MavenReport.class.isAssignableFrom( Class.forName( 
md.getImplementation(), false, classLoader ) );
+        }
+        catch ( Exception e )
+        {
+            getLog().warn( "Couldn't identify if this goal is a report goal.", 
e );
+            return false;
+        }
+    }
+
     /**
      * Gets the effective string to use for the plugin/mojo/parameter 
description.
      *


Reply via email to