From be05f6d6b38afcfd945d68d375846b7c5e2db4b4 Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Thu, 21 Nov 2024 16:58:15 +0100 Subject: [PATCH] Feature: Use argument files (#70) --- .github/workflows/build-linux.yml | 39 +++++++------------------- .github/workflows/build-mac.yml | 39 +++++++------------------- .github/workflows/build-win.yml | 40 +++++++-------------------- build_linux.sh | 38 ++++++------------------- build_mac.sh | 37 ++++++------------------- build_win.ps1 | 46 ++++++++++--------------------- dist/jlink.args | 9 ++++++ dist/jpackage.args | 20 ++++++++++++++ 8 files changed, 92 insertions(+), 176 deletions(-) create mode 100644 dist/jlink.args create mode 100644 dist/jpackage.args diff --git a/.github/workflows/build-linux.yml b/.github/workflows/build-linux.yml index ee16919..ca85d8e 100644 --- a/.github/workflows/build-linux.yml +++ b/.github/workflows/build-linux.yml @@ -77,36 +77,17 @@ jobs: cp LICENSE.txt target cp target/cryptomator-*.jar target/mods - name: Run jlink - run: > - "${JAVA_HOME}/bin/jlink" - --verbose - --output target/runtime - --module-path "${JAVA_HOME}/jmods" - --add-modules java.base,java.compiler,java.naming,java.xml - --strip-native-commands - --no-header-files - --no-man-pages - --strip-debug - --compress zip-6 + run: | + envsubst < dist/jlink.args > target/jlink.args + "${JAVA_HOME}/bin/jlink" '@./target/jlink.args' - name: Run jpackage - run: > - "${JAVA_HOME}/bin/jpackage" - --verbose - --type app-image - --runtime-image target/runtime - --input target/libs - --module-path target/mods - --module org.cryptomator.cli/org.cryptomator.cli.CryptomatorCli - --dest target - --name cryptomator-cli - --vendor "Skymatic GmbH" - --copyright "(C) 2016 - 2024 Skymatic GmbH" - --app-version "${{ needs.prepare.outputs.semVerNum }}" - --java-options "-Dorg.cryptomator.cli.version=${{ needs.prepare.outputs.semVerStr }}" - --java-options "--enable-native-access=${{ matrix.native-access-lib }}" - --java-options "-Xss5m" - --java-options "-Xmx256m" - --java-options "-Dfile.encoding=\"utf-8\"" + run: | + envsubst < dist/jpackage.args > target/jpackage.args + "${JAVA_HOME}/bin/jpackage" '@./target/jpackage.args' + env: + JP_APP_VERSION: ${{ needs.prepare.outputs.semVerNum }} + APP_VERSION: ${{ needs.prepare.outputs.semVerStr }} + NATIVE_ACCESS_PACKAGE: ${{ matrix.native-access-lib }} - uses: actions/upload-artifact@v4 with: name: cryptomator-cli-linux-${{ matrix.architecture }} diff --git a/.github/workflows/build-mac.yml b/.github/workflows/build-mac.yml index b14d5f0..539aa4c 100644 --- a/.github/workflows/build-mac.yml +++ b/.github/workflows/build-mac.yml @@ -75,36 +75,17 @@ jobs: cp LICENSE.txt target cp target/cryptomator-*.jar target/mods - name: Run jlink - run: > - "${JAVA_HOME}/bin/jlink" - --verbose - --output target/runtime - --module-path "${JAVA_HOME}/jmods" - --add-modules java.base,java.compiler,java.naming,java.xml - --strip-native-commands - --no-header-files - --no-man-pages - --strip-debug - --compress zip-6 + run: | + envsubst < dist/jlink.args > target/jlink.args + "${JAVA_HOME}/bin/jlink" '@./target/jlink.args' - name: Run jpackage - run: > - "${JAVA_HOME}/bin/jpackage" - --verbose - --type app-image - --runtime-image target/runtime - --input target/libs - --module-path target/mods - --module org.cryptomator.cli/org.cryptomator.cli.CryptomatorCli - --dest target - --name cryptomator-cli - --vendor "Skymatic GmbH" - --copyright "(C) 2016 - 2024 Skymatic GmbH" - --app-version "${{ needs.prepare.outputs.semVerNum }}" - --java-options "-Dorg.cryptomator.cli.version=${{ needs.prepare.outputs.semVerStr }}" - --java-options "--enable-native-access=org.cryptomator.jfuse.mac" - --java-options "-Xss5m" - --java-options "-Xmx256m" - --java-options "-Dfile.encoding=\"utf-8\"" + run: | + envsubst < dist/jpackage.args > target/jpackage.args + "${JAVA_HOME}/bin/jpackage" '@./target/jpackage.args' + env: + JP_APP_VERSION: ${{ needs.prepare.outputs.semVerNum }} + APP_VERSION: ${{ needs.prepare.outputs.semVerStr }} + NATIVE_ACCESS_PACKAGE: org.cryptomator.jfuse.mac - uses: actions/upload-artifact@v4 with: name: cryptomator-cli-mac-${{ matrix.architecture }} diff --git a/.github/workflows/build-win.yml b/.github/workflows/build-win.yml index ac1ff6c..639ba44 100644 --- a/.github/workflows/build-win.yml +++ b/.github/workflows/build-win.yml @@ -67,37 +67,17 @@ jobs: cp LICENSE.txt target cp target/cryptomator-*.jar target/mods - name: Run jlink - run: > - "${JAVA_HOME}/bin/jlink" - --verbose - --output target/runtime - --module-path "${JAVA_HOME}/jmods" - --add-modules java.base,java.compiler,java.naming,java.xml - --strip-native-commands - --no-header-files - --no-man-pages - --strip-debug - --compress zip-6 + run: | + envsubst < dist/jlink.args > target/jlink.args + "${JAVA_HOME}/bin/jlink" '@./target/jlink.args' - name: Run jpackage - run: > - "${JAVA_HOME}/bin/jpackage" - --verbose - --type app-image - --runtime-image target/runtime - --input target/libs - --module-path target/mods - --module org.cryptomator.cli/org.cryptomator.cli.CryptomatorCli - --dest target - --name cryptomator-cli - --vendor "Skymatic GmbH" - --copyright "(C) 2016 - 2024 Skymatic GmbH" - --app-version "${{ needs.prepare.outputs.semVerNum }}" - --java-options "-Dorg.cryptomator.cli.version=${{ needs.prepare.outputs.semVerStr }}" - --java-options "--enable-native-access=org.cryptomator.jfuse.win" - --java-options "-Xss5m" - --java-options "-Xmx256m" - --java-options "-Dfile.encoding=\"utf-8\"" - --win-console + run: | + envsubst < dist/jpackage.args > target/jpackage.args + "${JAVA_HOME}/bin/jpackage" '@./target/jpackage.args' --win-console + env: + JP_APP_VERSION: ${{ needs.prepare.outputs.semVerNum }} + APP_VERSION: ${{ needs.prepare.outputs.semVerStr }} + NATIVE_ACCESS_PACKAGE: org.cryptomator.jfuse.win - uses: actions/upload-artifact@v4 with: name: cryptomator-cli-win-x64 diff --git a/build_linux.sh b/build_linux.sh index da5dc5f..d1be9cc 100644 --- a/build_linux.sh +++ b/build_linux.sh @@ -3,6 +3,8 @@ set -euxo pipefail echo "Building cryptomator cli..." +export APP_VERSION='0.1.0-local' + # Check if Maven is installed if ! command -v mvn &> /dev/null; then echo "Maven is not installed. Please install Maven to proceed." @@ -29,23 +31,15 @@ cp ./LICENSE.txt ./target/ mv ./target/cryptomator-cli-*.jar ./target/mods echo "Creating JRE with jlink..." -"$JAVA_HOME/bin/jlink" \ - --verbose \ - --output target/runtime \ - --module-path "${JAVA_HOME}/jmods" \ - --add-modules java.base,java.compiler,java.naming,java.xml \ - --strip-native-commands \ - --no-header-files \ - --no-man-pages \ - --strip-debug \ - --compress zip-0 +envsubst < dist/jlink.args > target/jlink.args +"$JAVA_HOME/bin/jlink" '@./target/jlink.args' if [ $? -ne 0 ] || [ ! -d ./target/runtime ]; then echo "JRE creation with jlink failed." exit 1 fi -NATIVE_ACCESS_PACKAGE="no.native.access.available" +export NATIVE_ACCESS_PACKAGE="no.native.access.available" _OS=$(uname -s) if (echo "$_OS" | grep -q "Linux.*") ; then _ARCH=$(uname -m) @@ -59,25 +53,11 @@ if (echo "$_OS" | grep -q "Linux.*") ; then fi fi +export JP_APP_VERSION='99.9.9' +envsubst < dist/jpackage.args > target/jpackage.args + echo "Creating app binary with jpackage..." -"$JAVA_HOME/bin/jpackage" \ - --verbose \ - --type app-image \ - --runtime-image target/runtime \ - --input target/libs \ - --module-path target/mods \ - --module org.cryptomator.cli/org.cryptomator.cli.CryptomatorCli \ - --dest target \ - --name cryptomator-cli \ - --vendor "Skymatic GmbH" \ - --copyright "(C) 2016 - 2024 Skymatic GmbH" \ - --app-version "0.0.1.0" \ - --java-options "-Dorg.cryptomator.cli.version=0.0.1-local" \ - --java-options "--enable-preview" \ - --java-options "--enable-native-access=${NATIVE_ACCESS_PACKAGE}" \ - --java-options "-Xss5m" \ - --java-options "-Xmx256m" \ - --java-options "-Dfile.encoding=utf-8" \ +"$JAVA_HOME/bin/jpackage" '@./target/jpackage.args' if [ $? -ne 0 ] || [ ! -d ./target/cryptomator-cli ]; then echo "Binary creation with jpackage failed." diff --git a/build_mac.sh b/build_mac.sh index 7d8350b..a46b5c5 100644 --- a/build_mac.sh +++ b/build_mac.sh @@ -2,6 +2,8 @@ echo "Building cryptomator cli..." +export APP_VERSION='0.1.0-local' + # Check if Maven is installed if ! command -v mvn &> /dev/null; then echo "Maven is not installed. Please install Maven to proceed." @@ -28,41 +30,20 @@ cp ./LICENSE.txt ./target/ mv ./target/cryptomator-cli-*.jar ./target/mods echo "Creating JRE with jlink..." -"$JAVA_HOME/bin/jlink" \ - --verbose \ - --output target/runtime \ - --module-path "${JAVA_HOME}/jmods" \ - --add-modules java.base,java.compiler,java.naming,java.xml \ - --strip-native-commands \ - --no-header-files \ - --no-man-pages \ - --strip-debug \ - --compress zip-0 +envsubst < dist/jlink.args > target/jlink.args +"$JAVA_HOME/bin/jlink" '@./target/jlink.args' if [ $? -ne 0 ] || [ ! -d ./target/runtime ]; then echo "JRE creation with jlink failed." exit 1 fi +export JP_APP_VERSION='99.9.9' +export NATIVE_ACCESS_PACKAGE="org.cryptomator.jfuse.mac" +envsubst < dist/jpackage.args > target/jpackage.args + echo "Creating app binary with jpackage..." -"$JAVA_HOME/bin/jpackage" \ - --verbose \ - --type app-image \ - --runtime-image target/runtime \ - --input target/libs \ - --module-path target/mods \ - --module org.cryptomator.cli/org.cryptomator.cli.CryptomatorCli \ - --dest target \ - --name cryptomator-cli \ - --vendor "Skymatic GmbH" \ - --copyright "(C) 2016 - 2024 Skymatic GmbH" \ - --app-version "99.9.9" \ - --java-options "-Dorg.cryptomator.cli.version=0.0.1-local" \ - --java-options "--enable-preview" \ - --java-options "--enable-native-access=org.cryptomator.jfuse.mac" \ - --java-options "-Xss5m" \ - --java-options "-Xmx256m" \ - --java-options "-Dfile.encoding=utf-8" \ +"$JAVA_HOME/bin/jpackage" '@./target/jpackage.args' if [ $? -ne 0 ] || [ ! -d ./target/cryptomator-cli.app ]; then echo "Binary creation with jpackage failed." diff --git a/build_win.ps1 b/build_win.ps1 index 3cafd14..6ee9772 100644 --- a/build_win.ps1 +++ b/build_win.ps1 @@ -1,5 +1,7 @@ "Building cryptomator cli..." +$appVersion='0.1.0-local' + # Check if maven is installed $commands = 'mvn' foreach ($cmd in $commands) { @@ -14,7 +16,7 @@ if(-not $env:JAVA_HOME) { # Check Java version $minJavaVersion=$(mvn help:evaluate "-Dexpression=jdk.version" -q -DforceStdout) $javaVersion = $(& "$env:JAVA_HOME\bin\java" --version) -split ' ' | Select-Object -Index 1 -if( ($javaVersion -split '.' | Select-Object -First 1) -ne "22") { +if( ($javaVersion.Split('.') | Select-Object -First 1) -ne "22") { throw "Java version $javaVersion is too old. Minimum required version is $minJavaVersion" } @@ -24,43 +26,25 @@ Copy-Item ./LICENSE.txt -Destination ./target -ErrorAction Stop Move-Item ./target/cryptomator-cli-*.jar ./target/mods -ErrorAction Stop Write-Host "Creating JRE with jlink..." -& $env:JAVA_HOME/bin/jlink ` ---verbose ` ---output target/runtime ` ---module-path "${env:JAVA_HOME}/jmods" ` ---add-modules java.base,java.compiler,java.naming,java.xml ` ---strip-native-commands ` ---no-header-files ` ---no-man-pages ` ---strip-debug ` ---compress zip-0 +Get-Content -Path './dist/jlink.args' | ForEach-Object { $_.Replace('${JAVA_HOME}', "$env:JAVA_HOME")} | Out-File -FilePath './target/jlink.args' +& $env:JAVA_HOME/bin/jlink `@./target/jlink.args if ( ($LASTEXITCODE -ne 0) -or (-not (Test-Path ./target/runtime))) { - throw "JRE creation with jLink failed with exit code $LASTEXITCODE." + throw "JRE creation with jLink failed with exit code $LASTEXITCODE." } +## powershell does not have envsubst +$jpAppVersion='99.9.9' +Get-Content -Path './dist/jpackage.args' | ForEach-Object { + $_.Replace('${APP_VERSION}', $appVersion). + Replace('${JP_APP_VERSION}', $jpAppVersion). + Replace('${NATIVE_ACCESS_PACKAGE}', 'org.cryptomator.jfuse.win') +} | Out-File -FilePath './target/jpackage.args' + # jpackage # app-version is hard coded, since the script is only for local test builds Write-Host "Creating app binary with jpackage..." -& $env:JAVA_HOME/bin/jpackage ` - --verbose ` - --type app-image ` - --runtime-image target/runtime ` - --input target/libs ` - --module-path target/mods ` - --module org.cryptomator.cli/org.cryptomator.cli.CryptomatorCli ` - --dest target ` - --name cryptomator-cli ` - --vendor "Skymatic GmbH" ` - --copyright "(C) 2016 - 2024 Skymatic GmbH" ` - --app-version "0.0.1.0" ` - --java-options "-Dorg.cryptomator.cli.version=0.0.1-local" ` - --java-options "--enable-preview" ` - --java-options "--enable-native-access=org.cryptomator.jfuse.win" ` - --java-options "-Xss5m" ` - --java-options "-Xmx256m" ` - --java-options '-Dfile.encoding="utf-8"' ` - --win-console +& $env:JAVA_HOME/bin/jpackage `@./target/jpackage.args --win-console if ( ($LASTEXITCODE -ne 0) -or (-not (Test-Path ./target/cryptomator-cli))) { throw "Binary creation with jpackage failed with exit code $LASTEXITCODE." diff --git a/dist/jlink.args b/dist/jlink.args new file mode 100644 index 0000000..c42f03f --- /dev/null +++ b/dist/jlink.args @@ -0,0 +1,9 @@ +--verbose +--module-path "${JAVA_HOME}/jmods" +--output target/runtime +--add-modules java.base,java.compiler,java.naming,java.xml +--strip-native-commands +--no-header-files +--no-man-pages +--strip-debug +--compress zip-6 \ No newline at end of file diff --git a/dist/jpackage.args b/dist/jpackage.args new file mode 100644 index 0000000..599212f --- /dev/null +++ b/dist/jpackage.args @@ -0,0 +1,20 @@ +# Contains three env vars: +# JP_APP_VERSION: The version needed for jpackage. This version _must_ follow the scheme Y.X.X, where Y >= 1 and X >=0 +# APP_VERSION: The actual, semantic version displayed in the cli app +# NATIVE_ACCESS_PACKAGE: The java package containing the fuse bindings for the system +--verbose +--type app-image +--runtime-image target/runtime +--input target/libs +--module-path target/mods +--module org.cryptomator.cli/org.cryptomator.cli.CryptomatorCli +--dest target +--name cryptomator-cli +--vendor "Skymatic GmbH" +--copyright "(C) 2016 - 2024 Skymatic GmbH" +--app-version "${JP_APP_VERSION}" +--java-options "-Dorg.cryptomator.cli.version=${APP_VERSION}" +--java-options "--enable-native-access=${NATIVE_ACCESS_PACKAGE}" +--java-options "-Xss5m" +--java-options "-Xmx256m" +--java-options "-Dfile.encoding=\"utf-8\"" \ No newline at end of file