View Javadoc

1   package org.apache.maven.report.projectinfo;
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.doxia.sink.Sink;
23  import org.apache.maven.model.IssueManagement;
24  import org.apache.maven.model.Model;
25  import org.apache.maven.plugins.annotations.Mojo;
26  import org.codehaus.plexus.i18n.I18N;
27  import org.codehaus.plexus.util.StringUtils;
28  
29  import java.util.Locale;
30  
31  /**
32   * Generates the Project Issue Tracking report.
33   *
34   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton </a>
35   * @version $Id: IssueTrackingReport.html 861765 2013-05-12 18:46:29Z hboutemy $
36   * @since 2.0
37   */
38  @Mojo( name = "issue-tracking" )
39  public class IssueTrackingReport
40      extends AbstractProjectInfoReport
41  {
42      // ----------------------------------------------------------------------
43      // Public methods
44      // ----------------------------------------------------------------------
45  
46      @Override
47      public void executeReport( Locale locale )
48      {
49          IssueTrackingRenderer r = new IssueTrackingRenderer( getSink(), getProject().getModel(), getI18N( locale ), locale );
50  
51          r.render();
52      }
53  
54      /** {@inheritDoc} */
55      public String getOutputName()
56      {
57          return "issue-tracking";
58      }
59  
60      @Override
61      protected String getI18Nsection()
62      {
63          return "issuetracking";
64      }
65  
66      // ----------------------------------------------------------------------
67      // Private
68      // ----------------------------------------------------------------------
69  
70      /**
71       * Internal renderer class
72       */
73      private static class IssueTrackingRenderer
74          extends AbstractProjectInfoRenderer
75      {
76          private Model model;
77  
78          IssueTrackingRenderer( Sink sink, Model model, I18N i18n, Locale locale )
79          {
80              super( sink, i18n, locale );
81  
82              this.model = model;
83          }
84  
85          @Override
86          protected String getI18Nsection()
87          {
88              return "issuetracking";
89          }
90  
91          @Override
92          public void renderBody()
93          {
94              IssueManagement issueManagement = model.getIssueManagement();
95              if ( issueManagement == null )
96              {
97                  startSection( getTitle() );
98  
99                  paragraph( getI18nString( "noissueManagement" ) );
100 
101                 endSection();
102 
103                 return;
104             }
105 
106             String system = issueManagement.getSystem();
107             String url = issueManagement.getUrl();
108 
109             // Overview
110             startSection( getI18nString( "overview.title" ) );
111 
112             if ( isIssueManagementSystem( system, "jira" ) )
113             {
114                 sink.paragraph();
115                 linkPatternedText( getI18nString( "jira.intro" ) );
116                 sink.paragraph_();
117             }
118             else if ( isIssueManagementSystem( system, "bugzilla" ) )
119             {
120                 sink.paragraph();
121                 linkPatternedText( getI18nString( "bugzilla.intro" ) );
122                 sink.paragraph_();
123             }
124             else if ( isIssueManagementSystem( system, "scarab" ) )
125             {
126                 sink.paragraph();
127                 linkPatternedText( getI18nString( "scarab.intro" ) );
128                 sink.paragraph_();
129             }
130             else if ( system == null || "".equals( system.trim() ) )
131             {
132                 paragraph( getI18nString( "general.intro" ) );
133             }
134             else
135             {
136                 paragraph( getI18nString( "custom.intro" ).replaceFirst( "%issueManagementSystem%", system ) );
137             }
138 
139             endSection();
140 
141             // Connection
142             startSection( getTitle() );
143 
144             paragraph( getI18nString( "intro" ) );
145 
146             verbatimLink( url, url );
147 
148             endSection();
149         }
150 
151         /**
152          * Checks if a issue management system is Jira, bugzilla...
153          *
154          * @param system
155          * @param im
156          * @return true if the issue management system is Jira, bugzilla, false otherwise.
157          */
158         private boolean isIssueManagementSystem( String system, String im )
159         {
160             if ( StringUtils.isEmpty( system ) )
161             {
162                 return false;
163             }
164 
165             if ( StringUtils.isEmpty( im ) )
166             {
167                 return false;
168             }
169 
170             return system.toLowerCase( Locale.ENGLISH ).startsWith( im.toLowerCase( Locale.ENGLISH ) );
171         }
172     }
173 }