Skip to content

Commit

Permalink
[MJAVADOC-819] Align archive generation code with Maven Source Plugin
Browse files Browse the repository at this point in the history
This closes #332
  • Loading branch information
michael-o committed Oct 29, 2024
1 parent 3a90de5 commit 6c5fdc0
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions src/main/java/org/apache/maven/plugins/javadoc/JavadocJarMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,23 +221,14 @@ protected String getClassifier() {
* @throws IOException {@link IOException}
*/
private File generateArchive(File javadocFiles, String jarFileName) throws ArchiverException, IOException {
File javadocJar = new File(jarOutputDirectory, jarFileName);

if (javadocJar.exists()) {
javadocJar.delete();
}

MavenArchiver archiver = new MavenArchiver();
archiver.setCreatedBy("Maven Javadoc Plugin", "org.apache.maven.plugins", "maven-javadoc-plugin");
archiver.setArchiver(jarArchiver);
archiver.setOutputFile(javadocJar);
archiver.setCreatedBy("Maven Javadoc Plugin", "org.apache.maven.plugins", "maven-javadoc-plugin");

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

if (!javadocFiles.exists()) {
getLog().warn("JAR will be empty - no content was marked for inclusion!");
} else {
if (javadocFiles.exists()) {
archiver.getArchiver().addDirectory(javadocFiles, DEFAULT_INCLUDES, DEFAULT_EXCLUDES);
}

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

File outputFile = new File(jarOutputDirectory, jarFileName);

// Why do we do this?
if (outputFile.exists()) {
outputFile.delete();
}
archiver.setOutputFile(outputFile);

try {
archiver.createArchive(session, project, archive);
} catch (ManifestException e) {
throw new ArchiverException("ManifestException: " + e.getMessage(), e);
} catch (DependencyResolutionRequiredException e) {
throw new ArchiverException("DependencyResolutionRequiredException: " + e.getMessage(), e);
} catch (ManifestException | DependencyResolutionRequiredException e) {
throw new ArchiverException("Error creating Javadoc archive: " + e.getMessage(), e);
}

return javadocJar;
return outputFile;
}
}

0 comments on commit 6c5fdc0

Please sign in to comment.