You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ja...@apache.org on 2026/04/18 16:39:27 UTC

(ofbiz-framework) 01/07: Fixed: Update StartupCommandUtil to fix warning messages for usage of deprecated methods in the org.apache.commons.cli library

This is an automated email from the ASF dual-hosted git repository.

jacopoc pushed a commit to branch release24.09
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git

commit cc85d8eccc0df67b86e9e1377816972511ef0f9a
Author: Jacopo Cappellato <ja...@gmail.com>
AuthorDate: Thu Apr 16 11:43:50 2026 +0200

    Fixed: Update StartupCommandUtil to fix warning messages for usage of deprecated methods in the org.apache.commons.cli library
    
    (cherry picked from commit 644e4d32c687674d92c08bf43bac94a1fffbae96)
---
 .../ofbiz/base/start/StartupCommandUtil.java       | 54 +++++++++++-----------
 1 file changed, 28 insertions(+), 26 deletions(-)

diff --git a/framework/start/src/main/java/org/apache/ofbiz/base/start/StartupCommandUtil.java b/framework/start/src/main/java/org/apache/ofbiz/base/start/StartupCommandUtil.java
index 3dc81b88b1..ba003d17bc 100644
--- a/framework/start/src/main/java/org/apache/ofbiz/base/start/StartupCommandUtil.java
+++ b/framework/start/src/main/java/org/apache/ofbiz/base/start/StartupCommandUtil.java
@@ -18,10 +18,7 @@
  *******************************************************************************/
 package org.apache.ofbiz.base.start;
 
-import java.io.OutputStreamWriter;
 import java.io.PrintStream;
-import java.io.PrintWriter;
-import java.nio.charset.StandardCharsets;
 import java.util.Arrays;
 import java.util.HashSet;
 import java.util.List;
@@ -33,7 +30,8 @@ import java.util.stream.Collectors;
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.CommandLineParser;
 import org.apache.commons.cli.DefaultParser;
-import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.help.HelpFormatter;
+import org.apache.commons.cli.help.TextHelpAppendable;
 import org.apache.commons.cli.Option;
 import org.apache.commons.cli.OptionGroup;
 import org.apache.commons.cli.Options;
@@ -82,7 +80,7 @@ public final class StartupCommandUtil {
             .longOpt(StartupOption.HELP.getName())
             .desc("Prints this help screen to the user")
             .hasArg(false)
-            .build();
+            .get();
     private static final Option LOAD_DATA = Option.builder("l")
             .longOpt(StartupOption.LOAD_DATA.getName())
             .desc("Creates tables/load data e.g:"
@@ -122,29 +120,29 @@ public final class StartupCommandUtil {
             .valueSeparator('=')
             .optionalArg(true)
             .argName("key=value")
-            .build();
+            .get();
     private static final Option PORTOFFSET = Option.builder("o")
             .longOpt(StartupOption.PORTOFFSET.getName())
             .desc("Offsets all default ports for OFBiz")
             .hasArg()
             .argName("offset")
             .optionalArg(false)
-            .build();
+            .get();
     private static final Option SHUTDOWN = Option.builder("d")
             .longOpt(StartupOption.SHUTDOWN.getName())
             .desc("Shutdown OFBiz")
             .hasArg(false)
-            .build();
+            .get();
     private static final Option START = Option.builder("u")
             .longOpt(StartupOption.START.getName())
             .desc("Start OFBiz")
             .hasArg(false)
-            .build();
+            .get();
     private static final Option STATUS = Option.builder("s")
             .longOpt(StartupOption.STATUS.getName())
             .desc("Gives the status of OFBiz")
             .hasArg(false)
-            .build();
+            .get();
     private static final Option TEST = Option.builder("t")
             .longOpt(StartupOption.TEST.getName())
             .desc("Runs the selected test or all if none selected e.g.: "
@@ -159,7 +157,7 @@ public final class StartupCommandUtil {
             .valueSeparator('=')
             .optionalArg(true)
             .argName("key=value")
-            .build();
+            .get();
 
     static List<StartupCommand> parseOfbizCommands(final String[] args) throws StartupException {
         CommandLine commandLine = null;
@@ -174,21 +172,25 @@ public final class StartupCommandUtil {
     }
 
     static void printOfbizStartupHelp(final PrintStream printStream) {
-        HelpFormatter formatter = new HelpFormatter();
-        formatter.printHelp(
-                new PrintWriter(new OutputStreamWriter(printStream, StandardCharsets.UTF_8), true),
-                HelpFormatter.DEFAULT_WIDTH + 6,
-                "ofbiz|ofbizDebug|ofbizBackground",
-                System.lineSeparator() + "Executes OFBiz command e.g. start, shutdown, check status, etc",
-                getOfbizStartupOptions(),
-                HelpFormatter.DEFAULT_LEFT_PAD,
-                HelpFormatter.DEFAULT_DESC_PAD,
-                "note: Only one command can execute at a time. Portoffset may be appended."
-                    + System.lineSeparator()
-                    + "Also a command must be invoked separately for each argument e.g."
-                    + System.lineSeparator()
-                    + "gradlew \"ofbiz --test component=somecomp --test case=somecase\"",
-                true);
+        HelpFormatter.Builder builder = HelpFormatter.builder();
+        builder.setShowSince(false);
+        builder.setHelpAppendable(new TextHelpAppendable(printStream));
+        HelpFormatter formatter = builder.get();
+        try {
+            formatter.printHelp(
+                    "ofbiz|ofbizDebug|ofbizBackground",
+                    System.lineSeparator() + "Executes OFBiz command e.g. start, shutdown, check status, etc",
+                    getOfbizStartupOptions(),
+                    "note: Only one command can execute at a time. Portoffset may be appended."
+                        + System.lineSeparator()
+                        + "Also a command must be invoked separately for each argument e.g."
+                        + System.lineSeparator()
+                        + "gradlew \"ofbiz --test component=somecomp --test case=somecase\"",
+                    true);
+        } catch (Exception e) {
+            // In case of any exception during help printing, print a simple help message without formatting
+            printStream.println("Usage: ofbiz|ofbizDebug|ofbizBackground [options]");
+        }
     }
 
     static void highlightAndPrintErrorMessage(String errorMessage) {