1 package org.apache.maven.plugin.javadoc; 2 3 /* 4 * Licensed to the Apache Software Foundation (ASF) under one 5 * or more contributor license agreements. See the NOTICE file 6 * distributed with this work for additional information 7 * regarding copyright ownership. The ASF licenses this file 8 * to you under the Apache License, Version 2.0 (the 9 * "License"); you may not use this file except in compliance 10 * with the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, 15 * software distributed under the License is distributed on an 16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 * KIND, either express or implied. See the License for the 18 * specific language governing permissions and limitations 19 * under the License. 20 */ 21 22 import java.io.File; 23 import java.util.ArrayList; 24 import java.util.Collections; 25 import java.util.List; 26 27 import org.apache.maven.artifact.resolver.ArtifactResolutionResult; 28 import org.apache.maven.plugin.javadoc.resolver.SourceResolverConfig; 29 import org.apache.maven.project.MavenProject; 30 import org.codehaus.plexus.util.StringUtils; 31 32 /** 33 * Bundles the Javadoc documentation for <code>test Java code</code> in an <b>NON aggregator</b> project into 34 * a jar using the standard <a href="http://java.sun.com/j2se/javadoc/">Javadoc Tool</a>. 35 * 36 * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a> 37 * @version $Id$ 38 * @since 2.5 39 * @goal test-jar 40 * @phase package 41 * @requiresDependencyResolution test 42 */ 43 public class TestJavadocJar 44 extends JavadocJar 45 { 46 // ---------------------------------------------------------------------- 47 // Javadoc Options (should be inline with Javadoc options defined in TestJavadocReport) 48 // ---------------------------------------------------------------------- 49 50 /** 51 * Specifies the destination directory where Javadoc saves the generated HTML files. 52 * <br/> 53 * See <a href="http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/javadoc.html#d">d</a>. 54 * <br/> 55 * 56 * @parameter default-value="${project.build.directory}/testapidocs" 57 * @required 58 */ 59 private File outputDirectory; 60 61 /** 62 * Specifies the Test title to be placed near the top of the overview summary file. 63 * <br/> 64 * See <a href="http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/javadoc.html#doctitle">doctitle</a>. 65 * <br/> 66 * 67 * @parameter expression="${testDoctitle}" alias="doctitle" 68 * default-value="${project.name} ${project.version} Test API" 69 * @since 2.5 70 */ 71 private String testDoctitle; 72 73 /** 74 * Specifies that Javadoc should retrieve the text for the Test overview documentation from the "source" file 75 * specified by path/filename and place it on the Overview page (overview-summary.html). 76 * <br/> 77 * See <a href="http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/javadoc.html#overview">overview</a>. 78 * <br/> 79 * 80 * @parameter expression="${testOverview}" alias="overview" 81 * default-value="${basedir}/src/test/javadoc/overview.html" 82 * @since 2.5 83 */ 84 private File testOverview; 85 86 /** 87 * Specifies the Test title to be placed in the HTML title tag. 88 * <br/> 89 * See <a href="http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/javadoc.html#windowtitle">windowtitle</a>. 90 * <br/> 91 * 92 * @parameter expression="${testWindowtitle}" alias="windowtitle" 93 * default-value="${project.name} ${project.version} Test API" 94 * @since 2.5 95 */ 96 private String testWindowtitle; 97 98 // ---------------------------------------------------------------------- 99 // Mojo Parameters (should be inline with options defined in TestJavadocReport) 100 // ---------------------------------------------------------------------- 101 102 /** 103 * Specifies the Test Javadoc resources directory to be included in the Javadoc (i.e. package.html, images...). 104 * 105 * @parameter expression="${basedir}/src/test/javadoc" alias="javadocDirectory" 106 * @since 2.5 107 */ 108 private File testJavadocDirectory; 109 110 // ---------------------------------------------------------------------- 111 // Protected methods 112 // ---------------------------------------------------------------------- 113 114 /** {@inheritDoc} */ 115 protected String getClassifier() 116 { 117 return "test-javadoc"; 118 } 119 120 // ---------------------------------------------------------------------- 121 // Important Note: should be inline with methods defined in TestJavadocReport 122 // ---------------------------------------------------------------------- 123 124 /** {@inheritDoc} */ 125 protected String getOutputDirectory() 126 { 127 return outputDirectory.getAbsoluteFile().toString(); 128 } 129 130 /** {@inheritDoc} */ 131 protected File getJavadocDirectory() 132 { 133 return testJavadocDirectory; 134 } 135 136 /** {@inheritDoc} */ 137 protected String getDoctitle() 138 { 139 return testDoctitle; 140 } 141 142 /** {@inheritDoc} */ 143 protected File getOverview() 144 { 145 return testOverview; 146 } 147 148 /** {@inheritDoc} */ 149 protected String getWindowtitle() 150 { 151 return testWindowtitle; 152 } 153 154 /** {@inheritDoc} */ 155 protected List getProjectBuildOutputDirs( MavenProject p ) 156 { 157 List dirs = new ArrayList(); 158 if ( StringUtils.isNotEmpty( p.getBuild().getOutputDirectory() ) ) 159 { 160 dirs.add( p.getBuild().getOutputDirectory() ); 161 } 162 if ( StringUtils.isNotEmpty( p.getBuild().getTestOutputDirectory() ) ) 163 { 164 dirs.add( p.getBuild().getTestOutputDirectory() ); 165 } 166 167 return dirs; 168 } 169 170 /** {@inheritDoc} */ 171 protected List getProjectSourceRoots( MavenProject p ) 172 { 173 if ( "pom".equals( p.getPackaging().toLowerCase() ) ) 174 { 175 return Collections.EMPTY_LIST; 176 } 177 178 return p.getTestCompileSourceRoots(); 179 } 180 181 /** {@inheritDoc} */ 182 protected List getExecutionProjectSourceRoots( MavenProject p ) 183 { 184 if ( "pom".equals( p.getExecutionProject().getPackaging().toLowerCase() ) ) 185 { 186 return Collections.EMPTY_LIST; 187 } 188 189 return p.getExecutionProject().getTestCompileSourceRoots(); 190 } 191 192 /** {@inheritDoc} */ 193 protected List getProjectArtifacts( MavenProject p ) 194 { 195 return p.getTestArtifacts(); 196 } 197 198 /** {@inheritDoc} */ 199 protected List getCompileArtifacts( ArtifactResolutionResult result ) 200 { 201 return JavadocUtil.getCompileArtifacts( result.getArtifacts(), true ); 202 } 203 204 /** 205 * Overriden to enable the resolution of -test-sources jar files. 206 * 207 * {@inheritDoc} 208 */ 209 protected SourceResolverConfig configureDependencySourceResolution( final SourceResolverConfig config ) 210 { 211 return super.configureDependencySourceResolution( config ).withoutCompileSources().withTestSources(); 212 } 213 }