in powershell-agent/src/main/java/jetbrains/buildServer/powershell/agent/detect/cmd/CommandLinePowerShellDetector.java [148:189]
private PowerShellInfo doDetect(@NotNull final String homePath,
@NotNull final String executable,
@NotNull final String scriptPath,
@NotNull final List<String> additionalParameters) {
PowerShellInfo result = null;
final File exeFile = new File(homePath, executable);
if (LOG.isDebugEnabled()) {
LOG.debug("Searching for PowerShell at " + exeFile.getAbsolutePath());
}
if (exeFile.isFile()) {
if (LOG.isDebugEnabled()) {
LOG.debug("Trying PowerShell executable: " + exeFile.getAbsolutePath());
}
String executablePath = exeFile.getAbsolutePath();
try {
final List<String> outputLines = myRunner.runDetectionScript(executablePath, scriptPath, additionalParameters);
if (LOG.isDebugEnabled()) {
LOG.debug("Detection script output at " + executablePath + "\n" + StringUtil.join(outputLines, "\n"));
}
if (outputLines.size() == 3) {
final PowerShellEdition edition = PowerShellEdition.fromString(outputLines.get(1));
if (edition != null) {
result = new PowerShellInfo(Boolean.parseBoolean(outputLines.get(2)) ? PowerShellBitness.x64 : PowerShellBitness.x86, exeFile.getParentFile(), outputLines.get(0), edition, executable);
LOG.info("Found: " + result);
} else {
LOG.warn("Failed to determine PowerShell edition for [" + executablePath + "]");
LOG.debug(StringUtil.join("\n", outputLines));
}
} else {
LOG.warn("Failed to parse output from PowerShell executable [" + executablePath + "]");
LOG.debug(StringUtil.join("\n", outputLines));
}
} catch (ExecutionException e) {
LOG.warnAndDebugDetails("Failed to run PowerShell detection script [" + scriptPath + "] with executable [" + executablePath + "]", e);
}
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("PowerShell at " + exeFile.getAbsolutePath() + " was not found");
}
}
return result;
}