1 package org.apache.maven.plugin.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.artifact.resolver.ArtifactResolutionResult;
24 import org.apache.maven.plugin.javadoc.resolver.SourceResolverConfig;
25 import org.apache.maven.plugins.annotations.LifecyclePhase;
26 import org.apache.maven.plugins.annotations.Mojo;
27 import org.apache.maven.plugins.annotations.Parameter;
28 import org.apache.maven.plugins.annotations.ResolutionScope;
29 import org.apache.maven.project.MavenProject;
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, threadSafe = true)
46 public class TestJavadocJar
47 extends JavadocJar
48 {
49
50
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
68
69
70 @Parameter( property = "testDoctitle", alias = "doctitle",
71 defaultValue = "${project.name} ${project.version} Test API" )
72 private String testDoctitle;
73
74
75
76
77
78
79
80
81
82
83 @Parameter( property = "testOverview", alias = "overview",
84 defaultValue = "${basedir}/src/test/javadoc/overview.html" )
85 private File testOverview;
86
87
88
89
90
91
92
93
94
95 @Parameter( property = "testWindowtitle", alias = "windowtitle",
96 defaultValue = "${project.name} ${project.version} Test API" )
97 private String testWindowtitle;
98
99
100
101
102
103
104
105
106
107
108 @Parameter( alias = "javadocDirectory", defaultValue = "${basedir}/src/test/javadoc" )
109 private File testJavadocDirectory;
110
111
112
113
114
115 @Override
116 protected String getClassifier()
117 {
118 return "test-javadoc";
119 }
120
121
122
123
124
125 @Override
126 protected String getOutputDirectory()
127 {
128 return outputDirectory.getAbsoluteFile().toString();
129 }
130
131 @Override
132 protected File getJavadocDirectory()
133 {
134 return testJavadocDirectory;
135 }
136
137 @Override
138 protected String getDoctitle()
139 {
140 return testDoctitle;
141 }
142
143 @Override
144 protected File getOverview()
145 {
146 return testOverview;
147 }
148
149 @Override
150 protected String getWindowtitle()
151 {
152 return testWindowtitle;
153 }
154
155 @Override
156 protected List<String> getProjectBuildOutputDirs( MavenProject p )
157 {
158 List<String> dirs = new ArrayList<String>();
159 if ( StringUtils.isNotEmpty( p.getBuild().getOutputDirectory() ) )
160 {
161 dirs.add( p.getBuild().getOutputDirectory() );
162 }
163 if ( StringUtils.isNotEmpty( p.getBuild().getTestOutputDirectory() ) )
164 {
165 dirs.add( p.getBuild().getTestOutputDirectory() );
166 }
167
168 return dirs;
169 }
170
171 @Override
172 protected List<String> getProjectSourceRoots( MavenProject p )
173 {
174 if ( "pom".equals( p.getPackaging().toLowerCase() ) )
175 {
176 return Collections.emptyList();
177 }
178
179 return p.getTestCompileSourceRoots();
180 }
181
182 @Override
183 protected List<String> getExecutionProjectSourceRoots( MavenProject p )
184 {
185 if ( "pom".equals( p.getExecutionProject().getPackaging().toLowerCase() ) )
186 {
187 return Collections.emptyList();
188 }
189
190 return p.getExecutionProject().getTestCompileSourceRoots();
191 }
192
193 @Override
194 protected List<Artifact> getProjectArtifacts( MavenProject p )
195 {
196 return p.getTestArtifacts();
197 }
198
199 @Override
200 protected List<Artifact> getCompileArtifacts( ArtifactResolutionResult result )
201 {
202 return JavadocUtil.getCompileArtifacts( result.getArtifacts(), true );
203 }
204
205
206
207
208
209
210 @Override
211 protected SourceResolverConfig configureDependencySourceResolution( final SourceResolverConfig config )
212 {
213 return super.configureDependencySourceResolution( config ).withoutCompileSources().withTestSources();
214 }
215 }