1 package org.apache.maven.plugin.issues;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.plugin.MojoExecutionException;
23
24 import java.util.ArrayList;
25 import java.util.List;
26
27
28
29
30
31
32
33
34 public class IssueUtils
35 {
36 public static final String SNAPSHOT_SUFFIX = "-SNAPSHOT";
37
38
39
40
41
42
43
44
45
46
47 public static List<Issue> filterIssuesWithVersionPrefix( List<Issue> issues, String prefix )
48 throws MojoExecutionException
49 {
50 List<Issue> filteredIssues = new ArrayList<Issue>();
51 boolean isFound = false;
52 Issue issue = null;
53
54 for ( int i = 0; i < issues.size(); i++ )
55 {
56 issue = (Issue) issues.get( i );
57
58 if ( issue.getFixVersions() != null )
59 {
60 for ( String fixVersion : issue.getFixVersions() )
61 {
62 if ( prefix == null || fixVersion.startsWith( prefix ) )
63 {
64 isFound = true;
65 filteredIssues.add( issue );
66 break;
67 }
68 }
69 }
70 }
71
72 if ( !isFound )
73 {
74 throw new MojoExecutionException(
75 "Couldn't find any issues with a Fix Version prefix of '" + prefix + "' among the supplied issues." );
76 }
77 return filteredIssues;
78 }
79
80
81
82
83
84
85
86
87
88
89
90
91
92 public static List<Issue> getIssuesForVersion( List<Issue> issues, String version )
93 throws MojoExecutionException
94 {
95 List<Issue> issuesForVersion = new ArrayList<Issue>();
96 boolean isFound = false;
97 Issue issue = null;
98 String releaseVersion = version;
99
100
101 if ( version != null && version.endsWith( SNAPSHOT_SUFFIX ) )
102 {
103 releaseVersion = version.substring( 0, version.length() - SNAPSHOT_SUFFIX.length() );
104 }
105
106 for ( int i = 0; i < issues.size(); i++ )
107 {
108 issue = (Issue) issues.get( i );
109
110 if ( issue.getFixVersions() != null && issue.getFixVersions().contains( releaseVersion ) )
111 {
112 isFound = true;
113 issuesForVersion.add( issue );
114 }
115 }
116
117 if ( !isFound )
118 {
119 throw new MojoExecutionException(
120 "Couldn't find any issues for the version '" + releaseVersion + "' among the supplied issues." );
121 }
122 return issuesForVersion;
123 }
124 }