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