From 700bf84b34e234025c59b92450ea9c2b9b605c48 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Sun, 29 Oct 2023 16:09:47 -0700 Subject: [PATCH] Made AbstractBootOperation more generic --- .../example/demo/DemoApplicationBuild.java | 8 +- .../bld/extension/AbstractBootOperation.java | 72 +++++------ .../rife/bld/extension/BootJarOperation.java | 117 +----------------- .../rife/bld/extension/BootWarOperation.java | 116 +---------------- .../bld/extension/BootJarOperationTest.java | 11 +- 5 files changed, 39 insertions(+), 285 deletions(-) diff --git a/examples/src/bld/java/com/example/demo/DemoApplicationBuild.java b/examples/src/bld/java/com/example/demo/DemoApplicationBuild.java index 8f1e5d7..cb06a4c 100644 --- a/examples/src/bld/java/com/example/demo/DemoApplicationBuild.java +++ b/examples/src/bld/java/com/example/demo/DemoApplicationBuild.java @@ -39,12 +39,8 @@ public class DemoApplicationBuild extends WebProject { } public static void main(String[] args) { - var level = Level.FINER; - var consoleHandler = new ConsoleHandler(); - consoleHandler.setLevel(level); - var logger = Logger.getLogger(BootJarOperation.class.getName()); - logger.addHandler(consoleHandler); - logger.setLevel(level); + var logger = Logger.getLogger("rife.bld.extension"); + logger.setLevel(Level.FINER); new DemoApplicationBuild().start(args); } diff --git a/src/main/java/rife/bld/extension/AbstractBootOperation.java b/src/main/java/rife/bld/extension/AbstractBootOperation.java index 4ffeaf8..59fb15a 100644 --- a/src/main/java/rife/bld/extension/AbstractBootOperation.java +++ b/src/main/java/rife/bld/extension/AbstractBootOperation.java @@ -16,7 +16,6 @@ package rife.bld.extension; -import rife.bld.Project; import rife.bld.operations.AbstractOperation; import rife.tools.FileUtils; import rife.tools.exceptions.FileUtilsErrorException; @@ -35,13 +34,14 @@ import java.util.logging.Logger; import java.util.spi.ToolProvider; /** - * Implements commons methods used by Spring Boot operations, such as {@link BootJarOperation} and + * Implements common methods used by Spring Boot operations, such as {@link BootJarOperation} and * {@link BootWarOperation}. * * @author Erik C. Thauvin * @since 1.0 */ -public abstract class AbstractBootOperation extends AbstractOperation { +public abstract class AbstractBootOperation> + extends AbstractOperation> { private final List infLibs_ = new ArrayList<>(); private final List launcherJars_ = new ArrayList<>(); private final List manifestAttributes_ = new ArrayList<>(); @@ -50,7 +50,6 @@ public abstract class AbstractBootOperation extends AbstractOperation jars) { + public T infLibs(List jars) { infLibs_.addAll(jars); - return this; + //noinspection unchecked + return (T) this; } /** @@ -220,9 +222,10 @@ public abstract class AbstractBootOperation extends AbstractOperation jars) throws IOException { + public T launcherJars(List jars) throws IOException { if (!jars.isEmpty()) { for (var j : jars) { if (!j.exists()) { @@ -270,15 +274,17 @@ public abstract class AbstractBootOperation extends AbstractOperation attributes) { + public T manifestAttributes(Collection attributes) { manifestAttributes_.addAll(attributes); - return this; + //noinspection unchecked + return (T) this; } /** @@ -329,30 +337,16 @@ public abstract class AbstractBootOperation extends AbstractOperationErik C. Thauvin * @since 1.0 */ -public class BootJarOperation extends AbstractBootOperation { +public class BootJarOperation extends AbstractBootOperation { private static final Logger LOGGER = Logger.getLogger(BootJarOperation.class.getName()); - /** - * Provides the destination file name that will be used for the JAR creation. - * - * @param name the JAR destination file name - * @return this operation instance - */ - @Override - public BootJarOperation destinationArchiveFileName(String name) { - return (BootJarOperation) super.destinationArchiveFileName(name); - } - - /** - * Provides the destination directory in which the JAR will be created. - * - * @param directory the JAR destination directory - * @return this operation instance - */ - @Override - public BootJarOperation destinationDirectory(File directory) throws IOException { - return (BootJarOperation) super.destinationDirectory(directory); - } - - /** - * Provides JAR libraries that will be used for the JAR creation. - * - * @param jars Java archive files - * @return this operation instance - */ - @Override - public BootJarOperation infLibs(List jars) { - return (BootJarOperation) super.infLibs(jars); - } - - /** - * Provides JAR libraries that will be used for the JAR creation. - * - * @param jar Java archive file - * @return this operation instance - */ - @Override - public BootJarOperation infLibs(File... jar) { - return (BootJarOperation) super.infLibs(jar); - } - - /** - * Part of the {@link #execute} operation, configure the JAR launcher ({@code spring-boot-loader}) class. - */ - @Override - public BootJarOperation launcherClass(String className) { - return (BootJarOperation) super.launcherClass(className); - } - - /** - * Part of the {@link #execute} operation, configure the launcher ({@code spring-boot-loader}) JAR(s). - */ - @Override - public BootJarOperation launcherJars(List jars) throws IOException { - return (BootJarOperation) super.launcherJars(jars); - } - - /** - * Provides the fully-qualified main class name. - */ - @Override - public BootJarOperation mainClass(String className) { - return (BootJarOperation) super.mainClass(className); - } - - /** - * Provides an attribute to put in the JAR manifest. - * - * @param name the attribute name to put in the manifest - * @param value the attribute value to put in the manifest - * @return this operation instance - */ - @Override - public BootJarOperation manifestAttribute(String name, String value) { - return (BootJarOperation) super.manifestAttribute(name, value); - } - - /** - * Provides a map of attributes to put in the jar manifest. - *

- * A copy will be created to allow this map to be independently modifiable. - * - * @param attributes the attributes to put in the manifest - * @return this operation instance - */ - @Override - public BootJarOperation manifestAttributes(Collection attributes) { - return (BootJarOperation) super.manifestAttributes(attributes); - } - - /** - * Provides the bld project. - */ - @Override - public BootJarOperation project(Project project) { - return (BootJarOperation) super.project(project); - } - - /** - * Provides source directories that will be used for the jar archive creation. - * - * @param directories source directories - * @return this operation instance - */ - @Override - public BootJarOperation sourceDirectories(File... directories) { - return (BootJarOperation) super.sourceDirectories(directories); - } - /** * Performs the BootJar operation. */ @@ -174,7 +61,6 @@ public class BootJarOperation extends AbstractBootOperation { } } - /** * Part of the {@link #execute} operation, creates the {@code BOOT-INF} staging directory. */ @@ -188,7 +74,6 @@ public class BootJarOperation extends AbstractBootOperation { * Configures the operation from a {@link Project}. */ public BootJarOperation fromProject(Project project) throws IOException { - project(project); mainClass(project.mainClass()); return destinationDirectory(project.buildDistDirectory()) diff --git a/src/main/java/rife/bld/extension/BootWarOperation.java b/src/main/java/rife/bld/extension/BootWarOperation.java index 80e17e2..505590f 100644 --- a/src/main/java/rife/bld/extension/BootWarOperation.java +++ b/src/main/java/rife/bld/extension/BootWarOperation.java @@ -34,122 +34,10 @@ import java.util.logging.Logger; * @author Erik C. Thauvin * @since 1.0 */ -public class BootWarOperation extends AbstractBootOperation { +public class BootWarOperation extends AbstractBootOperation { private static final Logger LOGGER = Logger.getLogger(BootWarOperation.class.getName()); private final List webInfProvidedLibs_ = new ArrayList<>(); - /** - * Provides the destination file name that will be used for the WAR creation. - * - * @param name the wAR archive destination file name - * @return this operation instance - */ - @Override - public BootWarOperation destinationArchiveFileName(String name) { - return (BootWarOperation) super.destinationArchiveFileName(name); - } - - /** - * Provides the destination directory in which the WAR will be created. - * - * @param directory the WAR destination directory - * @return this operation instance - */ - @Override - public BootWarOperation destinationDirectory(File directory) throws IOException { - return (BootWarOperation) super.destinationDirectory(directory); - } - - /** - * Provides JAR libraries that will be used for the WAR creation. - * - * @param jars Java archive files - * @return this operation instance - */ - @Override - public BootWarOperation infLibs(List jars) { - return (BootWarOperation) super.infLibs(jars); - } - - /** - * Provides JAR libraries that will be used for the WAR creation. - * - * @param jar Java archive file - * @return this operation instance - */ - @Override - public BootWarOperation infLibs(File... jar) { - return (BootWarOperation) super.infLibs(jar); - } - - /** - * Part of the {@link #execute} operation, configure the JAR launcher ({@code spring-boot-loader}) class. - */ - @Override - public BootWarOperation launcherClass(String className) { - return (BootWarOperation) super.launcherClass(className); - } - - /** - * Part of the {@link #execute} operation, configure the launcher ({@code spring-boot-loader}) JAR(s). - */ - @Override - public BootWarOperation launcherJars(List jars) throws IOException { - return (BootWarOperation) super.launcherJars(jars); - } - - /** - * Provides the fully-qualified main class name. - */ - @Override - public BootWarOperation mainClass(String className) { - return (BootWarOperation) super.mainClass(className); - } - - /** - * Provides an attribute to put in the JAR manifest. - * - * @param name the attribute name to put in the manifest - * @param value the attribute value to put in the manifest - * @return this operation instance - */ - @Override - public BootWarOperation manifestAttribute(String name, String value) { - return (BootWarOperation) super.manifestAttribute(name, value); - } - - /** - * Provides a map of attributes to put in the jar manifest. - *

- * A copy will be created to allow this map to be independently modifiable. - * - * @param attributes the attributes to put in the manifest - * @return this operation instance - */ - @Override - public BootWarOperation manifestAttributes(Collection attributes) { - return (BootWarOperation) super.manifestAttributes(attributes); - } - - /** - * Provides the bld project. - */ - @Override - public BootWarOperation project(Project project) { - return (BootWarOperation) super.project(project); - } - - /** - * Provides source directories that will be used for the jar archive creation. - * - * @param directories source directories - * @return this operation instance - */ - @Override - public BootWarOperation sourceDirectories(File... directories) { - return (BootWarOperation) super.sourceDirectories(directories); - } - /** * Performs the BootJar operation. */ @@ -204,7 +92,6 @@ public class BootWarOperation extends AbstractBootOperation { * @param project the project to configure the operation from */ public BootWarOperation fromProject(Project project) throws IOException { - project(project); mainClass(project.mainClass()); return destinationDirectory(project.buildDistDirectory()) @@ -224,7 +111,6 @@ public class BootWarOperation extends AbstractBootOperation { .sourceDirectories(project.buildMainDirectory(), project.srcMainResourcesDirectory()); } - /** * Provides JAR libraries that will be used for the WAR creation in {@code /WEB-INF/lib-provided}. * diff --git a/src/test/java/rife/bld/extension/BootJarOperationTest.java b/src/test/java/rife/bld/extension/BootJarOperationTest.java index cc48e56..ef28039 100644 --- a/src/test/java/rife/bld/extension/BootJarOperationTest.java +++ b/src/test/java/rife/bld/extension/BootJarOperationTest.java @@ -177,9 +177,7 @@ class BootJarOperationTest { "BOOT-INF/classes/rife/\n" + "BOOT-INF/classes/rife/bld/\n" + "BOOT-INF/classes/rife/bld/extension/\n" + - "BOOT-INF/classes/rife/bld/extension/AbstractBootOperation$ManifestAttribute.class\n" + "BOOT-INF/classes/rife/bld/extension/AbstractBootOperation.class\n" + - "BOOT-INF/classes/rife/bld/extension/BootJarOperation$ManifestAttribute.class\n" + "BOOT-INF/classes/rife/bld/extension/BootJarOperation.class\n" + "BOOT-INF/classes/rife/bld/extension/BootManifestAttribute.class\n" + "BOOT-INF/classes/rife/bld/extension/BootWarOperation.class\n" + @@ -187,7 +185,7 @@ class BootJarOperationTest { "BOOT-INF/lib/" + SPRING_BOOT + '\n' + "BOOT-INF/lib/" + SPRING_BOOT_ACTUATOR + '\n' + "META-INF/\n" + - "META-INF/MANIFEST.MF" + LAUNCHER_JARS); + "META-INF/MANIFEST.MF\n" + LAUNCHER_JARS); FileUtils.deleteDirectory(tmp_dir); } @@ -213,9 +211,7 @@ class BootJarOperationTest { "BOOT-INF/classes/rife/\n" + "BOOT-INF/classes/rife/bld/\n" + "BOOT-INF/classes/rife/bld/extension/\n" + - "BOOT-INF/classes/rife/bld/extension/AbstractBootOperation$ManifestAttribute.class\n" + "BOOT-INF/classes/rife/bld/extension/AbstractBootOperation.class\n" + - "BOOT-INF/classes/rife/bld/extension/BootJarOperation$ManifestAttribute.class\n" + "BOOT-INF/classes/rife/bld/extension/BootJarOperation.class\n" + "BOOT-INF/classes/rife/bld/extension/BootManifestAttribute.class\n" + "BOOT-INF/classes/rife/bld/extension/BootWarOperation.class\n" + @@ -224,7 +220,7 @@ class BootJarOperationTest { "BOOT-INF/lib/" + SPRING_BOOT + '\n' + "BOOT-INF/lib/" + SPRING_BOOT_ACTUATOR + '\n' + "META-INF/\n" + - "META-INF/MANIFEST.MF" + LAUNCHER_JARS); + "META-INF/MANIFEST.MF\n" + LAUNCHER_JARS); FileUtils.deleteDirectory(tmp_dir); } @@ -235,7 +231,6 @@ class BootJarOperationTest { var project = new CustomProject(tmp_dir); var bootJar = new BootJarOperation().fromProject(project); - assertThat(bootJar.project()).as("project").isEqualTo(project); assertThat(bootJar.mainClass()).as("mainClass").isEqualTo(MAIN_CLASS); assertThat(bootJar.sourceDirectories()).as("sourceDirectories.size").hasSize(2); assertThat(bootJar.manifestAttributes()).as("manifestAttributes.size").hasSize(3); @@ -280,9 +275,7 @@ class BootJarOperationTest { "WEB-INF/classes/rife/\n" + "WEB-INF/classes/rife/bld/\n" + "WEB-INF/classes/rife/bld/extension/\n" + - "WEB-INF/classes/rife/bld/extension/AbstractBootOperation$ManifestAttribute.class\n" + "WEB-INF/classes/rife/bld/extension/AbstractBootOperation.class\n" + - "WEB-INF/classes/rife/bld/extension/BootJarOperation$ManifestAttribute.class\n" + "WEB-INF/classes/rife/bld/extension/BootJarOperation.class\n" + "WEB-INF/classes/rife/bld/extension/BootManifestAttribute.class\n" + "WEB-INF/classes/rife/bld/extension/BootWarOperation.class\n" +