From a6efced67f2b79011e0068fdaa8dbe60e7256a5c Mon Sep 17 00:00:00 2001 From: Christian Stein Date: Thu, 4 Aug 2022 12:06:37 +0200 Subject: [PATCH 1/5] Add input to override Java version Fixes #34 --- .gitignore | 2 ++ action.yml | 18 +++++++++++++++--- src/Download.java | 11 ++++++++++- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 20bf749..351f7f0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ .idea/ classes/ + +*.iml diff --git a/action.yml b/action.yml index dcfdd47..d81279d 100644 --- a/action.yml +++ b/action.yml @@ -19,9 +19,13 @@ inputs: required: true default: 'latest' install: - description: 'Install the downloaded JDK archive file by running actions/setup-java, default to `true`' + description: 'Install the downloaded JDK archive file by running actions/setup-java, defaults to `true`' required: true default: 'true' + install-as-version: + description: 'Controls which value is passed as `java-version` to actions/setup-java, defaults to `PARSE_URI`' + default: 'PARSE_URI' + required: true uri: description: 'URI of JDK archive file to download' required: false @@ -44,9 +48,17 @@ runs: JAVA=$JAVA_HOME_17_X64/bin/java DOWNLOAD=$GITHUB_ACTION_PATH/src/Download.java if [ ! -z "${{ inputs.uri }}" ]; then - $JAVA $DOWNLOAD ${{ inputs.uri }} + $JAVA \ + -Dinstall-as-version="${{ inputs.install-as-version }}" + $DOWNLOAD \ + ${{ inputs.uri }} else - $JAVA $DOWNLOAD ${{ inputs.website }} ${{ inputs.release }} ${{ inputs.version }} + $JAVA \ + -Dinstall-as-version="${{ inputs.install-as-version }}" + $DOWNLOAD \ + ${{ inputs.website }} \ + ${{ inputs.release }} \ + ${{ inputs.version }} fi - name: 'Install Java Development Kit' if: ${{ inputs.install == 'true' }} diff --git a/src/Download.java b/src/Download.java index 1aab55b..e04ca3e 100644 --- a/src/Download.java +++ b/src/Download.java @@ -98,7 +98,7 @@ static void main(boolean dryRun, String... args) { // Set outputs outputs.put("archive", archive.toString()); - outputs.put("version", website.parseVersion(uri).orElse("UNKNOWN-VERSION")); + outputs.put("version", website.computeVersionString(uri)); } catch (Exception exception) { exception.printStackTrace(System.err); GitHub.error("Error detected: " + exception); @@ -289,6 +289,15 @@ default Path computeArchivePath(String uri) { return cache.resolve(file); } + default String computeVersionString(String uri) { + var version = System.getProperty("install-as-version", "PARSE_URI"); + return switch (version) { + case "PARSE_URI" -> parseVersion(uri).orElse("UNKNOWN-VERSION"); + case "HASH_URI" -> Integer.toString(uri.hashCode()); + default -> version; + }; + } + /** Try to parse version information from the given uri. */ default Optional parseVersion(String uri) { for (var versionPattern : parseVersionPatterns()) { From ecac7abc4413f7109442e362de8ab1f9d8bc3696 Mon Sep 17 00:00:00 2001 From: Christian Stein Date: Thu, 4 Aug 2022 12:11:21 +0200 Subject: [PATCH 2/5] Fix shell syntax --- action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index d81279d..b047c9c 100644 --- a/action.yml +++ b/action.yml @@ -49,12 +49,12 @@ runs: DOWNLOAD=$GITHUB_ACTION_PATH/src/Download.java if [ ! -z "${{ inputs.uri }}" ]; then $JAVA \ - -Dinstall-as-version="${{ inputs.install-as-version }}" + -Dinstall-as-version="${{ inputs.install-as-version }}" \ $DOWNLOAD \ ${{ inputs.uri }} else $JAVA \ - -Dinstall-as-version="${{ inputs.install-as-version }}" + -Dinstall-as-version="${{ inputs.install-as-version }}" \ $DOWNLOAD \ ${{ inputs.website }} \ ${{ inputs.release }} \ From cb667c5ff04c579b7975101005e8a9fc84dd80db Mon Sep 17 00:00:00 2001 From: Christian Stein Date: Thu, 4 Aug 2022 12:50:04 +0200 Subject: [PATCH 3/5] Make default value depend on release input --- action.yml | 4 +++- src/Download.java | 7 ++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/action.yml b/action.yml index b047c9c..389477c 100644 --- a/action.yml +++ b/action.yml @@ -23,7 +23,9 @@ inputs: required: true default: 'true' install-as-version: - description: 'Controls which value is passed as `java-version` to actions/setup-java, defaults to `PARSE_URI`' + description: ' + Controls which value is passed as `java-version` to actions/setup-java, defaults to `PARSE_URI` + if `release` starts with a digit, else it defaults to `HASH_URI`' default: 'PARSE_URI' required: true uri: diff --git a/src/Download.java b/src/Download.java index e04ca3e..cb81433 100644 --- a/src/Download.java +++ b/src/Download.java @@ -98,7 +98,8 @@ static void main(boolean dryRun, String... args) { // Set outputs outputs.put("archive", archive.toString()); - outputs.put("version", website.computeVersionString(uri)); + var digit = Character.isDigit(jdk.version().charAt(0)); + outputs.put("version", website.computeVersionString(uri, digit ? "PARSE_URI" : "HASH_URI")); } catch (Exception exception) { exception.printStackTrace(System.err); GitHub.error("Error detected: " + exception); @@ -289,8 +290,8 @@ default Path computeArchivePath(String uri) { return cache.resolve(file); } - default String computeVersionString(String uri) { - var version = System.getProperty("install-as-version", "PARSE_URI"); + default String computeVersionString(String uri, String defaultVersion) { + var version = System.getProperty("install-as-version", defaultVersion); return switch (version) { case "PARSE_URI" -> parseVersion(uri).orElse("UNKNOWN-VERSION"); case "HASH_URI" -> Integer.toString(uri.hashCode()); From cbc0d11f27c692de6bc8e5f7a1431989d99edb00 Mon Sep 17 00:00:00 2001 From: Christian Stein Date: Thu, 4 Aug 2022 12:56:41 +0200 Subject: [PATCH 4/5] Fix action configuration --- action.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/action.yml b/action.yml index 389477c..7ae6eb1 100644 --- a/action.yml +++ b/action.yml @@ -23,11 +23,10 @@ inputs: required: true default: 'true' install-as-version: - description: ' + description: Controls which value is passed as `java-version` to actions/setup-java, defaults to `PARSE_URI` - if `release` starts with a digit, else it defaults to `HASH_URI`' - default: 'PARSE_URI' - required: true + if `release` starts with a digit, else it defaults to `HASH_URI` + required: false uri: description: 'URI of JDK archive file to download' required: false From 00f114ec7d1c549fee7b47d905b2eb9e7c2c7431 Mon Sep 17 00:00:00 2001 From: Christian Stein Date: Thu, 4 Aug 2022 15:44:26 +0200 Subject: [PATCH 5/5] Use default version for null and blank property value --- src/Download.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Download.java b/src/Download.java index cb81433..cd61e5d 100644 --- a/src/Download.java +++ b/src/Download.java @@ -291,7 +291,9 @@ default Path computeArchivePath(String uri) { } default String computeVersionString(String uri, String defaultVersion) { - var version = System.getProperty("install-as-version", defaultVersion); + var property = System.getProperty("install-as-version"); + GitHub.debug("install-as-version: " + property); + var version = property == null || property.isBlank() ? defaultVersion : property; return switch (version) { case "PARSE_URI" -> parseVersion(uri).orElse("UNKNOWN-VERSION"); case "HASH_URI" -> Integer.toString(uri.hashCode());