mirror of
				https://gitea.com/actions/setup-java.git
				synced 2025-11-04 07:47:06 +00:00 
			
		
		
		
	Default to runner architecture (#376)
This commit is contained in:
		@@ -88,7 +88,7 @@ export class AdoptDistribution extends JavaBase {
 | 
			
		||||
 | 
			
		||||
  private async getAvailableVersions(): Promise<IAdoptAvailableVersions[]> {
 | 
			
		||||
    const platform = this.getPlatformOption();
 | 
			
		||||
    const arch = this.architecture;
 | 
			
		||||
    const arch = this.distributionArchitecture();
 | 
			
		||||
    const imageType = this.packageType;
 | 
			
		||||
    const versionRange = encodeURI('[1.0,100.0]'); // retrieve all available versions
 | 
			
		||||
    const releaseType = this.stable ? 'ga' : 'ea';
 | 
			
		||||
 
 | 
			
		||||
@@ -7,6 +7,7 @@ import * as httpm from '@actions/http-client';
 | 
			
		||||
import { getToolcachePath, isVersionSatisfies } from '../util';
 | 
			
		||||
import { JavaDownloadRelease, JavaInstallerOptions, JavaInstallerResults } from './base-models';
 | 
			
		||||
import { MACOS_JAVA_CONTENT_POSTFIX } from '../constants';
 | 
			
		||||
import os from 'os';
 | 
			
		||||
 | 
			
		||||
export abstract class JavaBase {
 | 
			
		||||
  protected http: httpm.HttpClient;
 | 
			
		||||
@@ -25,7 +26,7 @@ export abstract class JavaBase {
 | 
			
		||||
    ({ version: this.version, stable: this.stable } = this.normalizeVersion(
 | 
			
		||||
      installerOptions.version
 | 
			
		||||
    ));
 | 
			
		||||
    this.architecture = installerOptions.architecture;
 | 
			
		||||
    this.architecture = installerOptions.architecture || os.arch();
 | 
			
		||||
    this.packageType = installerOptions.packageType;
 | 
			
		||||
    this.checkLatest = installerOptions.checkLatest;
 | 
			
		||||
  }
 | 
			
		||||
@@ -150,4 +151,24 @@ export abstract class JavaBase {
 | 
			
		||||
    core.setOutput('version', version);
 | 
			
		||||
    core.exportVariable(`JAVA_HOME_${majorVersion}_${this.architecture.toUpperCase()}`, toolPath);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  protected distributionArchitecture(): string {
 | 
			
		||||
    // default mappings of config architectures to distribution architectures
 | 
			
		||||
    // override if a distribution uses any different names; see liberica for an example
 | 
			
		||||
 | 
			
		||||
    // node's os.arch() - which this defaults to - can return any of:
 | 
			
		||||
    // 'arm', 'arm64', 'ia32', 'mips', 'mipsel', 'ppc', 'ppc64', 's390', 's390x', and 'x64'
 | 
			
		||||
    // so we need to map these to java distribution architectures
 | 
			
		||||
    // 'amd64' is included here too b/c it's a common alias for 'x64' people might use explicitly
 | 
			
		||||
    switch (this.architecture) {
 | 
			
		||||
      case 'amd64':
 | 
			
		||||
        return 'x64';
 | 
			
		||||
      case 'ia32':
 | 
			
		||||
        return 'x86';
 | 
			
		||||
      case 'arm64':
 | 
			
		||||
        return 'aarch64';
 | 
			
		||||
      default:
 | 
			
		||||
        return this.architecture;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -68,7 +68,7 @@ export class CorrettoDistribution extends JavaBase {
 | 
			
		||||
 | 
			
		||||
  private async getAvailableVersions(): Promise<ICorrettoAvailableVersions[]> {
 | 
			
		||||
    const platform = this.getPlatformOption();
 | 
			
		||||
    const arch = this.architecture;
 | 
			
		||||
    const arch = this.distributionArchitecture();
 | 
			
		||||
    const imageType = this.packageType;
 | 
			
		||||
 | 
			
		||||
    if (core.isDebug()) {
 | 
			
		||||
 
 | 
			
		||||
@@ -10,7 +10,7 @@ import path from 'path';
 | 
			
		||||
 | 
			
		||||
const supportedPlatform = `'linux', 'linux-musl', 'macos', 'solaris', 'windows'`;
 | 
			
		||||
 | 
			
		||||
const supportedArchitecture = `'x86', 'x64', 'armv7', 'aarch64', 'ppc64le'`;
 | 
			
		||||
const supportedArchitectures = `'x86', 'x64', 'armv7', 'aarch64', 'ppc64le'`;
 | 
			
		||||
 | 
			
		||||
export class LibericaDistributions extends JavaBase {
 | 
			
		||||
  constructor(installerOptions: JavaInstallerOptions) {
 | 
			
		||||
@@ -112,7 +112,8 @@ export class LibericaDistributions extends JavaBase {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private getArchitectureOptions(): ArchitectureOptions {
 | 
			
		||||
    switch (this.architecture) {
 | 
			
		||||
    const arch = this.distributionArchitecture();
 | 
			
		||||
    switch (arch) {
 | 
			
		||||
      case 'x86':
 | 
			
		||||
        return { bitness: '32', arch: 'x86' };
 | 
			
		||||
      case 'x64':
 | 
			
		||||
@@ -125,7 +126,7 @@ export class LibericaDistributions extends JavaBase {
 | 
			
		||||
        return { bitness: '64', arch: 'ppc' };
 | 
			
		||||
      default:
 | 
			
		||||
        throw new Error(
 | 
			
		||||
          `Architecture '${this.architecture}' is not supported. Supported architectures: ${supportedArchitecture}`
 | 
			
		||||
          `Architecture '${this.architecture}' is not supported. Supported architectures: ${supportedArchitectures}`
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
@@ -156,4 +157,14 @@ export class LibericaDistributions extends JavaBase {
 | 
			
		||||
    }
 | 
			
		||||
    return mainVersion;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  protected distributionArchitecture(): string {
 | 
			
		||||
    let arch = super.distributionArchitecture();
 | 
			
		||||
    switch (arch) {
 | 
			
		||||
      case 'arm':
 | 
			
		||||
        return 'armv7';
 | 
			
		||||
      default:
 | 
			
		||||
        return arch;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -37,7 +37,8 @@ export class MicrosoftDistributions extends JavaBase {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  protected async findPackageForDownload(range: string): Promise<JavaDownloadRelease> {
 | 
			
		||||
    if (this.architecture !== 'x64' && this.architecture !== 'aarch64') {
 | 
			
		||||
    const arch = this.distributionArchitecture();
 | 
			
		||||
    if (arch !== 'x64' && arch !== 'aarch64') {
 | 
			
		||||
      throw new Error(`Unsupported architecture: ${this.architecture}`);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -55,7 +56,7 @@ export class MicrosoftDistributions extends JavaBase {
 | 
			
		||||
      throw new Error('Could not load manifest for Microsoft Build of OpenJDK');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const foundRelease = await tc.findFromManifest(range, true, manifest, this.architecture);
 | 
			
		||||
    const foundRelease = await tc.findFromManifest(range, true, manifest, arch);
 | 
			
		||||
 | 
			
		||||
    if (!foundRelease) {
 | 
			
		||||
      throw new Error(
 | 
			
		||||
 
 | 
			
		||||
@@ -86,7 +86,7 @@ export class TemurinDistribution extends JavaBase {
 | 
			
		||||
 | 
			
		||||
  private async getAvailableVersions(): Promise<ITemurinAvailableVersions[]> {
 | 
			
		||||
    const platform = this.getPlatformOption();
 | 
			
		||||
    const arch = this.architecture;
 | 
			
		||||
    const arch = this.distributionArchitecture();
 | 
			
		||||
    const imageType = this.packageType;
 | 
			
		||||
    const versionRange = encodeURI('[1.0,100.0]'); // retrieve all available versions
 | 
			
		||||
    const releaseType = this.stable ? 'ga' : 'ea';
 | 
			
		||||
 
 | 
			
		||||
@@ -131,14 +131,17 @@ export class ZuluDistribution extends JavaBase {
 | 
			
		||||
    hw_bitness: string;
 | 
			
		||||
    abi: string;
 | 
			
		||||
  } {
 | 
			
		||||
    if (this.architecture == 'x64') {
 | 
			
		||||
      return { arch: 'x86', hw_bitness: '64', abi: '' };
 | 
			
		||||
    } else if (this.architecture == 'x86') {
 | 
			
		||||
      return { arch: 'x86', hw_bitness: '32', abi: '' };
 | 
			
		||||
    } else if (this.architecture == 'arm64') {
 | 
			
		||||
      return { arch: 'arm', hw_bitness: '64', abi: '' };
 | 
			
		||||
    } else {
 | 
			
		||||
      return { arch: this.architecture, hw_bitness: '', abi: '' };
 | 
			
		||||
    const arch = this.distributionArchitecture();
 | 
			
		||||
    switch (arch) {
 | 
			
		||||
      case 'x64':
 | 
			
		||||
        return { arch: 'x86', hw_bitness: '64', abi: '' };
 | 
			
		||||
      case 'x86':
 | 
			
		||||
        return { arch: 'x86', hw_bitness: '32', abi: '' };
 | 
			
		||||
      case 'aarch64':
 | 
			
		||||
      case 'arm64':
 | 
			
		||||
        return { arch: 'arm', hw_bitness: '64', abi: '' };
 | 
			
		||||
      default:
 | 
			
		||||
        return { arch: arch, hw_bitness: '', abi: '' };
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user