Skip to content

Add install-as-version input #35

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

Merged
merged 5 commits into from
Aug 5, 2022
Merged
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
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