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 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<Release> getReleases( List<Issue> issues ) 50 { 51 // A Map of releases keyed by fixVersion 52 Map<String,Release> releasesMap = new HashMap<String,Release>(); 53 54 // Loop through all issues looking for fixVersions 55 for ( Issue issue : issues ) 56 { 57 // Do NOT create a release for issues that lack a fixVersion 58 if ( issue.getFixVersions() != null ) 59 { 60 for ( String fixVersion : issue.getFixVersions() ) 61 { 62 // Try to get a matching Release from the map 63 Release release = releasesMap.get( fixVersion ); 64 if ( release == null ) 65 { 66 // Add a new Release to the Map if it wasn't there 67 release = new Release(); 68 release.setVersion( fixVersion ); 69 releasesMap.put( fixVersion, release ); 70 } 71 72 // Add this issue as an Action to this release 73 Action action = createAction( issue ); 74 release.addAction( action ); 75 } 76 } 77 } 78 79 // Extract the releases from the Map to a List 80 List<Release> releasesList = new ArrayList<Release>(); 81 for ( Release release : releasesMap.values() ) 82 { 83 releasesList.add( release ); 84 } 85 return releasesList; 86 } 87 88 /** 89 * Create an <code>Action</code> from an issue. 90 * 91 * @param issue The issue to extract the information from 92 * @return An <code>Action</code> 93 */ 94 public static Action createAction( Issue issue ) 95 { 96 Action action = new Action(); 97 98 // @todo We need to add something like issue.getPresentationIdentifier() to be able to support other IMSes beside JIRA 99 action.setIssue( issue.getKey() ); 100 101 // @todo To support types for different IMSes we need some way to map these values to the ones used in a particular IMS 102 String type = ""; 103 if ( issue.getType().equals( "Bug" ) ) 104 { 105 type = "fix"; 106 } 107 else if ( issue.getType().equals( "New Feature" ) ) 108 { 109 type = "add"; 110 } 111 else if ( issue.getType().equals( "Improvement" ) ) 112 { 113 type = "update"; 114 } 115 action.setType( type ); 116 117 action.setDev( issue.getAssignee() ); 118 119 // Set dueTo to the empty String instead of null to make Velocity happy 120 action.setDueTo( "" ); 121 //action.setDueTo( issue.getReporter() ); 122 123 action.setAction( issue.getSummary() ); 124 return action; 125 } 126 }