From 2f3fd3f9a700e4af38aeb0c633107486205c93ee Mon Sep 17 00:00:00 2001 From: "M. Scott Ford" Date: Thu, 15 Dec 2022 15:04:53 -0500 Subject: [PATCH 1/6] Adds a note about Java support --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d6883f8..0e567f1 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Freshli Agent: Java -This application is used by the [`freshli` CLI](https://github.com/corgibytes/freshli-cli) to detect and process manifest files from the Java ecosystem. +This application is used by the [`freshli` CLI](https://github.com/corgibytes/freshli-cli) to detect and process manifest files from the Java ecosystem. It runs on Java 8 or newer, and is tested against Java 8, 11, and 17 on both Windows and Linux. ## Building From bf601cc64fab2df6b00c7cda857a8ff39b4bafc8 Mon Sep 17 00:00:00 2001 From: "M. Scott Ford" Date: Fri, 23 Dec 2022 19:38:34 -0500 Subject: [PATCH 2/6] Creates native image with embedded JRE * Uses jpackage and jlink to create platform specific executables that have a custom JRE bundled with them * Uses tags in git to determine the version number --- README.md | 16 ++++++------ bin/build.rb | 2 +- build.gradle.kts | 51 +++++++++++++++++++++++++++++++++------ features/support/aruba.rb | 11 ++++++--- gradle/ide.gradle | 8 ++++++ gradle/release.gradle | 20 +++++++++++++++ version.properties | 5 ++++ 7 files changed, 93 insertions(+), 20 deletions(-) create mode 100644 gradle/ide.gradle create mode 100644 gradle/release.gradle create mode 100644 version.properties diff --git a/README.md b/README.md index 0e567f1..30ec76b 100644 --- a/README.md +++ b/README.md @@ -33,21 +33,21 @@ ruby .\bin\build.rb #### Using Gradle -Make sure you have JDK version 17 or later installed and have your `JAVA_HOME` environment varibale set appropriately. +Make sure you have JDK version 17 or later installed and have your `JAVA_HOME` environment variable set appropriately. Run the following command to create a complete deployable distribution for the project. On macOS or Linux: ```bash -./gradlew installDist +./gradlew jpackageImage ``` On Windows: ```pwsh -.\gradlew.bat installDist +.\gradlew.bat jpackageImage ``` -This will create `build/install/freshli-agent-java`. Within that folder, the `bin` directory contains wrappers for running the application. Adding the full path to that `bin` directory to the `PATH` environment variable will enable you to run `freshli-agent-java` from any directory. +This will create `build/jpackage/freshli-agent-java`. Adding that directory to the `PATH` environment variable will enable you to run `freshli-agent-java` from outside of that directory. ## Running @@ -75,18 +75,18 @@ On Windows: `.\gradlew.bat run --args="--help" ``` -#### Running from Distribution Directory +#### Running from build image directory -You can run the program from the distribution that's created by the `installDist` Gradle task. +You can run the program from the directory that's created by the `jpackgaeImage` Gradle task. On macOS and Linux: ```bash -./build/install/freshli-agent-java/bin/freshli-agent-java.bat --help +./build/jpackage/freshli-agent-java/freshli-agent-java --help ``` On Windows: ```pwsh -.\build\install\freshli-agent-java\bin\freshli-agent-java --help +.\build\jpackage\freshli-agent-java\freshli-agent-java.exe --help ``` ### Running Tests diff --git a/bin/build.rb b/bin/build.rb index 09752b8..a1ee623 100755 --- a/bin/build.rb +++ b/bin/build.rb @@ -7,6 +7,6 @@ enable_dotnet_command_colors -status = execute('./gradlew installDist') +status = execute('./gradlew jpackageImage') exit(status.exitstatus) diff --git a/build.gradle.kts b/build.gradle.kts index 2893a7d..bf61fdb 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,17 +1,39 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - -plugins { - kotlin("jvm") version "1.7.22" - application -} +import org.apache.tools.ant.taskdefs.condition.Os group = "com.corgibytes" -version = "1.0-SNAPSHOT" + +buildscript { + repositories { + mavenLocal() // for local testing of shipkit + gradlePluginPortal() + mavenCentral() + } + dependencies { + classpath("org.shipkit:shipkit-auto-version:1.+") + classpath("org.shipkit:shipkit-changelog:1.+") + } +} repositories { + mavenLocal() mavenCentral() } +extensions.findByName("buildScan")?.withGroovyBuilder { + setProperty("termsOfServiceUrl", "https://gradle.com/terms-of-service") + setProperty("termsOfServiceAgree", "yes") +} + +apply("gradle/release.gradle") +apply("gradle/ide.gradle") + +plugins { + kotlin("jvm") version "1.7.22" + id("org.beryx.runtime") version "1.12.7" + application +} + dependencies { implementation("com.github.ajalt.clikt:clikt:3.5.0") implementation("com.corgibytes:dependency-history-maven:2.0.17") @@ -28,9 +50,24 @@ tasks.test { } tasks.withType { - kotlinOptions.jvmTarget = "1.8" + kotlinOptions.jvmTarget = "17" } application { mainClass.set("com.corgibytes.freshli.agent.java.MainKt") } + +runtime { + options.set(listOf("--strip-debug", "--compress", "2", "--no-header-files", "--no-man-pages")) + modules.set(listOf( + "java.base", + "java.xml", + "jdk.crypto.ec" + )) + + jpackage { + if (!Os.isFamily(Os.FAMILY_WINDOWS)) { + imageOptions = listOf("--win-console") + } + } +} diff --git a/features/support/aruba.rb b/features/support/aruba.rb index eae7766..55f1f09 100644 --- a/features/support/aruba.rb +++ b/features/support/aruba.rb @@ -8,8 +8,8 @@ config.exit_timeout = 300 # Use aruba working directory config.home_directory = File.join(config.root_directory, config.working_directory) - # include the `freshli-agent-java` run scripts from the build directory in the path - config.command_search_paths << File.expand_path('../../build/install/freshli-agent-java/bin', __dir__) + # include the `freshli-agent-java` native image from the build directory in the path + config.command_search_paths << File.expand_path('../../build/jpackage/freshli-agent-java', __dir__) end # Contains helper methods for coping with platform specific differences @@ -19,7 +19,10 @@ def self.null_output_target end def self.normalize_file_separators(value) - separator = File::ALT_SEPARATOR || File::SEPARATOR - value.gsub('/', separator) + value.gsub('/', file_separator) + end + + def self.file_separator + File::ALT_SEPARATOR || File::SEPARATOR end end diff --git a/gradle/ide.gradle b/gradle/ide.gradle new file mode 100644 index 0000000..df8dd21 --- /dev/null +++ b/gradle/ide.gradle @@ -0,0 +1,8 @@ +// Based on: https://github.com/shipkit/shipkit-demo/blob/f604dbf393f9549cc78c7c57b05dc69f9c7ab0fc/gradle/ide.gradle +assert rootProject == project + +allprojects { + apply plugin: 'idea' +} + +idea.project.vcs = 'Git' diff --git a/gradle/release.gradle b/gradle/release.gradle new file mode 100644 index 0000000..393fb6b --- /dev/null +++ b/gradle/release.gradle @@ -0,0 +1,20 @@ +// Based on: https://github.com/shipkit/shipkit-demo/blob/f604dbf393f9549cc78c7c57b05dc69f9c7ab0fc/gradle/release.gradle + +//Plugin jars are added to the buildscript classpath in the root build.gradle file +apply plugin: "org.shipkit.shipkit-auto-version" + +apply plugin: "org.shipkit.shipkit-changelog" +tasks.named("generateChangelog") { + previousRevision = project.ext.'shipkit-auto-version.previous-tag' + githubToken = System.getenv("GITHUB_TOKEN") + repository = "corgibytes/dependency-history-maven" +} + +apply plugin: "org.shipkit.shipkit-github-release" +tasks.named("githubRelease") { + dependsOn tasks.named("generateChangelog") + repository = "corgibytes/dependency-history-maven" + changelog = tasks.named("generateChangelog").get().outputFile + githubToken = System.getenv("GITHUB_TOKEN") + newTagRevision = System.getenv("GITHUB_SHA") +} diff --git a/version.properties b/version.properties new file mode 100644 index 0000000..96f1419 --- /dev/null +++ b/version.properties @@ -0,0 +1,5 @@ +# shipkit-auto-version Gradle plugin uses this version spec to deduct the version to build +# it increments patch version based on most recent tag. +# You can put explicit version here if needed, e.g. "1.0.0" +# More information: https://github.com/shipkit/shipkit-auto-version/blob/master/README.md +version=1.0.* From a9321543e4137f4d2462afb5909a8885b416a001 Mon Sep 17 00:00:00 2001 From: "M. Scott Ford" Date: Fri, 23 Dec 2022 19:41:07 -0500 Subject: [PATCH 3/6] Updates build matrix * Removes testing against multiple java versions, since the JRE is embedded into the executable * Adds macOS as a platform for testing on --- .github/workflows/ci.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 22f1728..87dfd26 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,8 +12,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, windows-latest] - java-version: [ '8', '11', '17' ] + os: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.os }} env: @@ -29,7 +28,7 @@ jobs: uses: actions/setup-java@v3 with: distribution: 'temurin' - java-version: ${{ matrix.java-version }} + java-version: '17' - name: "[Setup] - Install Ruby" uses: ruby/setup-ruby@v1 @@ -44,7 +43,6 @@ jobs: chmod a+x cyclonedx-linux-x64 mv cyclonedx-linux-x64 cyclonedx echo "$GITHUB_WORKSPACE/bin" >> $GITHUB_PATH - - name: "[Lint] - run linters" run: | From 83f13b118a6404db05ec5c1d7ed232fa9e0e28e4 Mon Sep 17 00:00:00 2001 From: "M. Scott Ford" Date: Fri, 23 Dec 2022 19:47:09 -0500 Subject: [PATCH 4/6] Uses string to specify ruby version --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 87dfd26..cb323b8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,7 +33,7 @@ jobs: - name: "[Setup] - Install Ruby" uses: ruby/setup-ruby@v1 with: - ruby-version: 3.0 # Not needed with a .ruby-version file + ruby-version: '3.0' # Not needed with a .ruby-version file bundler-cache: true - name: "[Setup] - Install CycloneDX CLI" From ecbf10cad5b877fde87d08229f309de2614b958f Mon Sep 17 00:00:00 2001 From: "M. Scott Ford" Date: Fri, 23 Dec 2022 19:49:06 -0500 Subject: [PATCH 5/6] Adds macOS runtime to the approved list --- Gemfile.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index b2e49fe..6eba63b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -44,6 +44,7 @@ GEM mime-types (3.4.1) mime-types-data (~> 3.2015) mime-types-data (3.2022.0105) + mini_portile2 (2.8.0) multi_test (1.1.0) parallel (1.22.1) parser (3.1.2.1) @@ -68,10 +69,8 @@ GEM rubocop-ast (1.23.0) parser (>= 3.1.1.0) ruby-progressbar (1.11.0) - sqlite3 (1.5.3-arm64-darwin) - sqlite3 (1.5.3-x64-mingw-ucrt) - sqlite3 (1.5.3-x64-mingw32) - sqlite3 (1.5.3-x86_64-linux) + sqlite3 (1.5.3) + mini_portile2 (~> 2.8.0) sys-uname (1.2.2) ffi (~> 1.1) thor (1.2.1) @@ -81,6 +80,7 @@ PLATFORMS arm64-darwin-21 x64-mingw-ucrt x64-mingw32 + x86_64-darwin-19 x86_64-linux DEPENDENCIES From efb72aa82c789c3b4f49bd4f3dd00c118a10ccae Mon Sep 17 00:00:00 2001 From: "M. Scott Ford" Date: Fri, 23 Dec 2022 19:54:05 -0500 Subject: [PATCH 6/6] Fixes logic error with Windows OS detection --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index bf61fdb..2a3b7f7 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -66,7 +66,7 @@ runtime { )) jpackage { - if (!Os.isFamily(Os.FAMILY_WINDOWS)) { + if (Os.isFamily(Os.FAMILY_WINDOWS)) { imageOptions = listOf("--win-console") } }