diff --git a/nucleus/core/kernel/src/main/java/org/glassfish/runnablejar/UberMain.java b/nucleus/core/kernel/src/main/java/org/glassfish/runnablejar/UberMain.java index 2f72b15a628..4149de5f8d8 100644 --- a/nucleus/core/kernel/src/main/java/org/glassfish/runnablejar/UberMain.java +++ b/nucleus/core/kernel/src/main/java/org/glassfish/runnablejar/UberMain.java @@ -192,7 +192,7 @@ private void executeCommandFromString(String stringCommand) { ? commandRunner.run(command) : commandRunner.run(command, commandParams); switch (result.getExitStatus()) { case SUCCESS: - logger.log(FINE, () -> "SUCCESS: " + result.getOutput()); + logger.log(INFO, () -> "SUCCESS: " + result.getOutput()); break; default: if (result.getFailureCause() != null) { diff --git a/nucleus/core/kernel/src/main/java/org/glassfish/runnablejar/commandline/Arguments.java b/nucleus/core/kernel/src/main/java/org/glassfish/runnablejar/commandline/Arguments.java index d78198c9196..956a5ec9ef5 100644 --- a/nucleus/core/kernel/src/main/java/org/glassfish/runnablejar/commandline/Arguments.java +++ b/nucleus/core/kernel/src/main/java/org/glassfish/runnablejar/commandline/Arguments.java @@ -32,6 +32,7 @@ import java.util.stream.Stream; import org.glassfish.embeddable.GlassFishProperties; +import org.glassfish.runnablejar.UberMain; /** * @@ -189,27 +190,25 @@ public void printHelp(Consumer lineConsumer) { } private String replaceArguments(String line) { - final WordWrapper wordWrapper = new WordWrapper(HELP_LINE_LENGTH, 40, HELP_LINE_INDENT); + final WordWrapCollector wordWrapper = new WordWrapCollector(HELP_LINE_LENGTH, 40, HELP_LINE_INDENT); final String arguments = Stream.concat( Arrays.stream(Option.values()) .map(option -> "[" + option.getUsage() + "]"), Stream.of("[applications or admin commands...]") ) - .map(wordWrapper::map) - .collect(Collectors.joining(" ")); + .collect(wordWrapper); return line.replace("${ARGUMENTS}", arguments); } private String replaceOptions(String line) { final String options = Arrays.stream(Option.values()) .map(option -> { - final WordWrapper wordWrapper = new WordWrapper(HELP_LINE_LENGTH, HELP_LINE_INDENT.length(), HELP_LINE_INDENT); + final WordWrapCollector wordWrapper = new WordWrapCollector(HELP_LINE_LENGTH, HELP_LINE_INDENT.length(), HELP_LINE_INDENT); return HELP_FIRST_LINE_INDENT + option.getUsage() + "\n" + HELP_LINE_INDENT + getStreamOfWords(option.getHelpText()) - .map(wordWrapper::map) - .collect(Collectors.joining(" ")); + .collect(wordWrapper); }) .collect(Collectors.joining("\n\n")); return line.replace( @@ -221,7 +220,8 @@ protected Stream getStreamOfWords(String helpText) { } private BufferedReader openManPageReader() { - final InputStream manPageInputStream = this.getClass().getClassLoader().getResourceAsStream("manpages/glassfish-embedded.1"); + final InputStream manPageInputStream = this.getClass().getClassLoader().getResourceAsStream( + UberMain.class.getPackageName().replace(".", "/") + "/glassfish-embedded.1"); return new BufferedReader(new InputStreamReader(manPageInputStream, StandardCharsets.UTF_8)); } diff --git a/nucleus/core/kernel/src/main/java/org/glassfish/runnablejar/commandline/UnknownPropertyException.java b/nucleus/core/kernel/src/main/java/org/glassfish/runnablejar/commandline/UnknownPropertyException.java index e9e31d0e728..252a88a875a 100644 --- a/nucleus/core/kernel/src/main/java/org/glassfish/runnablejar/commandline/UnknownPropertyException.java +++ b/nucleus/core/kernel/src/main/java/org/glassfish/runnablejar/commandline/UnknownPropertyException.java @@ -21,20 +21,18 @@ */ public class UnknownPropertyException extends Exception { - private String key; - private String value; + private final String key; + private final String value; public UnknownPropertyException(String key, String value) { + this.key = key; + this.value = value; } public String getKey() { return key; } - public String getValue() { - return value; - } - @Override public String getMessage() { return "Unknown property " + key + "=" + value; diff --git a/nucleus/core/kernel/src/main/java/org/glassfish/runnablejar/commandline/WordWrapper.java b/nucleus/core/kernel/src/main/java/org/glassfish/runnablejar/commandline/WordWrapCollector.java similarity index 52% rename from nucleus/core/kernel/src/main/java/org/glassfish/runnablejar/commandline/WordWrapper.java rename to nucleus/core/kernel/src/main/java/org/glassfish/runnablejar/commandline/WordWrapCollector.java index ea22d697245..0bd139adee8 100644 --- a/nucleus/core/kernel/src/main/java/org/glassfish/runnablejar/commandline/WordWrapper.java +++ b/nucleus/core/kernel/src/main/java/org/glassfish/runnablejar/commandline/WordWrapCollector.java @@ -26,75 +26,53 @@ * * @author Ondro Mihalyi */ -public class WordWrapper { +public final class WordWrapCollector implements Collector{ - final int MAX_LINE_LENGTH; - final String HELP_LINE_INDENT; - int characterCount; + private final int MAX_LINE_LENGTH; + private final String HELP_LINE_INDENT; + private int characterCount; - public WordWrapper(int maxLineLength, int initialIndent, String otherLinesIndentText) { + public WordWrapCollector(int maxLineLength, int initialIndent, String otherLinesIndentText) { this.MAX_LINE_LENGTH = maxLineLength; this.HELP_LINE_INDENT = otherLinesIndentText; this.characterCount = initialIndent; } - public String map(String optionText) { - String[] optionTextLines = optionText.split("\n", -1); - StringBuilder sb = new StringBuilder(); - boolean first = true; - for (String optionTextLine : optionTextLines) { - if (!first) { - sb.append("\n" + HELP_LINE_INDENT); - characterCount = HELP_LINE_INDENT.length(); - } - characterCount += optionTextLine.length() + 1; - if (characterCount > MAX_LINE_LENGTH) { - final String newOptionText = HELP_LINE_INDENT + optionTextLine; - characterCount = newOptionText.length(); - sb.append("\n").append(newOptionText); - } else { - sb.append(optionTextLine); - } - first = false; - } - return sb.toString(); + @Override + public Supplier supplier() { + return StringBuilder::new; } - public Collector collector() { - return new Collector() { - @Override - public Supplier supplier() { - return StringBuilder::new; - } - - @Override - public BiConsumer accumulator() { - return (assembly, item) -> appendItem(assembly, item); + @Override + public BiConsumer accumulator() { + return (assembly, item) -> { + for (String word : item.split(" ")) { + appendItem(assembly, word); } + }; + } - @Override - public BinaryOperator combiner() { - return (sb1, sb2) -> sb1.append(sb2); - } + @Override + public BinaryOperator combiner() { + return (sb1, sb2) -> sb1.append(sb2); + } - @Override - public Function finisher() { - return StringBuilder::toString; - } + @Override + public Function finisher() { + return StringBuilder::toString; + } - @Override - public Set characteristics() { - return Set.of(); - } - }; + @Override + public Set characteristics() { + return Set.of(); } - protected static char lastChar(StringBuilder assembly) { + private static char lastChar(StringBuilder assembly) { return assembly.charAt(assembly.length() - 1); } - protected void appendItem(StringBuilder assembly, String item) { - final String modifiedItem = map(item); + private void appendItem(StringBuilder assembly, String item) { + final String modifiedItem = wrapWord(item); if (assembly.length() == 0 || Set.of('\n', ' ').contains(lastChar(assembly)) || modifiedItem.startsWith("\n") @@ -105,4 +83,28 @@ protected void appendItem(StringBuilder assembly, String item) { } assembly.append(modifiedItem); } + + // move word to the next row if needs to be wrapped + private String wrapWord(String word) { + String[] lines = word.split("\n", -1); + StringBuilder sb = new StringBuilder(); + boolean first = true; + for (String line : lines) { + if (!first) { + sb.append("\n").append(HELP_LINE_INDENT); + characterCount = HELP_LINE_INDENT.length(); + } + characterCount += line.length() + 1; + if (characterCount > MAX_LINE_LENGTH) { + final String modifiedLine = HELP_LINE_INDENT + line; + characterCount = modifiedLine.length(); + sb.append("\n").append(modifiedLine); + } else { + sb.append(line); + } + first = false; + } + return sb.toString(); + } + } diff --git a/nucleus/core/bootstrap/src/main/resources/manpages/glassfish-embedded.1 b/nucleus/core/kernel/src/main/manpages/org/glassfish/runnablejar/glassfish-embedded.1 similarity index 70% rename from nucleus/core/bootstrap/src/main/resources/manpages/glassfish-embedded.1 rename to nucleus/core/kernel/src/main/manpages/org/glassfish/runnablejar/glassfish-embedded.1 index e485382b228..01ce5695d49 100644 --- a/nucleus/core/bootstrap/src/main/resources/manpages/glassfish-embedded.1 +++ b/nucleus/core/kernel/src/main/manpages/org/glassfish/runnablejar/glassfish-embedded.1 @@ -4,7 +4,7 @@ NAME glassfish-embedded - Start GlassFish Embedded as an executable JAR SYNOPSIS - java -jar glassfish-embedded-all.jar ${ARGUMENTS} + java -jar glassfish-embedded.jar ${ARGUMENTS} DESCRIPTION GlassFish Embedded can be executed as an executable JAR file. This starts @@ -35,14 +35,15 @@ ${OPTIONS} Any argument that doesn't start with a hyphen (-), is treated as follows: - - If it's a file or directory, it's deployed at startup as an application. If it's - the only application deployed at startup, it's deployed under the root context '/'. - Otherwise it's deployed under the context root derived from the name of the file - or deployment descriptors. - - In all other cases, the argument is executed as a GlassFish admin command. - Individual commands must be enclosed in quotes if they contain spaces. GlassFish - admin commands are the same commands supported by GlassFish Server's "asadmin" - command line tool or by the "CommandRunner" Java class in GlassFish Simple Public API. + - If it's a file or directory, it's deployed at startup as an application. + If only application is deployed at startup, it's deployed under the root + context '/'. Otherwise it's deployed under the context root derived from + the name of the file or deployment descriptors. + - In all other cases, the argument is executed as a GlassFish admin + command. Individual commands must be enclosed in quotes if they contain + spaces. GlassFish admin commands are the same commands supported by + GlassFish Server's "asadmin" command line tool or by the "CommandRunner" + Java class in GlassFish Simple Public API. DEFAULT CONFIGURATION @@ -55,23 +56,23 @@ EXAMPLES Example 1: Run an application from command line On port 8080 and root context by default - java -jar glassfish-embedded-all.jar app.war + java -jar glassfish-embedded.jar app.war Example 2: Run an app on a different port - java -jar glassfish-embedded-all.jar --httpPort=8090 app.war + java -jar glassfish-embedded.jar --httpPort=8090 app.war Example 3: Run a custom deploy command on startup - Sets a custom root context. Custom commands need to be enclosed in quotes - if they contain spaces. + Sets a custom root context. Custom commands need to be enclosed in + quotes if they contain spaces. - java -jar glassfish-embedded-all.jar "deploy --contextroot=/app app.war" + java -jar glassfish-embedded.jar "deploy --contextroot=/app app.war" Example 4: Run 2 applications from command line Deploys applications on different context roots, based on the file name or info in the application descriptors. - java -jar glassfish-embedded-all.jar app1.war app2.war + java -jar glassfish-embedded.jar app1.war app2.war EXIT STATUS 0 @@ -83,4 +84,4 @@ EXIT STATUS SEE ALSO deploy(1), asadmin(1) -Jakarta EE 10 13 Sep 2024 glassfish-embedded(1) \ No newline at end of file +Jakarta EE 10 13 Sep 2024 glassfish-embedded(1) \ No newline at end of file diff --git a/nucleus/core/kernel/src/test/java/org/glassfish/runnablejar/commandline/WordWrapperTest.java b/nucleus/core/kernel/src/test/java/org/glassfish/runnablejar/commandline/WordWrapperTest.java index c5a63b2fcc8..dff418c337b 100644 --- a/nucleus/core/kernel/src/test/java/org/glassfish/runnablejar/commandline/WordWrapperTest.java +++ b/nucleus/core/kernel/src/test/java/org/glassfish/runnablejar/commandline/WordWrapperTest.java @@ -32,10 +32,11 @@ public class WordWrapperTest { @Test public void testWrapper() { final int MAX_LINE_LENGTH = 80; - final WordWrapper wordWrapper = new WordWrapper(MAX_LINE_LENGTH, 8, " "); + final WordWrapCollector wordWrapper = new WordWrapCollector(MAX_LINE_LENGTH, 8, " "); String message = " " - + Arrays.stream(Option.PROPERTIES.getHelpText().split(" ")) - .collect(wordWrapper.collector()); + + Arrays.stream(Option.values()) + .map(Option::getHelpText) + .collect(wordWrapper); final List linesEndingWithSpace = message.lines() .filter(line -> line.endsWith(" ")) .collect(toList());