You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by re...@apache.org on 2023/08/08 10:08:37 UTC

svn commit: r1911541 - in /jackrabbit/branches/2.20: ./ jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/Main.java

Author: reschke
Date: Tue Aug  8 10:08:37 2023
New Revision: 1911541

URL: http://svn.apache.org/viewvc?rev=1911541&view=rev
Log:
JCR-4957: jackrabbit-standalone: restore binary compat with 2.21.16 (merged r1911367 into 2.20)

Modified:
    jackrabbit/branches/2.20/   (props changed)
    jackrabbit/branches/2.20/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/Main.java

Propchange: jackrabbit/branches/2.20/
------------------------------------------------------------------------------
  Merged /jackrabbit/trunk:r1911367

Modified: jackrabbit/branches/2.20/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/Main.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.20/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/Main.java?rev=1911541&r1=1911540&r2=1911541&view=diff
==============================================================================
--- jackrabbit/branches/2.20/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/Main.java (original)
+++ jackrabbit/branches/2.20/jackrabbit-standalone-components/src/main/java/org/apache/jackrabbit/standalone/Main.java Tue Aug  8 10:08:37 2023
@@ -58,46 +58,13 @@ public class Main {
      */
     public static void main(String[] args) throws Exception {
         Options options = new Options();
+        CommandLine command = createCommand(args, options);
 
-        options.addOption("?", "help", false, "print this message");
-        options.addOption("n", "notice", false, "print copyright notices");
-        options.addOption("l", "license", false, "print license information");
-        options.addOption(
-                "b", "backup", false, "create a backup of the repository");
-        options.addOption(
-                "i", "cli", true, "command line access to a remote repository");
-
-        options.addOption("q", "quiet", false, "disable console output");
-        options.addOption("d", "debug", false, "enable debug logging");
-
-        options.addOption("h", "host", true, "IP address of the HTTP server");
-        options.addOption("p", "port", true, "TCP port of the HTTP server (8080)");
-        options.addOption("f", "file", true, "location of this jar file");
-        options.addOption("r", "repo", true, "repository directory (jackrabbit)");
-        options.addOption("c", "conf", true, "repository configuration file");
-        options.addOption(
-                "R", "backup-repo", true,
-                "backup repository directory (jackrabbit-backupN)");
-        options.addOption(
-                "C", "backup-conf", true,
-                "backup repository configuration file");
-
-        CommandLine command = new DefaultParser().parse(options, args);
-
-        String defaultFile = "jackrabbit-standalone.jar";
-        URL location =
-                Main.class.getProtectionDomain().getCodeSource().getLocation();
-        if (location != null && "file".equals(location.getProtocol())) {
-            File file = new File(location.getPath());
-            if (file.isFile()) {
-                defaultFile = location.getPath();
-            }
-        }
-        File file = new File(command.getOptionValue("file", defaultFile));
+        File jarFile = findJarFileLocation(command);
 
         if (command.hasOption("help")) {
             HelpFormatter formatter = new HelpFormatter();
-            formatter.printHelp("java -jar " + file.getName(), options, true);
+            formatter.printHelp("java -jar " + jarFile.getName(), options, true);
         } else if (command.hasOption("notice")) {
             copyToOutput("/META-INF/NOTICE.txt");
         } else if (command.hasOption("license")) {
@@ -126,53 +93,69 @@ public class Main {
                 // already logged out
             }
         } else {
-            File repository =
-                    new File(command.getOptionValue("repo", "jackrabbit"));
-            repository.mkdirs();
-            File log = new File(repository, "log");
-            log.mkdir();
-
-            if (!command.hasOption("quiet")) {
-                System.out.println("Using repository directory " + repository);
-                System.out.println("Writing log messages to " + log);
-            }
+            new Main(command).run(jarFile);
+        }
+    }
 
-            setSystemPropertyIfMissing(
-                    "jackrabbit.log",
-                    new File(log, "jackrabbit.log").getPath());
-            setSystemPropertyIfMissing(
-                    "jetty.log",
-                    new File(log, "jetty.log").getPath());
-
-            if (command.hasOption("debug")) {
-                setSystemPropertyIfMissing("log.level", "DEBUG");
-            } else {
-                setSystemPropertyIfMissing("log.level", "INFO");
-            }
+    private static CommandLine createCommand(String[] args, Options options) throws ParseException {
+        options.addOption("?", "help", false, "print this message");
+        options.addOption("n", "notice", false, "print copyright notices");
+        options.addOption("l", "license", false, "print license information");
+        options.addOption(
+                "b", "backup", false, "create a backup of the repository");
+        options.addOption(
+                "i", "cli", true, "command line access to a remote repository");
+
+        options.addOption("q", "quiet", false, "disable console output");
+        options.addOption("d", "debug", false, "enable debug logging");
 
-            setSystemPropertyIfMissing(
-                    "derby.stream.error.file",
-                    new File(log, "derby.log").getPath());
+        options.addOption("h", "host", true, "IP address of the HTTP server");
+        options.addOption("p", "port", true, "TCP port of the HTTP server (8080)");
+        options.addOption("f", "file", true, "location of this jar file");
+        options.addOption("r", "repo", true, "repository directory (jackrabbit)");
+        options.addOption("c", "conf", true, "repository configuration file");
+        options.addOption(
+                "R", "backup-repo", true,
+                "backup repository directory (jackrabbit-backupN)");
+        options.addOption(
+                "C", "backup-conf", true,
+                "backup repository configuration file");
 
-            new Main(command).run(file, repository, log);
+        return new DefaultParser().parse(options, args);
+    }
+    
+    private static File findJarFileLocation(CommandLine command) {
+        String defaultFile = "jackrabbit-standalone.jar";
+        URL location =
+                Main.class.getProtectionDomain().getCodeSource().getLocation();
+        if (location != null && "file".equals(location.getProtocol())) {
+            File file = new File(location.getPath());
+            if (file.isFile()) {
+                defaultFile = location.getPath();
+            }
         }
+        return new File(command.getOptionValue("file", defaultFile));
     }
-
+    
     private static void setSystemPropertyIfMissing(String key, String value) {
         if (System.getProperty(key) == null) {
             System.setProperty(key, value);
         }
     }
 
-    private CommandLine command;
+    private final CommandLine command;
+
+    private final RequestLogHandler accessLog;
 
-    private final RequestLogHandler accessLog = new RequestLogHandler();
+    private final WebAppContext webapp;
 
-    private final WebAppContext webapp = new WebAppContext();
+    private final Server server;
 
-    private final Server server = new Server();
+    private final ServerConnector connector;
 
-    private final ServerConnector connector = new ServerConnector(server);
+    private final File repository; 
+
+    private final File log; 
 
     /**
      * Construct Main application instance.
@@ -180,17 +163,69 @@ public class Main {
      * <EM>Note:</EM> Constructor is protected because other projects such as Commons VFS can extend this for some reasons
      *       (e.g, unit testing against Jackrabbit WebDAV).
      */
-    protected Main(CommandLine command) throws ParseException {
+    private Main(CommandLine command) throws ParseException {
         this.command = command;
+
+        repository = new File(command.getOptionValue("repo", "jackrabbit"));
+        repository.mkdirs();
+        log = new File(repository, "log");
+        log.mkdir();
+
+        if (!command.hasOption("quiet")) {
+            System.out.println("Using repository directory " + repository);
+            System.out.println("Writing log messages to " + log);
+        }
+
+        setSystemPropertyIfMissing(
+                "jackrabbit.log",
+                new File(log, "jackrabbit.log").getPath());
+        setSystemPropertyIfMissing(
+                "jetty.log",
+                new File(log, "jetty.log").getPath());
+
+        if (command.hasOption("debug")) {
+            setSystemPropertyIfMissing("log.level", "DEBUG");
+        } else {
+            setSystemPropertyIfMissing("log.level", "INFO");
+        }
+
+        setSystemPropertyIfMissing(
+                "derby.stream.error.file",
+                new File(log, "derby.log").getPath());
+
+        accessLog = new RequestLogHandler();
+        webapp = new WebAppContext();
+        server = new Server();
+        connector = new ServerConnector(server);
     }
 
     /**
+     * Construct Main application instance.
+     * <P>
+     * <EM>Note:</EM> Constructor is protected because other projects such as Commons VFS can extend this for some reasons
+     *       (e.g, unit testing against Jackrabbit WebDAV).
+     */
+    protected Main(String[] args) throws ParseException {
+        this(createCommand(args, new Options()));
+    }
+
+    /**
+     * Run this Main application.
+     * <P>
+     * <EM>Note:</EM> this is public because this can be used by other projects in unit tests. e.g, Commons-VFS.
+     * @throws Exception if any exception occurs
+     */
+    public void run() throws Exception {
+        run(findJarFileLocation(command));
+    }
+    
+    /**
      * Run this Main application.
      * <P>
      * <EM>Note:</EM> this is public because this can be used by other projects in unit tests. e.g, Commons-VFS.
      * @throws Exception if any exception occurs
      */
-    public void run(File file, File repository, File log) throws Exception {
+    private void run(File jarFile) throws Exception {
         message("Welcome to Apache Jackrabbit!");
         message("-------------------------------");
 
@@ -200,7 +235,7 @@ public class Main {
             message("Starting the server...");
             File tmp = new File(repository, "tmp");
             tmp.mkdir();
-            prepareWebapp(file, repository, tmp);
+            prepareWebapp(jarFile, repository, tmp);
             accessLog.setHandler(webapp);
             prepareAccessLog(log);
             server.setHandler(accessLog);