Merge pull request #33350 from StitzL

* pr/33350:
  Improve log message when repackaging by specifying the involved files

Closes gh-33350
This commit is contained in:
Moritz Halbritter 2023-01-31 13:29:18 +01:00
commit db80fc1734
2 changed files with 12 additions and 5 deletions

View File

@ -65,7 +65,9 @@ class JarIntegrationTests extends AbstractArchiveIntegrationTests {
.hasEntryWithNameStartingWith("BOOT-INF/lib/jakarta.servlet-api-6") .hasEntryWithNameStartingWith("BOOT-INF/lib/jakarta.servlet-api-6")
.hasEntryWithName("BOOT-INF/classes/org/test/SampleApplication.class") .hasEntryWithName("BOOT-INF/classes/org/test/SampleApplication.class")
.hasEntryWithName("org/springframework/boot/loader/JarLauncher.class"); .hasEntryWithName("org/springframework/boot/loader/JarLauncher.class");
assertThat(buildLog(project)).contains("Replacing main artifact with repackaged archive") assertThat(buildLog(project))
.contains("Replacing main artifact " + repackaged + " with repackaged archive,")
.contains("The original artifact has been renamed to " + original)
.contains("Installing " + repackaged + " to").doesNotContain("Installing " + original + " to"); .contains("Installing " + repackaged + " to").doesNotContain("Installing " + original + " to");
}); });
} }
@ -107,7 +109,9 @@ class JarIntegrationTests extends AbstractArchiveIntegrationTests {
assertThat(original).isFile(); assertThat(original).isFile();
File repackaged = new File(project, "target/jar-classifier-source-0.0.1.BUILD-SNAPSHOT-test.jar"); File repackaged = new File(project, "target/jar-classifier-source-0.0.1.BUILD-SNAPSHOT-test.jar");
assertThat(jar(repackaged)).hasEntryWithNameStartingWith("BOOT-INF/classes/"); assertThat(jar(repackaged)).hasEntryWithNameStartingWith("BOOT-INF/classes/");
assertThat(buildLog(project)).contains("Replacing artifact with classifier test with repackaged archive") assertThat(buildLog(project))
.contains("Replacing artifact with classifier test " + repackaged + " with repackaged archive,")
.contains("The original artifact has been renamed to " + original)
.doesNotContain("Installing " + original + " to").contains("Installing " + repackaged + " to"); .doesNotContain("Installing " + original + " to").contains("Installing " + repackaged + " to");
}); });
} }

View File

@ -279,7 +279,7 @@ public class RepackageMojo extends AbstractPackagerMojo {
private void updateArtifact(Artifact source, File target, File original) { private void updateArtifact(Artifact source, File target, File original) {
if (this.attach) { if (this.attach) {
attachArtifact(source, target); attachArtifact(source, target, original);
} }
else if (source.getFile().equals(target) && original.exists()) { else if (source.getFile().equals(target) && original.exists()) {
String artifactId = (this.classifier != null) ? "artifact with classifier " + this.classifier String artifactId = (this.classifier != null) ? "artifact with classifier " + this.classifier
@ -292,7 +292,7 @@ public class RepackageMojo extends AbstractPackagerMojo {
} }
} }
private void attachArtifact(Artifact source, File target) { private void attachArtifact(Artifact source, File target, File original) {
if (this.classifier != null && !source.getFile().equals(target)) { if (this.classifier != null && !source.getFile().equals(target)) {
getLog().info("Attaching repackaged archive " + target + " with classifier " + this.classifier); getLog().info("Attaching repackaged archive " + target + " with classifier " + this.classifier);
this.projectHelper.attachArtifact(this.project, this.project.getPackaging(), this.classifier, target); this.projectHelper.attachArtifact(this.project, this.project.getPackaging(), this.classifier, target);
@ -300,7 +300,10 @@ public class RepackageMojo extends AbstractPackagerMojo {
else { else {
String artifactId = (this.classifier != null) ? "artifact with classifier " + this.classifier String artifactId = (this.classifier != null) ? "artifact with classifier " + this.classifier
: "main artifact"; : "main artifact";
getLog().info("Replacing " + artifactId + " with repackaged archive"); getLog().info(
String.format("Replacing %s %s with repackaged archive, adding nested dependencies in BOOT-INF/.",
artifactId, source.getFile()));
getLog().info("The original artifact has been renamed to " + original);
source.setFile(target); source.setFile(target);
} }
} }