Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
b2da088
Implement support for custom vendors in setup-java
Mar 8, 2021
cfdcd68
minor improvements
Mar 8, 2021
1d25bcb
minor refactoring
Mar 8, 2021
330fe63
Add unit tests and e2e tests
Mar 8, 2021
ab1f15d
Update documentation for setup-java@v2 release
Mar 8, 2021
c65c532
minor improvements
Mar 8, 2021
9979ab3
regenerate dist
Mar 8, 2021
e6d2942
fix comments
Mar 9, 2021
f02cd99
Merge branch 'implement-v2-installers' into implement-v2-tests
Mar 9, 2021
87febe1
resolve comments
Mar 9, 2021
7006d0b
resolve comments
Mar 9, 2021
54adc86
fix tests
Mar 9, 2021
6738676
Update README.md
maxim-lobanov Mar 9, 2021
50ef02a
Apply suggestions from code review
maxim-lobanov Mar 9, 2021
fb17d02
fix minor nitpicks
Mar 10, 2021
408d6f3
handle 4th digit
Mar 10, 2021
793a1df
Merge branch 'implement-v2-installers' into implement-v2-tests
Mar 10, 2021
e9a0f2c
pull latest main
Mar 10, 2021
caf7917
Merge branch 'implement-v2-installers' into implement-v2-docs
Mar 10, 2021
f6c63d8
Update README.md
Mar 10, 2021
c94ef7c
rename adoptium to adopt
Mar 11, 2021
2ff07ea
Merge branch 'implement-v2-installers' into implement-v2-tests
Mar 11, 2021
491094c
rename adoptium to adopt
Mar 11, 2021
4423435
Merge branch 'implement-v2-installers' into implement-v2-docs
Mar 11, 2021
f761609
rename adoptium to adopt
Mar 11, 2021
03ecfa0
Update README.md
Mar 11, 2021
fde2f0f
make java-version and distribution required for action
Mar 12, 2021
0f6f6e1
Merge pull request #133 from actions/implement-v2-tests
maxim-lobanov Mar 15, 2021
20a04c5
Merge pull request #134 from actions/implement-v2-docs
maxim-lobanov Mar 15, 2021
fc17803
update readme
Mar 15, 2021
f20fd47
fix tests
Mar 15, 2021
f74bcbe
fix e2e tests
Mar 15, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3,264 changes: 3,145 additions & 119 deletions dist/cleanup/index.js

Large diffs are not rendered by default.

