Coverage Report - org.apache.maven.plugin.issues.IssueUtils
 
Classes in this File Line Coverage Branch Coverage Complexity
IssueUtils
50%
15/30
46%
11/24
6,5
 
 1  
 package org.apache.maven.plugin.issues;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *    http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import org.apache.maven.plugin.MojoExecutionException;
 23  
 
 24  
 import java.util.ArrayList;
 25  
 import java.util.List;
 26  
 
 27  
 /**
 28  
  * A utility class for working with issue objects.
 29  
  *
 30  
  * @author Dennis Lundberg
 31  
  * @version $Id: org.apache.maven.plugin.issues.IssueUtils.html 816598 2012-05-08 12:46:49Z hboutemy $
 32  
  * @since 2.4
 33  
  */
 34  0
 public class IssueUtils
 35  
 {
 36  
     public static final String SNAPSHOT_SUFFIX = "-SNAPSHOT";
 37  
 
 38  
     /**
 39  
      * Find the issues that has a Fix Version that matches the supplied prefix.
 40  
      *
 41  
      * @param issues A list of issues
 42  
      * @param prefix The prefix of the "Fix Version" that should match
 43  
      * @return A <code>List</code> of issues fixed in versions that match the supplied prefix
 44  
      * @throws org.apache.maven.plugin.MojoExecutionException
 45  
      *          If no issues could be found for the supplied prefix
 46  
      */
 47  
     public static List filterIssuesWithVersionPrefix( List issues, String prefix )
 48  
         throws MojoExecutionException
 49  
     {
 50  8
         List filteredIssues = new ArrayList();
 51  8
         boolean isFound = false;
 52  8
         Issue issue = null;
 53  
 
 54  24
         for ( int i = 0; i < issues.size(); i++ )
 55  
         {
 56  16
             issue = (Issue) issues.get( i );
 57  
 
 58  16
             if ( issue.getFixVersions() != null )
 59  
             {
 60  22
                 for ( int j = 0; j < issue.getFixVersions().size(); j++ )
 61  
                 {
 62  16
                     String fixVersion = (String) issue.getFixVersions().get( j );
 63  16
                     if ( prefix == null || fixVersion.startsWith( prefix ) )
 64  
                     {
 65  10
                         isFound = true;
 66  10
                         filteredIssues.add( issue );
 67  10
                         break;
 68  
                     }
 69  
                 }
 70  
             }
 71  
         }
 72  
 
 73  8
         if ( !isFound )
 74  
         {
 75  2
             throw new MojoExecutionException(
 76  
                 "Couldn't find any issues with a Fix Version prefix of '" + prefix + "' among the supplied issues." );
 77  
         }
 78  6
         return filteredIssues;
 79  
     }
 80  
 
 81  
     /**
 82  
      * Find the issues for only the supplied version, by matching the "Fix for"
 83  
      * version in the supplied list of issues with the supplied version.
 84  
      * If the supplied version is a SNAPSHOT, then that part of the version
 85  
      * will be removed prior to the matching.
 86  
      *
 87  
      * @param issues A list of issues
 88  
      * @param version The version that issues should be returned for
 89  
      * @return A <code>List</code> of issues for the supplied version
 90  
      * @throws org.apache.maven.plugin.MojoExecutionException
 91  
      *          If no issues could be found for the supplied version
 92  
      */
 93  
     public static List getIssuesForVersion( List issues, String version )
 94  
         throws MojoExecutionException
 95  
     {
 96  0
         List issuesForVersion = new ArrayList();
 97  0
         boolean isFound = false;
 98  0
         Issue issue = null;
 99  0
         String releaseVersion = version;
 100  
 
 101  
         // Remove "-SNAPSHOT" from the end of the version, if it's there
 102  0
         if ( version != null && version.endsWith( SNAPSHOT_SUFFIX ) )
 103  
         {
 104  0
             releaseVersion = version.substring( 0, version.length() - SNAPSHOT_SUFFIX.length() );
 105  
         }
 106  
 
 107  0
         for ( int i = 0; i < issues.size(); i++ )
 108  
         {
 109  0
             issue = (Issue) issues.get( i );
 110  
 
 111  0
             if ( issue.getFixVersions() != null && issue.getFixVersions().contains( releaseVersion ) )
 112  
             {
 113  0
                 isFound = true;
 114  0
                 issuesForVersion.add( issue );
 115  
             }
 116  
         }
 117  
 
 118  0
         if ( !isFound )
 119  
         {
 120  0
             throw new MojoExecutionException(
 121  
                 "Couldn't find any issues for the version '" + releaseVersion + "' among the supplied issues." );
 122  
         }
 123  0
         return issuesForVersion;
 124  
     }
 125  
 }