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.trac;
20  
21  import java.net.MalformedURLException;
22  import java.util.HashMap;
23  import java.util.List;
24  import java.util.Locale;
25  import java.util.Map;
26  import java.util.ResourceBundle;
27  
28  import org.apache.maven.plugins.annotations.Mojo;
29  import org.apache.maven.plugins.annotations.Parameter;
30  import org.apache.maven.plugins.changes.AbstractChangesReport;
31  import org.apache.maven.plugins.changes.ProjectUtils;
32  import org.apache.maven.plugins.changes.issues.Issue;
33  import org.apache.maven.plugins.changes.issues.IssuesReportHelper;
34  import org.apache.maven.plugins.changes.issues.IssuesReportRenderer;
35  import org.apache.maven.reporting.MavenReportException;
36  import org.apache.xmlrpc.XmlRpcException;
37  
38  /**
39   * Goal which downloads issues from the Issue Tracking System and generates a report.
40   *
41   * @author Noriko Kinugasa
42   * @version $Id$
43   * @since 2.1
44   * @deprecated prepared for removal in next major version due to lack of maintainers
45   */
46  @Deprecated
47  @Mojo(name = "trac-changes", threadSafe = true)
48  public class TracChangesReport extends AbstractChangesReport {
49  
50      /**
51       * Valid Trac columns.
52       */
53      private static final Map<String, Integer> TRAC_COLUMNS = new HashMap<>();
54  
55      static {
56          TRAC_COLUMNS.put("Assignee", IssuesReportHelper.COLUMN_ASSIGNEE);
57          TRAC_COLUMNS.put("Component", IssuesReportHelper.COLUMN_COMPONENT);
58          TRAC_COLUMNS.put("Created", IssuesReportHelper.COLUMN_CREATED);
59          TRAC_COLUMNS.put("Fix Version", IssuesReportHelper.COLUMN_FIX_VERSION);
60          TRAC_COLUMNS.put("Id", IssuesReportHelper.COLUMN_ID);
61          TRAC_COLUMNS.put("Priority", IssuesReportHelper.COLUMN_PRIORITY);
62          TRAC_COLUMNS.put("Reporter", IssuesReportHelper.COLUMN_REPORTER);
63          TRAC_COLUMNS.put("Resolution", IssuesReportHelper.COLUMN_RESOLUTION);
64          TRAC_COLUMNS.put("Status", IssuesReportHelper.COLUMN_STATUS);
65          TRAC_COLUMNS.put("Summary", IssuesReportHelper.COLUMN_SUMMARY);
66          TRAC_COLUMNS.put("Type", IssuesReportHelper.COLUMN_TYPE);
67          TRAC_COLUMNS.put("Updated", IssuesReportHelper.COLUMN_UPDATED);
68      }
69  
70      /**
71       * Sets the column names that you want to show in the report. The columns will appear in the report in the same
72       * order as you specify them here. Multiple values can be separated by commas.
73       * <p>
74       * Valid columns are: <code>Assignee</code>, <code>Component</code>, <code>Created</code>, <code>Fix Version</code>,
75       * <code>Id</code>, <code>Priority</code>, <code>Reporter</code>, <code>Resolution</code>, <code>Status</code>,
76       * <code>Summary</code>, <code>Type</code> and <code>Updated</code>.
77       * </p>
78       *
79       * @since 2.2
80       */
81      @Parameter(defaultValue = "Id,Type,Summary,Assignee,Reporter,Priority,Status,Resolution,Created,Updated")
82      private String columnNames;
83  
84      /**
85       * Defines the Trac query for searching ticket.
86       */
87      @Parameter(defaultValue = "order=id")
88      private String query;
89  
90      /**
91       * Defines the Trac password for authentication into a private Trac installation.
92       */
93      @Parameter
94      private String tracPassword;
95  
96      /**
97       * Defines the Trac username for authentication into a private Trac installation.
98       */
99      @Parameter
100     private String tracUser;
101 
102     /* --------------------------------------------------------------------- */
103     /* Public methods */
104     /* --------------------------------------------------------------------- */
105 
106     /**
107      * @see org.apache.maven.reporting.AbstractMavenReport#canGenerateReport()
108      */
109     @Override
110     public boolean canGenerateReport() {
111         // Run only at the execution root
112         if (runOnlyAtExecutionRoot && !isThisTheExecutionRoot()) {
113             getLog().info("Skipping the Trac Report in this project because it's not the Execution Root");
114             return false;
115         }
116         String message = ProjectUtils.validateIssueManagement(project, "Trac", "Trac Report");
117         if (message != null) {
118             getLog().warn(message);
119         }
120         return message == null;
121     }
122 
123     @Override
124     public void executeReport(Locale locale) throws MavenReportException {
125         // Validate parameters
126         List<Integer> columnIds = IssuesReportHelper.getColumnIds(columnNames, TRAC_COLUMNS);
127         if (columnIds.isEmpty()) {
128             // This can happen if the user has configured column names and they are all invalid
129             throw new MavenReportException(
130                     "maven-changes-plugin: None of the configured columnNames '" + columnNames + "' are valid.");
131         }
132 
133         try {
134             // Download issues
135             TracDownloader issueDownloader = new TracDownloader();
136             configureIssueDownloader(issueDownloader);
137 
138             List<Issue> issueList = issueDownloader.getIssueList();
139 
140             // Generate the report
141             IssuesReportRenderer report = new IssuesReportRenderer(getSink(), getBundle(locale), columnIds, issueList);
142             report.render();
143 
144         } catch (MalformedURLException e) {
145             // Rethrow this error so that the build fails
146             throw new MavenReportException("The Trac URL is incorrect.");
147         } catch (XmlRpcException e) {
148             // Rethrow this error so that the build fails
149             throw new MavenReportException("XmlRpc Error.", e);
150         } catch (Exception e) {
151             throw new MavenReportException(e.getMessage(), e);
152         }
153     }
154 
155     @Override
156     public String getDescription(Locale locale) {
157         return getBundle(locale).getString("report.issues.description");
158     }
159 
160     @Override
161     public String getName(Locale locale) {
162         return getBundle(locale).getString("report.issues.name");
163     }
164 
165     @Override
166     @Deprecated
167     public String getOutputName() {
168         return "trac-changes";
169     }
170 
171     /* --------------------------------------------------------------------- */
172     /* Private methods */
173     /* --------------------------------------------------------------------- */
174 
175     private ResourceBundle getBundle(Locale locale) {
176         return ResourceBundle.getBundle("trac-report", locale, this.getClass().getClassLoader());
177     }
178 
179     private void configureIssueDownloader(TracDownloader issueDownloader) {
180         issueDownloader.setProject(project);
181         issueDownloader.setQuery(query);
182         issueDownloader.setTracPassword(tracPassword);
183         issueDownloader.setTracUser(tracUser);
184     }
185 }