View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.plugins.changes.issues;
20  
21  import java.util.HashMap;
22  import java.util.Map;
23  
24  import org.apache.maven.plugin.MojoExecutionException;
25  import org.apache.maven.plugins.changes.IssueType;
26  
27  /**
28   * Historically, this plugin started out working against an IMS-neutral XML file, and then added extensive support for
29   * JIRA with some small snippets of code for other issue management systems. This class is intended to start a cleaner
30   * modularity for support of multiple systems.<br>
31   * Initially, all it provides is a structure for mapping from per-IMS issue types to the three categories defined in
32   * {@link org.apache.maven.plugins.changes.IssueAdapter}. <br>
33   * Note that the map in here is <strong>not</strong> immutable. It contains the default configuration for an IMS. Users
34   * are expected to add entries to the map via configuration to reflect their customizations.
35   *
36   * @version $Id$
37   */
38  public abstract class AbstractIssueManagementSystem implements IssueManagementSystem {
39      protected Map<String, IssueType> issueTypeMap;
40  
41      protected AbstractIssueManagementSystem() {
42          issueTypeMap = new HashMap<>();
43      }
44  
45      /*
46       * (non-Javadoc)
47       * @see org.apache.maven.plugins.issues.IssueManagementSystem#getIssueTypeMap()
48       */
49      public Map<String, IssueType> getIssueTypeMap() {
50          return issueTypeMap;
51      }
52  
53      /*
54       * (non-Javadoc)
55       * @see org.apache.maven.plugins.issues.IssueManagementSystem#getName()
56       */
57      public abstract String getName();
58  
59      /*
60       * (non-Javadoc)
61       * @see org.apache.maven.plugins.issues.IssueManagementSystem#applyConfiguration(java.util.Map)
62       */
63      public void applyConfiguration(Map<String, String> issueTypes) throws MojoExecutionException {
64          for (Map.Entry<String, String> me : issueTypes.entrySet()) {
65              IssueType type = IssueType.lookupByKey(me.getKey());
66              if (type == null) {
67                  throw new MojoExecutionException("Invalid issue action " + me.getKey());
68              }
69              String imsTypes = me.getValue();
70              String[] imsTypeArray = imsTypes.split(",");
71              for (String imsType : imsTypeArray) {
72                  issueTypeMap.put(imsType, type);
73              }
74          }
75      }
76  }