[MCHANGES-266] It is not possible to disable the reports in submodules

git-svn-id: https://svn.apache.org/repos/asf/maven/plugins/trunk@1578624 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/maven/plugin/changes/AbstractChangesReport.java b/src/main/java/org/apache/maven/plugin/changes/AbstractChangesReport.java
index 609c5fb..caf149f 100644
--- a/src/main/java/org/apache/maven/plugin/changes/AbstractChangesReport.java
+++ b/src/main/java/org/apache/maven/plugin/changes/AbstractChangesReport.java
@@ -36,6 +36,7 @@
 import org.apache.maven.doxia.siterenderer.RendererException;
 import org.apache.maven.doxia.siterenderer.SiteRenderingContext;
 import org.apache.maven.doxia.siterenderer.sink.SiteRendererSink;
+import org.apache.maven.execution.MavenSession;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugins.annotations.Component;
 import org.apache.maven.plugins.annotations.Parameter;
@@ -67,6 +68,14 @@
     extends AbstractMavenReport
 {
     /**
+     * The current project base directory.
+     *
+     * @since 2.10
+     */
+    @Parameter( property = "basedir", required = true )
+    protected String basedir;
+
+    /**
      * Report output directory. Note that this parameter is only relevant if the goal is run from the command line or
      * from the default build lifecycle. If the goal is run indirectly as part of a site generation, the output
      * directory configured in the Maven Site Plugin is used instead.
@@ -85,6 +94,24 @@
     private String outputEncoding;
 
     /**
+     * This will cause the execution to be run only at the top of a given module
+     * tree. That is, run in the project contained in the same folder where the
+     * mvn execution was launched.
+     *
+     * @since 2.10
+     */
+    @Parameter( property = "changes.runOnlyAtExecutionRoot", defaultValue = "false" )
+    protected boolean runOnlyAtExecutionRoot;
+
+    /**
+     * The Maven Session.
+     *
+     * @since 2.10
+     */
+    @Component
+    protected MavenSession mavenSession;
+
+    /**
      * Doxia Site Renderer.
      */
     @Component
@@ -244,4 +271,26 @@
     {
         return siteRenderer;
     }
+
+    /**
+     * Returns <code>true</code> if the current project is located at the
+     * Execution Root Directory (where mvn was launched).
+     *
+     * @return <code>true</code> if the current project is at the Execution Root
+     */
+    protected boolean isThisTheExecutionRoot()
+    {
+        getLog().debug( "Root Folder:" + mavenSession.getExecutionRootDirectory() );
+        getLog().debug( "Current Folder:" + basedir );
+        boolean result = mavenSession.getExecutionRootDirectory().equalsIgnoreCase( basedir );
+        if ( result )
+        {
+            getLog().debug( "This is the execution root." );
+        }
+        else
+        {
+            getLog().debug( "This is NOT the execution root." );
+        }
+        return result;
+    }
 }
diff --git a/src/main/java/org/apache/maven/plugin/changes/ChangesMojo.java b/src/main/java/org/apache/maven/plugin/changes/ChangesMojo.java
index 2404fe0..6e445a6 100644
--- a/src/main/java/org/apache/maven/plugin/changes/ChangesMojo.java
+++ b/src/main/java/org/apache/maven/plugin/changes/ChangesMojo.java
@@ -238,6 +238,12 @@
 
     public boolean canGenerateReport()
     {
+        // Run only at the execution root
+        if ( runOnlyAtExecutionRoot && !isThisTheExecutionRoot() )
+        {
+            getLog().info( "Skipping the Changes Report in this project because it's not the Execution Root" );
+            return false;
+        }
         return xmlPath.isFile();
     }
 
diff --git a/src/main/java/org/apache/maven/plugin/github/GitHubMojo.java b/src/main/java/org/apache/maven/plugin/github/GitHubMojo.java
index 4a0b604..43e3470 100644
--- a/src/main/java/org/apache/maven/plugin/github/GitHubMojo.java
+++ b/src/main/java/org/apache/maven/plugin/github/GitHubMojo.java
@@ -136,6 +136,12 @@
      */
     public boolean canGenerateReport()
     {
+        // Run only at the execution root
+        if ( runOnlyAtExecutionRoot && !isThisTheExecutionRoot() )
+        {
+            getLog().info( "Skipping the GitHub Report in this project because it's not the Execution Root" );
+            return false;
+        }
         return ProjectUtils.validateIfIssueManagementComplete( project, "GitHub", "GitHub Report", getLog() );
     }
 
diff --git a/src/main/java/org/apache/maven/plugin/jira/JiraMojo.java b/src/main/java/org/apache/maven/plugin/jira/JiraMojo.java
index 1ac32c1..2fe3e1d 100644
--- a/src/main/java/org/apache/maven/plugin/jira/JiraMojo.java
+++ b/src/main/java/org/apache/maven/plugin/jira/JiraMojo.java
@@ -326,6 +326,12 @@
      */
     public boolean canGenerateReport()
     {
+        // Run only at the execution root
+        if ( runOnlyAtExecutionRoot && !isThisTheExecutionRoot() )
+        {
+            getLog().info( "Skipping the JIRA Report in this project because it's not the Execution Root" );
+            return false;
+        }
         if ( skip )
         {
             return false;
diff --git a/src/main/java/org/apache/maven/plugin/trac/TracMojo.java b/src/main/java/org/apache/maven/plugin/trac/TracMojo.java
index df8803d..bd243d9 100644
--- a/src/main/java/org/apache/maven/plugin/trac/TracMojo.java
+++ b/src/main/java/org/apache/maven/plugin/trac/TracMojo.java
@@ -132,6 +132,12 @@
      */
     public boolean canGenerateReport()
     {
+        // Run only at the execution root
+        if ( runOnlyAtExecutionRoot && !isThisTheExecutionRoot() )
+        {
+            getLog().info( "Skipping the Trac Report in this project because it's not the Execution Root" );
+            return false;
+        }
         return ProjectUtils.validateIfIssueManagementComplete( project, "Trac", "Trac Report", getLog() );
     }