You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by tr...@apache.org on 2018/04/03 00:11:26 UTC

svn commit: r1828191 - in /jackrabbit/commons/filevault/trunk/vault-cli/src/main: appassembler/unix-template.sh appassembler/windows-template.bat java/org/apache/jackrabbit/vault/cli/VaultFsApp.java

Author: tripod
Date: Tue Apr  3 00:11:25 2018
New Revision: 1828191

URL: http://svn.apache.org/viewvc?rev=1828191&view=rev
Log:
JCRVLT-284 Add support through environment var to directly control the line separator (fix #21)

Modified:
    jackrabbit/commons/filevault/trunk/vault-cli/src/main/appassembler/unix-template.sh
    jackrabbit/commons/filevault/trunk/vault-cli/src/main/appassembler/windows-template.bat
    jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/cli/VaultFsApp.java

Modified: jackrabbit/commons/filevault/trunk/vault-cli/src/main/appassembler/unix-template.sh
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-cli/src/main/appassembler/unix-template.sh?rev=1828191&r1=1828190&r2=1828191&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-cli/src/main/appassembler/unix-template.sh (original)
+++ jackrabbit/commons/filevault/trunk/vault-cli/src/main/appassembler/unix-template.sh Tue Apr  3 00:11:25 2018
@@ -12,6 +12,11 @@
 #  VLT_OPTS - parameters passed to the Java VM when running Vault
 #    e.g. to debug vault itself, use
 #      set VLT_OPTS=-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
+#
+# LINE SEPARATOR
+# Because it can be pretty tricky to shove a newline character into a batch or shell script and the text "\n" doesn't get
+# interpreted as what you might think by Java, vlt will instead look for LF | CRLF in a system property called vlt.line.separator
+# and if it exists, it will set the appropriate Java System property accordingly, e.g. -Dvlt.line.separator=LF
 #----------------------------------------------------------------------------
 
 if [ -f /etc/vaultrc ] ; then

Modified: jackrabbit/commons/filevault/trunk/vault-cli/src/main/appassembler/windows-template.bat
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-cli/src/main/appassembler/windows-template.bat?rev=1828191&r1=1828190&r2=1828191&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-cli/src/main/appassembler/windows-template.bat (original)
+++ jackrabbit/commons/filevault/trunk/vault-cli/src/main/appassembler/windows-template.bat Tue Apr  3 00:11:25 2018
@@ -11,6 +11,11 @@
 @REM VLT_OPTS - parameters passed to the Java VM when running vlt
 @REM     e.g. to debug vlt itself, use
 @REM set VLT_OPTS=-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
+@REM
+@REM LINE SEPARATOR
+@REM Because it can be pretty tricky to shove a newline character into a batch or shell script and the text "\n" doesn't get
+@REM interpreted as what you might think by Java, vlt will instead look for LF | CRLF in a system property called vlt.line.separator
+@REM and if it exists, it will set the appropriate Java System property accordingly, e.g. -Dvlt.line.separator=LF
 @REM ----------------------------------------------------------------------------
 
 @REM Begin all REM lines with '@' in case VLT_BATCH_ECHO is 'on'

Modified: jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/cli/VaultFsApp.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/cli/VaultFsApp.java?rev=1828191&r1=1828190&r2=1828191&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/cli/VaultFsApp.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/cli/VaultFsApp.java Tue Apr  3 00:11:25 2018
@@ -126,7 +126,6 @@ public class VaultFsApp extends Abstract
         new VaultFsApp().run(args);
     }
 
-
     public VaultFsApp() {
     }
 
@@ -460,6 +459,7 @@ public class VaultFsApp extends Abstract
      */
     protected void init() {
         super.init();
+        initLineSeparator();
 
         // init providers
         repProvider = new RepositoryProvider();
@@ -509,6 +509,29 @@ public class VaultFsApp extends Abstract
     }
 
     /**
+     * initializes the process wide line separator based on the {@code vlt.line.separator} system property. This helps
+     * supporting windows batch files, where passing a different line separator is very difficult via script.
+     *
+     * <ul>
+     * <li>if {@code vlt.line.separator} is {@code "LF"}, the java system property {@code line.separator} will be set to {@code "\n"}.</li>
+     * <li>if {@code vlt.line.separator} is {@code "CRLF"}, the java system property {@code line.separator} will be set to {@code "\r\n"}.</li>
+     * <li>if {@code vlt.line.separator} is missing, the system property will not be altered.</li>
+     * </ul>
+     */
+    private static void initLineSeparator() {
+        final String vltSep = System.getProperty("vlt.line.separator");
+        if (vltSep != null) {
+            if ("LF".equals(vltSep)) {
+                System.setProperty("line.separator","\n");
+            } else if ("CRLF".equals(vltSep)) {
+                System.setProperty("line.separator","\r\n");
+            } else {
+                log.warn("Warning, invalid vtl.line.separator value '{}' ignored", vltSep);
+            }
+        }
+    }
+
+    /**
      * {@inheritDoc}
      */
     protected void close() {