use of jetbrains.buildServer.powershell.common.PowerShellEdition in project teamcity-powershell by JetBrains.
the class BasePowerShellService method selectTool.
private PowerShellInfo selectTool() throws RunBuildException {
final BuildProgressLogger buildLogger = getBuild().getBuildLogger();
PowerShellInfo result;
if (getRunnerContext().isVirtualContext()) {
if (SystemInfo.isWindows) {
throw new RunBuildException("PowerShell is not supported on windows containers");
}
buildLogger.logMessage(internalize(createTextMessage("PowerShell is running in virtual agent context")));
result = VirtualPowerShellSupport.getVirtualPowerShell();
} else {
buildLogger.logMessage(internalize(createTextMessage("PowerShell running in non-virtual agent context")));
final PowerShellBitness bit = PowerShellBitness.fromString(getRunnerParameters().get(RUNNER_BITNESS));
final String version = getRunnerParameters().get(RUNNER_MIN_VERSION);
final PowerShellEdition edition = PowerShellEdition.fromString(getRunnerParameters().get(RUNNER_EDITION));
result = myInfoProvider.selectTool(bit, version, edition);
if (result == null) {
throw new RunBuildException("Could not select PowerShell for given bitness " + (bit == null ? "<Auto>" : bit.getDisplayName() + " and version " + (version == null ? "<Any>" : version)));
}
}
return result;
}
use of jetbrains.buildServer.powershell.common.PowerShellEdition in project teamcity-powershell by JetBrains.
the class PowerShellInfoProvider method selectTool.
@Nullable
public PowerShellInfo selectTool(@Nullable final PowerShellBitness bit, @Nullable final String version, @Nullable final PowerShellEdition edition) {
// filter by edition
List<PowerShellInfo> availableShells = myHolder.getShells();
if (edition != null) {
availableShells = CollectionsUtil.filterCollection(availableShells, new Filter<PowerShellInfo>() {
@Override
public boolean accept(@NotNull PowerShellInfo data) {
return edition.equals(data.getEdition());
}
});
}
// filter by version
if (version != null) {
availableShells = CollectionsUtil.filterCollection(availableShells, new Filter<PowerShellInfo>() {
@Override
public boolean accept(@NotNull PowerShellInfo data) {
return VersionComparatorUtil.compare(data.getVersion(), version) >= 0;
}
});
}
// filter by bitness
if (bit != null) {
availableShells = CollectionsUtil.filterCollection(availableShells, new Filter<PowerShellInfo>() {
@Override
public boolean accept(@NotNull PowerShellInfo data) {
return data.getBitness().equals(bit);
}
});
}
if (availableShells.isEmpty()) {
return null;
}
if (availableShells.size() == 1) {
return availableShells.get(0);
}
// prefer desktop over core
if (edition == null) {
Map<PowerShellEdition, List<PowerShellInfo>> byEdition = new HashMap<PowerShellEdition, List<PowerShellInfo>>();
for (PowerShellInfo info : availableShells) {
if (!byEdition.containsKey(info.getEdition())) {
byEdition.put(info.getEdition(), new ArrayList<PowerShellInfo>());
}
byEdition.get(info.getEdition()).add(info);
}
if (byEdition.get(PowerShellEdition.DESKTOP) != null) {
availableShells = byEdition.get(PowerShellEdition.DESKTOP);
} else {
availableShells = byEdition.get(PowerShellEdition.CORE);
}
}
if (availableShells.size() == 1) {
return availableShells.get(0);
}
// prefer 64bit over 32bit
if (bit == null) {
Map<PowerShellBitness, List<PowerShellInfo>> byBits = new HashMap<PowerShellBitness, List<PowerShellInfo>>();
for (PowerShellInfo info : availableShells) {
if (!byBits.containsKey(info.getBitness())) {
byBits.put(info.getBitness(), new ArrayList<PowerShellInfo>());
}
byBits.get(info.getBitness()).add(info);
}
if (byBits.containsKey(PowerShellBitness.x64)) {
availableShells = byBits.get(PowerShellBitness.x64);
} else {
availableShells = byBits.get(PowerShellBitness.x86);
}
}
if (availableShells.size() == 1) {
return availableShells.get(0);
}
// select max available version
Collections.sort(availableShells, new Comparator<PowerShellInfo>() {
@Override
public int compare(PowerShellInfo info1, PowerShellInfo info2) {
return VersionComparatorUtil.compare(info1.getVersion(), info2.getVersion());
}
});
return availableShells.get(0);
}
use of jetbrains.buildServer.powershell.common.PowerShellEdition in project teamcity-powershell by JetBrains.
the class CommandLinePowerShellDetector method doDetect.
@Nullable
private PowerShellInfo doDetect(@NotNull final String homePath, @NotNull final String executable, @NotNull final String scriptPath) {
PowerShellInfo result = null;
final File exeFile = new File(homePath, executable);
if (LOG.isDebugEnabled()) {
LOG.debug("Searching for PowerShell at " + exeFile.getAbsolutePath());
}
if (exeFile.isFile()) {
String executablePath = exeFile.getAbsolutePath();
try {
final List<String> outputLines = myRunner.runDetectionScript(executablePath, scriptPath);
if (outputLines.size() == 3) {
final PowerShellEdition edition = PowerShellEdition.fromString(outputLines.get(1));
if (edition != null) {
result = new PowerShellInfo(Boolean.valueOf(outputLines.get(2)) ? PowerShellBitness.x64 : PowerShellBitness.x86, exeFile.getParentFile(), outputLines.get(0), edition, executable);
} 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;
}
use of jetbrains.buildServer.powershell.common.PowerShellEdition in project teamcity-powershell by JetBrains.
the class CommandLineProviderTest method setUp.
@SuppressWarnings("ResultOfMethodCallIgnored")
@Override
@BeforeMethod
public void setUp() throws Exception {
super.setUp();
m = new Mockery() {
{
setImposteriser(ClassImposteriser.INSTANCE);
}
};
myInfo = m.mock(PowerShellInfo.class);
final PowerShellEdition edition = SystemInfo.isWindows ? PowerShellEdition.DESKTOP : PowerShellEdition.CORE;
m.checking(new Expectations() {
{
allowing(myInfo).getEdition();
will(returnValue(edition));
}
});
myProvider = new PowerShellCommandLineProvider();
myScriptsRootDir = createTempDir();
myScriptFile = new File(myScriptsRootDir, SCRIPT_FILE_NAME);
myScriptFile.createNewFile();
super.registerAsTempFile(myScriptFile);
}
Aggregations