Unverified Commit 0f481fcb authored by Lukasz's avatar Lukasz Committed by GitHub
Browse files

feat: Add distribution detection support to .sdkmanrc file (#975)

* feat: Add distribution detection support to .sdkmanrc file

Extends .sdkmanrc support to automatically detect Java distribution from SDKMAN identifiers (e.g., java=21.0.5-tem maps to temurin distribution).

Makes distribution input optional when using .sdkmanrc with distribution suffix.

* fix: align SDKMAN sem identifier mapping

* fix: support SDKMAN albba identifier

* docs: clarify sdkmanrc distribution inference scope

Co-authored-by: default avatarCopilot <[email protected]>

* Add Tencent Kona SDKMAN mapping and format sdkmanrc docs as a table

- Map SDKMAN 'kona' identifier to the 'kona' distribution (added in #672)
- Add a .sdkmanrc test case for the kona suffix
- Convert the inline SDKMAN suffix mapping in advanced-usage.md to a table
- Rebuild dist bundles

Co-authored-by: default avatarCopilot App <[email protected]>

---------

Co-authored-by: default avatarBruno Borges <[email protected]>
Co-authored-by: default avatarCopilot <[email protected]>
Co-authored-by: default avatarBruno Borges <[email protected]>
parent c4922bf8
Loading
Loading
Loading
Loading
+2 −2
Changes for README.md: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -29,9 +29,9 @@ For more details, see the full release notes on the [releases page](https://git

  - `java-version`: The Java version that is going to be set up. Takes a whole or [semver](#supported-version-syntax) Java version. If not specified, the action will expect `java-version-file` input to be specified.

  - `java-version-file`: The path to a file containing java version. Supported file types are `.java-version` and `.tool-versions`. See more details in [about .java-version-file](docs/advanced-usage.md#Java-version-file).
  - `java-version-file`: The path to a file containing java version. Supported file types are `.java-version`, `.tool-versions`, and `.sdkmanrc`. See more details in [about .java-version-file](docs/advanced-usage.md#Java-version-file).

  - `distribution`: _(required)_ Java [distribution](#supported-distributions).
  - `distribution`: Java [distribution](#supported-distributions). Required unless `java-version-file` points to `.sdkmanrc` with a recognized distribution suffix (for example `java=21.0.5-tem`).

  - `java-package`: The packaging variant of the chosen distribution. Possible values: `jdk`, `jre`, `jdk+fx`, `jre+fx`. Default value: `jdk`.

+10 −10
Changes for __tests__/data/sdkman-java-versions.csv: 10 added lines, 10 removed lines.
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@
7.0.352-zulu, 7.0.352
8.0.282-trava, 8.0.282
8.0.432-albba, 8.0.432
8.0.432-amzn, 8.0.432
8.0.432-amzn, 8
8.0.432-kona, 8.0.432
8.0.432-librca, 8.0.432
8.0.432-sem, 8.0.432
@@ -10,7 +10,7 @@
8.0.432-zulu, 8.0.432
8.0.432.fx-librca, 8.0.432
8.0.432.fx-zulu, 8.0.432
8.0.442-amzn, 8.0.442
8.0.442-amzn, 8
8.0.442-librca, 8.0.442
8.0.442-tem, 8.0.442
8.0.442-zulu, 8.0.442
@@ -19,7 +19,7 @@
11.0.14.1-jbr, 11.0.14
11.0.15-trava, 11.0.15
11.0.25-albba, 11.0.25
11.0.25-amzn, 11.0.25
11.0.25-amzn, 11
11.0.25-kona, 11.0.25
11.0.25-librca, 11.0.25
11.0.25-ms, 11.0.25
@@ -29,7 +29,7 @@
11.0.25-zulu, 11.0.25
11.0.25.fx-librca, 11.0.25
11.0.25.fx-zulu, 11.0.25
11.0.26-amzn, 11.0.26
11.0.26-amzn, 11
11.0.26-librca, 11.0.26
11.0.26-ms, 11.0.26
11.0.26-sapmchn, 11.0.26
@@ -40,7 +40,7 @@
17.0.12-jbr, 17.0.12
17.0.12-oracle, 17.0.12
17.0.13-albba, 17.0.13
17.0.13-amzn, 17.0.13
17.0.13-amzn, 17
17.0.13-kona, 17.0.13
17.0.13-librca, 17.0.13
17.0.13-ms, 17.0.13
@@ -52,7 +52,7 @@
17.0.13.crac-zulu, 17.0.13
17.0.13.fx-librca, 17.0.13
17.0.13.fx-zulu, 17.0.13
17.0.14-amzn, 17.0.14
17.0.14-amzn, 17
17.0.14-librca, 17.0.14
17.0.14-ms, 17.0.14
17.0.14-sapmchn, 17.0.14
@@ -62,7 +62,7 @@
17.0.9-graalce, 17.0.9
21.0.2-graalce, 21.0.2
21.0.2-open, 21.0.2
21.0.5-amzn, 21.0.5
21.0.5-amzn, 21
21.0.5-graal, 21.0.5
21.0.5-jbr, 21.0.5
21.0.5-kona, 21.0.5
@@ -77,7 +77,7 @@
21.0.5.crac-zulu, 21.0.5
21.0.5.fx-librca, 21.0.5
21.0.5.fx-zulu, 21.0.5
21.0.6-amzn, 21.0.6
21.0.6-amzn, 21
21.0.6-graal, 21.0.6
21.0.6-librca, 21.0.6
21.0.6-ms, 21.0.6
@@ -94,7 +94,7 @@
22.3.5.r17-mandrel, 22.3.5
22.3.5.r17-nik, 22.3.5
23-open, 23
23.0.1-amzn, 23.0.1
23.0.1-amzn, 23
23.0.1-graal, 23.0.1
23.0.1-graalce, 23.0.1
23.0.1-librca, 23.0.1
@@ -106,7 +106,7 @@
23.0.1.crac-zulu, 23.0.1
23.0.1.fx-librca, 23.0.1
23.0.1.fx-zulu, 23.0.1
23.0.2-amzn, 23.0.2
23.0.2-amzn, 23
23.0.2-graal, 23.0.2
23.0.2-graalce, 23.0.2
23.0.2-librca, 23.0.2
+55 −10
Changes for __tests__/util.test.ts: 55 added lines, 10 removed lines.
Original line number Diff line number Diff line
@@ -166,15 +166,60 @@ describe('validatePaginationUrl', () => {
describe('getVersionFromFileContent', () => {
  describe('.sdkmanrc', () => {
    it.each([
      ['java=11.0.20.1-tem', '11.0.20'],
      ['java = 11.0.20.1-tem', '11.0.20'],
      ['java=11.0.20.1-tem # a comment in sdkmanrc', '11.0.20'],
      ['java=11.0.20.1-tem\n#java=21.0.20.1-tem\n', '11.0.20'], // choose first match
      ['java=11.0.20.1-tem\njava=21.0.20.1-tem\n', '11.0.20'], // choose first match
      ['#java=11.0.20.1-tem\njava=21.0.20.1-tem\n', '21.0.20'] // first one is 'commented' in .sdkmanrc
    ])('parsing %s should return %s', (content: string, expected: string) => {
      const actual = getVersionFromFileContent(content, 'openjdk', '.sdkmanrc');
      expect(actual).toBe(expected);
      ['java=11.0.20.1-tem', '11.0.20', 'temurin'],
      ['java = 11.0.20.1-tem', '11.0.20', 'temurin'],
      ['java=11.0.20.1-tem # a comment in sdkmanrc', '11.0.20', 'temurin'],
      ['java=11.0.20.1-tem\n#java=21.0.20.1-tem\n', '11.0.20', 'temurin'], // choose first match
      ['java=11.0.20.1-tem\njava=21.0.20.1-tem\n', '11.0.20', 'temurin'], // choose first match
      ['#java=11.0.20.1-tem\njava=21.0.20.1-tem\n', '21.0.20', 'temurin'], // first one is 'commented' in .sdkmanrc
      ['java=21.0.5-zulu', '21.0.5', 'zulu'],
      ['java=17.0.13-albba', '17.0.13', 'dragonwell'],
      ['java=17.0.13-amzn', '17', 'corretto'],
      ['java=21.0.5-graal', '21.0.5', 'graalvm'],
      ['java=17.0.9-graalce', '17.0.9', 'graalvm'],
      ['java=11.0.25-librca', '11.0.25', 'liberica'],
      ['java=11.0.25-ms', '11.0.25', 'microsoft'],
      ['java=21.0.5-oracle', '21.0.5', 'oracle'],
      ['java=11.0.25-sapmchn', '11.0.25', 'sapmachine'],
      ['java=21.0.5-jbr', '21.0.5', 'jetbrains'],
      ['java=11.0.25-sem', '11.0.25', 'semeru'],
      ['java=17.0.13-dragonwell', '17.0.13', 'dragonwell'],
      ['java=21.0.5-kona', '21.0.5', 'kona']
    ])(
      'parsing %s should return version %s and distribution %s',
      (content: string, expectedVersion: string, expectedDist: string) => {
        const actual = getVersionFromFileContent(
          content,
          'openjdk',
          '.sdkmanrc'
        );
        expect(actual?.version).toBe(expectedVersion);
        expect(actual?.distribution).toBe(expectedDist);
      }
    );

    it('should warn and return undefined distribution for unknown identifier', () => {
      const warnSpy = jest.spyOn(core, 'warning');
      const actual = getVersionFromFileContent(
        'java=21.0.5-unknown',
        'temurin',
        '.sdkmanrc'
      );
      expect(actual?.version).toBe('21.0.5');
      expect(actual?.distribution).toBeUndefined();
      expect(warnSpy).toHaveBeenCalledWith(
        expect.stringContaining('Unknown SDKMAN distribution identifier')
      );
    });

    it('should return version without distribution when no suffix provided', () => {
      const actual = getVersionFromFileContent(
        'java=11.0.20',
        'temurin',
        '.sdkmanrc'
      );
      expect(actual?.version).toBe('11.0.20');
      expect(actual?.distribution).toBeUndefined();
    });

    describe('known versions', () => {
@@ -193,7 +238,7 @@ describe('getVersionFromFileContent', () => {
            'openjdk',
            '.sdkmanrc'
          );
          expect(actual).toBe(expected);
          expect(actual?.version).toBe(expected);
        }
      );
    });
+2 −2
Changes for action.yml: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -10,8 +10,8 @@ inputs:
    description: 'The path to a file containing the Java version to set up (.java-version, .tool-versions, .sdkmanrc). Used when java-version is not set. See examples of supported syntax in README file'
    required: false
  distribution:
    description: 'Java distribution. See the list of supported distributions in README file'
    required: true
    description: 'Java distribution. See the list of supported distributions in README file. This input is required except when java-version-file points to .sdkmanrc with a recognized distribution suffix (e.g., java=21.0.5-tem).'
    required: false
  java-package:
    description: 'The package type (jdk, jre, jdk+fx, jre+fx)'
    required: false
+46 −7
Changes for dist/cleanup/index.js: 46 added lines, 7 removed lines.
Original line number Diff line number Diff line
@@ -52572,8 +52572,9 @@ function isCacheFeatureAvailable() {
}
exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
function getVersionFromFileContent(content, distributionName, versionFile) {
    var _a, _b, _c, _d, _e;
    var _a, _b, _c;
    let javaVersionRegExp;
    let extractedDistribution;
    function getFileName(versionFile) {
        return path_1.default.basename(versionFile);
    }
@@ -52583,14 +52584,23 @@ function getVersionFromFileContent(content, distributionName, versionFile) {
            /^java\s+(?:\S*-)?(?<version>\d+(?:\.\d+)*([+_.-](?:openj9[-._]?\d[\w.-]*|java\d+|jre[-_\w]*|OpenJDK\d+[\w_.-]*|[a-z0-9]+))*)/im;
    }
    else if (versionFileName == '.sdkmanrc') {
        javaVersionRegExp = /^java\s*=\s*(?<version>[^-]+)/m;
        // Match both version and optional distribution identifier
        javaVersionRegExp =
            /^java\s*=\s*(?<version>[^-\s]+)(?:-(?<distribution>[a-z0-9]+))?/m;
    }
    else {
        javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
    }
    const capturedVersion = ((_b = (_a = content.match(javaVersionRegExp)) === null || _a === void 0 ? void 0 : _a.groups) === null || _b === void 0 ? void 0 : _b.version)
        ? (_d = (_c = content.match(javaVersionRegExp)) === null || _c === void 0 ? void 0 : _c.groups) === null || _d === void 0 ? void 0 : _d.version
    const match = content.match(javaVersionRegExp);
    const capturedVersion = ((_a = match === null || match === void 0 ? void 0 : match.groups) === null || _a === void 0 ? void 0 : _a.version)
        ? match.groups.version
        : '';
    // Extract distribution from .sdkmanrc file
    if (versionFileName == '.sdkmanrc' && ((_b = match === null || match === void 0 ? void 0 : match.groups) === null || _b === void 0 ? void 0 : _b.distribution)) {
        const sdkmanDist = match.groups.distribution;
        extractedDistribution = mapSdkmanDistribution(sdkmanDist);
        core.debug(`Parsed distribution '${extractedDistribution}' from SDKMAN identifier '${sdkmanDist}'`);
    }
    core.debug(`Parsed version '${capturedVersion}' from file '${versionFileName}'`);
    if (!capturedVersion) {
        return null;
@@ -52604,13 +52614,42 @@ function getVersionFromFileContent(content, distributionName, versionFile) {
    if (!version) {
        return null;
    }
    if (constants_1.DISTRIBUTIONS_ONLY_MAJOR_VERSION.includes(distributionName)) {
        const coerceVersion = (_e = semver.coerce(version)) !== null && _e !== void 0 ? _e : version;
    // Apply DISTRIBUTIONS_ONLY_MAJOR_VERSION logic whenever the effective distribution
    // (either explicitly provided or extracted from the version file) is in the list.
    if (constants_1.DISTRIBUTIONS_ONLY_MAJOR_VERSION.includes(extractedDistribution || distributionName)) {
        const coerceVersion = (_c = semver.coerce(version)) !== null && _c !== void 0 ? _c : version;
        version = semver.major(coerceVersion).toString();
    }
    return version.toString();
    return {
        version: version.toString(),
        distribution: extractedDistribution
    };
}
exports.getVersionFromFileContent = getVersionFromFileContent;
// Map SDKMAN distribution identifiers to setup-java distribution names
function mapSdkmanDistribution(sdkmanDist) {
    const distributionMap = {
        tem: 'temurin',
        sem: 'semeru',
        albba: 'dragonwell',
        zulu: 'zulu',
        amzn: 'corretto',
        graal: 'graalvm',
        graalce: 'graalvm',
        librca: 'liberica',
        ms: 'microsoft',
        oracle: 'oracle',
        sapmchn: 'sapmachine',
        jbr: 'jetbrains',
        dragonwell: 'dragonwell',
        kona: 'kona'
    };
    const mapped = distributionMap[sdkmanDist.toLowerCase()];
    if (!mapped) {
        core.warning(`Unknown SDKMAN distribution identifier '${sdkmanDist}'. Please specify the distribution explicitly.`);
    }
    return mapped;
}
// By convention, action expects version 8 in the format `8.*` instead of `1.8`
function avoidOldNotation(content) {
    return content.startsWith('1.') ? content.substring(2) : content;
Loading