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 TestJavadocJarMojo extends JavadocJarMojo {
51
52
53
54
55
56
57
58
59
60 @Parameter(
61 property = "testDoctitle",
62 alias = "doctitle",
63 defaultValue = "${project.name} ${project.version} Test API")
64 private String testDoctitle;
65
66
67
68
69
70
71
72 @Parameter(
73 property = "testOverview",
74 alias = "overview",
75 defaultValue = "${basedir}/src/test/javadoc/overview.html")
76 private File testOverview;
77
78
79
80
81
82
83 @Parameter(
84 property = "testWindowtitle",
85 alias = "windowtitle",
86 defaultValue = "${project.name} ${project.version} Test API")
87 private String testWindowtitle;
88
89
90
91
92
93
94
95
96
97
98 @Parameter(alias = "javadocDirectory", defaultValue = "${basedir}/src/test/javadoc")
99 private File testJavadocDirectory;
100
101
102
103
104 @Parameter(property = "maven.javadoc.testClassifier", defaultValue = "test-javadoc", required = true)
105 private String testClassifier;
106
107
108
109
110
111 @Override
112 protected String getClassifier() {
113 return testClassifier;
114 }
115
116
117
118
119
120 @Override
121 protected File getJavadocDirectory() {
122 return testJavadocDirectory;
123 }
124
125 @Override
126 protected String getDoctitle() {
127 return testDoctitle;
128 }
129
130 @Override
131 protected File getOverview() {
132 return testOverview;
133 }
134
135 @Override
136 protected String getWindowtitle() {
137 return testWindowtitle;
138 }
139
140 @Override
141 protected List<File> getProjectBuildOutputDirs(MavenProject p) {
142 List<File> dirs = new ArrayList<>();
143 if (StringUtils.isNotEmpty(p.getBuild().getOutputDirectory())) {
144 dirs.add(new File(p.getBuild().getOutputDirectory()));
145 }
146 if (StringUtils.isNotEmpty(p.getBuild().getTestOutputDirectory())) {
147 dirs.add(new File(p.getBuild().getTestOutputDirectory()));
148 }
149
150 return dirs;
151 }
152
153 @Override
154 protected List<String> getProjectSourceRoots(MavenProject p) {
155 if ("pom".equals(p.getPackaging().toLowerCase())) {
156 return Collections.emptyList();
157 }
158
159 return p.getTestCompileSourceRoots();
160 }
161
162 @Override
163 protected List<String> getExecutionProjectSourceRoots(MavenProject p) {
164 if ("pom".equals(p.getExecutionProject().getPackaging().toLowerCase())) {
165 return Collections.emptyList();
166 }
167
168 return p.getExecutionProject().getTestCompileSourceRoots();
169 }
170
171 @Override
172 protected ScopeDependencyFilter getDependencyScopeFilter() {
173 return new ScopeDependencyFilter(
174 Arrays.asList(
175 Artifact.SCOPE_COMPILE, Artifact.SCOPE_PROVIDED, Artifact.SCOPE_SYSTEM, Artifact.SCOPE_TEST),
176 null);
177 }
178
179
180
181
182
183
184 @Override
185 protected SourceResolverConfig configureDependencySourceResolution(final SourceResolverConfig config) {
186 return super.configureDependencySourceResolution(config)
187 .withoutCompileSources()
188 .withTestSources();
189 }
190
191 @Override
192 protected boolean isTest() {
193 return true;
194 }
195 }