Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
IssueAdapter |
|
| 5.0;5 |
1 | package org.apache.maven.plugin.changes; | |
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.issues.Issue; | |
23 | import org.apache.maven.plugins.changes.model.Action; | |
24 | import org.apache.maven.plugins.changes.model.Release; | |
25 | ||
26 | import java.util.ArrayList; | |
27 | import java.util.HashMap; | |
28 | import java.util.Iterator; | |
29 | import java.util.List; | |
30 | import java.util.Map; | |
31 | ||
32 | /** | |
33 | * An adapter that can adapt issue management system data models to the data model used | |
34 | * in the changes.xml file. | |
35 | * | |
36 | * @author Dennis Lundberg | |
37 | * @version $Id$ | |
38 | * @since 2.4 | |
39 | */ | |
40 | 0 | public class IssueAdapter |
41 | { | |
42 | /** | |
43 | * Adapt a <code>List</code> of <code>Issue</code>s to a | |
44 | * <code>List</code> of <code>Release</code>s. | |
45 | * | |
46 | * @param issues The issues | |
47 | * @return A list of releases | |
48 | */ | |
49 | public static List getReleases( List issues ) | |
50 | { | |
51 | // A Map of releases keyed by fixVersion | |
52 | 0 | Map releasesMap = new HashMap(); |
53 | ||
54 | // Loop through all issues looking for fixVersions | |
55 | 0 | for ( int i = 0; i < issues.size(); i++ ) |
56 | { | |
57 | 0 | Issue issue = (Issue) issues.get( i ); |
58 | // Do NOT create a release for issues that lack a fixVersion | |
59 | 0 | if ( issue.getFixVersions() != null ) |
60 | { | |
61 | 0 | for ( Iterator iterator = issue.getFixVersions().iterator(); iterator.hasNext(); ) |
62 | { | |
63 | 0 | String fixVersion = (String) iterator.next(); |
64 | ||
65 | // Try to get a matching Release from the map | |
66 | 0 | Release release = (Release) releasesMap.get( fixVersion ); |
67 | 0 | if ( release == null ) |
68 | { | |
69 | // Add a new Release to the Map if it wasn't there | |
70 | 0 | release = new Release(); |
71 | 0 | release.setVersion( fixVersion ); |
72 | 0 | releasesMap.put( fixVersion, release ); |
73 | } | |
74 | ||
75 | // Add this issue as an Action to this release | |
76 | 0 | Action action = createAction( issue ); |
77 | 0 | release.addAction( action ); |
78 | 0 | } |
79 | } | |
80 | } | |
81 | ||
82 | // Extract the releases from the Map to a List | |
83 | 0 | List releasesList = new ArrayList(); |
84 | 0 | for ( Iterator iterator = releasesMap.entrySet().iterator(); iterator.hasNext(); ) |
85 | { | |
86 | 0 | Release o = (Release) ( (Map.Entry) iterator.next() ).getValue(); |
87 | 0 | releasesList.add( o ); |
88 | 0 | } |
89 | 0 | return releasesList; |
90 | } | |
91 | ||
92 | /** | |
93 | * Create an <code>Action</code> from an issue. | |
94 | * | |
95 | * @param issue The issue to extract the information from | |
96 | * @return An <code>Action</code> | |
97 | */ | |
98 | public static Action createAction( Issue issue ) | |
99 | { | |
100 | 0 | Action action = new Action(); |
101 | ||
102 | // @todo We need to add something like issue.getPresentationIdentifier() to be able to support other IMSes beside JIRA | |
103 | 0 | action.setIssue( issue.getKey() ); |
104 | ||
105 | // @todo To support types for different IMSes we need some way to map these values to the ones used in a particular IMS | |
106 | 0 | String type = ""; |
107 | 0 | if ( issue.getType().equals( "Bug" ) ) |
108 | { | |
109 | 0 | type = "fix"; |
110 | } | |
111 | 0 | else if ( issue.getType().equals( "New Feature" ) ) |
112 | { | |
113 | 0 | type = "add"; |
114 | } | |
115 | 0 | else if ( issue.getType().equals( "Improvement" ) ) |
116 | { | |
117 | 0 | type = "update"; |
118 | } | |
119 | 0 | action.setType( type ); |
120 | ||
121 | 0 | action.setDev( issue.getAssignee() ); |
122 | ||
123 | // Set dueTo to the empty String instead of null to make Velocity happy | |
124 | 0 | action.setDueTo( "" ); |
125 | //action.setDueTo( issue.getReporter() ); | |
126 | ||
127 | 0 | action.setAction( issue.getSummary() ); |
128 | 0 | return action; |
129 | } | |
130 | } |