1 package org.apache.maven.plugins.javadoc;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.artifact.Artifact;
23 import org.apache.maven.plugins.annotations.LifecyclePhase;
24 import org.apache.maven.plugins.annotations.Mojo;
25 import org.apache.maven.plugins.annotations.Parameter;
26 import org.apache.maven.plugins.annotations.ResolutionScope;
27 import org.apache.maven.plugins.javadoc.resolver.SourceResolverConfig;
28 import org.apache.maven.project.MavenProject;
29 import org.apache.maven.shared.artifact.filter.resolve.ScopeFilter;
30 import org.codehaus.plexus.util.StringUtils;
31
32 import java.io.File;
33 import java.util.ArrayList;
34 import java.util.Collections;
35 import java.util.List;
36
37
38
39
40
41
42
43
44
45 @Mojo( name = "test-jar", defaultPhase = LifecyclePhase.PACKAGE, requiresDependencyResolution = ResolutionScope.TEST,
46 threadSafe = true )
47 public class TestJavadocJar
48 extends JavadocJar
49 {
50
51
52
53
54
55
56
57
58
59
60 @Parameter( defaultValue = "${project.build.directory}/testapidocs", required = true )
61 private File outputDirectory;
62
63
64
65
66
67
68
69
70
71 @Parameter( property = "testDoctitle", alias = "doctitle",
72 defaultValue = "${project.name} ${project.version} Test API" )
73 private String testDoctitle;
74
75
76
77
78
79
80
81
82
83
84 @Parameter( property = "testOverview", alias = "overview",
85 defaultValue = "${basedir}/src/test/javadoc/overview.html" )
86 private File testOverview;
87
88
89
90
91
92
93
94
95
96
97 @Parameter( property = "testWindowtitle", alias = "windowtitle",
98 defaultValue = "${project.name} ${project.version} Test API" )
99 private String testWindowtitle;
100
101
102
103
104
105
106
107
108
109
110 @Parameter( alias = "javadocDirectory", defaultValue = "${basedir}/src/test/javadoc" )
111 private File testJavadocDirectory;
112
113
114
115
116 @Parameter( property = "maven.javadoc.testClassifier", defaultValue = "test-javadoc", required = true )
117 private String testClassifier;
118
119
120
121
122
123 @Override
124 protected String getClassifier()
125 {
126 return testClassifier;
127 }
128
129
130
131
132
133 @Override
134 protected String getOutputDirectory()
135 {
136 return outputDirectory.getAbsoluteFile().toString();
137 }
138
139 @Override
140 protected File getJavadocDirectory()
141 {
142 return testJavadocDirectory;
143 }
144
145 @Override
146 protected String getDoctitle()
147 {
148 return testDoctitle;
149 }
150
151 @Override
152 protected File getOverview()
153 {
154 return testOverview;
155 }
156
157 @Override
158 protected String getWindowtitle()
159 {
160 return testWindowtitle;
161 }
162
163 @Override
164 protected List<File> getProjectBuildOutputDirs( MavenProject p )
165 {
166 List<File> dirs = new ArrayList<>();
167 if ( StringUtils.isNotEmpty( p.getBuild().getOutputDirectory() ) )
168 {
169 dirs.add( new File( p.getBuild().getOutputDirectory() ) );
170 }
171 if ( StringUtils.isNotEmpty( p.getBuild().getTestOutputDirectory() ) )
172 {
173 dirs.add( new File( p.getBuild().getTestOutputDirectory() ) );
174 }
175
176 return dirs;
177 }
178
179 @Override
180 protected List<String> getProjectSourceRoots( MavenProject p )
181 {
182 if ( "pom".equals( p.getPackaging().toLowerCase() ) )
183 {
184 return Collections.emptyList();
185 }
186
187 return p.getTestCompileSourceRoots();
188 }
189
190 @Override
191 protected List<String> getExecutionProjectSourceRoots( MavenProject p )
192 {
193 if ( "pom".equals( p.getExecutionProject().getPackaging().toLowerCase() ) )
194 {
195 return Collections.emptyList();
196 }
197
198 return p.getExecutionProject().getTestCompileSourceRoots();
199 }
200
201 @Override
202 protected ScopeFilter getDependencyScopeFilter()
203 {
204 return ScopeFilter.including( Artifact.SCOPE_COMPILE, Artifact.SCOPE_PROVIDED, Artifact.SCOPE_SYSTEM,
205 Artifact.SCOPE_TEST );
206 }
207
208
209
210
211
212
213 @Override
214 protected SourceResolverConfig configureDependencySourceResolution( final SourceResolverConfig config )
215 {
216 return super.configureDependencySourceResolution( config ).withoutCompileSources().withTestSources();
217 }
218
219 @Override
220 protected boolean isTest()
221 {
222 return true;
223 }
224 }