diff --git a/dist/microprofile/src/main/java/cloud/piranha/dist/microprofile/MicroProfilePiranhaMain.java b/dist/microprofile/src/main/java/cloud/piranha/dist/microprofile/MicroProfilePiranhaMain.java index 2cb82c5798..71ed06ab9a 100644 --- a/dist/microprofile/src/main/java/cloud/piranha/dist/microprofile/MicroProfilePiranhaMain.java +++ b/dist/microprofile/src/main/java/cloud/piranha/dist/microprofile/MicroProfilePiranhaMain.java @@ -28,22 +28,20 @@ package cloud.piranha.dist.microprofile; import cloud.piranha.extension.microprofile.MicroProfileExtension; +import cloud.piranha.single.SingleMain; import cloud.piranha.single.SinglePiranhaBuilder; -import static java.lang.System.Logger.Level.WARNING; -import java.lang.System.Logger; -import java.lang.System.Logger.Level; /** - * The Main for Piranha Web Profile. + * The Main for Piranha Micro Profile. + * + *

+ * This version of Main sets the extension class to the MicroProfileExtension to + * deliver Piranha Micro Profile (unless it was overridden). + *

* * @author Manfred Riem (mriem@manorrock.com) */ -public class MicroProfilePiranhaMain { - - /** - * Stores the logger. - */ - private static final Logger LOGGER = System.getLogger(MicroProfilePiranhaMain.class.getName()); +public class MicroProfilePiranhaMain extends SingleMain { /** * Main method. @@ -53,126 +51,12 @@ public class MicroProfilePiranhaMain { public static void main(String[] arguments) { SinglePiranhaBuilder builder = new MicroProfilePiranhaMain().processArguments(arguments); if (builder != null) { + if (builder.getConfiguration().getClass("extensionClass") == null) { + builder.extensionClass(MicroProfileExtension.class); + } builder.build().start(); } else { showHelp(); } } - - /** - * Process the arguments. - * - * @param arguments the arguments. - */ - private SinglePiranhaBuilder processArguments(String[] arguments) { - - SinglePiranhaBuilder builder = new SinglePiranhaBuilder() - .extensionClass(MicroProfileExtension.class) - .exitOnStop(true); - int httpPort = 0; - int httpsPort = 0; - if (arguments != null) { - for (int i = 0; i < arguments.length; i++) { - if (arguments[i].equals("--extension-class")) { - builder = builder.extensionClass(arguments[i + 1]); - } - if (arguments[i].equals("--context-path")) { - builder = builder.contextPath(arguments[i + 1]); - } - if (arguments[i].equals("--help")) { - return null; - } - if (arguments[i].equals("--http-port")) { - int arg = Integer.parseInt(arguments[i + 1]); - builder = builder.httpPort(arg); - httpPort = arg; - } - if (arguments[i].equals("--http-server-class")) { - builder = builder.httpServerClass(arguments[i + 1]); - } - if (arguments[i].equals("--https-keystore-file")) { - builder = builder.httpsKeystoreFile(arguments[i + 1]); - } - if (arguments[i].equals("--https-keystore-password")) { - builder = builder.httpsKeystorePassword(arguments[i + 1]); - } - if (arguments[i].equals("--https-port")) { - int arg = Integer.parseInt(arguments[i + 1]); - builder = builder.httpsPort(arg); - httpsPort = arg; - } - if (arguments[i].equals("--https-server-class")) { - builder = builder.httpsServerClass(arguments[i + 1]); - } - if (arguments[i].equals("--https-truststore-file")) { - builder = builder.httpsTruststoreFile(arguments[i + 1]); - } - if (arguments[i].equals("--https-truststore-password")) { - builder = builder.httpsTruststorePassword(arguments[i + 1]); - } - if (arguments[i].equals("--jpms")) { - builder = builder.jpms(true); - } - if (arguments[i].equals("--logging-level")) { - builder = builder.loggingLevel(arguments[i + 1]); - } - if (arguments[i].equals("--verbose")) { - builder = builder.verbose(true); - } - if (arguments[i].equals("--war-file")) { - builder = builder.warFile(arguments[i + 1]); - } - if (arguments[i].equals("--webapp-dir")) { - builder = builder.webAppDir(arguments[i + 1]); - } - if (arguments[i].equals("--write-pid")) { - builder = builder.pid(ProcessHandle.current().pid()); - } - } - checkPorts(httpPort, httpsPort); - } - return builder; - } - - private void checkPorts(int httpPort, int httpsPort) { - if(httpsPort != 0 && httpPort == httpsPort) { - LOGGER.log(WARNING, "The http and the https ports are the same. Please use different ports"); - System.exit(-1); - } - } - - /** - * Show help. - */ - private static void showHelp() { - LOGGER.log(Level.INFO, ""); - LOGGER.log(Level.INFO, - """ - --extension-class - Set the extension to use - --help - Show this help - --context-path - Set the Servlet context path - --http-port - Set the HTTP port (use -1 to disable) - --http-server-class - Set the HTTP server class to use - --https-keystore-file - Set the HTTPS keystore file (applies to - the whole JVM) - --https-keystore-password - Set the HTTPS keystore password - (applies to the whole JVM) - --https-port - Set the HTTPS port (disabled by - default) - --https-server-class - Set the HTTPS server class to use - --https-truststore-file - Set the HTTPS keystore file (applies to - the whole JVM) - --https-truststore-password - Set the HTTPS keystore password - (applies to the whole JVM) - --jpms - Enable Java Platform Module System - --logging-level - Set the logging level - --verbose - Shows the runtime parameters - --war-file - The WAR file to deploy - --webapp-dir - The directory to use for the web - application (auto creates when it does - not exist, if omitted runtime will use - the filename portion of --war-file) - --write-pid - Write out a PID file - """); - } } diff --git a/dist/microprofile/src/main/java/module-info.java b/dist/microprofile/src/main/java/module-info.java index 9e983c3e18..c77dbb4582 100644 --- a/dist/microprofile/src/main/java/module-info.java +++ b/dist/microprofile/src/main/java/module-info.java @@ -27,7 +27,7 @@ */ /** - * This module delivers the Piranha MicroProfile distribution. + * This module delivers the Piranha Micro Profile distribution. * * @author Manfred Riem (mriem@manorrock.com) */ @@ -37,5 +37,4 @@ opens cloud.piranha.dist.microprofile; requires cloud.piranha.extension.microprofile; requires cloud.piranha.single; - requires java.logging; } diff --git a/dist/servlet/src/main/java/cloud/piranha/dist/servlet/ServletPiranhaMain.java b/dist/servlet/src/main/java/cloud/piranha/dist/servlet/ServletPiranhaMain.java index e9e1a0701d..f91d842a0b 100644 --- a/dist/servlet/src/main/java/cloud/piranha/dist/servlet/ServletPiranhaMain.java +++ b/dist/servlet/src/main/java/cloud/piranha/dist/servlet/ServletPiranhaMain.java @@ -28,22 +28,20 @@ package cloud.piranha.dist.servlet; import cloud.piranha.extension.servlet.ServletExtension; +import cloud.piranha.single.SingleMain; import cloud.piranha.single.SinglePiranhaBuilder; -import static java.lang.System.Logger.Level.WARNING; -import java.lang.System.Logger; -import java.lang.System.Logger.Level; /** * The Main for Piranha Servlet. * + *

+ * This version of Main sets the extension class to the ServletExtension to + * deliver Piranha Servlet (unless it was overridden). + *

+ * * @author Manfred Riem (mriem@manorrock.com) */ -public class ServletPiranhaMain { - - /** - * Stores the logger. - */ - private static final Logger LOGGER = System.getLogger(ServletPiranhaMain.class.getName()); +public class ServletPiranhaMain extends SingleMain { /** * Main method. @@ -53,130 +51,12 @@ public class ServletPiranhaMain { public static void main(String[] arguments) { SinglePiranhaBuilder builder = new ServletPiranhaMain().processArguments(arguments); if (builder != null) { + if (builder.getConfiguration().getClass("extensionClass") == null) { + builder.extensionClass(ServletExtension.class); + } builder.build().start(); } else { showHelp(); } } - - /** - * Process the arguments. - * - * @param arguments the arguments. - */ - private SinglePiranhaBuilder processArguments(String[] arguments) { - - SinglePiranhaBuilder builder = new SinglePiranhaBuilder() - .extensionClass(ServletExtension.class) - .exitOnStop(true); - int httpPort = 0; - int httpsPort = 0; - if (arguments != null) { - for (int i = 0; i < arguments.length; i++) { - if (arguments[i].equals("--extension-class")) { - builder = builder.extensionClass(arguments[i + 1]); - } - if (arguments[i].equals("--context-path")) { - builder = builder.contextPath(arguments[i + 1]); - } - if (arguments[i].equals("--enable-crac")) { - builder = builder.crac(true); - } - if (arguments[i].equals("--help")) { - return null; - } - if (arguments[i].equals("--http-port")) { - int arg = Integer.parseInt(arguments[i + 1]); - builder = builder.httpPort(arg); - httpPort = arg; - } - if (arguments[i].equals("--http-server-class")) { - builder = builder.httpServerClass(arguments[i + 1]); - } - if (arguments[i].equals("--https-keystore-file")) { - builder = builder.httpsKeystoreFile(arguments[i + 1]); - } - if (arguments[i].equals("--https-keystore-password")) { - builder = builder.httpsKeystorePassword(arguments[i + 1]); - } - if (arguments[i].equals("--https-port")) { - int arg = Integer.parseInt(arguments[i + 1]); - builder = builder.httpsPort(arg); - httpsPort = arg; - } - if (arguments[i].equals("--https-server-class")) { - builder = builder.httpsServerClass(arguments[i + 1]); - } - if (arguments[i].equals("--https-truststore-file")) { - builder = builder.httpsTruststoreFile(arguments[i + 1]); - } - if (arguments[i].equals("--https-truststore-password")) { - builder = builder.httpsTruststorePassword(arguments[i + 1]); - } - if (arguments[i].equals("--jpms")) { - builder = builder.jpms(true); - } - if (arguments[i].equals("--logging-level")) { - builder = builder.loggingLevel(arguments[i + 1]); - } - if (arguments[i].equals("--verbose")) { - builder = builder.verbose(true); - } - if (arguments[i].equals("--war-file")) { - builder = builder.warFile(arguments[i + 1]); - } - if (arguments[i].equals("--webapp-dir")) { - builder = builder.webAppDir(arguments[i + 1]); - } - if (arguments[i].equals("--write-pid")) { - builder = builder.pid(ProcessHandle.current().pid()); - } - } - checkPorts(httpPort, httpsPort); - } - return builder; - } - - private void checkPorts(int httpPort, int httpsPort) { - if(httpsPort != 0 && httpPort == httpsPort) { - LOGGER.log(WARNING, "The http and the https ports are the same. Please use different ports"); - System.exit(-1); - } - } - - /** - * Show help. - */ - private static void showHelp() { - LOGGER.log(Level.INFO, ""); - LOGGER.log(Level.INFO, - """ - --extension-class - Set the extension to use - --help - Show this help - --context-path - Set the Servlet context path - --enable-crac - Enable Project CRaC support - --http-port - Set the HTTP port (use -1 to disable) - --http-server-class - Set the HTTP server class to use - --https-keystore-file - Set the HTTPS keystore file (applies to - the whole JVM) - --https-keystore-password - Set the HTTPS keystore password - (applies to the whole JVM) - --https-port - Set the HTTPS port (disabled by - default) - --https-server-class - Set the HTTPS server class to use - --https-truststore-file - Set the HTTPS keystore file (applies to - the whole JVM) - --https-truststore-password - Set the HTTPS keystore password - (applies to the whole JVM) - --jpms - Enable Java Platform Module System - --logging-level - Set the logging level - --verbose - Shows the runtime parameters - --war-file - The WAR file to deploy - --webapp-dir - The directory to use for the web - application (auto creates when it does - not exist, if omitted runtime will use - the filename portion of --war-file) - --write-pid - Write out a PID file - """); - } } diff --git a/dist/servlet/src/main/java/module-info.java b/dist/servlet/src/main/java/module-info.java index 9751fca849..cc97d17534 100644 --- a/dist/servlet/src/main/java/module-info.java +++ b/dist/servlet/src/main/java/module-info.java @@ -37,5 +37,4 @@ opens cloud.piranha.dist.servlet; requires cloud.piranha.extension.servlet; requires cloud.piranha.single; - requires java.logging; } diff --git a/dist/webprofile/src/main/java/cloud/piranha/dist/webprofile/WebProfilePiranhaMain.java b/dist/webprofile/src/main/java/cloud/piranha/dist/webprofile/WebProfilePiranhaMain.java index 177ffcd77e..7ed4c4ec0a 100644 --- a/dist/webprofile/src/main/java/cloud/piranha/dist/webprofile/WebProfilePiranhaMain.java +++ b/dist/webprofile/src/main/java/cloud/piranha/dist/webprofile/WebProfilePiranhaMain.java @@ -28,22 +28,20 @@ package cloud.piranha.dist.webprofile; import cloud.piranha.extension.webprofile.WebProfileExtension; +import cloud.piranha.single.SingleMain; import cloud.piranha.single.SinglePiranhaBuilder; -import static java.lang.System.Logger.Level.WARNING; -import java.lang.System.Logger; -import java.lang.System.Logger.Level; /** * The Main for Piranha Web Profile. * + *

+ * This version of Main sets the extension class to the WebProfileExtension to + * deliver Piranha Core Profile (unless it was overridden). + *

+ * * @author Manfred Riem (mriem@manorrock.com) */ -public class WebProfilePiranhaMain { - - /** - * Stores the logger. - */ - private static final Logger LOGGER = System.getLogger(WebProfilePiranhaMain.class.getName()); +public class WebProfilePiranhaMain extends SingleMain { /** * Main method. @@ -53,126 +51,12 @@ public class WebProfilePiranhaMain { public static void main(String[] arguments) { SinglePiranhaBuilder builder = new WebProfilePiranhaMain().processArguments(arguments); if (builder != null) { + if (builder.getConfiguration().getClass("extensionClass") == null) { + builder.extensionClass(WebProfileExtension.class); + } builder.build().start(); } else { showHelp(); } } - - /** - * Process the arguments. - * - * @param arguments the arguments. - */ - private SinglePiranhaBuilder processArguments(String[] arguments) { - - SinglePiranhaBuilder builder = new SinglePiranhaBuilder() - .extensionClass(WebProfileExtension.class) - .exitOnStop(true); - int httpPort = 0; - int httpsPort = 0; - if (arguments != null) { - for (int i = 0; i < arguments.length; i++) { - if (arguments[i].equals("--extension-class")) { - builder = builder.extensionClass(arguments[i + 1]); - } - if (arguments[i].equals("--context-path")) { - builder = builder.contextPath(arguments[i + 1]); - } - if (arguments[i].equals("--help")) { - return null; - } - if (arguments[i].equals("--http-port")) { - int arg = Integer.parseInt(arguments[i + 1]); - builder = builder.httpPort(arg); - httpPort = arg; - } - if (arguments[i].equals("--http-server-class")) { - builder = builder.httpServerClass(arguments[i + 1]); - } - if (arguments[i].equals("--https-keystore-file")) { - builder = builder.httpsKeystoreFile(arguments[i + 1]); - } - if (arguments[i].equals("--https-keystore-password")) { - builder = builder.httpsKeystorePassword(arguments[i + 1]); - } - if (arguments[i].equals("--https-port")) { - int arg = Integer.parseInt(arguments[i + 1]); - builder = builder.httpsPort(arg); - httpsPort = arg; - } - if (arguments[i].equals("--https-server-class")) { - builder = builder.httpsServerClass(arguments[i + 1]); - } - if (arguments[i].equals("--https-truststore-file")) { - builder = builder.httpsTruststoreFile(arguments[i + 1]); - } - if (arguments[i].equals("--https-truststore-password")) { - builder = builder.httpsTruststorePassword(arguments[i + 1]); - } - if (arguments[i].equals("--jpms")) { - builder = builder.jpms(true); - } - if (arguments[i].equals("--logging-level")) { - builder = builder.loggingLevel(arguments[i + 1]); - } - if (arguments[i].equals("--verbose")) { - builder = builder.verbose(true); - } - if (arguments[i].equals("--war-file")) { - builder = builder.warFile(arguments[i + 1]); - } - if (arguments[i].equals("--webapp-dir")) { - builder = builder.webAppDir(arguments[i + 1]); - } - if (arguments[i].equals("--write-pid")) { - builder = builder.pid(ProcessHandle.current().pid()); - } - } - checkPorts(httpPort, httpsPort); - } - return builder; - } - - private void checkPorts(int httpPort, int httpsPort) { - if(httpsPort != 0 && httpPort == httpsPort) { - LOGGER.log(WARNING, "The http and the https ports are the same. Please use different ports"); - System.exit(-1); - } - } - - /** - * Show help. - */ - private static void showHelp() { - LOGGER.log(Level.INFO, ""); - LOGGER.log(Level.INFO, - """ - --extension-class - Set the extension to use - --help - Show this help - --context-path - Set the Servlet context path - --http-port - Set the HTTP port (use -1 to disable) - --http-server-class - Set the HTTP server class to use - --https-keystore-file - Set the HTTPS keystore file (applies to - the whole JVM) - --https-keystore-password - Set the HTTPS keystore password - (applies to the whole JVM) - --https-port - Set the HTTPS port (disabled by - default) - --https-server-class - Set the HTTPS server class to use - --https-truststore-file - Set the HTTPS keystore file (applies to - the whole JVM) - --https-truststore-password - Set the HTTPS keystore password - (applies to the whole JVM) - --jpms - Enable Java Platform Module System - --logging-level - Set the logging level - --verbose - Shows the runtime parameters - --war-file - The WAR file to deploy - --webapp-dir - The directory to use for the web - application (auto creates when it does - not exist, if omitted runtime will use - the filename portion of --war-file) - --write-pid - Write out a PID file - """); - } } diff --git a/dist/webprofile/src/main/java/module-info.java b/dist/webprofile/src/main/java/module-info.java index 96f18525fd..263b434cd8 100644 --- a/dist/webprofile/src/main/java/module-info.java +++ b/dist/webprofile/src/main/java/module-info.java @@ -27,7 +27,7 @@ */ /** - * This module delivers the Piranha WebProfile distribution. + * This module delivers the Piranha Web Profile distribution. * * @author Manfred Riem (mriem@manorrock.com) */ @@ -37,5 +37,4 @@ opens cloud.piranha.dist.webprofile; requires cloud.piranha.extension.webprofile; requires cloud.piranha.single; - requires java.logging; }