Skip to content

Commit

Permalink
mvnd native executable is not passing -Dkey=val to the daemon #157
Browse files Browse the repository at this point in the history
  • Loading branch information
ppalaga committed Oct 27, 2020
1 parent 6e46188 commit 59a9bba
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
1 change: 1 addition & 0 deletions client/pom.xml
Expand Up @@ -122,6 +122,7 @@
-H:IncludeResources=org/jboss/fuse/mvnd/.*
-H:IncludeResources=org/jline/utils/.*
-H:IncludeResources=org/fusesource/jansi/jansi.properties
-H:-ParseRuntimeOptions
</buildArgs>
</configuration>
</plugin>
Expand Down
Expand Up @@ -88,7 +88,6 @@ public ExecutionResult execute(ClientOutput output, List<String> argv) {
boolean version = false;
boolean showVersion = false;
boolean debug = false;
final Properties commandLineProperties = new Properties();
for (String arg : argv) {
switch (arg) {
case "-v":
Expand All @@ -111,9 +110,9 @@ public ExecutionResult execute(ClientOutput output, List<String> argv) {
if (arg.startsWith("-D")) {
final int eqPos = arg.indexOf('=');
if (eqPos >= 0) {
commandLineProperties.setProperty(arg.substring(2, eqPos), arg.substring(eqPos + 1));
System.setProperty(arg.substring(2, eqPos), arg.substring(eqPos + 1));
} else {
commandLineProperties.setProperty(arg.substring(2), "");
System.setProperty(arg.substring(2), "");
}
}
args.add(arg);
Expand Down
Expand Up @@ -42,11 +42,14 @@ public class ModuleAndPluginNativeIT {
@Test
void cleanInstall() throws IOException, InterruptedException {
final Path helloPath = layout.multiModuleProjectDirectory().resolve("hello/target/hello.txt");
try {
Files.deleteIfExists(helloPath);
} catch (IOException e) {
throw new RuntimeException("Could not delete " + helloPath);
}
final Path helloPropertyPath = layout.multiModuleProjectDirectory().resolve("hello/target/hello.property.txt");
Stream.of(helloPath, helloPropertyPath).forEach(p -> {
try {
Files.deleteIfExists(p);
} catch (IOException e) {
throw new RuntimeException("Could not delete " + p);
}
});

final Path localMavenRepo = layout.getLocalMavenRepository();
TestUtils.deleteDir(localMavenRepo);
Expand All @@ -59,10 +62,13 @@ void cleanInstall() throws IOException, InterruptedException {
/* Build #1: with "Hello" output to target/hello.txt */
{
final ClientOutput output = Mockito.mock(ClientOutput.class);
client.execute(output, "clean", "install", "-e", "-Dmvnd.log.level=DEBUG").assertSuccess();
client.execute(output, "clean", "install", "-e", "-Dmvnd.log.level=DEBUG", "-Dhello.property=Hello1")
.assertSuccess();

Assertions.assertThat(helloPath).exists();
Assertions.assertThat(helloPath).usingCharset(StandardCharsets.UTF_8).hasContent("Hello");
Assertions.assertThat(helloPropertyPath).exists();
Assertions.assertThat(helloPropertyPath).usingCharset(StandardCharsets.UTF_8).hasContent("Hello1");
Stream.of(installedJars).forEach(jar -> Assertions.assertThat(jar).exists());
}

Expand All @@ -75,10 +81,12 @@ void cleanInstall() throws IOException, InterruptedException {
final ClientOutput output = Mockito.mock(ClientOutput.class);
client.execute(output,
"clean",
"install", "-e", "-Dmvnd.log.level=DEBUG").assertSuccess();
"install", "-e", "-Dmvnd.log.level=DEBUG", "-Dhello.property=Hello2").assertSuccess();

Assertions.assertThat(helloPath).exists();
Assertions.assertThat(helloPath).usingCharset(StandardCharsets.UTF_8).hasContent("Hi");
Assertions.assertThat(helloPropertyPath).exists();
Assertions.assertThat(helloPropertyPath).usingCharset(StandardCharsets.UTF_8).hasContent("Hello2");
Stream.of(installedJars).forEach(jar -> Assertions.assertThat(jar).exists());
}

Expand Down
Expand Up @@ -35,13 +35,17 @@ public class HelloMojo extends AbstractMojo {
@Parameter
File file;

@Parameter(property = "hello.property", defaultValue = "Hello")
String property;

@Override
public void execute() throws MojoExecutionException, MojoFailureException {

try {
final Path path = file.toPath();
Files.createDirectories(path.getParent());
Files.write(path, "Hello".getBytes(StandardCharsets.UTF_8));
Files.write(path.getParent().resolve("hello.property.txt"), property.getBytes(StandardCharsets.UTF_8));
} catch (IOException e) {
throw new RuntimeException("", e);
}
Expand Down

0 comments on commit 59a9bba

Please sign in to comment.