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