1 package org.apache.maven.plugin.javadoc;
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.Collections;
25 import java.util.List;
26
27 import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
28 import org.apache.maven.project.MavenProject;
29 import org.codehaus.plexus.util.StringUtils;
30
31 /**
32 * Bundles the Javadoc documentation for <code>test Java code</code> in an <b>NON aggregator</b> project into
33 * a jar using the standard <a href="http://java.sun.com/j2se/javadoc/">Javadoc Tool</a>.
34 *
35 * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
36 * @version $Id: TestJavadocJar.html 829392 2012-08-19 17:29:37Z hboutemy $
37 * @since 2.5
38 * @goal test-jar
39 * @phase package
40 * @requiresDependencyResolution test
41 */
42 public class TestJavadocJar
43 extends JavadocJar
44 {
45 // ----------------------------------------------------------------------
46 // Javadoc Options (should be inline with Javadoc options defined in TestJavadocReport)
47 // ----------------------------------------------------------------------
48
49 /**
50 * Specifies the destination directory where Javadoc saves the generated HTML files.
51 * <br/>
52 * See <a href="http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/javadoc.html#d">d</a>.
53 * <br/>
54 *
55 * @parameter default-value="${project.build.directory}/testapidocs"
56 * @required
57 */
58 private File outputDirectory;
59
60 /**
61 * Specifies the Test title to be placed near the top of the overview summary file.
62 * <br/>
63 * See <a href="http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/javadoc.html#doctitle">doctitle</a>.
64 * <br/>
65 *
66 * @parameter expression="${testDoctitle}" alias="doctitle"
67 * default-value="${project.name} ${project.version} Test API"
68 * @since 2.5
69 */
70 private String testDoctitle;
71
72 /**
73 * Specifies that Javadoc should retrieve the text for the Test overview documentation from the "source" file
74 * specified by path/filename and place it on the Overview page (overview-summary.html).
75 * <br/>
76 * See <a href="http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/javadoc.html#overview">overview</a>.
77 * <br/>
78 *
79 * @parameter expression="${testOverview}" alias="overview"
80 * default-value="${basedir}/src/test/javadoc/overview.html"
81 * @since 2.5
82 */
83 private File testOverview;
84
85 /**
86 * Specifies the Test title to be placed in the HTML title tag.
87 * <br/>
88 * See <a href="http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/javadoc.html#windowtitle">windowtitle</a>.
89 * <br/>
90 *
91 * @parameter expression="${testWindowtitle}" alias="windowtitle"
92 * default-value="${project.name} ${project.version} Test API"
93 * @since 2.5
94 */
95 private String testWindowtitle;
96
97 // ----------------------------------------------------------------------
98 // Mojo Parameters (should be inline with options defined in TestJavadocReport)
99 // ----------------------------------------------------------------------
100
101 /**
102 * Specifies the Test Javadoc resources directory to be included in the Javadoc (i.e. package.html, images...).
103 *
104 * @parameter expression="${basedir}/src/test/javadoc" alias="javadocDirectory"
105 * @since 2.5
106 */
107 private File testJavadocDirectory;
108
109 // ----------------------------------------------------------------------
110 // Protected methods
111 // ----------------------------------------------------------------------
112
113 /** {@inheritDoc} */
114 protected String getClassifier()
115 {
116 return "test-javadoc";
117 }
118
119 // ----------------------------------------------------------------------
120 // Important Note: should be inline with methods defined in TestJavadocReport
121 // ----------------------------------------------------------------------
122
123 /** {@inheritDoc} */
124 protected String getOutputDirectory()
125 {
126 return outputDirectory.getAbsoluteFile().toString();
127 }
128
129 /** {@inheritDoc} */
130 protected File getJavadocDirectory()
131 {
132 return testJavadocDirectory;
133 }
134
135 /** {@inheritDoc} */
136 protected String getDoctitle()
137 {
138 return testDoctitle;
139 }
140
141 /** {@inheritDoc} */
142 protected File getOverview()
143 {
144 return testOverview;
145 }
146
147 /** {@inheritDoc} */
148 protected String getWindowtitle()
149 {
150 return testWindowtitle;
151 }
152
153 /** {@inheritDoc} */
154 protected List getProjectBuildOutputDirs( MavenProject p )
155 {
156 List dirs = new ArrayList();
157 if ( StringUtils.isNotEmpty( p.getBuild().getOutputDirectory() ) )
158 {
159 dirs.add( p.getBuild().getOutputDirectory() );
160 }
161 if ( StringUtils.isNotEmpty( p.getBuild().getTestOutputDirectory() ) )
162 {
163 dirs.add( p.getBuild().getTestOutputDirectory() );
164 }
165
166 return dirs;
167 }
168
169 /** {@inheritDoc} */
170 protected List getProjectSourceRoots( MavenProject p )
171 {
172 if ( "pom".equals( p.getPackaging().toLowerCase() ) )
173 {
174 return Collections.EMPTY_LIST;
175 }
176
177 return p.getTestCompileSourceRoots();
178 }
179
180 /** {@inheritDoc} */
181 protected List getExecutionProjectSourceRoots( MavenProject p )
182 {
183 if ( "pom".equals( p.getExecutionProject().getPackaging().toLowerCase() ) )
184 {
185 return Collections.EMPTY_LIST;
186 }
187
188 return p.getExecutionProject().getTestCompileSourceRoots();
189 }
190
191 /** {@inheritDoc} */
192 protected List getProjectArtifacts( MavenProject p )
193 {
194 return p.getTestArtifacts();
195 }
196
197 /** {@inheritDoc} */
198 protected List getCompileArtifacts( ArtifactResolutionResult result )
199 {
200 return JavadocUtil.getCompileArtifacts( result.getArtifacts(), true );
201 }
202 }