You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by kw...@apache.org on 2017/11/22 15:57:10 UTC

[1/2] qpid-broker-j git commit: QPID-7892: [Java Broker] Escape regexp special characters in logback file name pattern for rolled log files

Repository: qpid-broker-j
Updated Branches:
  refs/heads/6.1.x bc81238bf -> b1eecae10


QPID-7892: [Java Broker] Escape regexp special characters in logback file name pattern for rolled log files

Cherry picked from master 8c26b53.


Project: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/commit/b3a65d50
Tree: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/tree/b3a65d50
Diff: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/diff/b3a65d50

Branch: refs/heads/6.1.x
Commit: b3a65d505a510c1b6ecf55db644d5bab33eba7ab
Parents: bc81238
Author: Alex Rudyy <or...@apache.org>
Authored: Thu Aug 31 13:42:24 2017 +0100
Committer: Keith Wall <kw...@apache.org>
Committed: Wed Nov 22 15:48:03 2017 +0000

----------------------------------------------------------------------
 .../logging/logback/RollingPolicyDecorator.java | 67 ++++++++++++++------
 1 file changed, 47 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/b3a65d50/broker-plugins/logging-logback/src/main/java/org/apache/qpid/server/logging/logback/RollingPolicyDecorator.java
----------------------------------------------------------------------
diff --git a/broker-plugins/logging-logback/src/main/java/org/apache/qpid/server/logging/logback/RollingPolicyDecorator.java b/broker-plugins/logging-logback/src/main/java/org/apache/qpid/server/logging/logback/RollingPolicyDecorator.java
index 1f8e49a..0d20a22 100644
--- a/broker-plugins/logging-logback/src/main/java/org/apache/qpid/server/logging/logback/RollingPolicyDecorator.java
+++ b/broker-plugins/logging-logback/src/main/java/org/apache/qpid/server/logging/logback/RollingPolicyDecorator.java
@@ -74,8 +74,9 @@ public class RollingPolicyDecorator implements RollingPolicy
 
         String filePathPattern = _decorated.getFileNamePattern();
         String filePathRegExp = new FileNamePattern(filePathPattern, _decorated.getContext()).toRegex();
-        _rolledFilesBaseFolder = getRolledFilesBaseFolderFromRegExp(filePathRegExp);
-        _rolledFileRegExp = Pattern.compile(filePathRegExp);
+        FilePathBaseFolderAndPatternPair pair = new FilePathBaseFolderAndPatternPair(filePathRegExp);
+        _rolledFilesBaseFolder = pair.getBaseFolder();
+        _rolledFileRegExp = pair.getPattern();
         _currentScanTask = null;
     }
 
@@ -159,24 +160,6 @@ public class RollingPolicyDecorator implements RollingPolicy
         return task;
     }
 
-    private Path getRolledFilesBaseFolderFromRegExp(String fileNamePattern)
-    {
-        int firstDigitPatternPosition= fileNamePattern.indexOf("\\d");
-        if (firstDigitPatternPosition == -1)
-        {
-            throw new RuntimeException("Rolling policy file pattern does not seem to contain date or integer token");
-        }
-        int slashBeforeDigitPatternPosition = fileNamePattern.lastIndexOf("/", firstDigitPatternPosition);
-        if (slashBeforeDigitPatternPosition != -1)
-        {
-            return new File(fileNamePattern.substring(0, slashBeforeDigitPatternPosition)).toPath().toAbsolutePath();
-        }
-        else
-        {
-            return new File(System.getProperty("user.dir")).toPath().toAbsolutePath();
-        }
-    }
-
     private class ScanTask implements Runnable
     {
         private int _rescanCounter;
@@ -309,4 +292,48 @@ public class RollingPolicyDecorator implements RollingPolicy
         }
 
     }