118 changes: 73 additions & 45 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -519,9 +519,16 @@ module.exports = maxSatisfying
/***/ }),
/* 15 */,
/* 16 */
/***/ (function(module) {
/***/ (function(module, __unusedexports, __webpack_require__) {

const SemVer = __webpack_require__(65)
const compareBuild = (a, b, loose) => {
const versionA = new SemVer(a, loose)
const versionB = new SemVer(b, loose)
return versionA.compare(versionB) || versionA.compareBuild(versionB)
}
module.exports = compareBuild

module.exports = require("tls");

/***/ }),
/* 17 */,
Expand Down Expand Up @@ -3966,7 +3973,7 @@ class JavaBase {
core.info(`Resolved Java ${foundJava.version} from tool-cache`);
}
else {
core.info(`Java ${this.version.raw} was not found in tool-cache. Trying to download...`);
core.info(`Java ${this.version} was not found in tool-cache. Trying to download...`);
const javaRelease = yield this.findPackageForDownload(this.version);
foundJava = yield this.downloadTool(javaRelease);
core.info(`Java ${foundJava.version} was downloaded`);
Expand All @@ -3979,8 +3986,7 @@ class JavaBase {
get toolcacheFolderName() {
return `Java_${this.distribution}_${this.packageType}`;
}
getToolcacheVersionName(resolvedVersion) {
let version = resolvedVersion;
getToolcacheVersionName(version) {
if (!this.stable) {
const cleanVersion = semver_1.default.clean(version);
return `${cleanVersion}-ea`;
Expand All @@ -3994,12 +4000,12 @@ class JavaBase {
.findAllVersions(this.toolcacheFolderName, this.architecture)
.filter(item => item.endsWith('-ea') === !this.stable);
const satisfiedVersions = availableVersions
.filter(item => semver_1.default.satisfies(item.replace(/-ea$/, ''), this.version))
.filter(item => util_1.isVersionSatisfies(this.version, item.replace(/-ea$/, '')))
.sort(semver_1.default.rcompare);
if (!satisfiedVersions || satisfiedVersions.length === 0) {
return null;
}
const javaPath = tc.find(this.toolcacheFolderName, satisfiedVersions[0], this.architecture);
const javaPath = util_1.getToolcachePath(this.toolcacheFolderName, satisfiedVersions[0], this.architecture);
if (!javaPath) {
return null;
}
Expand All @@ -4008,28 +4014,32 @@ class JavaBase {
path: javaPath
};
}
setJavaDefault(version, toolPath) {
core.exportVariable('JAVA_HOME', toolPath);
core.addPath(path_1.default.join(toolPath, 'bin'));
core.setOutput('distribution', this.distribution);
core.setOutput('path', toolPath);
core.setOutput('version', version);
}
// this function validates and parse java version to its normal semver notation
normalizeVersion(version) {
let stable = true;
if (version.endsWith('-ea')) {
version = version.replace(/-ea$/, '');
stable = false;
}
else if (version.includes('-ea.')) {
// transform '11.0.3-ea.2' -> '11.0.3+2'
version = version.replace('-ea.', '+');
stable = false;
}
if (!semver_1.default.validRange(version)) {
throw new Error(`The string '${version}' is not valid SemVer notation for a Java version. Please check README file for code snippets and more detailed information`);
}
return {
version: new semver_1.default.Range(version),
version,
stable
};
}
setJavaDefault(version, toolPath) {
core.exportVariable('JAVA_HOME', toolPath);
core.addPath(path_1.default.join(toolPath, 'bin'));
core.setOutput('distribution', this.distribution);
core.setOutput('path', toolPath);
core.setOutput('version', version);
}
}
exports.JavaBase = JavaBase;

Expand Down Expand Up @@ -7822,7 +7832,7 @@ util_1.applyMixin(ElementImpl_1.ElementImpl, SlotableImpl_1.SlotableImpl);
/* 120 */
/***/ (function(module, __unusedexports, __webpack_require__) {

const compareBuild = __webpack_require__(465)
const compareBuild = __webpack_require__(16)
const sort = (list, loose) => list.sort((a, b) => compareBuild(a, b, loose))
module.exports = sort

Expand Down Expand Up @@ -9013,7 +9023,7 @@ function _unique(values) {


var net = __webpack_require__(631);
var tls = __webpack_require__(16);
var tls = __webpack_require__(818);
var http = __webpack_require__(605);
var https = __webpack_require__(34);
var events = __webpack_require__(614);
Expand Down Expand Up @@ -9352,7 +9362,7 @@ class LocalDistribution extends base_installer_1.JavaBase {
core.info(`Resolved Java ${foundJava.version} from tool-cache`);
}
else {
core.info(`Java ${this.version.raw} was not found in tool-cache. Trying to unpack JDK file...`);
core.info(`Java ${this.version} was not found in tool-cache. Trying to unpack JDK file...`);
if (!this.jdkFile) {
throw new Error("'jdkFile' is not specified");
}
Expand All @@ -9365,7 +9375,7 @@ class LocalDistribution extends base_installer_1.JavaBase {
const extractedJavaPath = yield util_1.extractJdkFile(jdkFilePath);
const archiveName = fs_1.default.readdirSync(extractedJavaPath)[0];
const archivePath = path_1.default.join(extractedJavaPath, archiveName);
const javaVersion = this.version.raw;
const javaVersion = this.version;
let javaPath = yield tc.cacheDir(archivePath, this.toolcacheFolderName, this.getToolcacheVersionName(javaVersion), this.architecture);
// for different Java distributions, postfix can exist or not so need to check both cases
if (process.platform === 'darwin' &&
Expand Down Expand Up @@ -12925,9 +12935,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDownloadArchiveExtension = exports.extractJdkFile = exports.getVersionFromToolcachePath = exports.getTempDir = void 0;
exports.getToolcachePath = exports.isVersionSatisfies = exports.getDownloadArchiveExtension = exports.extractJdkFile = exports.getVersionFromToolcachePath = exports.getTempDir = void 0;
const os_1 = __importDefault(__webpack_require__(87));
const path_1 = __importDefault(__webpack_require__(622));
const fs = __importStar(__webpack_require__(747));
const semver = __importStar(__webpack_require__(876));
const tc = __importStar(__webpack_require__(139));
function getTempDir() {
let tempDirectory = process.env['RUNNER_TEMP'] || os_1.default.tmpdir();
Expand Down Expand Up @@ -12965,6 +12977,30 @@ function getDownloadArchiveExtension() {
return process.platform === 'win32' ? 'zip' : 'tar.gz';
}
exports.getDownloadArchiveExtension = getDownloadArchiveExtension;
function isVersionSatisfies(range, version) {
var _a;
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
// since semver.satisfies doesn't handle 4th digit
const semRange = semver.parse(range);
if (semRange && ((_a = semRange.build) === null || _a === void 0 ? void 0 : _a.length) > 0) {
return semver.compareBuild(range, version) === 0;
}
}
return semver.satisfies(version, range);
}
exports.isVersionSatisfies = isVersionSatisfies;
function getToolcachePath(toolName, version, architecture) {
var _a;
const toolcacheRoot = (_a = process.env['RUNNER_TOOL_CACHE']) !== null && _a !== void 0 ? _a : '';
const fullPath = path_1.default.join(toolcacheRoot, toolName, version, architecture);
if (fs.existsSync(fullPath)) {
return fullPath;
}
return null;
}
exports.getToolcachePath = getToolcachePath;


/***/ }),
Expand Down Expand Up @@ -13294,7 +13330,7 @@ function write(directory, settings) {
return __awaiter(this, void 0, void 0, function* () {
const location = path.join(directory, exports.SETTINGS_FILE);
if (fs.existsSync(location)) {
core.warning(`Overwriting existing file ${location}`);
core.info(`Overwriting existing file ${location}`);
}
else {
core.info(`Writing ${location}`);
Expand Down Expand Up @@ -13765,7 +13801,7 @@ class AdoptiumDistribution extends base_installer_1.JavaBase {
};
});
const satisfiedVersions = availableVersionsWithBinaries
.filter(item => semver_1.default.satisfies(item.version, version))
.filter(item => util_1.isVersionSatisfies(version, item.version))
.sort((a, b) => {
return -semver_1.default.compareBuild(a.version, b.version);
});
Expand All @@ -13775,7 +13811,7 @@ class AdoptiumDistribution extends base_installer_1.JavaBase {
const availableOptionsMessage = availableOptions
? `\nAvailable versions: ${availableOptions}`
: '';
throw new Error(`Could not find satisfied version for SemVer '${version.raw}'. ${availableOptionsMessage}`);
throw new Error(`Could not find satisfied version for SemVer '${version}'. ${availableOptionsMessage}`);
}
return resolvedFullVersion;
});
Expand Down Expand Up @@ -13804,8 +13840,7 @@ class AdoptiumDistribution extends base_installer_1.JavaBase {
const platform = this.getPlatformOption();
const arch = this.architecture;
const imageType = this.packageType;
const versionRange = '[1.0,100.0]'; // retrieve all available versions
const encodedVersionRange = encodeURI(versionRange);
const versionRange = encodeURI('[1.0,100.0]'); // retrieve all available versions
const releaseType = this.stable ? 'ga' : 'ea';
console.time('adopt-retrieve-available-versions');
const baseRequestArguments = [
Expand All @@ -13826,7 +13861,7 @@ class AdoptiumDistribution extends base_installer_1.JavaBase {
const availableVersions = [];
while (true) {
const requestArguments = `${baseRequestArguments}&page_size=20&page=${page_index}`;
const availableVersionsUrl = `https://api.adoptopenjdk.net/v3/assets/version/${encodedVersionRange}?${requestArguments}`;
const availableVersionsUrl = `https://api.adoptopenjdk.net/v3/assets/version/${versionRange}?${requestArguments}`;
if (core.isDebug() && page_index === 0) {
// url is identical except page_index so print it once for debug
core.debug(`Gathering available versions from '${availableVersionsUrl}'`);
Expand Down Expand Up @@ -14083,7 +14118,7 @@ class ZuluDistribution extends base_installer_1.JavaBase {
};
});
const satisfiedVersions = availableVersions
.filter(item => semver_1.default.satisfies(item.version, version))
.filter(item => util_1.isVersionSatisfies(version, item.version))
.sort((a, b) => {
// Azul provides two versions: jdk_version and azul_version
// we should sort by both fields by descending
Expand All @@ -14102,7 +14137,7 @@ class ZuluDistribution extends base_installer_1.JavaBase {
const availableOptionsMessage = availableOptions
? `\nAvailable versions: ${availableOptions}`
: '';
throw new Error(`Could not find satisfied version for semver ${version.raw}. ${availableOptionsMessage}`);
throw new Error(`Could not find satisfied version for semver ${version}. ${availableOptionsMessage}`);
}
return resolvedFullVersion;
});
Expand Down Expand Up @@ -19280,19 +19315,7 @@ exports.traversal_filter = traversal_filter;
//# sourceMappingURL=TraversalAlgorithm.js.map

/***/ }),
/* 465 */
/***/ (function(module, __unusedexports, __webpack_require__) {

const SemVer = __webpack_require__(65)
const compareBuild = (a, b, loose) => {
const versionA = new SemVer(a, loose)
const versionB = new SemVer(b, loose)
return versionA.compare(versionB) || versionA.compareBuild(versionB)
}
module.exports = compareBuild


/***/ }),
/* 465 */,
/* 466 */,
/* 467 */,
/* 468 */
Expand Down Expand Up @@ -27409,7 +27432,7 @@ exports.utf8Decode = utf8Decode;
/* 593 */
/***/ (function(module, __unusedexports, __webpack_require__) {

const compareBuild = __webpack_require__(465)
const compareBuild = __webpack_require__(16)
const rsort = (list, loose) => list.sort((a, b) => compareBuild(b, a, loose))
module.exports = rsort

Expand Down Expand Up @@ -38425,7 +38448,12 @@ exports.asciiSerializationOfAnOrigin = asciiSerializationOfAnOrigin;
/* 815 */,
/* 816 */,
/* 817 */,
/* 818 */,
/* 818 */
/***/ (function(module) {

module.exports = require("tls");

/***/ }),
/* 819 */,
/* 820 */
/***/ (function(__unusedmodule, exports, __webpack_require__) {
Expand Down Expand Up @@ -40883,7 +40911,7 @@ module.exports = {
compare: __webpack_require__(874),
rcompare: __webpack_require__(630),
compareLoose: __webpack_require__(283),
compareBuild: __webpack_require__(465),
compareBuild: __webpack_require__(16),
sort: __webpack_require__(120),
rsort: __webpack_require__(593),
gt: __webpack_require__(486),
Expand Down
Binary file removed dist/setup/unzip
Binary file not shown.
2 changes: 1 addition & 1 deletion src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export function generate(
async function write(directory: string, settings: string) {
const location = path.join(directory, SETTINGS_FILE);
if (fs.existsSync(location)) {
core.warning(`Overwriting existing file ${location}`);
core.info(`Overwriting existing file ${location}`);
} else {
core.info(`Writing ${location}`);
}
Expand Down
13 changes: 6 additions & 7 deletions src/distributions/adoptium/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import { JavaBase } from '../base-installer';
import { IAdoptiumAvailableVersions } from './models';
import { JavaInstallerOptions, JavaDownloadRelease, JavaInstallerResults } from '../base-models';
import { MACOS_JAVA_CONTENT_POSTFIX } from '../../constants';
import { extractJdkFile, getDownloadArchiveExtension } from '../../util';
import { extractJdkFile, getDownloadArchiveExtension, isVersionSatisfies } from '../../util';

export class AdoptiumDistribution extends JavaBase {
constructor(installerOptions: JavaInstallerOptions) {
super('Adoptium', installerOptions);
}

protected async findPackageForDownload(version: semver.Range): Promise<JavaDownloadRelease> {
protected async findPackageForDownload(version: string): Promise<JavaDownloadRelease> {
const availableVersionsRaw = await this.getAvailableVersions();
const availableVersionsWithBinaries = availableVersionsRaw
.filter(item => item.binaries.length > 0)
Expand All @@ -28,7 +28,7 @@ export class AdoptiumDistribution extends JavaBase {
});

const satisfiedVersions = availableVersionsWithBinaries
.filter(item => semver.satisfies(item.version, version))
.filter(item => isVersionSatisfies(version, item.version))
.sort((a, b) => {
return -semver.compareBuild(a.version, b.version);
});
Expand All @@ -40,7 +40,7 @@ export class AdoptiumDistribution extends JavaBase {
? `\nAvailable versions: ${availableOptions}`
: '';
throw new Error(
`Could not find satisfied version for SemVer '${version.raw}'. ${availableOptionsMessage}`
`Could not find satisfied version for SemVer '${version}'. ${availableOptionsMessage}`
);
}

Expand Down Expand Up @@ -78,8 +78,7 @@ export class AdoptiumDistribution extends JavaBase {
const platform = this.getPlatformOption();
const arch = this.architecture;
const imageType = this.packageType;
const versionRange = '[1.0,100.0]'; // retrieve all available versions
const encodedVersionRange = encodeURI(versionRange);
const versionRange = encodeURI('[1.0,100.0]'); // retrieve all available versions
const releaseType = this.stable ? 'ga' : 'ea';

console.time('adopt-retrieve-available-versions');
Expand All @@ -103,7 +102,7 @@ export class AdoptiumDistribution extends JavaBase {
const availableVersions: IAdoptiumAvailableVersions[] = [];
while (true) {
const requestArguments = `${baseRequestArguments}&page_size=20&page=${page_index}`;
const availableVersionsUrl = `https://api.adoptopenjdk.net/v3/assets/version/${encodedVersionRange}?${requestArguments}`;
const availableVersionsUrl = `https://api.adoptopenjdk.net/v3/assets/version/${versionRange}?${requestArguments}`;
if (core.isDebug() && page_index === 0) {
// url is identical except page_index so print it once for debug
core.debug(`Gathering available versions from '${availableVersionsUrl}'`);
Expand Down
Loading