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