maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From denn...@apache.org
Subject svn commit: r620269 - in /maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira: JiraMojo.java JiraReportGenerator.java
Date Sun, 10 Feb 2008 12:15:39 GMT
Author: dennisl
Date: Sun Feb 10 04:15:38 2008
New Revision: 620269

URL: http://svn.apache.org/viewvc?rev=620269&view=rev
Log:
[MCHANGES-99] Make it possible to show issues only for the current release

Modified:
    maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/JiraMojo.java
    maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/JiraReportGenerator.java

Modified: maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/JiraMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/JiraMojo.java?rev=620269&r1=620268&r2=620269&view=diff
==============================================================================
--- maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/JiraMojo.java
(original)
+++ maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/JiraMojo.java
Sun Feb 10 04:15:38 2008
@@ -241,6 +241,15 @@
     private String webPassword;
 
     /**
+     * If you only want to show issues for the current version in the report.
+     * The current version being used is <code>${project.version}</code> minus
+     * any "-SNAPSHOT" suffix.
+     *
+     * @parameter default-value="false"
+     */
+    private boolean onlyCurrentVersion;
+
+    /**
      * @see org.apache.maven.reporting.AbstractMavenReport#canGenerateReport()
      */
     public boolean canGenerateReport()
@@ -263,9 +272,10 @@
 
             if ( jiraXmlPath.isFile() )
             {
-                report = new JiraReportGenerator( jiraXmlPath, columnNames );
+                report = new JiraReportGenerator( jiraXmlPath, columnNames, project.getVersion(),
+                                                  onlyCurrentVersion );
 
-                report.doGenerateReport( getBundle( locale ), getSink() );
+                report.doGenerateReport( getBundle( locale ), getSink(), getLog() );
             }
             else
             {

Modified: maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/JiraReportGenerator.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/JiraReportGenerator.java?rev=620269&r1=620268&r2=620269&view=diff
==============================================================================
--- maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/JiraReportGenerator.java
(original)
+++ maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/JiraReportGenerator.java
Sun Feb 10 04:15:38 2008
@@ -20,9 +20,12 @@
  */
 
 import org.apache.maven.doxia.sink.Sink;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.logging.Log;
 import org.apache.maven.reporting.MavenReportException;
 
 import java.io.File;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.ResourceBundle;
 
@@ -59,19 +62,36 @@
         /* 10 */ "Component"
     };
 
+    private static final String SNAPSHOT_SUFFIX = "-SNAPSHOT";
+
     private int[] columnOrder;
 
+    private String currentVersion = null;
+
     private JiraXML jira;
 
+    private boolean onlyCurrentVersion = false;
+
     public JiraReportGenerator()
     {
 
     }
 
-    public JiraReportGenerator( File xmlPath, String columnNames )
+    /**
+     *
+     * @param xmlFile An xml file containing issues from JIRA
+     * @param columnNames The names of the columns to include in the report
+     * @param currentVersion The current version of the project
+     * @param onlyCurrentVersion If only issues for the current version will be included
in the report
+     */
+    public JiraReportGenerator( File xmlFile, String columnNames, String currentVersion,
+                                boolean onlyCurrentVersion)
         throws MavenReportException
     {
-        jira = new JiraXML( xmlPath );
+        this.currentVersion = currentVersion;
+        this.onlyCurrentVersion = onlyCurrentVersion;
+
+        jira = new JiraXML( xmlFile );
 
         String[] columnNamesArray = columnNames.split( "," );
         int validColumnNames = 0;
@@ -109,10 +129,17 @@
         sinkEndReport( sink );
     }
 
-    public void doGenerateReport( ResourceBundle bundle, Sink sink )
+    public void doGenerateReport( ResourceBundle bundle, Sink sink, Log log )
+        throws MojoExecutionException
     {
         List issueList = jira.getIssueList();
 
+        if ( onlyCurrentVersion )
+        {
+            issueList = getIssuesForCurrentRelease( issueList );
+            log.info( "The JIRA Report will contain issues only for the current version."
);
+        }
+
         sinkBeginReport( sink, bundle );
 
         constructHeaderRow( sink, issueList, bundle );
@@ -334,5 +361,49 @@
         sink.text( text );
 
         sink.sectionTitle1_();
+    }
+
+    /**
+     * Find the issues for only the current release, by matching the "Fix for"
+     * version in the supplied list of issues with the current version from the
+     * pom. If the current version is a SNAPSHOT, then that part of the version
+     * will be removed prior to the matching.
+     *
+     * @param allIssues A list of all issues from JIRA
+     * @return A <code>List</code> of issues for the current release of the current
project
+     * @throws org.apache.maven.plugin.MojoExecutionException
+     *          If no issues could be found for the current release
+     */
+    public List getIssuesForCurrentRelease( List allIssues )
+        throws MojoExecutionException
+    {
+        List currentReleaseIssues = new ArrayList();
+        boolean isFound = false;
+        JiraIssue issue = null;
+        String releaseVersion = currentVersion;
+
+        // Remove "-SNAPSHOT" from the end of the version, if it's there
+        if ( currentVersion != null && currentVersion.endsWith( SNAPSHOT_SUFFIX )
)
+        {
+            releaseVersion = currentVersion.substring( 0, currentVersion.length() - SNAPSHOT_SUFFIX.length()
);
+        }
+
+        for ( int i = 0; i < allIssues.size(); i++ )
+        {
+            issue = (JiraIssue) allIssues.get( i );
+
+            if ( issue.getFixVersion() != null && issue.getFixVersion().equals( releaseVersion
) )
+            {
+                isFound = true;
+                currentReleaseIssues.add( issue );
+            }
+        }
+
+        if ( !isFound )
+        {
+            throw new MojoExecutionException(
+                "Couldn't find any issues for the version '" + releaseVersion + "' among
the supplied issues." );
+        }
+        return currentReleaseIssues;
     }
 }



Mime
View raw message