Compare commits
	
		
			16 Commits
		
	
	
		
			v2.4.0
			...
			tiwarishub
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 600cfee239 | |||
| efbea1411b | |||
| c41070eda4 | |||
| f69f00b5e5 | |||
| 2e1dfa1fb4 | |||
| a12e082d83 | |||
| 04d53533c2 | |||
| d8da887cad | |||
| f0bb916062 | |||
| d23aed3c80 | |||
| 8d22286106 | |||
| db2f350d2b | |||
| 6df0b04fb5 | |||
| a1ad2000b3 | |||
| faa22ddfbc | |||
| a388b3faf4 | 
							
								
								
									
										5
									
								
								.github/workflows/build.yml
									
									
									
									
										vendored
									
									
										
										
										Executable file → Normal file
									
								
							
							
						
						
									
										5
									
								
								.github/workflows/build.yml
									
									
									
									
										vendored
									
									
										
										
										Executable file → Normal file
									
								
							@ -20,10 +20,11 @@ jobs:
 | 
			
		||||
        os: [ubuntu-latest, windows-latest, macos-latest]
 | 
			
		||||
    steps:
 | 
			
		||||
      - uses: actions/checkout@v2
 | 
			
		||||
      - name: Setup Node.JS 12
 | 
			
		||||
      - name: Setup Node.JS 16
 | 
			
		||||
        uses: actions/setup-node@v2
 | 
			
		||||
        with:
 | 
			
		||||
          node-version: 12.x
 | 
			
		||||
          node-version: 16.x
 | 
			
		||||
          cache: npm
 | 
			
		||||
      - run: npm ci
 | 
			
		||||
      - run: npm run build
 | 
			
		||||
      - run: npm run format-check
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										4
									
								
								.github/workflows/check-dist.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								.github/workflows/check-dist.yml
									
									
									
									
										vendored
									
									
								
							@ -23,10 +23,10 @@ jobs:
 | 
			
		||||
    steps:
 | 
			
		||||
      - uses: actions/checkout@v2
 | 
			
		||||
 | 
			
		||||
      - name: Set Node.js 12.x
 | 
			
		||||
      - name: Set Node.js 16.x
 | 
			
		||||
        uses: actions/setup-node@v1
 | 
			
		||||
        with:
 | 
			
		||||
          node-version: 12.x
 | 
			
		||||
          node-version: 16.x
 | 
			
		||||
 | 
			
		||||
      - name: Install dependencies
 | 
			
		||||
        run: npm ci
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										18
									
								
								.github/workflows/e2e-versions.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										18
									
								
								.github/workflows/e2e-versions.yml
									
									
									
									
										vendored
									
									
								
							@ -20,8 +20,11 @@ jobs:
 | 
			
		||||
      fail-fast: false
 | 
			
		||||
      matrix:
 | 
			
		||||
        os: [macos-latest, windows-latest, ubuntu-latest]
 | 
			
		||||
        distribution: ['temurin', 'adopt', 'adopt-openj9', 'zulu', 'liberica'] # internally 'adopt-hotspot' is the same as 'adopt'
 | 
			
		||||
        distribution: ['temurin', 'adopt', 'adopt-openj9', 'zulu', 'liberica', 'microsoft' ] # internally 'adopt-hotspot' is the same as 'adopt'
 | 
			
		||||
        version: ['8', '11', '16']
 | 
			
		||||
        exclude:
 | 
			
		||||
        - distribution: microsoft
 | 
			
		||||
          version: 8
 | 
			
		||||
    steps:
 | 
			
		||||
      - name: Checkout
 | 
			
		||||
        uses: actions/checkout@v2
 | 
			
		||||
@ -174,16 +177,17 @@ jobs:
 | 
			
		||||
        run: bash __tests__/verify-java.sh "${{ matrix.version }}" "${{ steps.setup-java.outputs.path }}"
 | 
			
		||||
        shell: bash
 | 
			
		||||
 | 
			
		||||
  setup-java-custom-architecture:
 | 
			
		||||
    name: ${{ matrix.distribution }} ${{ matrix.version }} (jdk-x86) - ${{ matrix.os }}
 | 
			
		||||
  # Only Liberica and Zulu provide x86
 | 
			
		||||
  setup-java-x86:
 | 
			
		||||
    name: ${{ matrix.distribution }} ${{ matrix.version }} (jdk-${{ matrix.architecture }}) - ${{ matrix.os }}
 | 
			
		||||
    needs: setup-java-major-minor-versions
 | 
			
		||||
    runs-on: ${{ matrix.os }}
 | 
			
		||||
    strategy:
 | 
			
		||||
      fail-fast: false
 | 
			
		||||
      matrix:
 | 
			
		||||
        # Only Zulu and Liberica provides x86 arch for now and only for windows / ubuntu
 | 
			
		||||
        # x86 is not supported on macOS
 | 
			
		||||
        os: [windows-latest, ubuntu-latest]
 | 
			
		||||
        distribution: ['zulu', 'liberica']
 | 
			
		||||
        distribution: ['liberica', 'zulu']
 | 
			
		||||
        version: ['11']
 | 
			
		||||
    steps:
 | 
			
		||||
      - name: Checkout
 | 
			
		||||
