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 1739 Pre and Post boot command parsing problem #1665

Merged
merged 3 commits into from
Jun 20, 2017
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 @@ -174,13 +174,7 @@ private void startConsole() throws IOException {
continue;
}
CommandRunner cmdRunner = gf.getCommandRunner();
String[] tokens = command.split("\\s");
CommandResult result = cmdRunner.run(tokens[0], Arrays.copyOfRange(tokens, 1, tokens.length));
System.out.println(result.getExitStatus());
System.out.println(result.getOutput());
if (result.getFailureCause() != null) {
result.getFailureCause().printStackTrace();
}
runCommand(cmdRunner, command);
}
} catch (Exception e) {
e.printStackTrace();
Expand Down Expand Up @@ -218,6 +212,43 @@ public void run() {
});

}

/**
* Runs a command read from a string
* @param cmdRunner
* @param line
* @throws GlassFishException
*/
private void runCommand(CommandRunner cmdRunner, String line) throws GlassFishException, IOException {

line = cleanCommand(line);
if(line == null) {
return;
}

System.out.println("Running command: " + line);
String[] tokens = line.split("\\s+");
CommandResult result = cmdRunner.run(tokens[0], Arrays.copyOfRange(tokens, 1, tokens.length));
System.out.println(result.getOutput());
if(result.getFailureCause() != null) {
result.getFailureCause().printStackTrace();
}
}

/**
* Cleans a command read from a string
* @param line
*/
private String cleanCommand(String line) {
if(line == null) {
return null;
}
line = line.replaceAll("#.*", ""); // Removes comments
if (line.isEmpty() || line.replaceAll("\\s", "").isEmpty()) {
return null;
}
return line;
}

/**
* Runs a series of commands from a file
Expand All @@ -230,25 +261,11 @@ private void doBootCommands(String file) {
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {

System.out.println("Reading in commandments from " + file);
String line = reader.readLine();;
String line = reader.readLine();
CommandRunner cmdRunner = gf.getCommandRunner();

while (line != null) {

String[] commmandParts = cleanCommand(line);
CommandRunner runner = gf.getCommandRunner();
CommandResult result;
if (!(commmandParts[0].isEmpty() || commmandParts[0].equals(" "))){

if (commmandParts.length == 1){
result = runner.run(commmandParts[0]);
} else {
String[] argv = commmandParts[1].split(" ");
result = runner.run(commmandParts[0], argv);
}
System.out.println(result.getOutput());
if (result.getFailureCause() != null){
throw result.getFailureCause();
}
}
runCommand(cmdRunner, line);
line = reader.readLine();
}
} catch (IOException ex) {
Expand All @@ -258,22 +275,6 @@ private void doBootCommands(String file) {
}
}

/**
* Cleans up a single line command to be space-seperated, comments removed etc.
* @param command
* @return
*/
private String[] cleanCommand(String command){
String line = command.split("#")[0];
line = line.trim();
if (!line.startsWith("set ")){
line = line.replaceAll("=", " ");
}
line = line.replaceAll("(\\s+)", " ");
String[] split = line.split(" ", 2);
return split;
}


}

Expand Down