Skip to content

Commit

Permalink
Add install-as-version input
Browse files Browse the repository at this point in the history
Fixes #34
  • Loading branch information
sormuras authored Aug 5, 2022
1 parent dfd0df3 commit c59dba7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.idea/
classes/

*.iml
19 changes: 16 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@ 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`
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
Expand All @@ -44,9 +49,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' }}
Expand Down
14 changes: 13 additions & 1 deletion src/Download.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ static void main(boolean dryRun, String... args) {

// Set outputs
outputs.put("archive", archive.toString());
outputs.put("version", website.parseVersion(uri).orElse("UNKNOWN-VERSION"));
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);
Expand Down Expand Up @@ -289,6 +290,17 @@ default Path computeArchivePath(String uri) {
return cache.resolve(file);
}

default String computeVersionString(String uri, String 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());
default -> version;
};
}

/** Try to parse version information from the given uri. */
default Optional<String> parseVersion(String uri) {
for (var versionPattern : parseVersionPatterns()) {
Expand Down

0 comments on commit c59dba7

Please sign in to comment.