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+ * 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+ * 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