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