diff --git a/src/it/projects/MJAVADOC-812/invoker.properties b/src/it/projects/MJAVADOC-812/invoker.properties new file mode 100644 index 00000000..8f6fc7b0 --- /dev/null +++ b/src/it/projects/MJAVADOC-812/invoker.properties @@ -0,0 +1,19 @@ +# 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. + +invoker.goals = javadoc:jar + diff --git a/src/it/projects/MJAVADOC-812/pom.xml b/src/it/projects/MJAVADOC-812/pom.xml new file mode 100644 index 00000000..c68d0e95 --- /dev/null +++ b/src/it/projects/MJAVADOC-812/pom.xml @@ -0,0 +1,37 @@ + + + + 4.0.0 + + org.apache.maven.plugins.javadoc.it + mjavadoc812 + 1.0-SNAPSHOT + jar + + https://issues.apache.org/jira/browse/MJAVADOC-812 + + + UTF-8 + + + + + + maven-javadoc-plugin + @project.version@ + + + + diff --git a/src/it/projects/MJAVADOC-812/verify.groovy b/src/it/projects/MJAVADOC-812/verify.groovy new file mode 100644 index 00000000..5fcc9494 --- /dev/null +++ b/src/it/projects/MJAVADOC-812/verify.groovy @@ -0,0 +1,22 @@ +/* + * 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. + */ + +def javadocJar = new File( basedir, 'target/mjavadoc812-1.0-SNAPSHOT-javadoc.jar') + +assert !javadocJar.exists() diff --git a/src/main/java/org/apache/maven/plugins/javadoc/JavadocJarMojo.java b/src/main/java/org/apache/maven/plugins/javadoc/JavadocJarMojo.java index 6a58e10b..f8ec1162 100644 --- a/src/main/java/org/apache/maven/plugins/javadoc/JavadocJarMojo.java +++ b/src/main/java/org/apache/maven/plugins/javadoc/JavadocJarMojo.java @@ -171,24 +171,28 @@ protected void doExecute() throws MojoExecutionException { failOnError("RuntimeException: Error while generating Javadoc", e); } - try { - File outputFile = generateArchive( - new File(getPluginReportOutputDirectory()), finalName + "-" + getClassifier() + ".jar"); - - if (!attach) { - getLog().info("NOT adding javadoc to attached artifacts list."); - } else { - // TODO: these introduced dependencies on the project are going to become problematic - can we - // export it - // through metadata instead? - projectHelper.attachArtifact(project, "javadoc", getClassifier(), outputFile); + File javadocOutputDirectory = new File(getPluginReportOutputDirectory()); + if (javadocOutputDirectory.exists()) { + try { + File outputFile = generateArchive(javadocOutputDirectory, finalName + "-" + getClassifier() + ".jar"); + + if (!attach) { + getLog().info("NOT adding javadoc to attached artifacts list."); + } else { + // TODO: these introduced dependencies on the project are going to become problematic - can we + // export it + // through metadata instead? + projectHelper.attachArtifact(project, "javadoc", getClassifier(), outputFile); + } + } catch (ArchiverException e) { + failOnError("ArchiverException: Error while creating archive", e); + } catch (IOException e) { + failOnError("IOException: Error while creating archive", e); + } catch (RuntimeException e) { + failOnError("RuntimeException: Error while creating archive", e); } - } catch (ArchiverException e) { - failOnError("ArchiverException: Error while creating archive", e); - } catch (IOException e) { - failOnError("IOException: Error while creating archive", e); - } catch (RuntimeException e) { - failOnError("RuntimeException: Error while creating archive", e); + } else { + getLog().info("No Javadoc in project. Archive not created."); } }