Skip to content

Commit 0c31b1e

Browse files
authored
Merge pull request #39 from fizzed/feature/powershell
Feature/powershell
2 parents ee8510a + 0c22c7f commit 0c31b1e

File tree

8 files changed

+51
-9
lines changed

8 files changed

+51
-9
lines changed

blaze-core/src/main/java/com/fizzed/blaze/Config.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public interface Config {
3737
static Boolean DEFAULT_DEPENDENCY_CLEAN = Boolean.FALSE;
3838

3939
static List<String> DEFAULT_COMMAND_EXTS_UNIX = Arrays.asList("", ".sh");
40-
static List<String> DEFAULT_COMMAND_EXTS_WINDOWS = Arrays.asList(".exe", ".bat", ".cmd");
40+
static List<String> DEFAULT_COMMAND_EXTS_WINDOWS = Arrays.asList(".exe", ".ps1", ".bat", ".cmd");
4141

4242
/**
4343
* Gets a configuration value by its key.

blaze-core/src/main/java/com/fizzed/blaze/local/LocalExec.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,17 @@ protected Exec.Result doRun() throws BlazeException {
120120
finalCommand.add("sh");
121121
finalCommand.add("-c");
122122
}
123-
123+
124+
// is this a powershell command?
125+
if (exeFile.getFileName().toString().toLowerCase().endsWith(".ps1")) {
126+
// we need to actually execute powershell.exe
127+
final Path powershellExe = new Which(context)
128+
.command("powershell")
129+
.run();
130+
131+
finalCommand.add(powershellExe.toAbsolutePath().toString());
132+
}
133+
124134
finalCommand.add(exeFile.toAbsolutePath().toString());
125135

126136
finalCommand.addAll(this.arguments);

blaze-core/src/test/java/com/fizzed/blaze/system/ExecTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,22 @@ public void captureOutput() throws Exception {
123123

124124
assertThat(output.trim(), is("Hello World 7586930100"));
125125
}
126+
127+
@Test
128+
public void captureOutputWithPs1() throws Exception {
129+
CaptureOutput capture = Streamables.captureOutput();
130+
131+
new LocalExec(context)
132+
.command("hello-world-test2") // will be .ps1 on windows, using powershell.exe
133+
.path(getBinDirAsResource())
134+
.pipeInput(Streamables.standardInput())
135+
.pipeOutput(capture)
136+
.run();
137+
138+
String output = capture.asString();
139+
140+
assertThat(output.trim(), is("Hello World 5624112309877"));
141+
}
126142

127143
@Test
128144
public void customInput() throws Exception {

blaze-core/src/test/java/com/fizzed/blaze/system/ShellTestHelper.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ static public File getBinDirAsResource() throws Exception {
2828
// fix permissions from maven copy (otherwise test fails)
2929
FileHelper.resourceAsFile("/bin/hello-world-test").setExecutable(true);
3030
FileHelper.resourceAsFile("/bin/hello-world-test.bat").setExecutable(true);
31+
FileHelper.resourceAsFile("/bin/hello-world-test2").setExecutable(true);
32+
FileHelper.resourceAsFile("/bin/hello-world-test2.ps1").setExecutable(true);
3133

3234
// must use a resource that exists to then get its parent
3335
return FileHelper.resourceAsFile("/bin/hello-world-test").getParentFile();

blaze-core/src/test/java/com/fizzed/blaze/system/WhichTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,22 @@ public void worksOnWindows() throws Exception {
7676
assertThat(Files.isRegularFile(f), is(true));
7777
assertThat(Files.isExecutable(f), is(true));
7878
}
79+
80+
@Test
81+
public void worksOnWindowsForPs1() throws Exception {
82+
assumeTrue("Test only valid on windows", ConfigHelper.OperatingSystem.windows());
83+
84+
Path f = new Which(context)
85+
.command("hello-world-test2")
86+
.path(getBinDirAsResource())
87+
.run();
88+
89+
log.debug("which: {}", f);
90+
91+
assertThat(f, is(not(nullValue())));
92+
// .ps1 should be preferred to .bat
93+
assertThat(f.getFileName().toString(), either(is("hello-world-test2")).or(is("hello-world-test2.ps1")));
94+
}
7995

8096
@Test
8197
public void worksOnUnix() throws Exception {
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/env sh
2+
echo "Hello World 5624112309877"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Write-Output "Hello World 5624112309877"

buildx-results.txt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
Buildx Results
22
--------------
33
Cross platform tests use the Buildx project: https://github.com/fizzed/buildx
4-
Commit: e1d7ca02771846e2fae81441202099a6b7f596b4
5-
Date: 2025-01-10T21:08:43.065163Z[UTC]
4+
Commit: 725390b97265018dce4d42f336f1a637fba91cec
5+
Date: 2025-01-21T20:54:53.271163Z[UTC]
66

7-
linux-x64 success
8-
linux-arm64 success
9-
linux_musl-x64 success
10-
macos-x64 success
11-
macos-arm64 success
127
windows-x64 success
138
windows-arm64 success
149

0 commit comments

Comments
 (0)