@ -194,7 +198,9 @@ jobs:
 | 
			
		||||
        with:
 | 
			
		||||
          distribution: ${{ matrix.distribution }}
 | 
			
		||||
          java-version: ${{ matrix.version }}
 | 
			
		||||
          architecture: x86
 | 
			
		||||
          architecture: 'x86'
 | 
			
		||||
      - name: Verify Java
 | 
			
		||||
        run: bash __tests__/verify-java.sh "${{ matrix.version }}" "${{ steps.setup-java.outputs.path }}"
 | 
			
		||||
        shell: bash
 | 
			
		||||
 | 
			
		||||
  # Only Microsoft provides AArch64. However, GitHub-hosted runners do not support this architecture.
 | 
			
		||||
							
								
								
									
										3
									
								
								.github/workflows/licensed.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								.github/workflows/licensed.yml
									
									
									
									
										vendored
									
									
								
							@ -7,6 +7,7 @@ on:
 | 
			
		||||
  pull_request:
 | 
			
		||||
    branches:
 | 
			
		||||
      - main
 | 
			
		||||
  workflow_dispatch:
 | 
			
		||||
 | 
			
		||||
jobs:
 | 
			
		||||
  test:
 | 
			
		||||
@ -18,7 +19,7 @@ jobs:
 | 
			
		||||
      - name: Install licensed
 | 
			
		||||
        run: |
 | 
			
		||||
          cd $RUNNER_TEMP
 | 
			
		||||
          curl -Lfs -o licensed.tar.gz https://github.com/github/licensed/releases/download/2.12.2/licensed-2.12.2-linux-x64.tar.gz
 | 
			
		||||
          curl -Lfs -o licensed.tar.gz https://github.com/github/licensed/releases/download/3.4.4/licensed-3.4.4-linux-x64.tar.gz
 | 
			
		||||
          sudo tar -xzf licensed.tar.gz
 | 
			
		||||
          sudo mv licensed /usr/local/bin/licensed
 | 
			
		||||
      - run: licensed status
 | 
			
		||||
 | 
			
		||||
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								.licenses/npm/node-fetch.dep.yml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								.licenses/npm/node-fetch.dep.yml
									
									
									
										generated
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							@ -59,13 +59,18 @@ Currently, the following distributions are supported:
 | 
			
		||||
