Skip to content

Commit c59dba7

Browse files
authored
Add install-as-version input
Fixes #34
1 parent dfd0df3 commit c59dba7

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
.idea/
22
classes/
3+
4+
*.iml

action.yml

+16-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,14 @@ inputs:
1919
required: true
2020
default: 'latest'
2121
install:
22-
description: 'Install the downloaded JDK archive file by running actions/setup-java, default to `true`'
22+
description: 'Install the downloaded JDK archive file by running actions/setup-java, defaults to `true`'
2323
required: true
2424
default: 'true'
25+
install-as-version:
26+
description:
27+
Controls which value is passed as `java-version` to actions/setup-java, defaults to `PARSE_URI`
28+
if `release` starts with a digit, else it defaults to `HASH_URI`
29+
required: false
2530
uri:
2631
description: 'URI of JDK archive file to download'
2732
required: false
@@ -44,9 +49,17 @@ runs:
4449
JAVA=$JAVA_HOME_17_X64/bin/java
4550
DOWNLOAD=$GITHUB_ACTION_PATH/src/Download.java
4651
if [ ! -z "${{ inputs.uri }}" ]; then
47-
$JAVA $DOWNLOAD ${{ inputs.uri }}
52+
$JAVA \
53+
-Dinstall-as-version="${{ inputs.install-as-version }}" \
54+
$DOWNLOAD \
55+
${{ inputs.uri }}
4856
else
49-
$JAVA $DOWNLOAD ${{ inputs.website }} ${{ inputs.release }} ${{ inputs.version }}
57+
$JAVA \
58+
-Dinstall-as-version="${{ inputs.install-as-version }}" \
59+
$DOWNLOAD \
60+
${{ inputs.website }} \
61+
${{ inputs.release }} \
62+
${{ inputs.version }}
5063
fi
5164
- name: 'Install Java Development Kit'
5265
if: ${{ inputs.install == 'true' }}

src/Download.java

+13-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ static void main(boolean dryRun, String... args) {
9898

9999
// Set outputs
100100
outputs.put("archive", archive.toString());
101-
outputs.put("version", website.parseVersion(uri).orElse("UNKNOWN-VERSION"));
101+
var digit = Character.isDigit(jdk.version().charAt(0));
102+
outputs.put("version", website.computeVersionString(uri, digit ? "PARSE_URI" : "HASH_URI"));
102103
} catch (Exception exception) {
103104
exception.printStackTrace(System.err);
104105
GitHub.error("Error detected: " + exception);
@@ -289,6 +290,17 @@ default Path computeArchivePath(String uri) {
289290
return cache.resolve(file);
290291
}
291292

293+
default String computeVersionString(String uri, String defaultVersion) {
294+
var property = System.getProperty("install-as-version");
295+
GitHub.debug("install-as-version: " + property);
296+
var version = property == null || property.isBlank() ? defaultVersion : property;
297+
return switch (version) {
298+
case "PARSE_URI" -> parseVersion(uri).orElse("UNKNOWN-VERSION");
299+
case "HASH_URI" -> Integer.toString(uri.hashCode());
300+
default -> version;
301+
};
302+
}
303+
292304
/** Try to parse version information from the given uri. */
293305
default Optional<String> parseVersion(String uri) {
294306
for (var versionPattern : parseVersionPatterns()) {

0 commit comments

Comments
 (0)