View Javadoc
1   package org.apache.maven.plugin.jxr;
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.plugins.annotations.Mojo;
23  import org.apache.maven.plugins.annotations.Parameter;
24  import org.apache.maven.project.MavenProject;
25  
26  import java.io.File;
27  import java.util.ArrayList;
28  import java.util.Arrays;
29  import java.util.List;
30  import java.util.Locale;
31  
32  /**
33   * Creates an html-based, cross referenced version of Java source code
34   * for a project.
35   *
36   * @author <a href="mailto:bellingard.NO-SPAM@gmail.com">Fabrice Bellingard</a>
37   * @version $Id: JxrReport.java 1587311 2014-04-14 20:39:58Z hboutemy $
38   */
39  @Mojo( name = "jxr" )
40  public class JxrReport
41      extends AbstractJxrReport
42  {
43      /**
44       * Source directories of the project.
45       */
46      @Parameter( defaultValue = "${project.compileSourceRoots}", required = true, readonly = true )
47      private List<String> sourceDirs;
48  
49      /**
50       * Specifies the source path where the java files are located.
51       * The paths are separated by '<code>;</code>'.
52       */
53      @Parameter
54      private String sourcePath;
55  
56      /**
57       * Folder where the Xref files will be copied to.
58       */
59      @Parameter( defaultValue = "${project.reporting.outputDirectory}/xref" )
60      private String destDir;
61  
62      /**
63       * Folder where Javadoc is generated for this project.
64       */
65      @Parameter( defaultValue = "${project.reporting.outputDirectory}/apidocs" )
66      private File javadocDir;
67  
68      /**
69       * @see org.apache.maven.plugin.jxr.AbstractJxrReport#getDestinationDirectory()
70       */
71      protected String getDestinationDirectory()
72      {
73          return destDir;
74      }
75  
76      /**
77       * @see org.apache.maven.plugin.jxr.AbstractJxrReport#getSourceRoots()
78       */
79      protected List<String> getSourceRoots()
80      {
81          if ( sourcePath != null )
82          {
83              String[] sourcePathArray = sourcePath.split( ";" );
84              if ( sourcePathArray.length > 0 )
85              {
86                  return Arrays.asList( sourcePathArray );
87              }
88          }
89  
90          List<String> l = new ArrayList<String>();
91  
92          if ( !"pom".equals( getProject().getPackaging().toLowerCase() ) )
93          {
94              l.addAll( sourceDirs );
95          }
96  
97          if ( getProject().getExecutionProject() != null )
98          {
99              if ( !"pom".equals( getProject().getExecutionProject().getPackaging().toLowerCase() ) )
100             {
101                 l.addAll( getProject().getExecutionProject().getCompileSourceRoots() );
102             }
103         }
104 
105         return l;
106     }
107 
108     /**
109      * @see org.apache.maven.plugin.jxr.AbstractJxrReport#getSourceRoots(org.apache.maven.project.MavenProject)
110      */
111     protected List<String> getSourceRoots( MavenProject project )
112     {
113         List<String> l = new ArrayList<String>();
114 
115         if ( !"pom".equals( project.getPackaging().toLowerCase() ) )
116         {
117             l.addAll( project.getCompileSourceRoots() );
118         }
119 
120         if ( project.getExecutionProject() != null )
121         {
122             if ( !"pom".equals( project.getExecutionProject().getPackaging().toLowerCase() ) )
123             {
124                 l.addAll( project.getExecutionProject().getCompileSourceRoots() );
125             }
126         }
127 
128         return l;
129     }
130 
131     /**
132      * @see org.apache.maven.reporting.MavenReport#getDescription(java.util.Locale)
133      */
134     public String getDescription( Locale locale )
135     {
136         return getBundle( locale ).getString( "report.xref.main.description" );
137     }
138 
139     /**
140      * @see org.apache.maven.reporting.MavenReport#getName(java.util.Locale)
141      */
142     public String getName( Locale locale )
143     {
144         return getBundle( locale ).getString( "report.xref.main.name" );
145     }
146 
147     /**
148      * @see org.apache.maven.reporting.MavenReport#getOutputName()
149      */
150     public String getOutputName()
151     {
152         return "xref/index";
153     }
154 
155     /**
156      * @see org.apache.maven.plugin.jxr.AbstractJxrReport#getJavadocDir()
157      */
158     protected File getJavadocDir()
159     {
160         return javadocDir;
161     }
162 
163     /**
164      * @see org.apache.maven.reporting.AbstractMavenReport#setReportOutputDirectory(java.io.File)
165      */
166     public void setReportOutputDirectory( File reportOutputDirectory )
167     {
168         if ( ( reportOutputDirectory != null ) && ( !reportOutputDirectory.getAbsolutePath().endsWith( "xref" ) ) )
169         {
170             this.destDir = new File( reportOutputDirectory, "xref" ).getAbsolutePath();
171         }
172         else
173         {
174             this.destDir = reportOutputDirectory.getAbsolutePath();
175         }
176     }
177 }