mirror of
				https://github.com/actions/setup-java.git
				synced 2025-10-31 14:30:53 +00:00 
			
		
		
		
	Add functionality to setup maven binary
Add functionality to setup maven in order to use for project building
This commit is contained in:
		
					parent
					
						
							
								104660f1cc
							
						
					
				
			
			
				commit
				
					
						6fa8ff8bf6
					
				
			
		
					 12 changed files with 222 additions and 127 deletions
				
			
		
							
								
								
									
										3
									
								
								dist/cleanup/index.js
									
										
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								dist/cleanup/index.js
									
										
									
										generated
									
									
										vendored
									
									
								
							|  | @ -1029,7 +1029,7 @@ module.exports = require("child_process"); | |||
| "use strict"; | ||||
| 
 | ||||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||||
| exports.STATE_GPG_PRIVATE_KEY_FINGERPRINT = exports.INPUT_DEFAULT_GPG_PASSPHRASE = exports.INPUT_DEFAULT_GPG_PRIVATE_KEY = exports.INPUT_MAVEN_SECURITY_SETTINGS_B64 = exports.INPUT_MAVEN_SETTINGS_B64 = exports.INPUT_MAVEN_KEYSTORE_PASSWORD = exports.INPUT_MAVEN_KEYSTORE_P12_B64 = exports.INPUT_MAVEN_CA_CERT_B64 = exports.INPUT_GPG_PASSPHRASE = exports.INPUT_GPG_PRIVATE_KEY = exports.INPUT_SETTINGS_PATH = exports.INPUT_SERVER_PASSWORD = exports.INPUT_SERVER_USERNAME = exports.INPUT_SERVER_ID = exports.INPUT_JDK_FILE = exports.INPUT_JAVA_PACKAGE = exports.INPUT_ARCHITECTURE = exports.INPUT_JAVA_VERSION = exports.INPUT_VERSION = void 0; | ||||
| exports.STATE_GPG_PRIVATE_KEY_FINGERPRINT = exports.INPUT_DEFAULT_GPG_PASSPHRASE = exports.INPUT_DEFAULT_GPG_PRIVATE_KEY = exports.INPUT_MAVEN_VERSION = exports.INPUT_MAVEN_SECURITY_SETTINGS_B64 = exports.INPUT_MAVEN_SETTINGS_B64 = exports.INPUT_MAVEN_KEYSTORE_PASSWORD = exports.INPUT_MAVEN_KEYSTORE_P12_B64 = exports.INPUT_MAVEN_CA_CERT_B64 = exports.INPUT_GPG_PASSPHRASE = exports.INPUT_GPG_PRIVATE_KEY = exports.INPUT_SETTINGS_PATH = exports.INPUT_SERVER_PASSWORD = exports.INPUT_SERVER_USERNAME = exports.INPUT_SERVER_ID = exports.INPUT_JDK_FILE = exports.INPUT_JAVA_PACKAGE = exports.INPUT_ARCHITECTURE = exports.INPUT_JAVA_VERSION = exports.INPUT_VERSION = void 0; | ||||
| exports.INPUT_VERSION = 'version'; | ||||
| exports.INPUT_JAVA_VERSION = 'java-version'; | ||||
| exports.INPUT_ARCHITECTURE = 'architecture'; | ||||
|  | @ -1046,6 +1046,7 @@ exports.INPUT_MAVEN_KEYSTORE_P12_B64 = 'maven-keystore-p12-b64'; | |||
| exports.INPUT_MAVEN_KEYSTORE_PASSWORD = 'maven-keystore-password'; | ||||
| exports.INPUT_MAVEN_SETTINGS_B64 = 'maven-settings-b64'; | ||||
| exports.INPUT_MAVEN_SECURITY_SETTINGS_B64 = 'maven-security-settings-b64'; | ||||
| exports.INPUT_MAVEN_VERSION = 'maven-version'; | ||||
| exports.INPUT_DEFAULT_GPG_PRIVATE_KEY = undefined; | ||||
| exports.INPUT_DEFAULT_GPG_PASSPHRASE = 'GPG_PASSPHRASE'; | ||||
| exports.STATE_GPG_PRIVATE_KEY_FINGERPRINT = 'gpg-private-key-fingerprint'; | ||||
|  |  | |||
							
								
								
									
										108
									
								
								dist/setup/index.js
									
										
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										108
									
								
								dist/setup/index.js
									
										
									
										generated
									
									
										vendored
									
									
								
							|  | @ -11056,29 +11056,25 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge | |||
