diff --git a/README.md b/README.md index e830213..487b80a 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ Don't forget to include the _Spring Boot Loader_ dependency to your project: ```java scope(standalone) - .include(dependency("org.springframeworkboot:spring-boot-loader:3.3.1")); + .include(dependency("org.springframeworkboot:spring-boot-loader:3.3.0")); ``` Please check the [BootJarOperation documentation](https://rife2.github.io/bld-spring-boot/rife/bld/extension/BootJarOperation.html#method-summary) diff --git a/examples/lib/bld/bld-wrapper.properties b/examples/lib/bld/bld-wrapper.properties index aba8240..1ab774a 100644 --- a/examples/lib/bld/bld-wrapper.properties +++ b/examples/lib/bld/bld-wrapper.properties @@ -1,7 +1,7 @@ bld.downloadExtensionJavadoc=false bld.downloadExtensionSources=true -bld.downloadLocation= -bld.extension-boot=com.uwyn.rife2:bld-spring-boot:0.9.5 +bld.extensions=com.uwyn.rife2:bld-spring-boot:0.9.4 bld.repositories=MAVEN_LOCAL,MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES +bld.downloadLocation= bld.sourceDirectories= bld.version=1.9.1 diff --git a/examples/src/bld/java/com/example/demo/DemoApplicationBuild.java b/examples/src/bld/java/com/example/demo/DemoApplicationBuild.java index d3e58c2..087e691 100644 --- a/examples/src/bld/java/com/example/demo/DemoApplicationBuild.java +++ b/examples/src/bld/java/com/example/demo/DemoApplicationBuild.java @@ -27,15 +27,15 @@ public class DemoApplicationBuild extends WebProject { repositories = List.of(MAVEN_CENTRAL); scope(compile) - .include(dependency("org.springframework.boot:spring-boot-starter:3.3.1")) - .include(dependency("org.springframework.boot:spring-boot-starter-actuator:3.3.1")) - .include(dependency("org.springframework.boot:spring-boot-starter-web:3.3.1")); + .include(dependency("org.springframework.boot:spring-boot-starter:3.3.0")) + .include(dependency("org.springframework.boot:spring-boot-starter-actuator:3.3.0")) + .include(dependency("org.springframework.boot:spring-boot-starter-web:3.3.0")); scope(test) - .include(dependency("org.springframework.boot:spring-boot-starter-test:3.3.1")) + .include(dependency("org.springframework.boot:spring-boot-starter-test:3.3.0")) .include(dependency("org.junit.jupiter:junit-jupiter:5.10.2")) .include(dependency("org.junit.platform:junit-platform-console-standalone:1.10.2")); scope(standalone) - .include(dependency("org.springframework.boot:spring-boot-loader:3.3.1")); + .include(dependency("org.springframework.boot:spring-boot-loader:3.3.0")); } public static void main(String[] args) { diff --git a/lib/bld/bld-wrapper.properties b/lib/bld/bld-wrapper.properties index e317c92..4cbfb76 100644 --- a/lib/bld/bld-wrapper.properties +++ b/lib/bld/bld-wrapper.properties @@ -1,7 +1,7 @@ bld.downloadExtensionJavadoc=false bld.downloadExtensionSources=true -bld.downloadLocation= -bld.extension-pmd=com.uwyn.rife2:bld-pmd:1.0.1 +bld.extension-pmd=com.uwyn.rife2:bld-pmd:0.9.9 bld.repositories=MAVEN_CENTRAL,MAVEN_LOCAL,RIFE2_RELEASES +bld.downloadLocation= bld.sourceDirectories= bld.version=1.9.1 diff --git a/src/bld/java/rife/bld/extension/SpringBootBuild.java b/src/bld/java/rife/bld/extension/SpringBootBuild.java index 90598cf..79968bb 100644 --- a/src/bld/java/rife/bld/extension/SpringBootBuild.java +++ b/src/bld/java/rife/bld/extension/SpringBootBuild.java @@ -33,7 +33,7 @@ public class SpringBootBuild extends Project { public SpringBootBuild() { pkg = "rife.bld.extension"; name = "bld-spring-boot"; - version = version(0, 9, 5); + version = version(0, 9, 5, "SNAPSHOT"); javaRelease = 17; @@ -47,7 +47,7 @@ public class SpringBootBuild extends Project { scope(test) .include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 10, 2))) .include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 10, 2))) - .include(dependency("org.assertj", "assertj-core", version(3, 26, 0))); + .include(dependency("org.assertj", "assertj-core", version(3, 25, 3))); javadocOperation() .javadocOptions() diff --git a/src/main/java/rife/bld/extension/AbstractBootOperation.java b/src/main/java/rife/bld/extension/AbstractBootOperation.java index a485812..4709c5f 100644 --- a/src/main/java/rife/bld/extension/AbstractBootOperation.java +++ b/src/main/java/rife/bld/extension/AbstractBootOperation.java @@ -26,10 +26,10 @@ import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; import java.nio.file.Files; -import java.nio.file.Path; import java.text.MessageFormat; -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import java.util.spi.ToolProvider; @@ -45,10 +45,10 @@ import java.util.spi.ToolProvider; public abstract class AbstractBootOperation> extends AbstractOperation> { private static final Logger LOGGER = Logger.getLogger(AbstractBootOperation.class.getName()); - private final Collection infLibs_ = new ArrayList<>(); - private final Collection launcherLibs_ = new ArrayList<>(); - private final Map manifestAttributes_ = new ConcurrentHashMap<>(); - private final Collection sourceDirectories_ = new ArrayList<>(); + private final List infLibs_ = new ArrayList<>(); + private final List launcherLibs_ = new ArrayList<>(); + private final List manifestAttributes_ = new ArrayList<>(); + private final List sourceDirectories_ = new ArrayList<>(); private File destinationDirectory_; private String destinationFileName_; private String launcherClass_; @@ -239,8 +239,8 @@ public abstract class AbstractBootOperation> var manifest = new File(meta_inf_dir, "MANIFEST.MF").toPath(); try (var fileWriter = Files.newBufferedWriter(manifest)) { - for (var set : manifestAttributes_.entrySet()) { - fileWriter.write(set.getKey() + ": " + set.getValue() + System.lineSeparator()); + for (var manifestAttribute : manifestAttributes()) { + fileWriter.write(manifestAttribute.name() + ": " + manifestAttribute.value() + System.lineSeparator()); } } } @@ -278,24 +278,12 @@ public abstract class AbstractBootOperation> return (T) this; } - /** - * Provides the libraries that will be stored in {@code BOOT-INF} or {@code WEB-INF}. - * - * @param jars one or more Java archive files - * @return this operation instance - */ - public T infLibs(String... jars) { - infLibs_.addAll(Arrays.stream(jars).map(File::new).toList()); - //noinspection unchecked - return (T) this; - } - /** * Retrieves the libraries in {@code BOOT-INF} or {@code WEB-INF}. * - * @return the Java archives + * @return a list of Java archives */ - public Collection infLibs() { + public List infLibs() { return infLibs_; } @@ -333,9 +321,9 @@ public abstract class AbstractBootOperation> /** * Retrieves the Spring Boot loader launcher libraries. * - * @return the Java archives + * @return a list of Java archives */ - public Collection launcherLibs() { + public List launcherLibs() { return launcherLibs_; } @@ -344,55 +332,16 @@ public abstract class AbstractBootOperation> * * @param jars a collection of Java archives * @return this operation instance - * @throws IOException if a JAR could not be found + * @throws IOException if an error occurs */ public T launcherLibs(Collection jars) throws IOException { - for (var j : jars) { - if (j.exists()) { - launcherLibs_.add(j); - } else { - throw new IOException("Spring Boot loader launcher library not found: " + j); - } - } - //noinspection unchecked - return (T) this; - } - - /** - * Provides the libraries for the Spring Boot loader launcher. - * - * @param jars one or more Java archives - * @return this operation instance - * @throws IOException if a JAR could not be found - */ - @SuppressWarnings("UnusedReturnValue") - public T launcherLibs(File... jars) throws IOException { - for (var j : jars) { - if (j.exists()) { - launcherLibs_.add(j); - } else { - throw new IOException("Spring Boot loader launcher library not found: " + j); - } - } - //noinspection unchecked - return (T) this; - } - - /** - * Provides the libraries for the Spring Boot loader launcher. - * - * @param jars one or more Java archives - * @return this operation instance - * @throws IOException if a JAR could not be found - */ - @SuppressWarnings("UnusedReturnValue") - public T launcherLibs(String... jars) throws IOException { - for (var j : jars) { - var p = Path.of(j); - if (Files.exists(p)) { - launcherLibs_.add(p.toFile()); - } else { - throw new IOException("Spring Boot loader launcher library not found: " + j); + if (!jars.isEmpty()) { + for (var j : jars) { + if (j.exists()) { + launcherLibs_.add(j); + } else { + throw new IOException("Spring Boot loader launcher library not found: " + j); + } } } //noinspection unchecked @@ -428,17 +377,17 @@ public abstract class AbstractBootOperation> * @return this operation instance */ public T manifestAttribute(String name, String value) { - manifestAttributes_.put(name, value); + manifestAttributes_.add(new BootManifestAttribute(name, value)); //noinspection unchecked return (T) this; } /** - * Retrieves the attributes that will be put in the archive manifest. + * Retrieves the list of attributes that will be put in the archive manifest. * - * @return the manifest attributes + * @return a list of manifest attributes */ - public Map manifestAttributes() { + public List manifestAttributes() { return manifestAttributes_; } @@ -447,10 +396,9 @@ public abstract class AbstractBootOperation> * * @param attributes the manifest attributes * @return this operation instance - * @see #manifestAttribute(String, String) */ - public T manifestAttributes(Map attributes) { - manifestAttributes_.putAll(attributes); + public T manifestAttributes(Collection attributes) { + manifestAttributes_.addAll(attributes); //noinspection unchecked return (T) this; } @@ -467,24 +415,12 @@ public abstract class AbstractBootOperation> return (T) this; } - /** - * Provides source directories that will be used for the archive creation. - * - * @param directories one or more source directories - * @return this operation instance - */ - public T sourceDirectories(String... directories) { - sourceDirectories_.addAll(Arrays.stream(directories).map(File::new).toList()); - //noinspection unchecked - return (T) this; - } - /** * Retrieves the source directories that will be used for the archive creation. * - * @return the source directories + * @return a list of directories */ - public Collection sourceDirectories() { + public List sourceDirectories() { return sourceDirectories_; } diff --git a/src/main/java/rife/bld/extension/BootJarOperation.java b/src/main/java/rife/bld/extension/BootJarOperation.java index 22edfe9..5667bfd 100644 --- a/src/main/java/rife/bld/extension/BootJarOperation.java +++ b/src/main/java/rife/bld/extension/BootJarOperation.java @@ -23,7 +23,7 @@ import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.util.Collection; -import java.util.Map; +import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; @@ -89,7 +89,7 @@ public class BootJarOperation extends AbstractBootOperation { * {@link Project#standaloneClasspathJars() standaloneClasspathJars} *
  • The {@link #mainClass(String) main class} to {@link Project#mainClass() mainClass}
  • *
  • The {@code Manifest-Version}, {@code Main-Class} and {@code Start-Class} - * {@link #manifestAttributes() manifest attributes}
  • + * {@link #manifestAttributes(Collection) manifest attributes} *
  • The {@link #sourceDirectories(File...) source directories} to * {@link Project#buildMainDirectory() buildMainDirectory} and * {@link Project#srcMainResourcesDirectory() srcMainResourcesDirectory}
  • @@ -107,10 +107,11 @@ public class BootJarOperation extends AbstractBootOperation { .launcherClass(BootUtils.launcherClass(project, "JarLauncher")) .launcherLibs(project.standaloneClasspathJars()) .mainClass(project.mainClass()) - .manifestAttributes(Map.of( - "Manifest-Version", "1.0", - "Main-Class", launcherClass(), - "Start-Class", mainClass())) + .manifestAttributes(List.of( + new BootManifestAttribute("Manifest-Version", "1.0"), + new BootManifestAttribute("Main-Class", launcherClass()), + new BootManifestAttribute("Start-Class", mainClass()) + )) .sourceDirectories(project.buildMainDirectory(), project.srcMainResourcesDirectory()); } } diff --git a/src/main/java/rife/bld/extension/BootManifestAttribute.java b/src/main/java/rife/bld/extension/BootManifestAttribute.java new file mode 100644 index 0000000..beac96d --- /dev/null +++ b/src/main/java/rife/bld/extension/BootManifestAttribute.java @@ -0,0 +1,28 @@ +/* + * Copyright 2023-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package rife.bld.extension; + +/** + * Constructs a new manifest attribute. + * + * @param name The attribute name + * @param value The attribute value + * @author Erik C. Thauvin + * @since 1.0 + */ +public record BootManifestAttribute(String name, String value) { +} diff --git a/src/main/java/rife/bld/extension/BootWarOperation.java b/src/main/java/rife/bld/extension/BootWarOperation.java index 9362df4..7ee8db7 100644 --- a/src/main/java/rife/bld/extension/BootWarOperation.java +++ b/src/main/java/rife/bld/extension/BootWarOperation.java @@ -25,7 +25,6 @@ import java.nio.file.Files; import java.util.ArrayList; import java.util.Collection; import java.util.List; -import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; @@ -113,7 +112,7 @@ public class BootWarOperation extends AbstractBootOperation { * {@link Project#standaloneClasspathJars() standaloneClasspathJars} *
  • The {@link #mainClass(String) main class} to {@link Project#mainClass() mainClass}
  • *
  • The {@code Manifest-Version}, {@code Main-Class} and {@code Start-Class} - * {@link #manifestAttributes() manifest attributes}
  • + * {@link #manifestAttributes(Collection) manifest attributes} *
  • The {@link #sourceDirectories(File...) source directories} to * {@link Project#buildMainDirectory() buildMainDirectory} and * {@link Project#srcMainResourcesDirectory() srcMainResourcesDirectory}
  • @@ -132,10 +131,11 @@ public class BootWarOperation extends AbstractBootOperation { .launcherClass(BootUtils.launcherClass(project, "WarLauncher")) .launcherLibs(project.standaloneClasspathJars()) .mainClass(project.mainClass()) - .manifestAttributes(Map.of( - "Manifest-Version", "1.0", - "Main-Class", launcherClass(), - "Start-Class", mainClass())) + .manifestAttributes(List.of( + new BootManifestAttribute("Manifest-Version", "1.0"), + new BootManifestAttribute("Main-Class", launcherClass()), + new BootManifestAttribute("Start-Class", mainClass()) + )) .providedLibs(project.providedClasspathJars()) .sourceDirectories(project.buildMainDirectory(), project.srcMainResourcesDirectory()); } diff --git a/src/test/java/rife/bld/extension/BootJarOperationTest.java b/src/test/java/rife/bld/extension/BootJarOperationTest.java index c5d5508..77c215a 100644 --- a/src/test/java/rife/bld/extension/BootJarOperationTest.java +++ b/src/test/java/rife/bld/extension/BootJarOperationTest.java @@ -35,7 +35,7 @@ import static org.assertj.core.api.Assertions.assertThatCode; class BootJarOperationTest { private static final String BLD = "bld-1.9.1.jar"; - private static final String BOOT_VERSION = "3.3.1"; + private static final String BOOT_VERSION = "3.3.0"; 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/"; @@ -180,13 +180,7 @@ class BootJarOperationTest { .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("class required"); - assertThatCode(() -> new BootWarOperation().launcherLibs(new File("foo"))) - .as("foo") - .isInstanceOf(IOException.class) - .hasMessageContaining("not found"); - - assertThatCode(() -> new BootWarOperation().launcherLibs("bar")) - .as("bar") + assertThatCode(() -> new BootWarOperation().launcherLibs(List.of(new File("foo")))) .isInstanceOf(IOException.class) .hasMessageContaining("not found"); @@ -227,6 +221,7 @@ class BootJarOperationTest { "BOOT-INF/classes/rife/bld/extension/\n" + "BOOT-INF/classes/rife/bld/extension/AbstractBootOperation.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/BootUtils.class\n" + "BOOT-INF/classes/rife/bld/extension/BootWarOperation.class\n" + "BOOT-INF/lib/\n" + @@ -244,9 +239,9 @@ class BootJarOperationTest { new BootJarOperation() .fromProject(new CustomProject(new File("."))) .launcherLibs(List.of(new File(EXAMPLES_LIB_STANDALONE + SPRING_BOOT_LOADER))) - .destinationDirectory(tmp_dir.getAbsolutePath()) - .infLibs(new File(EXAMPLES_LIB_COMPILE + SPRING_BOOT).getAbsolutePath(), - new File(EXAMPLES_LIB_COMPILE + SPRING_BOOT_ACTUATOR).getAbsolutePath()) + .destinationDirectory(tmp_dir) + .infLibs(new File(EXAMPLES_LIB_COMPILE + SPRING_BOOT), + new File(EXAMPLES_LIB_COMPILE + SPRING_BOOT_ACTUATOR)) .execute(); var jarFile = new File(tmp_dir, "test_project-0.0.1-boot.jar"); @@ -261,6 +256,7 @@ class BootJarOperationTest { "BOOT-INF/classes/rife/bld/extension/\n" + "BOOT-INF/classes/rife/bld/extension/AbstractBootOperation.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/BootUtils.class\n" + "BOOT-INF/classes/rife/bld/extension/BootWarOperation.class\n" + "BOOT-INF/lib/\n" + @@ -282,11 +278,14 @@ class BootJarOperationTest { assertThat(bootJar.mainClass()).as("mainClass").isEqualTo(MAIN_CLASS); assertThat(bootJar.sourceDirectories()).as("sourceDirectories.size").hasSize(2); assertThat(bootJar.manifestAttributes()).as("manifestAttributes.size").hasSize(3); - assertThat(bootJar.manifestAttributes().get("Manifest-Version")).as("Manifest-Version").isEqualTo("1.0"); - assertThat(bootJar.manifestAttributes().get("Main-Class")).as("Main-Class").endsWith("JarLauncher"); - assertThat(bootJar.manifestAttributes().get("Start-Class")).as("Start-Class").isEqualTo(MAIN_CLASS); + assertThat(bootJar.manifestAttributes().get(0)).as("Manifest-Version") + .isEqualTo(new BootManifestAttribute("Manifest-Version", "1.0")); + assertThat(bootJar.manifestAttributes().get(1).value()).as("Main-Class").endsWith("JarLauncher"); + assertThat(bootJar.manifestAttributes().get(2)).as("Start-Class") + .isEqualTo(new BootManifestAttribute("Start-Class", MAIN_CLASS)); assertThat(bootJar.manifestAttribute("Manifest-Test", "tsst") - .manifestAttributes().get("Manifest-Test")).as("Manifest-Test").isEqualTo("tsst"); + .manifestAttributes()).as("Manifest-Test").hasSize(4) + .element(3).extracting(BootManifestAttribute::name).isEqualTo("Manifest-Test"); assertThat(bootJar.destinationDirectory()).as("destinationDirectory").isDirectory(); assertThat(bootJar.destinationDirectory().getAbsolutePath()).as("destinationDirectory") .isEqualTo(Path.of(tmp_dir.getPath(), "build", "dist").toString()); @@ -324,6 +323,7 @@ class BootJarOperationTest { "WEB-INF/classes/rife/bld/extension/\n" + "WEB-INF/classes/rife/bld/extension/AbstractBootOperation.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/BootUtils.class\n" + "WEB-INF/classes/rife/bld/extension/BootWarOperation.class\n" + "WEB-INF/lib/\n" +