From b245397550b393b709cfebb6b38e27de6fa55a91 Mon Sep 17 00:00:00 2001 From: Matt Gill Date: Fri, 9 Jun 2017 11:43:29 +0100 Subject: [PATCH 1/3] Corrected the two parsing methods to the same one --- .../glassfish/bootstrap/GlassFishMain.java | 63 +++++++------------ 1 file changed, 22 insertions(+), 41 deletions(-) diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/GlassFishMain.java b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/GlassFishMain.java index c406c9614b7..f29340b6ce0 100644 --- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/GlassFishMain.java +++ b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/GlassFishMain.java @@ -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(); @@ -218,6 +212,21 @@ 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 { + 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(); + } + } /** * Runs a series of commands from a file @@ -230,25 +239,13 @@ 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(); - } - } + if (!(line.isEmpty() || line.contains("#"))) { + runCommand(cmdRunner, line); + } line = reader.readLine(); } } catch (IOException ex) { @@ -258,22 +255,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; - } - } From 9a426a575f393a264dfc442eabefb45315dbc073 Mon Sep 17 00:00:00 2001 From: Matt Gill Date: Fri, 9 Jun 2017 13:13:28 +0100 Subject: [PATCH 2/3] Changed comment parsing line to still read commands before comment on same line --- .../sun/enterprise/glassfish/bootstrap/GlassFishMain.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/GlassFishMain.java b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/GlassFishMain.java index f29340b6ce0..60024671307 100644 --- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/GlassFishMain.java +++ b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/GlassFishMain.java @@ -243,7 +243,10 @@ private void doBootCommands(String file) { CommandRunner cmdRunner = gf.getCommandRunner(); while (line != null) { - if (!(line.isEmpty() || line.contains("#"))) { + if (!line.isEmpty()) { + if(line.contains("#")) { + line = line.split("#")[0]; + } runCommand(cmdRunner, line); } line = reader.readLine(); From ae694b346f5759064a4d426676d7a82b308c08cf Mon Sep 17 00:00:00 2001 From: Matt Gill Date: Mon, 12 Jun 2017 09:43:36 +0100 Subject: [PATCH 3/3] Changed parsing to allow for multiple spaces and corrected comment removal code --- .../glassfish/bootstrap/GlassFishMain.java | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/GlassFishMain.java b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/GlassFishMain.java index 60024671307..e0383fa08c8 100644 --- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/GlassFishMain.java +++ b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/GlassFishMain.java @@ -212,6 +212,7 @@ public void run() { }); } + /** * Runs a command read from a string * @param cmdRunner @@ -219,14 +220,35 @@ public void run() { * @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"); + 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 @@ -243,12 +265,7 @@ private void doBootCommands(String file) { CommandRunner cmdRunner = gf.getCommandRunner(); while (line != null) { - if (!line.isEmpty()) { - if(line.contains("#")) { - line = line.split("#")[0]; - } - runCommand(cmdRunner, line); - } + runCommand(cmdRunner, line); line = reader.readLine(); } } catch (IOException ex) {