|     }); | ||||
| }; | ||||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||||
| exports.setupMaven = exports.validateOptions = void 0; | ||||
| exports.setupMaven = exports.isValidOptions = void 0; | ||||
| const core = __importStar(__webpack_require__(470)); | ||||
| const fs = __importStar(__webpack_require__(747)); | ||||
| const path = __importStar(__webpack_require__(622)); | ||||
| const constants = __importStar(__webpack_require__(694)); | ||||
| const os = __importStar(__webpack_require__(87)); | ||||
| const exec = __importStar(__webpack_require__(986)); | ||||
| const io = __importStar(__webpack_require__(1)); | ||||
| function validateOptions(opts) { | ||||
|     if ((opts.caCert === '' || | ||||
|         opts.keystore === '' || | ||||
|         opts.password === '' || | ||||
|         opts.securitySettings === '', | ||||
|         opts.settings === '')) { | ||||
|         core.debug('maven options set is not valid: some field is empty'); | ||||
|         return false; | ||||
|     } | ||||
|     return true; | ||||
| function isValidOptions(mvnOpts) { | ||||
|     return (mvnOpts.caCert !== '' && | ||||
|         mvnOpts.keystore !== '' && | ||||
|         mvnOpts.password !== '' && | ||||
|         mvnOpts.securitySettings !== '' && | ||||
|         mvnOpts.settings !== ''); | ||||
| } | ||||
| exports.validateOptions = validateOptions; | ||||
| exports.isValidOptions = isValidOptions; | ||||
| function setupMaven(opts) { | ||||
|     return __awaiter(this, void 0, void 0, function* () { | ||||
|         const settingsDir = path.join(core.getInput(constants.INPUT_SETTINGS_PATH) || os.homedir(), core.getInput(constants.INPUT_SETTINGS_PATH) ? '' : '.m2'); | ||||
|         const certDir = path.join(os.homedir(), 'certs'); | ||||
|         fs.writeFileSync(path.join(settingsDir, 'settings.xml'), btoa(opts.settings), { | ||||
|             encoding: 'utf-8', | ||||
|             flag: 'w' | ||||
|  | @ -11087,26 +11083,35 @@ function setupMaven(opts) { | |||
|             encoding: 'utf-8', | ||||
|             flag: 'w' | ||||
|         }); | ||||
|         const certDir = path.join(os.homedir(), 'certs'); | ||||
|         const rooCaPath = path.join(certDir, 'rootca.crt'); | ||||
|         yield io.mkdirP(certDir); | ||||
|         fs.writeFileSync(path.join(certDir, 'rootca.crt'), btoa(opts.caCert), { | ||||
|         fs.writeFileSync(rooCaPath, btoa(opts.caCert), { | ||||
|             encoding: 'utf-8', | ||||
|             flag: 'w' | ||||
|         }); | ||||
|         const p12Path = path.join(certDir, 'certificate.p12'); | ||||
|         fs.writeFileSync(p12Path, btoa(opts.keystore), { | ||||
|             encoding: 'utf-8', | ||||
|             flag: 'w' | ||||
|         }); | ||||
|         const password = btoa(opts.password); | ||||
|         core.exportVariable('MAVEN_OPTS', `-Djavax.net.ssl.keyStore=${p12Path} -Djavax.net.ssl.keyStoreType=pkcs12 -Djavax.net.ssl.keyStorePassword=${password}`); | ||||
|         fs.writeFileSync(p12Path, Buffer.from(opts.keystore, 'base64')); | ||||
|         core.exportVariable('MAVEN_OPTS', `-Djavax.net.ssl.keyStore=${p12Path} -Djavax.net.ssl.keyStoreType=pkcs12 -Djavax.net.ssl.keyStorePassword=${opts.password}`); | ||||
|         yield exec.exec(path.join(opts.javaPath, 'bin/keytool'), [ | ||||
|             '-importcert', | ||||
|             '-cacerts', | ||||
|             '-storepass', | ||||
|             'changeit', | ||||
|             '-noprompt', | ||||
|             '-alias', | ||||
|             'mycert', | ||||
|             '-file', | ||||
|             rooCaPath | ||||
|         ]); | ||||
|         core.debug(`added maven opts for MTLS access`); | ||||
|     }); | ||||
| } | ||||
| exports.setupMaven = setupMaven; | ||||
| const btoa = function (str) { | ||||
| const atob = function (str) { | ||||
|     return Buffer.from(str, 'binary').toString('base64'); | ||||
| }; | ||||
| const atob = function (str) { | ||||
| const btoa = function (str) { | ||||
|     return Buffer.from(str, 'base64').toString('binary'); | ||||
| }; | ||||
| 
 | ||||
|  | @ -30166,7 +30171,7 @@ exports.StaticRangeImpl = StaticRangeImpl; | |||
| "use strict"; | ||||
| 
 | ||||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||||
| exports.STATE_GPG_PRIVATE_KEY_FINGERPRINT = exports.INPUT_DEFAULT_GPG_PASSPHRASE = exports.INPUT_DEFAULT_GPG_PRIVATE_KEY = exports.INPUT_MAVEN_SECURITY_SETTINGS_B64 = exports.INPUT_MAVEN_SETTINGS_B64 = exports.INPUT_MAVEN_KEYSTORE_PASSWORD = exports.INPUT_MAVEN_KEYSTORE_P12_B64 = exports.INPUT_MAVEN_CA_CERT_B64 = exports.INPUT_GPG_PASSPHRASE = exports.INPUT_GPG_PRIVATE_KEY = exports.INPUT_SETTINGS_PATH = exports.INPUT_SERVER_PASSWORD = exports.INPUT_SERVER_USERNAME = exports.INPUT_SERVER_ID = exports.INPUT_JDK_FILE = exports.INPUT_JAVA_PACKAGE = exports.INPUT_ARCHITECTURE = exports.INPUT_JAVA_VERSION = exports.INPUT_VERSION = void 0; | ||||
| exports.STATE_GPG_PRIVATE_KEY_FINGERPRINT = exports.INPUT_DEFAULT_GPG_PASSPHRASE = exports.INPUT_DEFAULT_GPG_PRIVATE_KEY = exports.INPUT_MAVEN_VERSION = exports.INPUT_MAVEN_SECURITY_SETTINGS_B64 = exports.INPUT_MAVEN_SETTINGS_B64 = exports.INPUT_MAVEN_KEYSTORE_PASSWORD = exports.INPUT_MAVEN_KEYSTORE_P12_B64 = exports.INPUT_MAVEN_CA_CERT_B64 = exports.INPUT_GPG_PASSPHRASE = exports.INPUT_GPG_PRIVATE_KEY = exports.INPUT_SETTINGS_PATH = exports.INPUT_SERVER_PASSWORD = exports.INPUT_SERVER_USERNAME = exports.INPUT_SERVER_ID = exports.INPUT_JDK_FILE = exports.INPUT_JAVA_PACKAGE = exports.INPUT_ARCHITECTURE = exports.INPUT_JAVA_VERSION = exports.INPUT_VERSION = void 0; | ||||
| exports.INPUT_VERSION = 'version'; | ||||
| exports.INPUT_JAVA_VERSION = 'java-version'; | ||||
| exports.INPUT_ARCHITECTURE = 'architecture'; | ||||
|  | @ -30183,6 +30188,7 @@ exports.INPUT_MAVEN_KEYSTORE_P12_B64 = 'maven-keystore-p12-b64'; | |||
| exports.INPUT_MAVEN_KEYSTORE_PASSWORD = 'maven-keystore-password'; | ||||
| exports.INPUT_MAVEN_SETTINGS_B64 = 'maven-settings-b64'; | ||||
| exports.INPUT_MAVEN_SECURITY_SETTINGS_B64 = 'maven-security-settings-b64'; | ||||
| exports.INPUT_MAVEN_VERSION = 'maven-version'; | ||||
| exports.INPUT_DEFAULT_GPG_PRIVATE_KEY = undefined; | ||||
| exports.INPUT_DEFAULT_GPG_PASSPHRASE = 'GPG_PASSPHRASE'; | ||||
| exports.STATE_GPG_PRIVATE_KEY_FINGERPRINT = 'gpg-private-key-fingerprint'; | ||||
|  | @ -33356,21 +33362,15 @@ function run() { | |||
|             if (!version) { | ||||
|                 version = core.getInput(constants.INPUT_JAVA_VERSION, { required: true }); | ||||
|             } | ||||
|             const mvnOpts = { | ||||
|             let mvnOpts = { | ||||
|                 caCert: core.getInput(constants.INPUT_MAVEN_CA_CERT_B64), | ||||
|                 keystore: core.getInput(constants.INPUT_MAVEN_KEYSTORE_P12_B64), | ||||
|                 password: core.getInput(constants.INPUT_MAVEN_KEYSTORE_PASSWORD), | ||||
|                 settings: core.getInput(constants.INPUT_MAVEN_SETTINGS_B64), | ||||
|                 securitySettings: core.getInput(constants.INPUT_MAVEN_SECURITY_SETTINGS_B64) | ||||
|                 securitySettings: core.getInput(constants.INPUT_MAVEN_SECURITY_SETTINGS_B64), | ||||
|                 javaPath: '' | ||||
|             }; | ||||
|             if ((mvnOpts.caCert !== '' || | ||||
|                 mvnOpts.keystore !== '' || | ||||
|                 mvnOpts.password !== '' || | ||||
|                 mvnOpts.securitySettings !== '', | ||||
|                 mvnOpts.settings !== '') && | ||||
|                 !maven_1.validateOptions(mvnOpts)) { | ||||
|                 throw new Error('Some of the Maven options is empty: please check maven-* parameters'); | ||||
|             } | ||||
|             const mvnVersion = core.getInput(constants.INPUT_MAVEN_VERSION); | ||||
|             const arch = core.getInput(constants.INPUT_ARCHITECTURE, { required: true }); | ||||
|             if (!['x86', 'x64'].includes(arch)) { | ||||
|                 throw new Error(`architecture "${arch}" is not in [x86 | x64]`); | ||||
|  | @ -33379,7 +33379,17 @@ function run() { | |||
|                 required: true | ||||
|             }); | ||||
|             const jdkFile = core.getInput(constants.INPUT_JDK_FILE, { required: false }); | ||||
|             yield installer.getJava(version, arch, jdkFile, javaPackage); | ||||
|             const javaPath = yield installer.getJava(version, arch, jdkFile, javaPackage); | ||||
|             if (mvnVersion !== '') { | ||||
|                 if (!maven_1.isValidOptions(mvnOpts)) { | ||||
|                     throw new Error('Some of the Maven options is empty: please check maven-* parameters'); | ||||
|                 } | ||||
|                 mvnOpts.javaPath = javaPath; | ||||
|                 yield installer.getMaven(mvnVersion); | ||||
|             } | ||||
|             else { | ||||
|                 mvnOpts = undefined; | ||||
|             } | ||||
|             const matchersPath = path.join(__dirname, '..', '..', '.github'); | ||||
|             core.info(`##[add-matcher]${path.join(matchersPath, 'java.json')}`); | ||||
|             const id = core.getInput(constants.INPUT_SERVER_ID, { required: false }); | ||||
|  | @ -38708,7 +38718,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge | |||
|     }); | ||||
| }; | ||||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||||
| exports.getJava = void 0; | ||||
| exports.getJava = exports.getMaven = void 0; | ||||
| const core = __importStar(__webpack_require__(470)); | ||||
| const io = __importStar(__webpack_require__(1)); | ||||
| const exec = __importStar(__webpack_require__(986)); | ||||
|  | @ -38720,6 +38730,33 @@ const semver = __importStar(__webpack_require__(280)); | |||
| const util = __importStar(__webpack_require__(322)); | ||||
| const tempDirectory = util.getTempDir(); | ||||
| const IS_WINDOWS = util.isWindows(); | ||||
| function getMaven(version) { | ||||
|     return __awaiter(this, void 0, void 0, function* () { | ||||
|         if (semver.valid(version) === null) { | ||||
|             throw new Error(`wrong version is set(${version}): supported version template: major.minor.patch`); | ||||
|         } | ||||
|         const majorVersion = semver.major(version); | ||||
|         let toolPath = tc.find('mvn', version); | ||||
|         if (toolPath) { | ||||
|             core.debug(`Tool found in cache ${toolPath}`); | ||||
|         } | ||||
|         else { | ||||
|             core.debug(`Downloading Maven from https://downloads.apache.org/maven/maven-${majorVersion}`); | ||||
|             const url = path.join(`https:///downloads.apache.org/maven/maven-${majorVersion}`, version, `binaries/apache-maven-${version}-bin.tar.gz`); | ||||
|             console.log(url); | ||||
|             const mvnTarFile = yield tc.downloadTool(url); | ||||
|             let tempDir = path.join(tempDirectory, 'temp_' + Math.floor(Math.random() * 2000000000)); | ||||
|             yield extractFiles(mvnTarFile, '.tar.gz', tempDir); | ||||
|             core.debug(`maven extracted to ${tempDir}`); | ||||
|             toolPath = yield tc.cacheDir(path.join(tempDir, `apache-maven-${version}`), 'mvn', version, 'x64'); | ||||
|         } | ||||
|         core.exportVariable('MAVEN_HOME', toolPath); | ||||
|         core.addPath(path.join(toolPath, 'bin')); | ||||
|         core.setOutput('path', toolPath); | ||||
|         core.setOutput('version', version); | ||||
|     }); | ||||
| } | ||||
| exports.getMaven = getMaven; | ||||
| function getJava(version, arch, jdkFile, javaPackage) { | ||||
|     return __awaiter(this, void 0, void 0, function* () { | ||||
|         let toolPath = tc.find(javaPackage, version); | ||||
|  | @ -38776,6 +38813,7 @@ function getJava(version, arch, jdkFile, javaPackage) { | |||
|         core.addPath(path.join(toolPath, 'bin')); | ||||
|         core.setOutput('path', toolPath); | ||||
|         core.setOutput('version', version); | ||||
|         return toolPath; | ||||
|     }); | ||||
| } | ||||
| exports.getJava = getJava; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue