mirror of
https://gitea.com/actions/setup-java.git
synced 2025-04-06 15:29:37 +00:00
Patch for java version file (#610)
* patch to extract file from other location * patch to extract filename from other directories * removed code failing checks * changed the validation for .java-version type
This commit is contained in:
12
src/util.ts
12
src/util.ts
@ -119,13 +119,17 @@ export function getVersionFromFileContent(
|
||||
versionFile: string
|
||||
): string | null {
|
||||
let javaVersionRegExp: RegExp;
|
||||
if (versionFile == '.tool-versions') {
|
||||
|
||||
function getFileName(versionFile: string) {
|
||||
return path.basename(versionFile);
|
||||
}
|
||||
|
||||
const versionFileName = getFileName(versionFile);
|
||||
if (versionFileName == '.tool-versions') {
|
||||
javaVersionRegExp =
|
||||
/^(java\s+)(?:\S*-)?v?(?<version>(\d+)(\.\d+)?(\.\d+)?(\+\d+)?(-ea(\.\d+)?)?)$/m;
|
||||
} else if (versionFile == '.java-version') {
|
||||
javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
|
||||
} else {
|
||||
throw new Error('Invalid version file');
|
||||
javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
|
||||
}
|
||||
|
||||
const fileContent = content.match(javaVersionRegExp)?.groups?.version
|
||||
|
Reference in New Issue
Block a user