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 940323 2010-05-02 22:07:05Z hboutemy $
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 void executeReport( Locale locale )
84      {
85          DependencyManagementRenderer r = new DependencyManagementRenderer( getSink(), locale, i18n, getLog(),
86                                                                             getManagementDependencies(),
87                                                                             artifactFactory, mavenProjectBuilder,
88                                                                             remoteRepositories, localRepository );
89          r.render();
90      }
91  
92      /** {@inheritDoc} */
93      public String getOutputName()
94      {
95          return "dependency-management";
96      }
97  
98      protected String getI18Nsection()
99      {
100         return "dependencyManagement";
101     }
102 
103     /** {@inheritDoc} */
104     public boolean canGenerateReport()
105     {
106         return getManagementDependencies().hasDependencies();
107     }
108 
109     // ----------------------------------------------------------------------
110     // Private methods
111     // ----------------------------------------------------------------------
112 
113     private ManagementDependencies getManagementDependencies()
114     {
115         if ( managementDependencies != null )
116         {
117             return managementDependencies;
118         }
119 
120         if ( project.getDependencyManagement() == null )
121         {
122             managementDependencies = new ManagementDependencies( null );
123         }
124         else
125         {
126             managementDependencies = new ManagementDependencies( project.getDependencyManagement().getDependencies() );
127         }
128 
129         return managementDependencies;
130     }
131 }