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 java.util.List;
23  import java.util.Locale;
24  
25  import org.apache.maven.artifact.factory.ArtifactFactory;
26  import org.apache.maven.project.MavenProjectBuilder;
27  import org.apache.maven.report.projectinfo.dependencies.ManagementDependencies;
28  import org.apache.maven.report.projectinfo.dependencies.renderer.DependencyManagementRenderer;
29  
30  
31  /**
32   * Generates the Project Dependency Management report.
33   *
34   * @author Nick Stolwijk
35   * @version $Id: DependencyManagementReport.java 728546 2008-12-21 22:56:51Z bentmann $
36   * @since 2.1
37   * @goal dependency-management
38   * @requiresDependencyResolution test
39   */
40  public class DependencyManagementReport
41      extends AbstractProjectInfoReport
42  {
43      // ----------------------------------------------------------------------
44      // Mojo components
45      // ----------------------------------------------------------------------
46  
47      /**
48       * Maven Project Builder component.
49       *
50       * @component
51       */
52      private MavenProjectBuilder mavenProjectBuilder;
53  
54      /**
55       * Maven Artifact Factory component.
56       *
57       * @component
58       */
59      private ArtifactFactory artifactFactory;
60  
61      // ----------------------------------------------------------------------
62      // Mojo parameters
63      // ----------------------------------------------------------------------
64  
65      /**
66       * Remote repositories used for the project.
67       *
68       * @since 2.1
69       * @parameter expression="${project.remoteArtifactRepositories}"
70       */
71      private List remoteRepositories;
72  
73      /**
74       * Lazy instantiation for management dependencies.
75       */
76      private ManagementDependencies managementDependencies;
77  
78      // ----------------------------------------------------------------------
79      // Public methods
80      // ----------------------------------------------------------------------
81  
82      /** {@inheritDoc} */
83      public String getName( Locale locale )
84      {
85          return i18n.getString( "project-info-report", locale, "report.dependencyManagement.name" );
86      }
87  
88      /** {@inheritDoc} */
89      public String getDescription( Locale locale )
90      {
91          return i18n.getString( "project-info-report", locale, "report.dependencyManagement.description" );
92      }
93  
94      /** {@inheritDoc} */
95      public void executeReport( Locale locale )
96      {
97          DependencyManagementRenderer r = new DependencyManagementRenderer( getSink(), locale, i18n, getLog(),
98                                                                             getManagementDependencies(),
99                                                                             artifactFactory, mavenProjectBuilder,
100                                                                            remoteRepositories, localRepository );
101         r.render();
102     }
103 
104     /** {@inheritDoc} */
105     public String getOutputName()
106     {
107         return "dependency-management";
108     }
109 
110     /** {@inheritDoc} */
111     public boolean canGenerateReport()
112     {
113         return getManagementDependencies().hasDependencies();
114     }
115 
116     // ----------------------------------------------------------------------
117     // Private methods
118     // ----------------------------------------------------------------------
119 
120     private ManagementDependencies getManagementDependencies()
121     {
122         if ( managementDependencies != null )
123         {
124             return managementDependencies;
125         }
126 
127         if ( project.getDependencyManagement() == null )
128         {
129             managementDependencies = new ManagementDependencies( null );
130         }
131         else
132         {
133             managementDependencies = new ManagementDependencies( project.getDependencyManagement().getDependencies() );
134         }
135 
136         return managementDependencies;
137     }
138 }