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