Author: michaelo Date: Thu Dec 17 22:33:10 2015 New Revision: 1720689 URL: http://svn.apache.org/viewvc?rev=1720689&view=rev Log: [MJAVADOC-431] Allow Javadoc Jar to contain Maven descriptor
Contributed by: Peter Lynch <[email protected]> This closes #73 Added: maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/JavadocArchiveConfiguration.java maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/stubs/JavadocJarArchiveConfigProjectStub.java maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/javadocjar-archive-config/ maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/javadocjar-archive-config/javadocjar/ maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/javadocjar-archive-config/javadocjar-archive-config.xml maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/javadocjar-archive-config/javadocjar/def/ maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/javadocjar-archive-config/javadocjar/def/App.java Modified: maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/JavadocJar.java maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/JavadocJarTest.java Added: maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/JavadocArchiveConfiguration.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/JavadocArchiveConfiguration.java?rev=1720689&view=auto ============================================================================== --- maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/JavadocArchiveConfiguration.java (added) +++ maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/JavadocArchiveConfiguration.java Thu Dec 17 22:33:10 2015 @@ -0,0 +1,36 @@ +package org.apache.maven.plugin.javadoc; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.maven.archiver.MavenArchiveConfiguration; + +/** + * For backwards compatibility, a custom archive configuration that defaults to not including the Maven descriptor. + * + * @see <a href="https://issues.apache.org/browse/MJAVADOC-431">MJAVADOC-431</a> + */ +public class JavadocArchiveConfiguration + extends MavenArchiveConfiguration +{ + public JavadocArchiveConfiguration() + { + setAddMavenDescriptor( false ); + } +} Modified: maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/JavadocJar.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/JavadocJar.java?rev=1720689&r1=1720688&r2=1720689&view=diff ============================================================================== --- maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/JavadocJar.java (original) +++ maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/JavadocJar.java Thu Dec 17 22:33:10 2015 @@ -130,7 +130,7 @@ public class JavadocJar * @since 2.5 */ @Parameter - private MavenArchiveConfiguration archive = new MavenArchiveConfiguration(); + private MavenArchiveConfiguration archive = new JavadocArchiveConfiguration(); /** * Path to the default MANIFEST file to use. It will be used if @@ -295,8 +295,6 @@ public class JavadocJar try { - // we don't want Maven stuff - archive.setAddMavenDescriptor( false ); archiver.createArchive( session, project, archive ); } catch ( ManifestException e ) Modified: maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/JavadocJarTest.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/JavadocJarTest.java?rev=1720689&r1=1720688&r2=1720689&view=diff ============================================================================== --- maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/JavadocJarTest.java (original) +++ maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/JavadocJarTest.java Thu Dec 17 22:33:10 2015 @@ -23,9 +23,11 @@ import org.apache.maven.plugin.testing.A import org.codehaus.plexus.util.FileUtils; import java.io.File; +import java.util.ArrayList; import java.util.Enumeration; -import java.util.Set; import java.util.HashSet; +import java.util.List; +import java.util.Set; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -134,4 +136,41 @@ public class JavadocJarTest new File( getBasedir(), "target/test/unit/javadocjar-failonerror/target/javadocjar-failonerror-javadoc.jar" ); assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) ); } + + public void testIncludeMavenDescriptorWhenExplicitlyConfigured() throws Exception + { + File testPom = + new File( getBasedir(), "src/test/resources/unit/javadocjar-archive-config/javadocjar-archive-config.xml" ); + JavadocJar mojo = (JavadocJar) lookupMojo( "jar", testPom ); + mojo.execute(); + + //check if the javadoc jar file was generated + File generatedFile = + new File( getBasedir(), "target/test/unit/javadocjar-archive-config/target/javadocjar-archive-config-javadoc.jar" ); + assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) ); + + //validate contents of jar file + ZipFile jar = new ZipFile( generatedFile ); + Set<String> set = new HashSet<String>(); + for (Enumeration<? extends ZipEntry> entries = jar.entries(); entries.hasMoreElements(); ) + { + ZipEntry entry = entries.nextElement(); + set.add( entry.getName() ); + } + jar.close(); + + List<String> expected = new ArrayList(); + expected.add( "META-INF/" ); + expected.add( "META-INF/maven/" ); + expected.add( "META-INF/maven/org.apache.maven.plugins.maven-javadoc-plugin.unit/" ); + expected.add( "META-INF/maven/org.apache.maven.plugins.maven-javadoc-plugin.unit/javadocjar-archive-config/" ); + expected.add( "META-INF/maven/org.apache.maven.plugins.maven-javadoc-plugin.unit/javadocjar-archive-config/pom.xml" ); + expected.add( "META-INF/maven/org.apache.maven.plugins.maven-javadoc-plugin.unit/javadocjar-archive-config/pom.properties" ); + + for (int i = 0; i < expected.size(); i++) + { + String entry = expected.get( i ); + assertTrue( "Expected jar to contain " + entry, set.contains( entry ) ); + } + } } Added: maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/stubs/JavadocJarArchiveConfigProjectStub.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/stubs/JavadocJarArchiveConfigProjectStub.java?rev=1720689&view=auto ============================================================================== --- maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/stubs/JavadocJarArchiveConfigProjectStub.java (added) +++ maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/stubs/JavadocJarArchiveConfigProjectStub.java Thu Dec 17 22:33:10 2015 @@ -0,0 +1,96 @@ +package org.apache.maven.plugin.javadoc.stubs; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.maven.model.Build; +import org.apache.maven.model.Scm; +import org.apache.maven.plugin.testing.stubs.MavenProjectStub; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +/** + * Project stub for testing archive configuration. + */ +public class JavadocJarArchiveConfigProjectStub + extends MavenProjectStub +{ + private Scm scm; + + public JavadocJarArchiveConfigProjectStub() + { + File projectFile = new File( getBasedir(), "javadocjar-archive-config.xml" ); + readModel( new File( getBasedir(), "javadocjar-archive-config.xml" ) ); + + setFile( projectFile ); + + setGroupId( getModel().getGroupId() ); + setArtifactId( getModel().getArtifactId() ); + setVersion( getModel().getVersion() ); + setName( getModel().getName() ); + setUrl( getModel().getUrl() ); + setPackaging( getModel().getPackaging() ); + + Scm scm = new Scm(); + scm.setConnection( "scm:svn:http://svn.apache.org/maven/sample/trunk" ); + setScm( scm ); + + JavadocPluginArtifactStub artifact = + new JavadocPluginArtifactStub( getGroupId(), getArtifactId(), getVersion(), getPackaging() ); + artifact.setArtifactHandler( new DefaultArtifactHandlerStub() ); + artifact.setType( "jar" ); + artifact.setBaseVersion( "1.0-SNAPSHOT" ); + setArtifact( artifact ); + + Build build = new Build(); + build.setFinalName( "javadocjar-archive-config" ); + build.setDirectory( super.getBasedir() + "/target/test/unit/javadocjar-archive-config/target" ); + setBuild( build ); + + List<String> compileSourceRoots = new ArrayList<String>(); + compileSourceRoots.add( getBasedir() + "/javadocjar/def" ); + setCompileSourceRoots( compileSourceRoots ); + } + + /** + * {@inheritDoc} + */ + public Scm getScm() + { + return scm; + } + + /** + * {@inheritDoc} + */ + public void setScm(Scm scm) + { + this.scm = scm; + } + + /** + * {@inheritDoc} + */ + public File getBasedir() + { + return new File( super.getBasedir() + "/src/test/resources/unit/javadocjar-archive-config" ); + } +} Added: maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/javadocjar-archive-config/javadocjar-archive-config.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/javadocjar-archive-config/javadocjar-archive-config.xml?rev=1720689&view=auto ============================================================================== --- maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/javadocjar-archive-config/javadocjar-archive-config.xml (added) +++ maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/javadocjar-archive-config/javadocjar-archive-config.xml Thu Dec 17 22:33:10 2015 @@ -0,0 +1,83 @@ +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <groupId>org.apache.maven.plugins.maven-javadoc-plugin.unit</groupId> + <artifactId>javadocjar-archive-config</artifactId> + <packaging>jar</packaging> + <version>1.0-SNAPSHOT</version> + <inceptionYear>2006</inceptionYear> + <name>Maven Javadoc Plugin Javadoc Jar Archive Config Test</name> + <url>http://maven.apache.org</url> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-javadoc-plugin</artifactId> + <configuration> + <project implementation="org.apache.maven.plugin.javadoc.stubs.JavadocJarArchiveConfigProjectStub"/> + <localRepository>${localRepository}</localRepository> + <jarOutputDirectory>${basedir}/target/test/unit/javadocjar-archive-config/target</jarOutputDirectory> + <outputDirectory>${basedir}/target/test/unit/javadocjar-archive-config/target/site/apidocs</outputDirectory> + <javadocOptionsDir>${basedir}/target/test/unit/javadocjar-archive-config/target/javadoc-bundle-options</javadocOptionsDir> + <finalName>javadocjar-archive-config</finalName> + <classifier>javadoc</classifier> + <attach>true</attach> + <breakiterator>false</breakiterator> + <old>false</old> + <show>protected</show> + <quiet>true</quiet> + <verbose>false</verbose> + <author>true</author> + <encoding>ISO-8859-1</encoding> + <docfilessubdirs>false</docfilessubdirs> + <linksource>false</linksource> + <nocomment>false</nocomment> + <nodeprecated>false</nodeprecated> + <nodeprecatedlist>false</nodeprecatedlist> + <nohelp>false</nohelp> + <noindex>false</noindex> + <nonavbar>false</nonavbar> + <nosince>false</nosince> + <notree>false</notree> + <serialwarn>false</serialwarn> + <splitindex>false</splitindex> + <stylesheet>java</stylesheet> + <!--commas in following elements are to test MJAVADOC-93--> + <doctitle>doc,title</doctitle> + <bottom>bottom,comma test</bottom> + <footer>my footer, and something</footer> + <header>my header, and something else</header> + <windowtitle>Maven Javadoc Plugin, Javadoc Jar Default Config Test 1.0-SNAPSHOT API</windowtitle> + <groups/> + <tags/> + <use>true</use> + <version>true</version> + <debug>true</debug> + <failOnError>true</failOnError> + <archive> + <addMavenDescriptor>true</addMavenDescriptor> + </archive> + </configuration> + </plugin> + </plugins> + </build> +</project> Added: maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/javadocjar-archive-config/javadocjar/def/App.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/javadocjar-archive-config/javadocjar/def/App.java?rev=1720689&view=auto ============================================================================== --- maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/javadocjar-archive-config/javadocjar/def/App.java (added) +++ maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/javadocjar-archive-config/javadocjar/def/App.java Thu Dec 17 22:33:10 2015 @@ -0,0 +1,48 @@ +package javadocjar.def; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * This is a sample app class with javadoc + */ +public class App +{ + + /** + * The main method + * + * @param args an array of strings that contains the arguments + */ + public static void main(String[] args) + { + System.out.println( "Sample Application." ); + } + + /** + * Sample method + * + * @param str the string to be displayed + */ + protected void sampleMethod(String str) + { + System.out.println( str ); + } + +}
