Author: dennisl Date: Thu Dec 30 19:02:15 2010 New Revision: 1053977 URL: http://svn.apache.org/viewvc?rev=1053977&view=rev Log: Refactoring: move to a helper method that has nothing to do with the report generation to a helper class.
Modified: maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/JiraHelper.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/JiraHelper.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/JiraHelper.java?rev=1053977&r1=1053976&r2=1053977&view=diff ============================================================================== --- maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/JiraHelper.java (original) +++ maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/jira/JiraHelper.java Thu Dec 30 19:02:15 2010 @@ -21,10 +21,13 @@ package org.apache.maven.plugin.jira; import java.text.NumberFormat; import java.text.ParsePosition; +import java.util.ArrayList; +import java.util.List; import java.util.StringTokenizer; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.methods.GetMethod; +import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.logging.Log; import org.apache.maven.wagon.proxy.ProxyInfo; @@ -38,6 +41,53 @@ public class JiraHelper { private static final String PID = "pid="; + private static final String SNAPSHOT_SUFFIX = "-SNAPSHOT"; + + /** + * Find the issues for only the supplied version, by matching the "Fix for" + * version in the supplied list of issues with the supplied version. + * If the supplied version is a SNAPSHOT, then that part of the version + * will be removed prior to the matching. + * + * @param issues A list of issues from JIRA + * @param version The version that issues should be returned for + * @return A <code>List</code> of issues for the supplied version + * @throws org.apache.maven.plugin.MojoExecutionException + * If no issues could be found for the supplied version + */ + public static List getIssuesForVersion( List issues, String version ) + throws MojoExecutionException + { + List issuesForVersion = new ArrayList(); + boolean isFound = false; + JiraIssue issue = null; + String releaseVersion = version; + + // Remove "-SNAPSHOT" from the end of the version, if it's there + if ( version != null && version.endsWith( SNAPSHOT_SUFFIX ) ) + { + releaseVersion = version.substring( 0, version.length() - SNAPSHOT_SUFFIX.length() ); + } + + for ( int i = 0; i < issues.size(); i++ ) + { + issue = (JiraIssue) issues.get( i ); + + if ( issue.getFixVersions() != null && issue.getFixVersions().contains( releaseVersion ) ) + { + isFound = true; + issuesForVersion.add( issue ); + } + } + + if ( !isFound ) + { + throw new MojoExecutionException( + "Couldn't find any issues for the version '" + releaseVersion + "' among the supplied issues." ); + } + return issuesForVersion; + } + /** * Try to get a JIRA pid from the issue management URL. * @@ -50,7 +100,7 @@ public class JiraHelper { String jiraId = null; GetMethod gm = new GetMethod( issueManagementUrl ); - + String projectPage; try { 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=1053977&r1=1053976&r2=1053977&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 Thu Dec 30 19:02:15 2010 @@ -25,7 +25,6 @@ import org.apache.maven.plugin.logging.L import org.apache.maven.reporting.MavenReportException; import java.io.File; -import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.ResourceBundle; @@ -63,8 +62,6 @@ public class JiraReportGenerator /* 10 */ "Component" }; - private static final String SNAPSHOT_SUFFIX = "-SNAPSHOT"; - private int[] columnOrder; private String currentVersion = null; @@ -141,7 +138,7 @@ public class JiraReportGenerator if ( onlyCurrentVersion ) { - issueList = getIssuesForVersion( issueList, currentVersion ); + issueList = JiraHelper.getIssuesForVersion( issueList, currentVersion ); log.info( "The JIRA Report will contain issues only for the current version." ); } @@ -372,52 +369,6 @@ public class JiraReportGenerator } /** - * Find the issues for only the supplied version, by matching the "Fix for" - * version in the supplied list of issues with the supplied version. - * If the supplied version is a SNAPSHOT, then that part of the version - * will be removed prior to the matching. - * - * @param issues A list of issues from JIRA - * @param version The version that issues should be returned for - * @return A <code>List</code> of issues for the supplied version - * @throws org.apache.maven.plugin.MojoExecutionException - * If no issues could be found for the supplied version - * @todo Move to a helper class - it has nothing to do with the report - */ - public static List getIssuesForVersion( List issues, String version ) - throws MojoExecutionException - { - List currentReleaseIssues = new ArrayList(); - boolean isFound = false; - JiraIssue issue = null; - String releaseVersion = version; - - // Remove "-SNAPSHOT" from the end of the version, if it's there - if ( version != null && version.endsWith( SNAPSHOT_SUFFIX ) ) - { - releaseVersion = version.substring( 0, version.length() - SNAPSHOT_SUFFIX.length() ); - } - - for ( int i = 0; i < issues.size(); i++ ) - { - issue = (JiraIssue) issues.get( i ); - - if ( issue.getFixVersions() != null && issue.getFixVersions().contains( 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; - } - - /** * Print a list of values separated by commas. * * @param values The values to print