Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creates platform specific executables with embedded JRE #59

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -29,12 +28,12 @@ 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
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"
Expand All @@ -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: |
Expand Down
8 changes: 4 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -81,6 +80,7 @@ PLATFORMS
arm64-darwin-21
x64-mingw-ucrt
x64-mingw32
x86_64-darwin-19
x86_64-linux

DEPENDENCIES
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion bin/build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@

enable_dotnet_command_colors

status = execute('./gradlew installDist')
status = execute('./gradlew jpackageImage')

exit(status.exitstatus)
51 changes: 44 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -28,9 +50,24 @@ tasks.test {
}

tasks.withType<KotlinCompile> {
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")
}
}
}
11 changes: 7 additions & 4 deletions features/support/aruba.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
8 changes: 8 additions & 0 deletions gradle/ide.gradle
Original file line number Diff line number Diff line change
@@ -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'
20 changes: 20 additions & 0 deletions gradle/release.gradle
Original file line number Diff line number Diff line change
@@ -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")
}
5 changes: 5 additions & 0 deletions version.properties
Original file line number Diff line number Diff line change
@@ -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.*