Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PAYARA-3091 Post Boot Commands Incorrect Quotation Mark Processing #3312

Merged
merged 3 commits into from
Oct 29, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
import java.util.Properties;

import static com.sun.enterprise.module.bootstrap.ArgumentManager.argsToMap;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
Expand All @@ -65,6 +67,9 @@
*/
public class GlassFishMain {

private static final Pattern COMMAND_PATTERN = Pattern.compile("([^\"']\\S*|\".*?\"|'.*?')\\s*");
private static final String[] COMMAND_TYPE = new String[0];

// TODO(Sahoo): Move the code to ASMain once we are ready to phase out ASMain

public static void main(final String args[]) throws Exception {
Expand Down Expand Up @@ -231,8 +236,11 @@ private void runCommand(CommandRunner cmdRunner, String line) throws GlassFishEx
}

System.out.println("Running command: " + line);
String[] tokens = line.split("\\s+");
CommandResult result = cmdRunner.run(tokens[0], Arrays.copyOfRange(tokens, 1, tokens.length));
List<String> tokens = parseCommand(line);
CommandResult result = cmdRunner.run(
tokens.get(0),
tokens.subList(1, tokens.size()).toArray(COMMAND_TYPE)
);
System.out.println(result.getOutput());
if(result.getFailureCause() != null) {
result.getFailureCause().printStackTrace();
Expand All @@ -249,12 +257,29 @@ private String cleanCommand(String line) {
}
line = line.replaceAll("^\\s*#.*", ""); // Removes comments at the start of lines
line = line.replaceAll("\\s#.*", ""); // Removes comments with whitespace before them. This allows for hashtags used in commands to be ignored.
line = line.replaceAll("\"", "");
if (line.isEmpty() || line.replaceAll("\\s", "").isEmpty()) {
return null;
}
return line;
}

/**
* Parse a command read from a string
* @param line
*/
private List<String> parseCommand(String line) {
List<String> tokens = new ArrayList<>();
Matcher matcher = COMMAND_PATTERN.matcher(line);
while (matcher.find()) {
String token = matcher.group(1);
if ((token.startsWith("\"") && token.endsWith("\""))
|| token.startsWith("'") && token.endsWith("'")) {
token = token.substring(1, token.length() - 1);
}
tokens.add(token);
}
return tokens;
}

/**
* Runs a series of commands from a file
Expand Down Expand Up @@ -284,7 +309,6 @@ private void doBootCommands(String file) {


private String getEnvironmentSubstitution(String value){
String origValue = value;
int i = 0; // Perform Environment variable substitution
Matcher m2 = p.matcher(value);

Expand Down