diff --git a/.github/workflows/bld.yml b/.github/workflows/bld.yml index 7d224f6..94c08ea 100644 --- a/.github/workflows/bld.yml +++ b/.github/workflows/bld.yml @@ -1,18 +1,16 @@ name: bld-ci -on: [push, pull_request, workflow_dispatch] - -env: - KOTLIN_HOME: /usr/share/kotlinc +on: [ push, pull_request, workflow_dispatch ] jobs: build-bld-project: - runs-on: ubuntu-latest - strategy: matrix: - java-version: [17, 21, 22] - kotlin-version: [ 1.19.24, 2.0.0 ] + java-version: [ 17, 21, 24 ] + kotlin-version: [ 1.9.25, 2.0.21, 2.1.20 ] + os: [ ubuntu-latest, windows-latest, macos-latest ] + + runs-on: ${{ matrix.os }} steps: - name: Checkout source repository @@ -26,8 +24,16 @@ jobs: distribution: "zulu" java-version: ${{ matrix.java-version }} + - name: Download dependencies [examples] + working-directory: examples + run: ./bld download + + - name: Compile and run [examples] + working-directory: examples + run: ./bld compile run + - name: Download dependencies run: ./bld download - name: Run tests - run: ./bld compile test + run: ./bld compile test \ No newline at end of file diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml index bf43624..508f6a5 100644 --- a/.github/workflows/pages.yml +++ b/.github/workflows/pages.yml @@ -47,11 +47,11 @@ jobs: uses: actions/configure-pages@v3 - name: Upload artifact - uses: actions/upload-pages-artifact@v1 + uses: actions/upload-pages-artifact@v3 with: # Upload generated Javadocs repository path: "build/javadoc/" - name: Deploy to GitHub Pages id: deployment - uses: actions/deploy-pages@v1 + uses: actions/deploy-pages@v4 diff --git a/.idea/copyright/Apache_License.xml b/.idea/copyright/Apache_License.xml index ade80da..4446c15 100644 --- a/.idea/copyright/Apache_License.xml +++ b/.idea/copyright/Apache_License.xml @@ -1,6 +1,6 @@ - - + \ No newline at end of file diff --git a/.idea/icon.svg b/.idea/icon.svg new file mode 100644 index 0000000..81220b4 --- /dev/null +++ b/.idea/icon.svg @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/.idea/libraries/bld.xml b/.idea/libraries/bld.xml index 5c4010c..153a060 100644 --- a/.idea/libraries/bld.xml +++ b/.idea/libraries/bld.xml @@ -2,12 +2,12 @@ - + - + diff --git a/.vscode/settings.json b/.vscode/settings.json index 4c33beb..ba429d0 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -9,7 +9,7 @@ ], "java.configuration.updateBuildConfiguration": "automatic", "java.project.referencedLibraries": [ - "${HOME}/.bld/dist/bld-2.1.0.jar", + "${HOME}/.bld/dist/bld-2.2.1.jar", "lib/**/*.jar" ] } diff --git a/README.md b/README.md index b151e19..23c69a2 100755 --- a/README.md +++ b/README.md @@ -3,12 +3,20 @@ [![License](https://img.shields.io/badge/license-Apache%20License%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![Java](https://img.shields.io/badge/java-17%2B-blue)](https://www.oracle.com/java/technologies/javase/jdk17-archive-downloads.html) -[![bld](https://img.shields.io/badge/2.1.0-FA9052?label=bld&labelColor=2392FF)](https://rife2.com/bld) +[![bld](https://img.shields.io/badge/2.2.1-FA9052?label=bld&labelColor=2392FF)](https://rife2.com/bld) [![Release](https://flat.badgen.net/maven/v/metadata-url/repo.rife2.com/releases/com/uwyn/rife2/bld-generated-version/maven-metadata.xml?color=blue)](https://repo.rife2.com/#/releases/com/uwyn/rife2/bld-generated-version) [![Snapshot](https://flat.badgen.net/maven/v/metadata-url/repo.rife2.com/snapshots/com/uwyn/rife2/bld-generated-version/maven-metadata.xml?label=snapshot)](https://repo.rife2.com/#/snapshots/com/uwyn/rife2/bld-generated-version) [![GitHub CI](https://github.com/rife2/bld-generated-version/actions/workflows/bld.yml/badge.svg)](https://github.com/rife2/bld-generated-version/actions/workflows/bld.yml) -To install, please refer to the [extensions documentation](https://github.com/rife2/bld/wiki/Extensions). +To install the latest version, add the following to the `lib/bld/bld-wrapper.properties` file: + +```properties +bld.extension-generated-version=com.uwyn.rife2:bld-generated-version +``` + +For more information, please refer to the [extensions](https://github.com/rife2/bld/wiki/Extensions) documentation. + +## Generate Version Data Class To automatically create a generated version class using the default template in your project on compile, add the following to your build file: ```java diff --git a/config/pmd.xml b/config/pmd.xml index 3d3203c..2641880 100644 --- a/config/pmd.xml +++ b/config/pmd.xml @@ -7,9 +7,9 @@ - - + + diff --git a/examples/.idea/libraries/bld.xml b/examples/.idea/libraries/bld.xml index 5c4010c..153a060 100644 --- a/examples/.idea/libraries/bld.xml +++ b/examples/.idea/libraries/bld.xml @@ -2,12 +2,12 @@ - + - + diff --git a/examples/.vscode/settings.json b/examples/.vscode/settings.json index 4c33beb..ba429d0 100644 --- a/examples/.vscode/settings.json +++ b/examples/.vscode/settings.json @@ -9,7 +9,7 @@ ], "java.configuration.updateBuildConfiguration": "automatic", "java.project.referencedLibraries": [ - "${HOME}/.bld/dist/bld-2.1.0.jar", + "${HOME}/.bld/dist/bld-2.2.1.jar", "lib/**/*.jar" ] } diff --git a/examples/lib/bld/bld-wrapper.jar b/examples/lib/bld/bld-wrapper.jar index aa7fc11..3842a62 100644 Binary files a/examples/lib/bld/bld-wrapper.jar and b/examples/lib/bld/bld-wrapper.jar differ diff --git a/examples/lib/bld/bld-wrapper.properties b/examples/lib/bld/bld-wrapper.properties index 83ddd2a..bc257d2 100644 --- a/examples/lib/bld/bld-wrapper.properties +++ b/examples/lib/bld/bld-wrapper.properties @@ -1,6 +1,6 @@ bld.downloadExtensionJavadoc=false bld.downloadExtensionSources=true bld.downloadLocation= -bld.extension-gv=com.uwyn.rife2:bld-generated-version:0.9.9 +bld.extension-gv=com.uwyn.rife2:bld-generated-version:1.0.1 bld.repositories=MAVEN_LOCAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES -bld.version=2.1.0 +bld.version=2.2.1 diff --git a/examples/src/bld/java/com/example/SampleBuild.java b/examples/src/bld/java/com/example/SampleBuild.java index f450b0c..c9303a6 100644 --- a/examples/src/bld/java/com/example/SampleBuild.java +++ b/examples/src/bld/java/com/example/SampleBuild.java @@ -27,8 +27,8 @@ public class SampleBuild extends Project { repositories = List.of(MAVEN_CENTRAL, RIFE2_RELEASES); scope(test) - .include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 11, 0))) - .include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 11, 0))); + .include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 12, 1))) + .include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 12, 1))); } public static void main(String[] args) { diff --git a/examples/src/main/java/com/example/GeneratedVersion.java b/examples/src/main/java/com/example/GeneratedVersion.java index 02a3347..64ecb97 100644 --- a/examples/src/main/java/com/example/GeneratedVersion.java +++ b/examples/src/main/java/com/example/GeneratedVersion.java @@ -12,7 +12,7 @@ import java.util.Date; */ public final class GeneratedVersion { public static final String PROJECT = "Sample"; - public static final Date BUILD_DATE = new Date(1725050914888L); + public static final Date BUILD_DATE = new Date(1736843939053L); public static final int MAJOR = 1; public static final int MINOR = 0; public static final int REVISION = 1; diff --git a/lib/bld/bld-wrapper.jar b/lib/bld/bld-wrapper.jar index ca94ae4..e26a2ae 100644 Binary files a/lib/bld/bld-wrapper.jar and b/lib/bld/bld-wrapper.jar differ diff --git a/lib/bld/bld-wrapper.properties b/lib/bld/bld-wrapper.properties index c3b3e47..42fad1d 100644 --- a/lib/bld/bld-wrapper.properties +++ b/lib/bld/bld-wrapper.properties @@ -1,6 +1,6 @@ bld.downloadExtensionJavadoc=false bld.downloadExtensionSources=true bld.downloadLocation= -bld.extension-pmd=com.uwyn.rife2:bld-pmd:1.1.5 +bld.extension-pmd=com.uwyn.rife2:bld-pmd:1.2.2 bld.repositories=MAVEN_CENTRAL,MAVEN_LOCAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES -bld.version=2.1.0 +bld.version=2.2.1 diff --git a/src/bld/java/rife/bld/extension/GeneratedVersionOperationBuild.java b/src/bld/java/rife/bld/extension/GeneratedVersionOperationBuild.java index 9f5158e..d355d07 100644 --- a/src/bld/java/rife/bld/extension/GeneratedVersionOperationBuild.java +++ b/src/bld/java/rife/bld/extension/GeneratedVersionOperationBuild.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023-2025 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. @@ -34,7 +34,7 @@ public class GeneratedVersionOperationBuild extends Project { public GeneratedVersionOperationBuild() { pkg = "rife.bld.extension"; name = "GeneratedVersionOperation"; - version = version(0, 9, 9); + version = version(1, 0, 1); javaRelease = 17; @@ -44,11 +44,11 @@ public class GeneratedVersionOperationBuild extends Project { repositories = List.of(MAVEN_CENTRAL, RIFE2_RELEASES, RIFE2_SNAPSHOTS); scope(compile) - .include(dependency("com.uwyn.rife2", "bld", version(2, 1, 0))); + .include(dependency("com.uwyn.rife2", "bld", version(2, 2, 1))); scope(test) - .include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 11, 0))) - .include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 11, 0))) - .include(dependency("org.assertj", "assertj-core", version(3, 26, 3))); + .include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 12, 1))) + .include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 12, 1))) + .include(dependency("org.assertj", "assertj-core", version(3, 27, 3))); precompileOperation() .templateTypes(TXT); @@ -63,28 +63,26 @@ public class GeneratedVersionOperationBuild extends Project { publishOperation() .repositories(version.isSnapshot() ? repository("rife2-snapshot") : repository("rife2")) + .repository(repository("github")) .info() .groupId("com.uwyn.rife2") .artifactId("bld-generated-version") .description("bld Extension to Generate Project Version Data") .url("https://github.com/rife2/generated-version") - .developer( - new PublishDeveloper() - .id("ethauvin") - .name("Erik C. Thauvin") - .email("erik@thauvin.net") - .url("https://erik.thauvin.net/") + .developer(new PublishDeveloper() + .id("ethauvin") + .name("Erik C. Thauvin") + .email("erik@thauvin.net") + .url("https://erik.thauvin.net/") ) - .license( - new PublishLicense() - .name("The Apache License, Version 2.0") - .url("https://www.apache.org/licenses/LICENSE-2.0.txt") + .license(new PublishLicense() + .name("The Apache License, Version 2.0") + .url("https://www.apache.org/licenses/LICENSE-2.0.txt") ) - .scm( - new PublishScm() - .connection("scm:git:https://github.com/rife2/generated-version.git") - .developerConnection("scm:git:git@github.com:rife2/generated-version.git") - .url("https://github.com/rife2/generated-version") + .scm(new PublishScm() + .connection("scm:git:https://github.com/rife2/generated-version.git") + .developerConnection("scm:git:git@github.com:rife2/generated-version.git") + .url("https://github.com/rife2/generated-version") ) .signKey(property("sign.key")) .signPassphrase(property("sign.passphrase")); diff --git a/src/main/java/rife/bld/extension/GeneratedVersion.java b/src/main/java/rife/bld/extension/GeneratedVersion.java index c7f4bc1..9ae40fb 100644 --- a/src/main/java/rife/bld/extension/GeneratedVersion.java +++ b/src/main/java/rife/bld/extension/GeneratedVersion.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023-2025 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. diff --git a/src/main/java/rife/bld/extension/GeneratedVersionOperation.java b/src/main/java/rife/bld/extension/GeneratedVersionOperation.java index 8968413..6a5e065 100644 --- a/src/main/java/rife/bld/extension/GeneratedVersionOperation.java +++ b/src/main/java/rife/bld/extension/GeneratedVersionOperation.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023-2025 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. diff --git a/src/test/java/rife/bld/extension/GeneratedVersionTest.java b/src/test/java/rife/bld/extension/GeneratedVersionTest.java index d4334ff..32e3508 100644 --- a/src/test/java/rife/bld/extension/GeneratedVersionTest.java +++ b/src/test/java/rife/bld/extension/GeneratedVersionTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023-2025 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. @@ -16,6 +16,7 @@ package rife.bld.extension; +import org.assertj.core.api.AutoCloseableSoftAssertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import rife.bld.BaseProject; @@ -70,6 +71,30 @@ class GeneratedVersionTest { logger.setUseParentHandlers(false); } + /** + * Compares two strings by removing all line separators and whitespace. + * + * @param text1 The first text to compare + * @param text2 The second text to compare + * @return true if the texts are equivalent when line separators are ignored, false otherwise + */ + static boolean compareTextIgnoringLineSeparators(String text1, String text2) { + // Handle null cases + if (text1 == null && text2 == null) { + return true; + } + if (text1 == null || text2 == null) { + return false; + } + + // Remove all line separators and whitespace + var cleanedText1 = text1.replaceAll("\\r?\\n|\\r|\\s", ""); + var cleanedText2 = text2.replaceAll("\\r?\\n|\\r|\\s", ""); + + // Compare the cleaned strings + return cleanedText1.equals(cleanedText2); + } + static void deleteOnExit(File folder) { folder.deleteOnExit(); for (var f : Objects.requireNonNull(folder.listFiles())) { @@ -91,21 +116,22 @@ class GeneratedVersionTest { gv.setClassName("MyVersion"); var t = gv.buildTemplate(); - assertThat(t.getContent()).isEqualTo(""" - package com.example.my; - - public final class MyVersion { - public static final int PROJECT = "My App"; - public static final int MAJOR = 2; - public static final int MINOR = 1; - public static final int REVISION = 3; - public static final String QUALIFIER = ""; - - private MyVersion() { - // no-op - } - } - """); + var v = gv.getProject().version(); + assertThat(v).extracting("majorInt", "minorInt", "revisionInt").as("version") + .containsExactly(2, 1, 3); + assertThat(compareTextIgnoringLineSeparators(t.getContent(), + String.format("package %s;" + + "public final class %s {" + + " public static final int PROJECT = \"%s\";" + + " public static final int MAJOR = %d;" + + " public static final int MINOR = %d;" + + " public static final int REVISION = %d;" + + " public static final String QUALIFIER = \"\";" + + " private MyVersion() {" + + " // no-op" + + " }" + + "}", gv.getPackageName(), gv.getClassName(), gv.getProjectName(), v.majorInt(), + v.minorInt(), v.revisionInt()))).as("template").isTrue(); } @Test @@ -116,9 +142,11 @@ class GeneratedVersionTest { var t = gv.buildTemplate(); assertThat(t).isNotNull(); - assertThat(gv.getProject()).isEqualTo(PROJECT); - assertThat(gv.getPackageName()).isEqualTo(PROJECT.pkg()); - assertThat(gv.getProjectName()).isEqualTo(PROJECT.name()); + try (var softly = new AutoCloseableSoftAssertions()) { + softly.assertThat(gv.getProject()).isEqualTo(PROJECT); + softly.assertThat(gv.getPackageName()).isEqualTo(PROJECT.pkg()); + softly.assertThat(gv.getProjectName()).isEqualTo(PROJECT.name()); + } assertThat(t.getContent()).contains("package com.example;").contains("class GeneratedVersion") .contains("PROJECT = \"MyExample\";").contains("MAJOR = 2").contains("MINOR = 1") @@ -147,7 +175,7 @@ class GeneratedVersionTest { tmpDir.deleteOnExit(); new GeneratedVersionOperation() - .fromProject(new BaseProjectBlueprint(new File("examples"), "com.example", "Example")) + .fromProject(new BaseProjectBlueprint(new File("examples"), "com.example", "Example", "Example")) .directory(tmpDir.getAbsolutePath()) //.classTemplate(new File("examples", "my_app_version.txt")) .classTemplate(new File("examples", "version.txt")) @@ -201,13 +229,15 @@ class GeneratedVersionTest { gv.setDirectory(new File("build")); gv.setExtension(".java"); - assertThat(gv.getProject()).as("project").isEqualTo(PROJECT); - assertThat(gv.getTemplate()).as("template").exists(); - assertThat(gv.getPackageName()).as("package name").isEqualTo("com.example.cool"); - assertThat(gv.getProjectName()).as("project name").isEqualTo("Cool App"); - assertThat(gv.getClassName()).as("class name").isEqualTo("CoolVersion"); - assertThat(gv.getExtension()).as("extension").isEqualTo(".java"); - assertThat(gv.getDirectory()).as("directory").isDirectory(); + try (var softly = new AutoCloseableSoftAssertions()) { + softly.assertThat(gv.getProject()).as("project").isEqualTo(PROJECT); + softly.assertThat(gv.getTemplate()).as("template").exists(); + softly.assertThat(gv.getPackageName()).as("package name").isEqualTo("com.example.cool"); + softly.assertThat(gv.getProjectName()).as("project name").isEqualTo("Cool App"); + softly.assertThat(gv.getClassName()).as("class name").isEqualTo("CoolVersion"); + softly.assertThat(gv.getExtension()).as("extension").isEqualTo(".java"); + softly.assertThat(gv.getDirectory()).as("directory").isDirectory(); + } } @Test