Skip to content

Commit

Permalink
Merge pull request #2481 from MattGill98/PAYARA-2555-Micro-Arquillian…
Browse files Browse the repository at this point in the history
…-Container-Doesnt-Allow-Spaces-In-Arguments

PAYARA-2555 Micro Arquillian Container Doesn't Allow Spaces In Arguments
  • Loading branch information
Pandrex247 committed Feb 28, 2018
2 parents d6c4685 + 215200e commit 84a8c45
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
import java.io.IOException;
import java.util.Properties;
import java.util.jar.JarFile;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.ZipEntry;

import org.jboss.arquillian.container.spi.ConfigurationException;
Expand Down Expand Up @@ -208,6 +210,26 @@ public void validate() throws ConfigurationException {
"Unable to find Payara Micro Jar version. Please check the file is a valid Payara Micro Jar.", e);
}
notNull(getMicroVersion(), "Unable to find Payara Micro Jar version. Please check the file is a valid Payara Micro Jar.");

// Escape spaces in paths for the cmd options
if (cmdOptions != null) {
cmdOptions = escapePaths(cmdOptions);
}
if (extraMicroOptions != null) {
extraMicroOptions = escapePaths(extraMicroOptions);
}
}

private String escapePaths(String input) {
Pattern pathPattern = Pattern.compile("((?>[\\/\\\\]|\\\\ )[\\w ]+) ([^-])");

Matcher matcher = pathPattern.matcher(input);
String output = input;
while (matcher.find()) {
output = matcher.replaceAll("$1\\\\ $2");
matcher = pathPattern.matcher(output);
}
return output;
}

private static String getConfigurableVariable(String systemPropertyName, String environmentVariableName, String defaultValue) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,16 +195,20 @@ public ProtocolMetaData deploy(Archive<?> archive) throws DeploymentException {
// Add the extra cmd options to the Payara Micro instance
if (configuration.getCmdOptions() != null) {
int index = 1;
for (String option : configuration.getCmdOptions().split(" ")) {
cmd.add(index, option);
// Split on non-escaped spaces
for (String option : configuration.getCmdOptions().split("(?<!\\\\) ")) {
// Unescape any path spaces before adding the string
cmd.add(index, option.replace("\\ ", " "));
index++;
}
}

// Add the extra micro options to the Payara Micro instance
if (configuration.getExtraMicroOptions() != null) {
for (String option : configuration.getExtraMicroOptions().split(" ")) {
cmd.add(option);
// Split on non-escaped spaces
for (String option : configuration.getExtraMicroOptions().split("(?<!\\\\) ")) {
// Unescape any path spaces before adding the string
cmd.add(option.replace("\\ ", " "));
}
}

Expand Down

0 comments on commit 84a8c45

Please sign in to comment.