Skip to content

Commit

Permalink
windows
Browse files Browse the repository at this point in the history
  • Loading branch information
elharo committed Dec 3, 2024
1 parent fb85e0e commit c48d6be
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions src/test/java/org/apache/maven/plugins/jlink/JLinkMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,25 @@

import org.apache.maven.shared.utils.cli.Commandline;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

public class JLinkMojoTest {

@Test
void double_quote_every_argument() throws Exception {
private JLinkMojo mojo = new JLinkMojo();

@BeforeEach
public void setUp() throws NoSuchFieldException, IllegalAccessException {
// given
JLinkMojo mojo = new JLinkMojo();
Field stripDebug = mojo.getClass().getDeclaredField("stripDebug");
stripDebug.setAccessible(true);
stripDebug.set(mojo, Boolean.TRUE);
}

@Test
void double_quote_every_argument() throws Exception {
// when
List<String> jlinkArgs = mojo.createJlinkArgs(List.of(), List.of());

Expand All @@ -46,16 +51,8 @@ void double_quote_every_argument() throws Exception {
}

@Test
void single_quotes_shell_command() throws Exception {

Assumptions.assumeFalse("windows".equals(System.getProperty("os.name")));
// TODO add a test for Windows

// given
JLinkMojo mojo = new JLinkMojo();
Field stripDebug = mojo.getClass().getDeclaredField("stripDebug");
stripDebug.setAccessible(true);
stripDebug.set(mojo, Boolean.TRUE);
void single_quotes_shell_command_unix() throws Exception {
Assumptions.assumeFalse(System.getProperty("os.name").startsWith("Windows"));

// when
List<String> jlinkArgs = mojo.createJlinkArgs(List.of("foo", "bar"), List.of("mvn", "jlink"));
Expand All @@ -66,4 +63,19 @@ void single_quotes_shell_command() throws Exception {
.isEqualTo(
"/bin/sh -c '/path/to/jlink \"--strip-debug\" \"--module-path\" \"foo:bar\" \"--add-modules\" \"mvn,jlink\"'");
}

@Test
void single_quotes_shell_command_windows() throws Exception {
Assumptions.assumeTrue(System.getProperty("os.name").startsWith("Windows"));

// when
List<String> jlinkArgs = mojo.createJlinkArgs(List.of("foo", "bar"), List.of("mvn", "jlink"));
Commandline cmdLine = JLinkExecutor.createJLinkCommandLine(new File("/path/to/jlink"), jlinkArgs);

// then
assertThat(cmdLine.toString()).startsWith("cmd.exe ");
assertThat(cmdLine.toString())
.contains(
"\\path\\to\\jlink \"-strip-debug\" \"module-path\" \"foo;bar\" \"-add-modules\" \"mvn,jlink");
}
}

0 comments on commit c48d6be

Please sign in to comment.