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;
20
21 import java.util.ArrayList;
22 import java.util.HashMap;
23 import java.util.List;
24 import java.util.Map;
25
26 import org.apache.maven.artifact.versioning.ComparableVersion;
27 import org.apache.maven.plugins.changes.issues.Issue;
28 import org.apache.maven.plugins.changes.issues.IssueManagementSystem;
29 import org.apache.maven.plugins.changes.model.Action;
30 import org.apache.maven.plugins.changes.model.Release;
31
32
33
34
35
36
37
38
39
40 public class IssueAdapter {
41 private static final String UNKNOWN_ISSUE_TYPE = "";
42
43 private IssueManagementSystem ims;
44
45
46
47
48
49
50 public IssueAdapter(IssueManagementSystem ims) {
51 this.ims = ims;
52 }
53
54 private Map<String, IssueType> getIssueTypeMap() {
55 return ims.getIssueTypeMap();
56 }
57
58
59
60
61
62
63
64 public List<Release> getReleases(List<Issue> issues) {
65
66 Map<String, Release> releasesMap = new HashMap<>();
67
68
69 for (Issue issue : issues) {
70
71 if (issue.getFixVersions() != null) {
72 for (String fixVersion : issue.getFixVersions()) {
73
74 Release release = releasesMap.get(fixVersion);
75 if (release == null) {
76
77 release = new Release();
78 release.setVersion(fixVersion);
79 releasesMap.put(fixVersion, release);
80 }
81
82
83 Action action = createAction(issue);
84 release.addAction(action);
85 }
86 }
87 }
88
89
90 List<Release> allReleases = new ArrayList<>(releasesMap.values());
91 allReleases.sort((release1, release2) -> {
92 ComparableVersion version1 = new ComparableVersion(release1.getVersion());
93 ComparableVersion version2 = new ComparableVersion(release2.getVersion());
94 return version2.compareTo(version1);
95 });
96
97 return allReleases;
98 }
99
100
101
102
103
104
105
106 public Action createAction(Issue issue) {
107 Action action = new Action();
108
109
110
111 action.setIssue(issue.getKey());
112
113
114 IssueType type;
115 if (getIssueTypeMap().containsKey(issue.getType())) {
116 type = getIssueTypeMap().get(issue.getType());
117 action.setType(type.modelRepresentation());
118 } else {
119 action.setType(UNKNOWN_ISSUE_TYPE);
120 }
121
122 action.setDev(issue.getAssignee());
123
124 action.setDueTo(issue.getReporter() == null ? "" : issue.getReporter());
125
126 action.setAction(issue.getSummary());
127 return action;
128 }
129 }