| `adopt` or `adopt-hotspot` | Adopt OpenJDK Hotspot | [Link](https://adoptopenjdk.net/) | [Link](https://adoptopenjdk.net/about.html) |
 | 
			
		||||
| `adopt-openj9` | Adopt OpenJDK OpenJ9 | [Link](https://adoptopenjdk.net/) | [Link](https://adoptopenjdk.net/about.html) |
 | 
			
		||||
| `liberica` | Liberica JDK | [Link](https://bell-sw.com/) | [Link](https://bell-sw.com/liberica_eula/) |
 | 
			
		||||
| `microsoft` | Microsoft Build of OpenJDK | [Link](https://www.microsoft.com/openjdk) | [Link](https://docs.microsoft.com/java/openjdk/faq)
 | 
			
		||||
 | 
			
		||||
**NOTE:** The different distributors can provide discrepant list of available versions / supported configurations. Please refer to the official documentation to see the list of supported versions.
 | 
			
		||||
 | 
			
		||||
**NOTE:** Adopt OpenJDK got moved to Eclipse Temurin and won't be updated anymore. It is highly recommended to migrate workflows from `adopt` to `temurin` to keep receiving software and security updates. See more details in the [Good-bye AdoptOpenJDK post](https://blog.adoptopenjdk.net/2021/08/goodbye-adoptopenjdk-hello-adoptium/).
 | 
			
		||||
 | 
			
		||||
### Caching packages dependencies
 | 
			
		||||
The action has a built-in functionality for caching and restoring dependencies. It uses [actions/cache](https://github.com/actions/cache) under hood for caching dependencies but requires less configuration settings. Supported package managers are gradle and maven. The cache input is optional, and caching is turned off by default.
 | 
			
		||||
The action has a built-in functionality for caching and restoring dependencies. It uses [actions/cache](https://github.com/actions/cache) under hood for caching dependencies but requires less configuration settings. Supported package managers are gradle and maven. The format of the used cache key is `setup-java-${{ platform }}-${{ packageManager }}-${{ fileHash }}`, where the hash is based on the following files:
 | 
			
		||||
- gradle: `**/*.gradle*`, `**/gradle-wrapper.properties`
 | 
			
		||||
- maven: `**/pom.xml`
 | 
			
		||||
 | 
			
		||||
The cache input is optional, and caching is turned off by default.
 | 
			
		||||
 | 
			
		||||
#### Caching gradle dependencies
 | 
			
		||||
```yaml
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										88
									
								
								__tests__/distributors/microsoft-installer.test.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										88
									
								
								__tests__/distributors/microsoft-installer.test.ts
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,88 @@
 | 
			
		||||
import { MicrosoftDistributions } from '../../src/distributions/microsoft/installer';
 | 
			
		||||
 | 
			
		||||
describe('findPackageForDownload', () => {
 | 
			
		||||
  let distribution: MicrosoftDistributions;
 | 
			
		||||
 | 
			
		||||
  beforeEach(() => {
 | 
			
		||||
    distribution = new MicrosoftDistributions({
 | 
			
		||||
      version: '',
 | 
			
		||||
      architecture: 'x64',
 | 
			
		||||
      packageType: 'jdk',
 | 
			
		||||
      checkLatest: false
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  it.each([
 | 
			
		||||
    [
 | 
			
		||||
      '17.x',
 | 
			
		||||
      '17.0.1',
 | 
			
		||||
      'https://aka.ms/download-jdk/microsoft-jdk-17.0.1.12.1-{{OS_TYPE}}-x64.{{ARCHIVE_TYPE}}'
 | 
			
		||||
    ],
 | 
			
		||||
    [
 | 
			
		||||
      '16.0.x',
 | 
			
		||||
      '16.0.2',
 | 
			
		||||
      'https://aka.ms/download-jdk/microsoft-jdk-16.0.2.7.1-{{OS_TYPE}}-x64.{{ARCHIVE_TYPE}}'
 | 
			
		||||
    ],
 | 
			
		||||
    [
 | 
			
		||||
      '11.0.13',
 | 
			
		||||
      '11.0.13',
 | 
			
		||||
      'https://aka.ms/download-jdk/microsoft-jdk-11.0.13.8.1-{{OS_TYPE}}-x64.{{ARCHIVE_TYPE}}'
 | 
			
		||||
    ]
 | 
			
		||||
  ])('version is %s -> %s', async (input, expectedVersion, expectedUrl) => {
 | 
			
		||||
    const result = await distribution['findPackageForDownload'](input);
 | 
			
		||||
    expect(result.version).toBe(expectedVersion);
 | 
			
		||||
    let os: string;
 | 
			
		||||
    let archive: string;
 | 
			
		||||
    switch (process.platform) {
 | 
			
		||||
      case 'darwin':
 | 
			
		||||
        os = 'macos';
 | 
			
		||||
        archive = 'tar.gz';
 | 
			
		||||
        break;
 | 
			
		||||
      case 'win32':
 | 
			
		||||
        os = 'windows';
 | 
			
		||||
        archive = 'zip';
 | 
			
		||||
        break;
 | 
			
		||||
      default:
 | 
			
		||||
        os = process.platform.toString();
 | 
			
		||||
        archive = 'tar.gz';
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
    const url = expectedUrl.replace('{{OS_TYPE}}', os).replace('{{ARCHIVE_TYPE}}', archive);
 | 
			
		||||
    expect(result.url).toBe(url);
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  it('should throw an error', async () => {
 | 
			
		||||
    await expect(distribution['findPackageForDownload']('8')).rejects.toThrow(
 | 
			
		||||
      /Could not find satisfied version for SemVer */
 | 
			
		||||
    );
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
describe('getPlatformOption', () => {
 | 
			
		||||
  const distributions = new MicrosoftDistributions({
 | 
			
		||||
    architecture: 'x64',
 | 
			
		||||
    version: '11',
 | 
			
		||||
    packageType: 'jdk',
 | 
			
		||||
    checkLatest: false
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  it.each([
 | 
			
		||||
    ['linux', 'tar.gz', 'linux'],
 | 
			
		||||
    ['darwin', 'tar.gz', 'macos'],
 | 
			
		||||
    ['win32', 'zip', 'windows']
 | 
			
		||||
  ])('os version %s -> %s', (input, expectedArchive, expectedOs) => {
 | 
			
		||||
    const actual = distributions['getPlatformOption'](input as NodeJS.Platform);
 | 
			
		||||
 | 
			
		||||
    expect(actual.archive).toEqual(expectedArchive);
 | 
			
		||||
    expect(actual.os).toEqual(expectedOs);
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  it.each(['aix', 'android', 'freebsd', 'openbsd', 'netbsd', 'solaris', 'cygwin'])(
 | 
			
		||||
    'not support os version %s',
 | 
			
		||||
    input => {
 | 
			
		||||
      expect(() => distributions['getPlatformOption'](input as NodeJS.Platform)).toThrow(
 | 
			
		||||
        /Platform '\w+' is not supported\. Supported platforms: .+/
 | 
			
		||||
      );
 | 
			
		||||
    }
 | 
			
		||||
  );
 | 
			
		||||
});
 | 
			
		||||
@ -67,6 +67,6 @@ outputs:
 | 
			
		||||
  path:
 | 
			
		||||
    description: 'Path to where the java environment has been installed (same as $JAVA_HOME)'
 | 
			
		||||
runs:
 | 
			
		||||
  using: 'node12'
 | 
			
		||||
  using: 'node16'
 | 
			
		||||
  main: 'dist/setup/index.js'
 | 
			
		||||
  post: 'dist/cleanup/index.js'
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										30
									
								
								dist/cleanup/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										30
									
								
								dist/cleanup/index.js
									
									
									
									
										vendored
									
									
								
							@ -43501,9 +43501,17 @@ AbortError.prototype = Object.create(Error.prototype);
 | 
			
		||||
AbortError.prototype.constructor = AbortError;
 | 
			
		||||
AbortError.prototype.name = 'AbortError';
 | 
			
		||||
 | 
			
		||||
const URL$1 = Url.URL || whatwgUrl.URL;
 | 
			
		||||
 | 
			
		||||
// fix an issue where "PassThrough", "resolve" aren't a named export for node <10
 | 
			
		||||
const PassThrough$1 = Stream.PassThrough;
 | 
			
		||||
const resolve_url = Url.resolve;
 | 
			
		||||
 | 
			
		||||
const isDomainOrSubdomain = function isDomainOrSubdomain(destination, original) {
 | 
			
		||||
	const orig = new URL$1(original).hostname;
 | 
			
		||||
	const dest = new URL$1(destination).hostname;
 | 
			
		||||
 | 
			
		||||
	return orig === dest || orig[orig.length - dest.length - 1] === '.' && orig.endsWith(dest);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Fetch function
 | 
			
		||||
@ -43591,7 +43599,19 @@ function fetch(url, opts) {
 | 
			
		||||
				const location = headers.get('Location');
 | 
			
		||||
 | 
			
		||||
				// HTTP fetch step 5.3
 | 
			
		||||
				const locationURL = location === null ? null : resolve_url(request.url, location);
 | 
			
		||||
				let locationURL = null;
 | 
			
		||||
				try {
 | 
			
		||||
					locationURL = location === null ? null : new URL$1(location, request.url).toString();
 | 
			
		||||
				} catch (err) {
 | 
			
		||||
					// error here can only be invalid URL in Location: header
 | 
			
		||||
					// do not throw when options.redirect == manual
 | 
			
		||||
					// let the user extract the errorneous redirect URL
 | 
			
		||||
					if (request.redirect !== 'manual') {
 | 
			
		||||
						reject(new FetchError(`uri requested responds with an invalid redirect URL: ${location}`, 'invalid-redirect'));
 | 
			
		||||
						finalize();
 | 
			
		||||
						return;
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				// HTTP fetch step 5.5
 | 
			
		||||
				switch (request.redirect) {
 | 
			
		||||
@ -43639,6 +43659,12 @@ function fetch(url, opts) {
 | 
			
		||||
							size: request.size
 | 
			
		||||
						};
 | 
			
		||||
 | 
			
		||||
						if (!isDomainOrSubdomain(request.url, locationURL)) {
 | 
			
		||||
							for (const name of ['authorization', 'www-authenticate', 'cookie', 'cookie2']) {
 | 
			
		||||
								requestOpts.headers.delete(name);
 | 
			
		||||
							}
 | 
			
		||||
						}
 | 
			
		||||
 | 
			
		||||
						// HTTP-redirect fetch step 9
 | 
			
		||||
						if (res.statusCode !== 303 && request.body && getTotalBytes(request) === null) {
 | 
			
		||||
							reject(new FetchError('Cannot follow redirect with body being a readable stream', 'unsupported-redirect'));
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										171
									
								
								dist/setup/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										171
									
								
								dist/setup/index.js
									
									
									
									
										vendored
									
									
								
							@ -13819,7 +13819,142 @@ exports.XMLCBWriter = XMLCBWriter;
 | 
			
		||||
/* 193 */,
 | 
			
		||||
/* 194 */,
 | 
			
		||||
/* 195 */,
 | 
			
		||||
/* 196 */,
 | 
			
		||||
/* 196 */
 | 
			
		||||
/***/ (function(__unusedmodule, exports, __webpack_require__) {
 | 
			
		||||
 | 
			
		||||
"use strict";
 | 
			
		||||
 | 
			
		||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
 | 
			
		||||
    if (k2 === undefined) k2 = k;
 | 
			
		||||
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
 | 
			
		||||
}) : (function(o, m, k, k2) {
 | 
			
		||||
    if (k2 === undefined) k2 = k;
 | 
			
		||||
    o[k2] = m[k];
 | 
			
		||||
}));
 | 
			
		||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
 | 
			
		||||
    Object.defineProperty(o, "default", { enumerable: true, value: v });
 | 
			
		||||
}) : function(o, v) {
 | 
			
		||||
    o["default"] = v;
 | 
			
		||||
});
 | 
			
		||||
var __importStar = (this && this.__importStar) || function (mod) {
 | 
			
		||||
    if (mod && mod.__esModule) return mod;
 | 
			
		||||
    var result = {};
 | 
			
		||||
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
 | 
			
		||||
    __setModuleDefault(result, mod);
 | 
			
		||||
    return result;
 | 
			
		||||
};
 | 
			
		||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
 | 
			
		||||
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
 | 
			
		||||
    return new (P || (P = Promise))(function (resolve, reject) {
 | 
			
		||||
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
 | 
			
		||||
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
 | 
			
		||||
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
 | 
			
		||||
        step((generator = generator.apply(thisArg, _arguments || [])).next());
 | 
			
		||||
    });
 | 
			
		||||
};
 | 
			
		||||
var __importDefault = (this && this.__importDefault) || function (mod) {
 | 
			
		||||
    return (mod && mod.__esModule) ? mod : { "default": mod };
 | 
			
		||||
};
 | 
			
		||||
Object.defineProperty(exports, "__esModule", { value: true });
 | 
			
		||||
exports.MicrosoftDistributions = void 0;
 | 
			
		||||
const base_installer_1 = __webpack_require__(83);
 | 
			
		||||
const semver_1 = __importDefault(__webpack_require__(876));
 | 
			
		||||
const util_1 = __webpack_require__(322);
 | 
			
		||||
const core = __importStar(__webpack_require__(470));
 | 
			
		||||
const tc = __importStar(__webpack_require__(139));
 | 
			
		||||
const fs_1 = __importDefault(__webpack_require__(747));
 | 
			
		||||
const path_1 = __importDefault(__webpack_require__(622));
 | 
			
		||||
class MicrosoftDistributions extends base_installer_1.JavaBase {
 | 
			
		||||
    constructor(installerOptions) {
 | 
			
		||||
        super('Microsoft', installerOptions);
 | 
			
		||||
    }
 | 
			
		||||
    downloadTool(javaRelease) {
 | 
			
		||||
        return __awaiter(this, void 0, void 0, function* () {
 | 
			
		||||
            core.info(`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`);
 | 
			
		||||
            const javaArchivePath = yield tc.downloadTool(javaRelease.url);
 | 
			
		||||
            core.info(`Extracting Java archive...`);
 | 
			
		||||
            const extension = util_1.getDownloadArchiveExtension();
 | 
			
		||||
            const extractedJavaPath = yield util_1.extractJdkFile(javaArchivePath, extension);
 | 
			
		||||
            const archiveName = fs_1.default.readdirSync(extractedJavaPath)[0];
 | 
			
		||||
            const archivePath = path_1.default.join(extractedJavaPath, archiveName);
 | 
			
		||||
            const javaPath = yield tc.cacheDir(archivePath, this.toolcacheFolderName, this.getToolcacheVersionName(javaRelease.version), this.architecture);
 | 
			
		||||
            return { version: javaRelease.version, path: javaPath };
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
    findPackageForDownload(range) {
 | 
			
		||||
        return __awaiter(this, void 0, void 0, function* () {
 | 
			
		||||
            if (this.architecture !== 'x64' && this.architecture !== 'aarch64') {
 | 
			
		||||
                throw new Error(`Unsupported architecture: ${this.architecture}`);
 | 
			
		||||
            }
 | 
			
		||||
            if (!this.stable) {
 | 
			
		||||
                throw new Error('Early access versions are not supported');
 | 
			
		||||
            }
 | 
			
		||||
            if (this.packageType !== 'jdk') {
 | 
			
		||||
                throw new Error('Microsoft Build of OpenJDK provides only the `jdk` package type');
 | 
			
		||||
            }
 | 
			
		||||
            const availableVersionsRaw = yield this.getAvailableVersions();
 | 
			
		||||
            const opts = this.getPlatformOption();
 | 
			
		||||
            const availableVersions = availableVersionsRaw.map(item => ({
 | 
			
		||||
                url: `https://aka.ms/download-jdk/microsoft-jdk-${item.version.join('.')}-${opts.os}-${this.architecture}.${opts.archive}`,
 | 
			
		||||
                version: this.convertVersionToSemver(item)
 | 
			
		||||
            }));
 | 
			
		||||
            const satisfiedVersion = availableVersions
 | 
			
		||||
                .filter(item => util_1.isVersionSatisfies(range, item.version))
 | 
			
		||||
                .sort((a, b) => -semver_1.default.compareBuild(a.version, b.version))[0];
 | 
			
		||||
            if (!satisfiedVersion) {
 | 
			
		||||
                const availableOptions = availableVersions.map(item => item.version).join(', ');
 | 
			
		||||
                const availableOptionsMessage = availableOptions
 | 
			
		||||
                    ? `\nAvailable versions: ${availableOptions}`
 | 
			
		||||
                    : '';
 | 
			
		||||
                throw new Error(`Could not find satisfied version for SemVer ${range}. ${availableOptionsMessage}`);
 | 
			
		||||
            }
 | 
			
		||||
            return satisfiedVersion;
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
    getAvailableVersions() {
 | 
			
		||||
        return __awaiter(this, void 0, void 0, function* () {
 | 
			
		||||
            // TODO get these dynamically!
 | 
			
		||||
            // We will need Microsoft to add an endpoint where we can query for versions.
 | 
			
		||||
            const jdkVersions = [
 | 
			
		||||
                {
 | 
			
		||||
                    version: [17, 0, 1, 12, 1]
 | 
			
		||||
                },
 | 
			
		||||
                {
 | 
			
		||||
                    version: [16, 0, 2, 7, 1]
 | 
			
		||||
                }
 | 
			
		||||
            ];
 | 
			
		||||
            // M1 is only supported for Java 16 & 17
 | 
			
		||||
            if (process.platform !== 'darwin' || this.architecture !== 'aarch64') {
 | 
			
		||||
                jdkVersions.push({
 | 
			
		||||
                    version: [11, 0, 13, 8, 1]
 | 
			
		||||
                });
 | 
			
		||||
            }
 | 
			
		||||
            return jdkVersions;
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
    getPlatformOption(platform = process.platform /* for testing */) {
 | 
			
		||||
        switch (platform) {
 | 
			
		||||
            case 'darwin':
 | 
			
		||||
                return { archive: 'tar.gz', os: 'macos' };
 | 
			
		||||
            case 'win32':
 | 
			
		||||
                return { archive: 'zip', os: 'windows' };
 | 
			
		||||
            case 'linux':
 | 
			
		||||
                return { archive: 'tar.gz', os: 'linux' };
 | 
			
		||||
            default:
 | 
			
		||||
                throw new Error(`Platform '${platform}' is not supported. Supported platforms: 'darwin', 'linux', 'win32'`);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    convertVersionToSemver(version) {
 | 
			
		||||
        const major = version.version[0];
 | 
			
		||||
        const minor = version.version[1];
 | 
			
		||||
        const patch = version.version[2];
 | 
			
		||||
        return `${major}.${minor}.${patch}`;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
exports.MicrosoftDistributions = MicrosoftDistributions;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/***/ }),
 | 
			
		||||
/* 197 */
 | 
			
		||||
/***/ (function(__unusedmodule, exports, __webpack_require__) {
 | 
			
		||||
 | 
			
		||||
@ -30552,9 +30687,17 @@ AbortError.prototype = Object.create(Error.prototype);
 | 
			
		||||
AbortError.prototype.constructor = AbortError;
 | 
			
		||||
AbortError.prototype.name = 'AbortError';
 | 
			
		||||
 | 
			
		||||
const URL$1 = Url.URL || whatwgUrl.URL;
 | 
			
		||||
 | 
			
		||||
// fix an issue where "PassThrough", "resolve" aren't a named export for node <10
 | 
			
		||||
const PassThrough$1 = Stream.PassThrough;
 | 
			
		||||
const resolve_url = Url.resolve;
 | 
			
		||||
 | 
			
		||||
const isDomainOrSubdomain = function isDomainOrSubdomain(destination, original) {
 | 
			
		||||
	const orig = new URL$1(original).hostname;
 | 
			
		||||
	const dest = new URL$1(destination).hostname;
 | 
			
		||||
 | 
			
		||||
	return orig === dest || orig[orig.length - dest.length - 1] === '.' && orig.endsWith(dest);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Fetch function
 | 
			
		||||
@ -30642,7 +30785,19 @@ function fetch(url, opts) {
 | 
			
		||||
				const location = headers.get('Location');
 | 
			
		||||
 | 
			
		||||
				// HTTP fetch step 5.3
 | 
			
		||||
				const locationURL = location === null ? null : resolve_url(request.url, location);
 | 
			
		||||
				let locationURL = null;
 | 
			
		||||
				try {
 | 
			
		||||
					locationURL = location === null ? null : new URL$1(location, request.url).toString();
 | 
			
		||||
				} catch (err) {
 | 
			
		||||
					// error here can only be invalid URL in Location: header
 | 
			
		||||
					// do not throw when options.redirect == manual
 | 
			
		||||
					// let the user extract the errorneous redirect URL
 | 
			
		||||
					if (request.redirect !== 'manual') {
 | 
			
		||||
						reject(new FetchError(`uri requested responds with an invalid redirect URL: ${location}`, 'invalid-redirect'));
 | 
			
		||||
						finalize();
 | 
			
		||||
						return;
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				// HTTP fetch step 5.5
 | 
			
		||||
				switch (request.redirect) {
 | 
			
		||||
@ -30690,6 +30845,12 @@ function fetch(url, opts) {
 | 
			
		||||
							size: request.size
 | 
			
		||||
						};
 | 
			
		||||
 | 
			
		||||
						if (!isDomainOrSubdomain(request.url, locationURL)) {
 | 
			
		||||
							for (const name of ['authorization', 'www-authenticate', 'cookie', 'cookie2']) {
 | 
			
		||||
								requestOpts.headers.delete(name);
 | 
			
		||||
							}
 | 
			
		||||
						}
 | 
			
		||||
 | 
			
		||||
						// HTTP-redirect fetch step 9
 | 
			
		||||
						if (res.statusCode !== 303 && request.body && getTotalBytes(request) === null) {
 | 
			
		||||
							reject(new FetchError('Cannot follow redirect with body being a readable stream', 'unsupported-redirect'));
 | 
			
		||||
@ -56004,6 +56165,7 @@ const installer_2 = __webpack_require__(834);
 | 
			
		||||
const installer_3 = __webpack_require__(584);
 | 
			
		||||
const installer_4 = __webpack_require__(439);
 | 
			
		||||
const installer_5 = __webpack_require__(507);
 | 
			
		||||
const installer_6 = __webpack_require__(196);
 | 
			
		||||
var JavaDistribution;
 | 
			
		||||
(function (JavaDistribution) {
 | 
			
		||||
    JavaDistribution["Adopt"] = "adopt";
 | 
			
		||||
@ -56013,6 +56175,7 @@ var JavaDistribution;
 | 
			
		||||
    JavaDistribution["Zulu"] = "zulu";
 | 
			
		||||
    JavaDistribution["Liberica"] = "liberica";
 | 
			
		||||
    JavaDistribution["JdkFile"] = "jdkfile";
 | 
			
		||||
    JavaDistribution["Microsoft"] = "microsoft";
 | 
			
		||||
})(JavaDistribution || (JavaDistribution = {}));
 | 
			
		||||
function getJavaDistribution(distributionName, installerOptions, jdkFile) {
 | 
			
		||||
    switch (distributionName) {
 | 
			
		||||
@ -56029,6 +56192,8 @@ function getJavaDistribution(distributionName, installerOptions, jdkFile) {
 | 
			
		||||
            return new installer_2.ZuluDistribution(installerOptions);
 | 
			
		||||
        case JavaDistribution.Liberica:
 | 
			
		||||
            return new installer_5.LibericaDistributions(installerOptions);
 | 
			
		||||
        case JavaDistribution.Microsoft:
 | 
			
		||||
            return new installer_6.MicrosoftDistributions(installerOptions);
 | 
			
		||||
        default:
 | 
			
		||||
            return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -65,6 +65,17 @@ steps:
 | 
			
		||||
- run: java -cp java HelloWorldApp
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
### Microsoft
 | 
			
		||||
```yaml
 | 
			
		||||
steps:
 | 
			
		||||
- uses: actions/checkout@v2
 | 
			
		||||
- uses: actions/setup-java@v2
 | 
			
		||||
  with:
 | 
			
		||||
    distribution: 'microsoft'
 | 
			
		||||
    java-version: '11'
 | 
			
		||||
- run: java -cp java HelloWorldApp
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
## Installing custom Java package type
 | 
			
		||||
```yaml
 | 
			
		||||
steps:
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										6677
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										6677
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@ -36,7 +36,7 @@
 | 
			
		||||
  },
 | 
			
		||||
  "devDependencies": {
 | 
			
		||||
    "@types/jest": "^27.0.2",
 | 
			
		||||
    "@types/node": "^12.19.13",
 | 
			
		||||
    "@types/node": "^16.11.25",
 | 
			
		||||
    "@types/semver": "^7.3.4",
 | 
			
		||||
    "@zeit/ncc": "^0.20.5",
 | 
			
		||||
    "jest": "^27.2.5",
 | 
			
		||||
@ -44,11 +44,5 @@
 | 
			
		||||
    "prettier": "^1.19.1",
 | 
			
		||||
    "ts-jest": "^27.0.5",
 | 
			
		||||
    "typescript": "^4.2.3"
 | 
			
		||||
  },
 | 
			
		||||
  "husky": {
 | 
			
		||||
    "skipCI": true,
 | 
			
		||||
    "hooks": {
 | 
			
		||||
      "pre-commit": "npm run build && npm run format"
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -5,6 +5,7 @@ import { ZuluDistribution } from './zulu/installer';
 | 
			
		||||
import { AdoptDistribution, AdoptImplementation } from './adopt/installer';
 | 
			
		||||
import { TemurinDistribution, TemurinImplementation } from './temurin/installer';
 | 
			
		||||
import { LibericaDistributions } from './liberica/installer';
 | 
			
		||||
import { MicrosoftDistributions } from './microsoft/installer';
 | 
			
		||||
 | 
			
		||||
enum JavaDistribution {
 | 
			
		||||
  Adopt = 'adopt',
 | 
			
		||||
@ -13,7 +14,8 @@ enum JavaDistribution {
 | 
			
		||||
  Temurin = 'temurin',
 | 
			
		||||
  Zulu = 'zulu',
 | 
			
		||||
  Liberica = 'liberica',
 | 
			
		||||
  JdkFile = 'jdkfile'
 | 
			
		||||
  JdkFile = 'jdkfile',
 | 
			
		||||
  Microsoft = 'microsoft'
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function getJavaDistribution(
 | 
			
		||||
@ -35,6 +37,8 @@ export function getJavaDistribution(
 | 
			
		||||
      return new ZuluDistribution(installerOptions);
 | 
			
		||||
    case JavaDistribution.Liberica:
 | 
			
		||||
      return new LibericaDistributions(installerOptions);
 | 
			
		||||
    case JavaDistribution.Microsoft:
 | 
			
		||||
      return new MicrosoftDistributions(installerOptions);
 | 
			
		||||
    default:
 | 
			
		||||
      return null;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										124
									
								
								src/distributions/microsoft/installer.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										124
									
								
								src/distributions/microsoft/installer.ts
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,124 @@
 | 
			
		||||
import { JavaBase } from '../base-installer';
 | 
			
		||||
import { JavaDownloadRelease, JavaInstallerOptions, JavaInstallerResults } from '../base-models';
 | 
			
		||||
import semver from 'semver';
 | 
			
		||||
import { extractJdkFile, getDownloadArchiveExtension, isVersionSatisfies } from '../../util';
 | 
			
		||||
import * as core from '@actions/core';
 | 
			
		||||
import { MicrosoftVersion, PlatformOptions } from './models';
 | 
			
		||||
import * as tc from '@actions/tool-cache';
 | 
			
		||||
import fs from 'fs';
 | 
			
		||||
import path from 'path';
 | 
			
		||||
 | 
			
		||||
export class MicrosoftDistributions extends JavaBase {
 | 
			
		||||
  constructor(installerOptions: JavaInstallerOptions) {
 | 
			
		||||
    super('Microsoft', installerOptions);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  protected async downloadTool(javaRelease: JavaDownloadRelease): Promise<JavaInstallerResults> {
 | 
			
		||||
    core.info(
 | 
			
		||||
      `Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`
 | 
			
		||||
    );
 | 
			
		||||
    const javaArchivePath = await tc.downloadTool(javaRelease.url);
 | 
			
		||||
 | 
			
		||||
    core.info(`Extracting Java archive...`);
 | 
			
		||||
    const extension = getDownloadArchiveExtension();
 | 
			
		||||
    const extractedJavaPath = await extractJdkFile(javaArchivePath, extension);
 | 
			
		||||
 | 
			
		||||
    const archiveName = fs.readdirSync(extractedJavaPath)[0];
 | 
			
		||||
    const archivePath = path.join(extractedJavaPath, archiveName);
 | 
			
		||||
 | 
			
		||||
    const javaPath = await tc.cacheDir(
 | 
			
		||||
      archivePath,
 | 
			
		||||
      this.toolcacheFolderName,
 | 
			
		||||
      this.getToolcacheVersionName(javaRelease.version),
 | 
			
		||||
      this.architecture
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    return { version: javaRelease.version, path: javaPath };
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  protected async findPackageForDownload(range: string): Promise<JavaDownloadRelease> {
 | 
			
		||||
    if (this.architecture !== 'x64' && this.architecture !== 'aarch64') {
 | 
			
		||||
      throw new Error(`Unsupported architecture: ${this.architecture}`);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (!this.stable) {
 | 
			
		||||
      throw new Error('Early access versions are not supported');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (this.packageType !== 'jdk') {
 | 
			
		||||
      throw new Error('Microsoft Build of OpenJDK provides only the `jdk` package type');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const availableVersionsRaw = await this.getAvailableVersions();
 | 
			
		||||
 | 
			
		||||
    const opts = this.getPlatformOption();
 | 
			
		||||
    const availableVersions = availableVersionsRaw.map(item => ({
 | 
			
		||||
      url: `https://aka.ms/download-jdk/microsoft-jdk-${item.version.join('.')}-${opts.os}-${
 | 
			
		||||
        this.architecture
 | 
			
		||||
      }.${opts.archive}`,
 | 
			
		||||
      version: this.convertVersionToSemver(item)
 | 
			
		||||
    }));
 | 
			
		||||
 | 
			
		||||
    const satisfiedVersion = availableVersions
 | 
			
		||||
      .filter(item => isVersionSatisfies(range, item.version))
 | 
			
		||||
      .sort((a, b) => -semver.compareBuild(a.version, b.version))[0];
 | 
			
		||||
 | 
			
		||||
    if (!satisfiedVersion) {
 | 
			
		||||
      const availableOptions = availableVersions.map(item => item.version).join(', ');
 | 
			
		||||
      const availableOptionsMessage = availableOptions
 | 
			
		||||
        ? `\nAvailable versions: ${availableOptions}`
 | 
			
		||||
        : '';
 | 
			
		||||
      throw new Error(
 | 
			
		||||
        `Could not find satisfied version for SemVer ${range}. ${availableOptionsMessage}`
 | 
			
		||||
      );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return satisfiedVersion;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private async getAvailableVersions(): Promise<MicrosoftVersion[]> {
 | 
			
		||||
    // TODO get these dynamically!
 | 
			
		||||
    // We will need Microsoft to add an endpoint where we can query for versions.
 | 
			
		||||
    const jdkVersions = [
 | 
			
		||||
      {
 | 
			
		||||
        version: [17, 0, 1, 12, 1]
 | 
			
		||||
      },
 | 
			
		||||
      {
 | 
			
		||||
        version: [16, 0, 2, 7, 1]
 | 
			
		||||
      }
 | 
			
		||||
    ];
 | 
			
		||||
 | 
			
		||||
    // M1 is only supported for Java 16 & 17
 | 
			
		||||
    if (process.platform !== 'darwin' || this.architecture !== 'aarch64') {
 | 
			
		||||
      jdkVersions.push({
 | 
			
		||||
        version: [11, 0, 13, 8, 1]
 | 
			
		||||
      });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return jdkVersions;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private getPlatformOption(
 | 
			
		||||
    platform: NodeJS.Platform = process.platform /* for testing */
 | 
			
		||||
  ): PlatformOptions {
 | 
			
		||||
    switch (platform) {
 | 
			
		||||
      case 'darwin':
 | 
			
		||||
        return { archive: 'tar.gz', os: 'macos' };
 | 
			
		||||
      case 'win32':
 | 
			
		||||
        return { archive: 'zip', os: 'windows' };
 | 
			
		||||
      case 'linux':
 | 
			
		||||
        return { archive: 'tar.gz', os: 'linux' };
 | 
			
		||||
      default:
 | 
			
		||||
        throw new Error(
 | 
			
		||||
          `Platform '${platform}' is not supported. Supported platforms: 'darwin', 'linux', 'win32'`
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private convertVersionToSemver(version: MicrosoftVersion): string {
 | 
			
		||||
    const major = version.version[0];
 | 
			
		||||
    const minor = version.version[1];
 | 
			
		||||
    const patch = version.version[2];
 | 
			
		||||
    return `${major}.${minor}.${patch}`;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										12
									
								
								src/distributions/microsoft/models.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								src/distributions/microsoft/models.ts
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,12 @@
 | 
			
		||||
type OsVersions = 'linux' | 'macos' | 'windows';
 | 
			
		||||
type ArchiveType = 'tar.gz' | 'zip';
 | 
			
		||||
 | 
			
		||||
export interface PlatformOptions {
 | 
			
		||||
  archive: ArchiveType;
 | 
			
		||||
  os: OsVersions;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export interface MicrosoftVersion {
 | 
			
		||||
  downloadUrl?: string;
 | 
			
		||||
  version: Array<number>;
 | 
			
		||||
}
 | 
			
		||||
@ -51,7 +51,7 @@ export function getDownloadArchiveExtension() {
 | 
			
		||||
export function isVersionSatisfies(range: string, version: string): boolean {
 | 
			
		||||
  if (semver.valid(range)) {
 | 
			
		||||
    // if full version with build digit is provided as a range (such as '1.2.3+4')
 | 
			
		||||
    // we should check for exact equal via compareBuild
 | 
			
		||||
    // Tes we should check for exact equal via compareBuild
 | 
			
		||||
    // since semver.satisfies doesn't handle 4th digit
 | 
			
		||||
    const semRange = semver.parse(range);
 | 
			
		||||
    if (semRange && semRange.build?.length > 0) {
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user