Compare commits

...

5 Commits

Author SHA1 Message Date
John Oliver
7a7ba2a749
Merge 5256614f4c into 4075bfc1b5 2023-08-31 11:01:20 +02:00
Marko Zivic
4075bfc1b5
Merge pull request #503 from gnodet/fix-xml-namespaces
Fix XML namespaces wrongly using https
2023-08-31 06:15:25 +02:00
John Oliver
5256614f4c add warning 2023-08-09 15:58:28 +01:00
John Oliver
7f1cc05ecf Make the Adoptopenjdk package type look at the Temurin repo first for latest assets 2023-08-08 13:02:14 +01:00
Guillaume Nodet
91f49aa1b0 Fix XML namespaces wrongly using https 2023-06-28 11:24:07 +02:00
6 changed files with 136 additions and 20 deletions

View File

@ -1,14 +1,11 @@
import {HttpClient} from '@actions/http-client';
import {IAdoptAvailableVersions} from '../../src/distributions/adopt/models';
import {
AdoptDistribution,
AdoptImplementation
} from '../../src/distributions/adopt/installer';
import {AdoptDistribution, AdoptImplementation} from '../../src/distributions/adopt/installer';
import {JavaInstallerOptions} from '../../src/distributions/base-models';
import os from 'os';
import manifestData from '../data/adopt.json';
import {TemurinDistribution, TemurinImplementation} from "../../src/distributions/temurin/installer";
describe('getAvailableVersions', () => {
let spyHttpClient: jest.SpyInstance;
@ -247,6 +244,85 @@ describe('findPackageForDownload', () => {
expect(resolvedVersion.version).toBe(expected);
});
describe('delegates to Temurin', () => {
it.each([
['9', '9.0.7+10'],
['15', '15.0.2+7'],
['15.0', '15.0.2+7'],
['15.0.2', '15.0.2+7'],
['15.0.1', '15.0.1+9.1'],
['11.x', '11.0.10+9'],
['x', '15.0.2+7'],
['12', '12.0.2+10.3'], // make sure that '12.0.2+10.1', '12.0.2+10.3', '12.0.2+10.2' are sorted correctly
['12.0.2+10.1', '12.0.2+10.1'],
['15.0.1+9', '15.0.1+9'],
['15.0.1+9.1', '15.0.1+9.1']
])('version is resolved correctly %s -> %s', async (input, expected) => {
const temurinDistribution = new TemurinDistribution(
{
version: '11',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
},
TemurinImplementation.Hotspot
);
const distribution = new AdoptDistribution(
{
version: '11',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
},
AdoptImplementation.Hotspot,
temurinDistribution
);
temurinDistribution['getAvailableVersions'] = async () => manifestData as any;
const resolvedVersion = await distribution['findPackageForDownload'](input);
expect(resolvedVersion.version).toBe(expected);
});
});
describe('Falls back if Temurin fails', () => {
it.each([
['9', '9.0.7+10']
])('version is resolved correctly %s -> %s', async (input, expected) => {
const temurinDistribution = new TemurinDistribution(
{
version: '11',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
},
TemurinImplementation.Hotspot
);
const distribution = new AdoptDistribution(
{
version: '11',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
},
AdoptImplementation.Hotspot,
temurinDistribution
);
temurinDistribution['findPackageForDownload'] = async () => new Promise(function () {
throw new Error("Could not find satisfied version for SemVer")
});
distribution['getAvailableVersions'] = async () => manifestData as any;
const resolvedVersion = await distribution['findPackageForDownload'](input);
expect(resolvedVersion.version).toBe(expected);
});
});
it('version is found but binaries list is empty', async () => {
const distribution = new AdoptDistribution(
{

View File

@ -77,9 +77,9 @@ describe('toolchains tests', () => {
};
const result = `<?xml version="1.0"?>
<toolchains xmlns="https://maven.apache.org/TOOLCHAINS/1.1.0"
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://maven.apache.org/TOOLCHAINS/1.1.0 https://maven.apache.org/xsd/toolchains-1.1.0.xsd">
<toolchains xmlns="http://maven.apache.org/TOOLCHAINS/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/TOOLCHAINS/1.1.0 https://maven.apache.org/xsd/toolchains-1.1.0.xsd">
<toolchain>
<type>jdk</type>
<provides>
@ -248,9 +248,9 @@ describe('toolchains tests', () => {
};
const expectedToolchains = `<?xml version="1.0"?>
<toolchains xmlns="https://maven.apache.org/TOOLCHAINS/1.1.0"
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://maven.apache.org/TOOLCHAINS/1.1.0 https://maven.apache.org/xsd/toolchains-1.1.0.xsd">
<toolchains xmlns="http://maven.apache.org/TOOLCHAINS/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/TOOLCHAINS/1.1.0 https://maven.apache.org/xsd/toolchains-1.1.0.xsd">
<toolchain>
<type>jdk</type>
<provides>

6
dist/setup/index.js vendored
View File

@ -103974,9 +103974,9 @@ function generateToolchainDefinition(original, version, vendor, id, jdkHome) {
else
xmlObj = xmlbuilder2_1.create({
toolchains: {
'@xmlns': 'https://maven.apache.org/TOOLCHAINS/1.1.0',
'@xmlns:xsi': 'https://www.w3.org/2001/XMLSchema-instance',
'@xsi:schemaLocation': 'https://maven.apache.org/TOOLCHAINS/1.1.0 https://maven.apache.org/xsd/toolchains-1.1.0.xsd',
'@xmlns': 'http://maven.apache.org/TOOLCHAINS/1.1.0',
'@xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
'@xsi:schemaLocation': 'http://maven.apache.org/TOOLCHAINS/1.1.0 https://maven.apache.org/xsd/toolchains-1.1.0.xsd',
toolchain: [
{
type: 'jdk',

View File

@ -17,6 +17,7 @@ import {
getDownloadArchiveExtension,
isVersionSatisfies
} from '../../util';
import {TemurinDistribution, TemurinImplementation} from "../temurin/installer";
export enum AdoptImplementation {
Hotspot = 'Hotspot',
@ -26,13 +27,52 @@ export enum AdoptImplementation {
export class AdoptDistribution extends JavaBase {
constructor(
installerOptions: JavaInstallerOptions,
private readonly jvmImpl: AdoptImplementation
private readonly jvmImpl: AdoptImplementation,
private readonly 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
if (temurinDistribution == null && jvmImpl == AdoptImplementation.Hotspot) {
this.temurinDistribution = new TemurinDistribution(
installerOptions,
TemurinImplementation.Hotspot);
}
}
protected async findPackageForDownload(
version: string
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 {
let result = await this.temurinDistribution.findPackageForDownload(version)
if (result != undefined) {
return result
}
} catch (error) {
if (error.message.includes('Could not find satisfied version')) {
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.")
}
}
}
// 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

@ -30,7 +30,7 @@ export class TemurinDistribution extends JavaBase {
super(`Temurin-${jvmImpl}`, installerOptions);
}
protected async findPackageForDownload(
public async findPackageForDownload(
version: string
): Promise<JavaDownloadRelease> {
const availableVersionsRaw = await this.getAvailableVersions();

View File

@ -104,10 +104,10 @@ export function generateToolchainDefinition(
} else
xmlObj = xmlCreate({
toolchains: {
'@xmlns': 'https://maven.apache.org/TOOLCHAINS/1.1.0',
'@xmlns:xsi': 'https://www.w3.org/2001/XMLSchema-instance',
'@xmlns': 'http://maven.apache.org/TOOLCHAINS/1.1.0',
'@xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
'@xsi:schemaLocation':
'https://maven.apache.org/TOOLCHAINS/1.1.0 https://maven.apache.org/xsd/toolchains-1.1.0.xsd',
'http://maven.apache.org/TOOLCHAINS/1.1.0 https://maven.apache.org/xsd/toolchains-1.1.0.xsd',
toolchain: [
{
type: 'jdk',