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