Skip to content

Commit 6c5fdc0

Browse files
committed
[MJAVADOC-819] Align archive generation code with Maven Source Plugin
This closes #332
1 parent 3a90de5 commit 6c5fdc0

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

Diff for: src/main/java/org/apache/maven/plugins/javadoc/JavadocJarMojo.java

+13-16
Original file line numberDiff line numberDiff line change
@@ -221,23 +221,14 @@ protected String getClassifier() {
221221
* @throws IOException {@link IOException}
222222
*/
223223
private File generateArchive(File javadocFiles, String jarFileName) throws ArchiverException, IOException {
224-
File javadocJar = new File(jarOutputDirectory, jarFileName);
225-
226-
if (javadocJar.exists()) {
227-
javadocJar.delete();
228-
}
229-
230224
MavenArchiver archiver = new MavenArchiver();
231-
archiver.setCreatedBy("Maven Javadoc Plugin", "org.apache.maven.plugins", "maven-javadoc-plugin");
232225
archiver.setArchiver(jarArchiver);
233-
archiver.setOutputFile(javadocJar);
226+
archiver.setCreatedBy("Maven Javadoc Plugin", "org.apache.maven.plugins", "maven-javadoc-plugin");
234227

235228
// configure for Reproducible Builds based on outputTimestamp value
236229
archiver.configureReproducibleBuild(outputTimestamp);
237230

238-
if (!javadocFiles.exists()) {
239-
getLog().warn("JAR will be empty - no content was marked for inclusion!");
240-
} else {
231+
if (javadocFiles.exists()) {
241232
archiver.getArchiver().addDirectory(javadocFiles, DEFAULT_INCLUDES, DEFAULT_EXCLUDES);
242233
}
243234

@@ -254,14 +245,20 @@ private File generateArchive(File javadocFiles, String jarFileName) throws Archi
254245
archive.setManifestFile(defaultManifestFile);
255246
}
256247

248+
File outputFile = new File(jarOutputDirectory, jarFileName);
249+
250+
// Why do we do this?
251+
if (outputFile.exists()) {
252+
outputFile.delete();
253+
}
254+
archiver.setOutputFile(outputFile);
255+
257256
try {
258257
archiver.createArchive(session, project, archive);
259-
} catch (ManifestException e) {
260-
throw new ArchiverException("ManifestException: " + e.getMessage(), e);
261-
} catch (DependencyResolutionRequiredException e) {
262-
throw new ArchiverException("DependencyResolutionRequiredException: " + e.getMessage(), e);
258+
} catch (ManifestException | DependencyResolutionRequiredException e) {
259+
throw new ArchiverException("Error creating Javadoc archive: " + e.getMessage(), e);
263260
}
264261

265-
return javadocJar;
262+
return outputFile;
266263
}
267264
}

0 commit comments

Comments
 (0)