mirror of
https://github.com/stCarolas/setup-maven.git
synced 2026-03-22 19:56:58 +00:00
61 lines
1.7 KiB
TypeScript
61 lines
1.7 KiB
TypeScript
// Load tempDirectory before it gets wiped by tool-cache
|
|
let tempDirectory = process.env['RUNNER_TEMPDIRECTORY'] || '';
|
|
|
|
import * as core from '@actions/core';
|
|
import * as tc from '@actions/tool-cache';
|
|
import * as path from 'path';
|
|
|
|
if (!tempDirectory) {
|
|
let baseLocation: string;
|
|
if (process.platform === 'win32') {
|
|
baseLocation = process.env['USERPROFILE'] || 'C:\\';
|
|
} else {
|
|
if (process.platform === 'darwin') {
|
|
baseLocation = '/Users';
|
|
} else {
|
|
baseLocation = '/home';
|
|
}
|
|
}
|
|
tempDirectory = path.join(baseLocation, 'actions', 'temp');
|
|
}
|
|
|
|
export async function getMaven(version: string, url: string) {
|
|
let toolPath: string;
|
|
toolPath = tc.find('maven', version);
|
|
|
|
if (!toolPath) {
|
|
toolPath = await downloadMaven(version, url);
|
|
}
|
|
|
|
toolPath = path.join(toolPath, 'bin');
|
|
core.addPath(toolPath);
|
|
}
|
|
|
|
function get_server_url(url: string) {
|
|
if (url && url.indexOf("http") == 0) {
|
|
return url;
|
|
}
|
|
switch (url) {
|
|
case "aliyun":
|
|
return "https://maven.aliyun.com/repository/public";
|
|
default:
|
|
break;
|
|
}
|
|
return "https://repo.maven.apache.org/maven2";
|
|
}
|
|
|
|
async function downloadMaven(version: string, url: string): Promise<string> {
|
|
const toolDirectoryName = `apache-maven-${version}`;
|
|
const downloadUrl = `${get_server_url(url)}/maven2/org/apache/maven/apache-maven/${version}/apache-maven-${version}-bin.tar.gz`;
|
|
console.log(`downloading ${downloadUrl}`);
|
|
|
|
try {
|
|
const downloadPath = await tc.downloadTool(downloadUrl);
|
|
const extractedPath = await tc.extractTar(downloadPath);
|
|
let toolRoot = path.join(extractedPath, toolDirectoryName);
|
|
return await tc.cacheDir(toolRoot, 'maven', version);
|
|
} catch (err) {
|
|
throw err;
|
|
}
|
|
}
|