Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
IssueUtils |
|
| 8.0;8 |
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$ | |
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<Issue> filterIssuesWithVersionPrefix( List<Issue> issues, String prefix ) | |
48 | throws MojoExecutionException | |
49 | { | |
50 | 4 | List<Issue> filteredIssues = new ArrayList<Issue>(); |
51 | 4 | boolean isFound = false; |
52 | 4 | Issue issue = null; |
53 | ||
54 | 12 | for ( int i = 0; i < issues.size(); i++ ) |
55 | { | |
56 | 8 | issue = (Issue) issues.get( i ); |
57 | ||
58 | 8 | if ( issue.getFixVersions() != null ) |
59 | { | |
60 | 8 | for ( String fixVersion : issue.getFixVersions() ) |
61 | { | |
62 | 8 | if ( prefix == null || fixVersion.startsWith( prefix ) ) |
63 | { | |
64 | 5 | isFound = true; |
65 | 5 | filteredIssues.add( issue ); |
66 | 5 | break; |
67 | } | |
68 | } | |
69 | } | |
70 | } | |
71 | ||
72 | 4 | if ( !isFound ) |
73 | { | |
74 | 1 | throw new MojoExecutionException( |
75 | "Couldn't find any issues with a Fix Version prefix of '" + prefix + "' among the supplied issues." ); | |
76 | } | |
77 | 3 | return filteredIssues; |
78 | } | |
79 | ||
80 | /** | |
81 | * Find the issues for only the supplied version, by matching the "Fix for" | |
82 | * version in the supplied list of issues with the supplied version. | |
83 | * If the supplied version is a SNAPSHOT, then that part of the version | |
84 | * will be removed prior to the matching. | |
85 | * | |
86 | * @param issues A list of issues | |
87 | * @param version The version that issues should be returned for | |
88 | * @return A <code>List</code> of issues for the supplied version | |
89 | * @throws org.apache.maven.plugin.MojoExecutionException | |
90 | * If no issues could be found for the supplied version | |
91 | */ | |
92 | public static List<Issue> getIssuesForVersion( List<Issue> issues, String version ) | |
93 | throws MojoExecutionException | |
94 | { | |
95 | 0 | List<Issue> issuesForVersion = new ArrayList<Issue>(); |
96 | 0 | boolean isFound = false; |
97 | 0 | Issue issue = null; |
98 | 0 | String releaseVersion = version; |
99 | ||
100 | // Remove "-SNAPSHOT" from the end of the version, if it's there | |
101 | 0 | if ( version != null && version.endsWith( SNAPSHOT_SUFFIX ) ) |
102 | { | |
103 | 0 | releaseVersion = version.substring( 0, version.length() - SNAPSHOT_SUFFIX.length() ); |
104 | } | |
105 | ||
106 | 0 | for ( int i = 0; i < issues.size(); i++ ) |
107 | { | |
108 | 0 | issue = (Issue) issues.get( i ); |
109 | ||
110 | 0 | if ( issue.getFixVersions() != null && issue.getFixVersions().contains( releaseVersion ) ) |
111 | { | |
112 | 0 | isFound = true; |
113 | 0 | issuesForVersion.add( issue ); |
114 | } | |
115 | } | |
116 | ||
117 | 0 | if ( !isFound ) |
118 | { | |
119 | 0 | throw new MojoExecutionException( |
120 | "Couldn't find any issues for the version '" + releaseVersion + "' among the supplied issues." ); | |
121 | } | |
122 | 0 | return issuesForVersion; |
123 | } | |
124 | } |