From c9fe353ce16f6eba44a5eceb9477111919a09c8f Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Tue, 31 Oct 2023 15:39:49 -0700 Subject: [PATCH] Javadocs and tests cleanup --- .../bld/extension/AbstractBootOperation.java | 59 +++++++++++-------- .../rife/bld/extension/BootWarOperation.java | 6 +- .../bld/extension/BootJarOperationTest.java | 13 ++-- 3 files changed, 45 insertions(+), 33 deletions(-) diff --git a/src/main/java/rife/bld/extension/AbstractBootOperation.java b/src/main/java/rife/bld/extension/AbstractBootOperation.java index df4bb43..d2045a6 100644 --- a/src/main/java/rife/bld/extension/AbstractBootOperation.java +++ b/src/main/java/rife/bld/extension/AbstractBootOperation.java @@ -95,7 +95,7 @@ public abstract class AbstractBootOperation> } /** - * Retrieves the destination directory in which the JAR will be created. + * Retrieves the destination directory in which the archive will be created. * * @return the destination directory */ @@ -247,7 +247,7 @@ public abstract class AbstractBootOperation> } /** - * Part of the {@link #execute} operation, create the manifest for the jar archive. + * Part of the {@link #execute} operation, create the manifest for the archive. * * @param stagingDirectory the staging directory */ @@ -255,9 +255,9 @@ public abstract class AbstractBootOperation> var meta_inf_dir = new File(stagingDirectory, "META-INF"); mkDirs(meta_inf_dir); - var manifest = new File(meta_inf_dir, "MANIFEST.MF"); + var manifest = new File(meta_inf_dir, "MANIFEST.MF").toPath(); - try (var fileWriter = Files.newBufferedWriter(manifest.toPath())) { + try (var fileWriter = Files.newBufferedWriter(manifest)) { for (var manifestAttribute : manifestAttributes()) { fileWriter.write(manifestAttribute.name() + ": " + manifestAttribute.value() + System.lineSeparator()); } @@ -265,19 +265,19 @@ public abstract class AbstractBootOperation> } /** - * Provides JAR libraries that will be stored in {@code BOOT-INF} or {@code WEB-INF}. + * Provides the libraries that will be stored in {@code BOOT-INF} or {@code WEB-INF}. * - * @param jars a list of Java archive files + * @param jars a collection of Java archive files * @return this operation instance */ - public T infLibs(List jars) { + public T infLibs(Collection jars) { infLibs_.addAll(jars); //noinspection unchecked return (T) this; } /** - * Provides JAR libraries that will be stored in {@code BOOT-INF} or {@code WEB-INF}. + * Provides the libraries that will be stored in {@code BOOT-INF} or {@code WEB-INF}. * * @param jar one or more Java archive file * @return this operation instance @@ -289,7 +289,7 @@ public abstract class AbstractBootOperation> } /** - * Retrieves the JAR libraries in {@code BOOT-INF} or {@code WEB-INF}. + * Retrieves the libraries in {@code BOOT-INF} or {@code WEB-INF}. * * @return a list of Java archives */ @@ -298,7 +298,13 @@ public abstract class AbstractBootOperation> } /** - * Provides the JAR launcher ({@code spring-boot-loader}) fully-qualified class name. + * Provides the launcher ({@code spring-boot-loader}) fully-qualified class name. + *

+ * For examples: + *

    + *
  • {@code org.springframework.boot.loader.WarLauncher}
  • + *
  • {@code org.springframework.boot.loader.JarLauncher}
  • + *
* * @param className the launcher class name * @return this operation instance @@ -310,7 +316,7 @@ public abstract class AbstractBootOperation> } /** - * Retrieves the JAR launcher ({@code spring-boot-loader}) fully-qualified class name. + * Retrieves the launcher ({@code spring-boot-loader}) fully-qualified class name. * * @return the launcher class name */ @@ -323,7 +329,7 @@ public abstract class AbstractBootOperation> } /** - * Retrieves the launcher ({@code spring-boot-loader}) JAR libraries. + * Retrieves the launcher ({@code spring-boot-loader}) libraries. * * @return a list of Java archives */ @@ -332,16 +338,16 @@ public abstract class AbstractBootOperation> } /** - * Provides the JAR libraries for the launcher ({@code spring-boot-loader}). + * Provides the libraries for the launcher ({@code spring-boot-loader}). * - * @param jars a list of a Java archives + * @param jars a collection of a Java archives * @return this operation instance */ - public T launcherLibs(List jars) throws IOException { + public T launcherLibs(Collection jars) throws IOException { if (!jars.isEmpty()) { for (var j : jars) { if (!j.exists()) { - throw new IOException("ERROR: launcher (spring-boot-loader) JAR(s) not found: " + j); + throw new IOException("ERROR: launcher (spring-boot-loader) library not found: " + j); } } launcherLibs_.addAll(jars); @@ -372,10 +378,10 @@ public abstract class AbstractBootOperation> } /** - * Provides an attribute to put in the JAR manifest. + * Provides an attribute to put in the archive manifest. * - * @param name the attribute name to put in the manifest - * @param value the attribute value to put in the manifest + * @param name the attribute name + * @param value the attribute value * @return this operation instance */ public T manifestAttribute(String name, String value) { @@ -385,7 +391,7 @@ public abstract class AbstractBootOperation> } /** - * Retrieves the list of attributes that will be put in the jar manifest. + * Retrieves the list of attributes that will be put in the archive manifest. * * @return a list of manifest attributes */ @@ -394,9 +400,9 @@ public abstract class AbstractBootOperation> } /** - * Provides a map of attributes to put in the jar manifest. + * Provides a map of attributes to put in the archive manifest. * - * @param attributes the attributes to put in the manifest + * @param attributes the manifest attributes * @return this operation instance */ public T manifestAttributes(Collection attributes) { @@ -406,7 +412,7 @@ public abstract class AbstractBootOperation> } /** - * Provides source directories that will be used for the jar archive creation. + * Provides source directories that will be used for the archive creation. * * @param directories one or more source directory * @return this operation instance @@ -418,7 +424,7 @@ public abstract class AbstractBootOperation> } /** - * Retrieves the source directories that will be used for the jar archive creation. + * Retrieves the source directories that will be used for the archive creation. * * @return a list of directories */ @@ -427,7 +433,8 @@ public abstract class AbstractBootOperation> } /** - * Verifies that all the elements required to create the archived have been provided, throws an + * Verifies that all the elements ({@link #mainClass() mainClass}, {@link #launcherClass() launcherClass} and + * {@link #launcherLibs() launcherLibs}) required to create the archive have been provided, throws an * {@link IllegalArgumentException} otherwise. * * @return {@code true} or an {@link IllegalArgumentException} @@ -439,7 +446,7 @@ public abstract class AbstractBootOperation> } else if (launcherClass().isEmpty()) { throw new IllegalArgumentException(("ERROR: launcher (spring-boot-loader) class required")); } else if (launcherLibs().isEmpty()) { - throw new IllegalArgumentException(("ERROR: launcher (spring-boot-loader) JAR(s) required")); + throw new IllegalArgumentException(("ERROR: launcher (spring-boot-loader) libraries required")); } return true; } diff --git a/src/main/java/rife/bld/extension/BootWarOperation.java b/src/main/java/rife/bld/extension/BootWarOperation.java index 2b05d0f..26795d8 100644 --- a/src/main/java/rife/bld/extension/BootWarOperation.java +++ b/src/main/java/rife/bld/extension/BootWarOperation.java @@ -66,7 +66,7 @@ public class BootWarOperation extends AbstractBootOperation { } /** - * Part of the {@link #execute} operation, copy the {@code WEB-INF/lib-provided} libs. + * Part of the {@link #execute} operation, copy the {@code WEB-INF/lib-provided} libraries. * * @param stagingWebInfDirectory the staging {@code WEB-INF/lib-provided} directory */ @@ -121,7 +121,7 @@ public class BootWarOperation extends AbstractBootOperation { } /** - * Provides JAR libraries that will be used for the WAR creation in {@code /WEB-INF/lib-provided}. + * Provides libraries that will be used for the WAR creation in {@code /WEB-INF/lib-provided}. * * @param jars a collection of Java archive files * @return this operation instance @@ -132,7 +132,7 @@ public class BootWarOperation extends AbstractBootOperation { } /** - * Provides the JAR libraries that will be used for the WAR creation in {@code /WEB-INF/lib-provided}. + * Provides the libraries that will be used for the WAR creation in {@code /WEB-INF/lib-provided}. * * @param jar one or more Java archive file * @return this operation instance diff --git a/src/test/java/rife/bld/extension/BootJarOperationTest.java b/src/test/java/rife/bld/extension/BootJarOperationTest.java index 956a354..250c8f3 100644 --- a/src/test/java/rife/bld/extension/BootJarOperationTest.java +++ b/src/test/java/rife/bld/extension/BootJarOperationTest.java @@ -36,6 +36,7 @@ import static org.assertj.core.api.Assertions.assertThatCode; class BootJarOperationTest { private static final String BLD = "bld-1.7.5.jar"; private static final String EXAMPLES_LIB_COMPILE = "examples/lib/compile/"; + private static final String EXAMPLES_LIB_RUNTIME = "examples/lib/runtime/"; private static final String EXAMPLES_LIB_STANDALONE = "examples/lib/standalone/"; private static final String LAUNCHER_JARS = """ org/ @@ -114,6 +115,7 @@ class BootJarOperationTest { org/springframework/boot/loader/util/SystemPropertyUtils.class """; private static final String MAIN_CLASS = "com.example.Foo"; + private static final String PROVIDED_LIB = "LatencyUtils-2.0.3.jar"; private static final String SPRING_BOOT = "spring-boot-3.1.5.jar"; private static final String SPRING_BOOT_ACTUATOR = "spring-boot-actuator-3.1.5.jar"; private static final String SPRING_BOOT_LOADER = "spring-boot-loader-3.1.5.jar"; @@ -227,7 +229,7 @@ class BootJarOperationTest { @Test void testProject() throws IOException { - var tmp_dir = Files.createTempDirectory("bootjartmp").toFile(); + var tmp_dir = Files.createTempDirectory("bootprjtmp").toFile(); var project = new CustomProject(tmp_dir); var bootJar = new BootJarOperation().fromProject(project); @@ -255,15 +257,17 @@ class BootJarOperationTest { @Test void testWarProjectExecute() throws Exception { var tmp_dir = Files.createTempDirectory("bootjartmp").toFile(); + var project = new CustomProject(new File(".")); new BootWarOperation() - .fromProject(new CustomProject(new File("."))) + .fromProject(project) .launcherLibs(List.of(new File(EXAMPLES_LIB_STANDALONE + SPRING_BOOT_LOADER))) .destinationDirectory(tmp_dir) .infLibs(new File(EXAMPLES_LIB_COMPILE + SPRING_BOOT), new File(EXAMPLES_LIB_COMPILE + SPRING_BOOT_ACTUATOR)) + .providedLibs(new File(EXAMPLES_LIB_RUNTIME + PROVIDED_LIB)) .execute(); - var warFile = new File(tmp_dir, "test_project-0.0.1-boot.war"); + var warFile = new File(tmp_dir, project.name() + '-' + project.version().toString() + "-boot.war"); assertThat(warFile).exists(); var jarEntries = readJarEntries(warFile); @@ -284,7 +288,8 @@ class BootJarOperationTest { "WEB-INF/lib/dist/\n" + "WEB-INF/lib/" + SPRING_BOOT + '\n' + "WEB-INF/lib/" + SPRING_BOOT_ACTUATOR + '\n' + - "WEB-INF/lib-provided/\n" + LAUNCHER_JARS); + "WEB-INF/lib-provided/\n" + + "WEB-INF/lib-provided/" + PROVIDED_LIB + '\n' + LAUNCHER_JARS); FileUtils.deleteDirectory(tmp_dir); }