Coverage Report - org.apache.maven.plugin.changes.IssueAdapter
 
Classes in this File Line Coverage Branch Coverage Complexity
IssueAdapter
48%
15/31
16%
2/12
2,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.plugin.issues.IssueManagementSystem;
 24  
 import org.apache.maven.plugins.changes.model.Action;
 25  
 import org.apache.maven.plugins.changes.model.Release;
 26  
 
 27  
 import java.util.ArrayList;
 28  
 import java.util.HashMap;
 29  
 import java.util.List;
 30  
 import java.util.Map;
 31  
 
 32  
 /**
 33  
  * An adapter that can adapt data models from other issue management system to the data models used in the changes.xml
 34  
  * file.
 35  
  * 
 36  
  * @author Dennis Lundberg
 37  
  * @version $Id: IssueAdapter.java 1135732 2011-06-14 18:30:09Z dennisl $
 38  
  * @since 2.4
 39  
  */
 40  
 public class IssueAdapter
 41  
 {
 42  
     private static final String UNKNOWN_ISSUE_TYPE = "";
 43  
     private IssueManagementSystem ims;
 44  
 
 45  
     /**
 46  
      * Create a new adapter.
 47  
      *
 48  
      * @param ims The issue management system that has the data that should be adapted
 49  
      */
 50  
     public IssueAdapter( IssueManagementSystem ims )
 51  3
     {
 52  3
         this.ims = ims;
 53  3
     }
 54  
 
 55  
     private Map<String, IssueType> getIssueTypeMap()
 56  
     {
 57  21
         return ims.getIssueTypeMap();
 58  
     }
 59  
 
 60  
     /**
 61  
      * Adapt a <code>List</code> of <code>Issue</code>s to a <code>List</code> of <code>Release</code>s.
 62  
      * 
 63  
      * @param issues The issues
 64  
      * @return A list of releases
 65  
      */
 66  
     public List<Release> getReleases( List<Issue> issues )
 67  
     {
 68  
         // A Map of releases keyed by fixVersion
 69  0
         Map<String, Release> releasesMap = new HashMap<String, Release>();
 70  
 
 71  
         // Loop through all issues looking for fixVersions
 72  0
         for ( Issue issue : issues )
 73  
         {
 74  
             // Do NOT create a release for issues that lack a fixVersion
 75  0
             if ( issue.getFixVersions() != null )
 76  
             {
 77  0
                 for ( String fixVersion : issue.getFixVersions() )
 78  
                 {
 79  
                     // Try to get a matching Release from the map
 80  0
                     Release release = releasesMap.get( fixVersion );
 81  0
                     if ( release == null )
 82  
                     {
 83  
                         // Add a new Release to the Map if it wasn't there
 84  0
                         release = new Release();
 85  0
                         release.setVersion( fixVersion );
 86  0
                         releasesMap.put( fixVersion, release );
 87  
                     }
 88  
 
 89  
                     // Add this issue as an Action to this release
 90  0
                     Action action = createAction( issue );
 91  0
                     release.addAction( action );
 92  0
                 }
 93  
             }
 94  
         }
 95  
 
 96  
         // Extract the releases from the Map to a List
 97  0
         List<Release> releasesList = new ArrayList<Release>();
 98  0
         for ( Release release : releasesMap.values() )
 99  
         {
 100  0
             releasesList.add( release );
 101  
         }
 102  0
         return releasesList;
 103  
     }
 104  
 
 105  
     /**
 106  
      * Create an <code>Action</code> from an issue.
 107  
      * 
 108  
      * @param issue The issue to extract the information from
 109  
      * @return An <code>Action</code>
 110  
      */
 111  
     public Action createAction( Issue issue )
 112  
     {
 113  13
         Action action = new Action();
 114  
 
 115  
         // @todo We need to add something like issue.getPresentationIdentifier() to be able to support other IMSes
 116  
         // beside JIRA
 117  13
         action.setIssue( issue.getKey() );
 118  
 
 119  
         // Try to map the IMS-specific issue type to one that is used in a changes.xml file
 120  13
         IssueType type = null;
 121  13
         if ( getIssueTypeMap().containsKey( issue.getType() ) )
 122  
         {
 123  8
             type = getIssueTypeMap().get( issue.getType() );
 124  8
             action.setType( type.modelRepresentation() );
 125  
         }
 126  
         else
 127  
         {
 128  5
             action.setType( UNKNOWN_ISSUE_TYPE );
 129  
         }
 130  
 
 131  13
         action.setDev( issue.getAssignee() );
 132  
 
 133  
         // Set dueTo to the empty String instead of null to make Velocity happy
 134  13
         action.setDueTo( "" );
 135  
         // action.setDueTo( issue.getReporter() );
 136  
 
 137  13
         action.setAction( issue.getSummary() );
 138  13
         return action;
 139  
     }
 140  
 }