+
+    private static class FilePathBaseFolderAndPatternPair
+    {
+        private static Pattern REGEX_SPECIAL_CHARACTERS = Pattern.compile("[{}()\\[\\].+*?^$\\\\|]");
+        private final Path _baseFolder;
+        private final Pattern _pattern;
+
+        public FilePathBaseFolderAndPatternPair(String fileNamePattern)
+        {
+            String path;
+            int firstDigitPatternPosition= fileNamePattern.indexOf("\\d");
+            if (firstDigitPatternPosition == -1)
+            {
+                throw new RuntimeException("Rolling policy file pattern does not seem to contain date or integer token");
+            }
+            int slashBeforeDigitPatternPosition = fileNamePattern.lastIndexOf("/", firstDigitPatternPosition);
+            if (slashBeforeDigitPatternPosition != -1)
+            {
+                path = fileNamePattern.substring(0, slashBeforeDigitPatternPosition);
+                fileNamePattern = fileNamePattern.substring( slashBeforeDigitPatternPosition + 1);
+            }
+            else
+            {
+                path = System.getProperty("user.dir");
+            }
+            _baseFolder = new File(path).toPath().toAbsolutePath();
+            _pattern = Pattern.compile(escape(path) + "/" + fileNamePattern);
+        }
+
+        private String escape(String string)
+        {
+            return REGEX_SPECIAL_CHARACTERS.matcher(string).replaceAll("\\\\$0");
+        }
+
+        public Path getBaseFolder()
+        {
+            return _baseFolder;
+        }
+
+        public Pattern getPattern()
+        {
+            return _pattern;
+        }
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


[2/2] qpid-broker-j git commit: QPID-7892: [Java Broker] Use Pattern#quote instead of own regexp escaping

Posted by kw...@apache.org.
QPID-7892: [Java Broker] Use Pattern#quote instead of own regexp escaping

Cherry picked from master 11a74ca.


Project: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/commit/b1eecae1
Tree: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/tree/b1eecae1
Diff: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/diff/b1eecae1

Branch: refs/heads/6.1.x
Commit: b1eecae10f741f1564d1b04982da6be3427481e4
Parents: b3a65d5
Author: Alex Rudyy <or...@apache.org>
Authored: Mon Sep 4 13:02:43 2017 +0100
Committer: Keith Wall <kw...@apache.org>
Committed: Wed Nov 22 15:48:36 2017 +0000

----------------------------------------------------------------------
 .../qpid/server/logging/logback/RollingPolicyDecorator.java  | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/b1eecae1/broker-plugins/logging-logback/src/main/java/org/apache/qpid/server/logging/logback/RollingPolicyDecorator.java
----------------------------------------------------------------------
diff --git a/broker-plugins/logging-logback/src/main/java/org/apache/qpid/server/logging/logback/RollingPolicyDecorator.java b/broker-plugins/logging-logback/src/main/java/org/apache/qpid/server/logging/logback/RollingPolicyDecorator.java
index 0d20a22..2d56156 100644
--- a/broker-plugins/logging-logback/src/main/java/org/apache/qpid/server/logging/logback/RollingPolicyDecorator.java
+++ b/broker-plugins/logging-logback/src/main/java/org/apache/qpid/server/logging/logback/RollingPolicyDecorator.java
@@ -295,7 +295,6 @@ public class RollingPolicyDecorator implements RollingPolicy
 
     private static class FilePathBaseFolderAndPatternPair
     {
-        private static Pattern REGEX_SPECIAL_CHARACTERS = Pattern.compile("[{}()\\[\\].+*?^$\\\\|]");
         private final Path _baseFolder;
         private final Pattern _pattern;
 
@@ -318,12 +317,7 @@ public class RollingPolicyDecorator implements RollingPolicy
                 path = System.getProperty("user.dir");
             }
             _baseFolder = new File(path).toPath().toAbsolutePath();
-            _pattern = Pattern.compile(escape(path) + "/" + fileNamePattern);
-        }
-
-        private String escape(String string)
-        {
-            return REGEX_SPECIAL_CHARACTERS.matcher(string).replaceAll("\\\\$0");
+            _pattern = Pattern.compile(Pattern.quote(path) + "/" + fileNamePattern);
         }
 
         public Path getBaseFolder()


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org