From 906dd890a5cf0fed404a01b12f05f061d0aeee77 Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Tue, 17 Feb 2026 15:36:49 +0000 Subject: [PATCH] Run `java` to show computed settings --- lib/start-proxy-action.js | 91 +++++++++++++++++++---------- src/start-proxy-action.ts | 2 +- src/start-proxy/environment.test.ts | 30 ++++++++-- src/start-proxy/environment.ts | 39 ++++++++++++- 4 files changed, 122 insertions(+), 40 deletions(-) diff --git a/lib/start-proxy-action.js b/lib/start-proxy-action.js index 1391f06a6..9801eba1b 100644 --- a/lib/start-proxy-action.js +++ b/lib/start-proxy-action.js @@ -20316,7 +20316,7 @@ var require_io = __commonJS({ exports2.mv = mv; exports2.rmRF = rmRF; exports2.mkdirP = mkdirP; - exports2.which = which4; + exports2.which = which5; exports2.findInPath = findInPath; var assert_1 = require("assert"); var path5 = __importStar2(require("path")); @@ -20392,13 +20392,13 @@ var require_io = __commonJS({ yield ioUtil.mkdir(fsPath, { recursive: true }); }); } - function which4(tool, check) { + function which5(tool, check) { return __awaiter2(this, void 0, void 0, function* () { if (!tool) { throw new Error("parameter 'tool' is required"); } if (check) { - const result = yield which4(tool, false); + const result = yield which5(tool, false); if (!result) { if (ioUtil.IS_WINDOWS) { throw new Error(`Unable to locate executable file: ${tool}. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also verify the file has a valid extension for an executable file.`); @@ -20579,11 +20579,11 @@ var require_toolrunner = __commonJS({ var events = __importStar2(require("events")); var child = __importStar2(require("child_process")); var path5 = __importStar2(require("path")); - var io4 = __importStar2(require_io()); + var io5 = __importStar2(require_io()); var ioUtil = __importStar2(require_io_util()); var timers_1 = require("timers"); var IS_WINDOWS = process.platform === "win32"; - var ToolRunner3 = class extends events.EventEmitter { + var ToolRunner4 = class extends events.EventEmitter { constructor(toolPath, args, options) { super(); if (!toolPath) { @@ -20795,7 +20795,7 @@ var require_toolrunner = __commonJS({ if (!ioUtil.isRooted(this.toolPath) && (this.toolPath.includes("/") || IS_WINDOWS && this.toolPath.includes("\\"))) { this.toolPath = path5.resolve(process.cwd(), this.options.cwd || process.cwd(), this.toolPath); } - this.toolPath = yield io4.which(this.toolPath, true); + this.toolPath = yield io5.which(this.toolPath, true); return new Promise((resolve2, reject) => __awaiter2(this, void 0, void 0, function* () { this._debug(`exec tool: ${this.toolPath}`); this._debug("arguments:"); @@ -20892,7 +20892,7 @@ var require_toolrunner = __commonJS({ }); } }; - exports2.ToolRunner = ToolRunner3; + exports2.ToolRunner = ToolRunner4; function argStringToArray(argString) { const args = []; let inQuotes = false; @@ -50659,7 +50659,7 @@ var require_cacheUtils = __commonJS({ var core12 = __importStar2(require_core()); var exec3 = __importStar2(require_exec()); var glob = __importStar2(require_glob()); - var io4 = __importStar2(require_io()); + var io5 = __importStar2(require_io()); var crypto2 = __importStar2(require("crypto")); var fs3 = __importStar2(require("fs")); var path5 = __importStar2(require("path")); @@ -50685,7 +50685,7 @@ var require_cacheUtils = __commonJS({ tempDirectory = path5.join(baseLocation, "actions", "temp"); } const dest = path5.join(tempDirectory, crypto2.randomUUID()); - yield io4.mkdirP(dest); + yield io5.mkdirP(dest); return dest; }); } @@ -50774,7 +50774,7 @@ var require_cacheUtils = __commonJS({ return constants_1.GnuTarPathOnWindows; } const versionOutput = yield getVersion("tar"); - return versionOutput.toLowerCase().includes("gnu tar") ? io4.which("tar") : ""; + return versionOutput.toLowerCase().includes("gnu tar") ? io5.which("tar") : ""; }); } function assertDefined(name, value) { @@ -96906,7 +96906,7 @@ var require_tar = __commonJS({ exports2.extractTar = extractTar2; exports2.createTar = createTar; var exec_1 = require_exec(); - var io4 = __importStar2(require_io()); + var io5 = __importStar2(require_io()); var fs_1 = require("fs"); var path5 = __importStar2(require("path")); var utils = __importStar2(require_cacheUtils()); @@ -96926,12 +96926,12 @@ var require_tar = __commonJS({ break; } case "darwin": { - const gnuTar = yield io4.which("gtar", false); + const gnuTar = yield io5.which("gtar", false); if (gnuTar) { return { path: gnuTar, type: constants_1.ArchiveToolType.GNU }; } else { return { - path: yield io4.which("tar", true), + path: yield io5.which("tar", true), type: constants_1.ArchiveToolType.BSD }; } @@ -96940,7 +96940,7 @@ var require_tar = __commonJS({ break; } return { - path: yield io4.which("tar", true), + path: yield io5.which("tar", true), type: constants_1.ArchiveToolType.GNU }; }); @@ -97070,7 +97070,7 @@ var require_tar = __commonJS({ function extractTar2(archivePath, compressionMethod) { return __awaiter2(this, void 0, void 0, function* () { const workingDirectory = getWorkingDirectory(); - yield io4.mkdirP(workingDirectory); + yield io5.mkdirP(workingDirectory); const commands = yield getCommands(compressionMethod, "extract", archivePath); yield execCommands(commands); }); @@ -97871,7 +97871,7 @@ var require_tool_cache = __commonJS({ exports2.isExplicitVersion = isExplicitVersion; exports2.evaluateVersions = evaluateVersions; var core12 = __importStar2(require_core()); - var io4 = __importStar2(require_io()); + var io5 = __importStar2(require_io()); var crypto2 = __importStar2(require("crypto")); var fs3 = __importStar2(require("fs")); var mm = __importStar2(require_manifest()); @@ -97898,7 +97898,7 @@ var require_tool_cache = __commonJS({ function downloadTool2(url, dest, auth2, headers) { return __awaiter2(this, void 0, void 0, function* () { dest = dest || path5.join(_getTempDirectory(), crypto2.randomUUID()); - yield io4.mkdirP(path5.dirname(dest)); + yield io5.mkdirP(path5.dirname(dest)); core12.debug(`Downloading ${url}`); core12.debug(`Destination ${dest}`); const maxAttempts = 3; @@ -97951,7 +97951,7 @@ var require_tool_cache = __commonJS({ if (!succeeded) { core12.debug("download failed"); try { - yield io4.rmRF(dest); + yield io5.rmRF(dest); } catch (err) { core12.debug(`Failed to delete '${dest}'. ${err.message}`); } @@ -98006,7 +98006,7 @@ var require_tool_cache = __commonJS({ silent: true }; try { - const powershellPath = yield io4.which("powershell", true); + const powershellPath = yield io5.which("powershell", true); yield (0, exec_1.exec)(`"${powershellPath}"`, args, options); } finally { process.chdir(originalCwd); @@ -98073,7 +98073,7 @@ var require_tool_cache = __commonJS({ if (core12.isDebug()) { args.push("-v"); } - const xarPath = yield io4.which("xar", true); + const xarPath = yield io5.which("xar", true); yield (0, exec_1.exec)(`"${xarPath}"`, _unique(args)); return dest; }); @@ -98096,7 +98096,7 @@ var require_tool_cache = __commonJS({ return __awaiter2(this, void 0, void 0, function* () { const escapedFile = file.replace(/'/g, "''").replace(/"|\n|\r/g, ""); const escapedDest = dest.replace(/'/g, "''").replace(/"|\n|\r/g, ""); - const pwshPath = yield io4.which("pwsh", false); + const pwshPath = yield io5.which("pwsh", false); if (pwshPath) { const pwshCommand = [ `$ErrorActionPreference = 'Stop' ;`, @@ -98132,7 +98132,7 @@ var require_tool_cache = __commonJS({ "-Command", powershellCommand ]; - const powershellPath = yield io4.which("powershell", true); + const powershellPath = yield io5.which("powershell", true); core12.debug(`Using powershell at path: ${powershellPath}`); yield (0, exec_1.exec)(`"${powershellPath}"`, args); } @@ -98140,7 +98140,7 @@ var require_tool_cache = __commonJS({ } function extractZipNix(file, dest) { return __awaiter2(this, void 0, void 0, function* () { - const unzipPath = yield io4.which("unzip", true); + const unzipPath = yield io5.which("unzip", true); const args = [file]; if (!core12.isDebug()) { args.unshift("-q"); @@ -98161,7 +98161,7 @@ var require_tool_cache = __commonJS({ const destPath = yield _createToolPath(tool, version, arch); for (const itemName of fs3.readdirSync(sourceDir)) { const s = path5.join(sourceDir, itemName); - yield io4.cp(s, destPath, { recursive: true }); + yield io5.cp(s, destPath, { recursive: true }); } _completeToolPath(tool, version, arch); return destPath; @@ -98179,7 +98179,7 @@ var require_tool_cache = __commonJS({ const destFolder = yield _createToolPath(tool, version, arch); const destPath = path5.join(destFolder, targetFile); core12.debug(`destination file ${destPath}`); - yield io4.cp(sourceFile, destPath); + yield io5.cp(sourceFile, destPath); _completeToolPath(tool, version, arch); return destFolder; }); @@ -98273,7 +98273,7 @@ var require_tool_cache = __commonJS({ if (!dest) { dest = path5.join(_getTempDirectory(), crypto2.randomUUID()); } - yield io4.mkdirP(dest); + yield io5.mkdirP(dest); return dest; }); } @@ -98282,9 +98282,9 @@ var require_tool_cache = __commonJS({ const folderPath = path5.join(_getCacheDirectory(), tool, semver6.clean(version) || version, arch || ""); core12.debug(`destination ${folderPath}`); const markerPath = `${folderPath}.complete`; - yield io4.rmRF(folderPath); - yield io4.rmRF(markerPath); - yield io4.mkdirP(folderPath); + yield io5.rmRF(folderPath); + yield io5.rmRF(markerPath); + yield io5.mkdirP(folderPath); return folderPath; }); } @@ -121815,6 +121815,8 @@ function generateCertificateAuthority(newCertGenFF) { // src/start-proxy/environment.ts var fs2 = __toESM(require("fs")); var path3 = __toESM(require("path")); +var toolrunner3 = __toESM(require_toolrunner()); +var io4 = __toESM(require_io()); function checkEnvVar(logger, name) { const value = process.env[name]; if (isDefined2(value)) { @@ -121902,6 +121904,32 @@ function checkJdkSettings(logger, jdkHome) { } } } +async function showJavaSettings(logger) { + try { + const java = await io4.which("java", true); + let output = ""; + await new toolrunner3.ToolRunner( + java, + ["-XshowSettings:all", "-XshowSettings:security:all", "-version"], + { + silent: true, + listeners: { + stdout: (data) => { + output += String(data); + }, + stderr: (data) => { + output += String(data); + } + } + } + ).exec(); + logger.startGroup("Java settings"); + logger.info(output); + logger.endGroup(); + } catch (err) { + logger.debug(`Failed to query java settings: ${getErrorMessage(err)}`); + } +} var ProxyEnvVars = /* @__PURE__ */ ((ProxyEnvVars2) => { ProxyEnvVars2["HTTP_PROXY"] = "HTTP_PROXY"; ProxyEnvVars2["HTTPS_PROXY"] = "HTTPS_PROXY"; @@ -121914,10 +121942,11 @@ function checkProxyEnvVars(logger) { checkEnvVar(logger, envVar.toLowerCase()); } } -function checkProxyEnvironment(logger, language) { +async function checkProxyEnvironment(logger, language) { checkProxyEnvVars(logger); if (language === void 0 || language === "java" /* java */) { checkJavaEnvVars(logger); + await showJavaSettings(logger); const jdks = discoverActionsJdks(); for (const jdk of jdks) { checkJdkSettings(logger, jdk); @@ -122047,7 +122076,7 @@ async function run(startedAt) { ); if (core11.isDebug() || isInTestMode()) { try { - checkProxyEnvironment(logger, language); + await checkProxyEnvironment(logger, language); } catch (err) { logger.debug( `Unable to inspect runner environment: ${getErrorMessage(err)}` diff --git a/src/start-proxy-action.ts b/src/start-proxy-action.ts index 806b9ef0b..3ee44a409 100644 --- a/src/start-proxy-action.ts +++ b/src/start-proxy-action.ts @@ -82,7 +82,7 @@ async function run(startedAt: Date) { // which may affect the operation of our proxy. if (core.isDebug() || util.isInTestMode()) { try { - checkProxyEnvironment(logger, language); + await checkProxyEnvironment(logger, language); } catch (err) { logger.debug( `Unable to inspect runner environment: ${util.getErrorMessage(err)}`, diff --git a/src/start-proxy/environment.test.ts b/src/start-proxy/environment.test.ts index 80a046a2e..8dcb4c7b2 100644 --- a/src/start-proxy/environment.test.ts +++ b/src/start-proxy/environment.test.ts @@ -2,7 +2,10 @@ import * as fs from "fs"; import * as os from "os"; import path from "path"; +import * as toolrunner from "@actions/exec/lib/toolrunner"; +import * as io from "@actions/io"; import test, { ExecutionContext } from "ava"; +import sinon from "sinon"; import { JavaEnvVars, KnownLanguage } from "../languages"; import { @@ -25,6 +28,15 @@ import { setupTests(test); +function stubToolrunner() { + sinon.stub(io, "which").throws(new Error("Java not installed")); + sinon.stub(toolrunner, "ToolRunner").returns({ + exec: async () => { + return 0; + }, + }); +} + function assertEnvVarLogMessages( t: ExecutionContext, envVars: string[], @@ -166,30 +178,36 @@ test("checkProxyEnvVars - credentials are removed from URLs", (t) => { ); }); -test("checkProxyEnvironment - includes base checks for all known languages", (t) => { +test("checkProxyEnvironment - includes base checks for all known languages", async (t) => { + stubToolrunner(); + for (const language of Object.values(KnownLanguage)) { const messages: LoggedMessage[] = []; const logger = getRecordingLogger(messages); - checkProxyEnvironment(logger, language); + await checkProxyEnvironment(logger, language); assertEnvVarLogMessages(t, Object.keys(ProxyEnvVars), messages, false); } }); -test("checkProxyEnvironment - includes Java checks for Java", (t) => { +test("checkProxyEnvironment - includes Java checks for Java", async (t) => { const messages: LoggedMessage[] = []; const logger = getRecordingLogger(messages); - checkProxyEnvironment(logger, KnownLanguage.java); + stubToolrunner(); + + await checkProxyEnvironment(logger, KnownLanguage.java); assertEnvVarLogMessages(t, Object.keys(ProxyEnvVars), messages, false); assertEnvVarLogMessages(t, JAVA_PROXY_ENV_VARS, messages, false); }); -test("checkProxyEnvironment - includes language-specific checks if the language is undefined", (t) => { +test("checkProxyEnvironment - includes language-specific checks if the language is undefined", async (t) => { const messages: LoggedMessage[] = []; const logger = getRecordingLogger(messages); - checkProxyEnvironment(logger, undefined); + stubToolrunner(); + + await checkProxyEnvironment(logger, undefined); assertEnvVarLogMessages(t, Object.keys(ProxyEnvVars), messages, false); assertEnvVarLogMessages(t, JAVA_PROXY_ENV_VARS, messages, false); }); diff --git a/src/start-proxy/environment.ts b/src/start-proxy/environment.ts index ba1f0b77b..13eb12190 100644 --- a/src/start-proxy/environment.ts +++ b/src/start-proxy/environment.ts @@ -1,6 +1,9 @@ import * as fs from "fs"; import * as path from "path"; +import * as toolrunner from "@actions/exec/lib/toolrunner"; +import * as io from "@actions/io"; + import { JavaEnvVars, KnownLanguage, Language } from "../languages"; import { Logger } from "../logging"; import { getErrorMessage, isDefined } from "../util"; @@ -128,6 +131,36 @@ export function checkJdkSettings(logger: Logger, jdkHome: string) { } } +/** Invokes `java` to get it to show us the active configuration. */ +async function showJavaSettings(logger: Logger): Promise { + try { + const java = await io.which("java", true); + + let output = ""; + await new toolrunner.ToolRunner( + java, + ["-XshowSettings:all", "-XshowSettings:security:all", "-version"], + { + silent: true, + listeners: { + stdout: (data) => { + output += String(data); + }, + stderr: (data) => { + output += String(data); + }, + }, + }, + ).exec(); + + logger.startGroup("Java settings"); + logger.info(output); + logger.endGroup(); + } catch (err) { + logger.debug(`Failed to query java settings: ${getErrorMessage(err)}`); + } +} + /** Enumerates environment variable names which may contain information about proxy settings. */ export enum ProxyEnvVars { HTTP_PROXY = "HTTP_PROXY", @@ -154,10 +187,10 @@ export function checkProxyEnvVars(logger: Logger) { * @param logger The logger to use. * @param language The enabled language, if known. */ -export function checkProxyEnvironment( +export async function checkProxyEnvironment( logger: Logger, language: Language | undefined, -) { +): Promise { // Determine whether there is an existing proxy configured. checkProxyEnvVars(logger); @@ -166,6 +199,8 @@ export function checkProxyEnvironment( if (language === undefined || language === KnownLanguage.java) { checkJavaEnvVars(logger); + await showJavaSettings(logger); + const jdks = discoverActionsJdks(); for (const jdk of jdks) { checkJdkSettings(logger, jdk);