Make the Adoptopenjdk package type look at the Temurin repo first for latest assets (#522)

* Make the Adoptopenjdk package type look at the Temurin repo first for latest assets

* Address Copilot code review comments

- Use strict equality (===, !==) instead of loose equality (==, !=) for all comparisons
- Properly handle caught errors with instanceof type narrowing before accessing properties
- Only fall back to legacy AdoptOpenJDK for specific version-not-found errors
- Rethrow unexpected errors to avoid masking real issues (network failures, rate limits, etc.)
- Fix error message check to match actual error text ('No matching version found')
- Remove unnecessary undefined check since method return type is never undefined
- Add @internal JSDoc annotation to TemurinDistribution.findPackageForDownload()
- Update tests to properly mock Temurin lookup failures for fallback behavior testing
- Rebuild dist files

* Always fall back to legacy AdoptOpenJDK but log all Temurin failures

- Change error handling to gracefully fall back for all errors, not just version-not-found
- Log version-not-found errors as notices with migration guidance
- Log other Temurin failures as debug messages for troubleshooting
- Improves resilience: users always get a result even if Temurin API has issues
- Maintains visibility: failures are still logged for debugging

* Fixes from review

* Fixes from review

* Fixes from review

* Regenerate dist
This commit is contained in:
John
2026-06-12 16:30:59 +01:00
committed by GitHub
parent 43120bc3c3
commit b24df5bba5
6 changed files with 163 additions and 20 deletions

View File

@@ -21,6 +21,7 @@ import {
MAX_PAGINATION_PAGES,
validatePaginationUrl
} from '../../util';
import {TemurinDistribution, TemurinImplementation} from '../temurin/installer';
export enum AdoptImplementation {
Hotspot = 'Hotspot',
@@ -28,15 +29,72 @@ export enum AdoptImplementation {
}
export class AdoptDistribution extends JavaBase {
private readonly temurinDistribution: TemurinDistribution | null;
constructor(
installerOptions: JavaInstallerOptions,
private readonly jvmImpl: AdoptImplementation
private readonly jvmImpl: AdoptImplementation,
temurinDistribution: TemurinDistribution | null = null
) {
super(`Adopt-${jvmImpl}`, installerOptions);
if (
temurinDistribution !== null &&
jvmImpl !== AdoptImplementation.Hotspot
) {
throw new Error('Only Hotspot JVM is supported by Temurin.');
}
// Only use the temurin repo for Hotspot JVMs
this.temurinDistribution =
temurinDistribution ??
(jvmImpl === AdoptImplementation.Hotspot
? new TemurinDistribution(
installerOptions,
TemurinImplementation.Hotspot
)
: null);
}
protected async findPackageForDownload(
version: string
): Promise<JavaDownloadRelease> {
if (this.jvmImpl === AdoptImplementation.Hotspot) {
core.notice(
"AdoptOpenJDK has moved to Eclipse Temurin https://github.com/actions/setup-java#supported-distributions please consider changing to the 'temurin' distribution type in your setup-java configuration."
);
}
if (
this.jvmImpl === AdoptImplementation.Hotspot &&
this.temurinDistribution !== null
) {
try {
return await this.temurinDistribution.findPackageForDownload(version);
} catch (error) {
// Log the failure but always fall back to legacy AdoptOpenJDK for resilience
const errorMessage =
error instanceof Error ? error.message : String(error);
if (error instanceof Error && error.name === 'VersionNotFoundError') {
core.notice(
'The JVM you are looking for could not be found in the Temurin repository, this likely indicates ' +
'that you are using an out of date version of Java, consider updating and moving to using the Temurin distribution type in setup-java.'
);
} else {
// Log other errors for debugging but gracefully fall back
core.debug(
`Temurin lookup failed: ${errorMessage}. Falling back to AdoptOpenJDK API.`
);
}
}
}
// failed to find a Temurin version, so fall back to AdoptOpenJDK
return this.findPackageForDownloadOldAdoptOpenJdk(version);
}
private async findPackageForDownloadOldAdoptOpenJdk(
version: string
): Promise<JavaDownloadRelease> {
const availableVersionsRaw = await this.getAvailableVersions();
const availableVersionsWithBinaries = availableVersionsRaw

View File

@@ -292,7 +292,9 @@ export abstract class JavaBase {
}
}
return new Error(parts.join('\n'));
const error = new Error(parts.join('\n'));
error.name = 'VersionNotFoundError';
return error;
}
protected setJavaDefault(version: string, toolPath: string) {

View File

@@ -34,7 +34,10 @@ export class TemurinDistribution extends JavaBase {
super(`Temurin-${jvmImpl}`, installerOptions);
}
protected async findPackageForDownload(
/**
* @internal For cross-distribution reuse only. Not intended as a public API.
*/
public async findPackageForDownload(
version: string
): Promise<JavaDownloadRelease> {
const availableVersionsRaw = await this.getAvailableVersions();