You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ma...@apache.org on 2017/02/05 21:30:58 UTC

[1/2] logging-log4j2 git commit: Update property tokenizer to support ENV_VAR_STYLE

Repository: logging-log4j2
Updated Branches:
  refs/heads/LOG4J2-1431 a9bcf176c -> 7ae6b8a87


Update property tokenizer to support ENV_VAR_STYLE

This makes the property name tokenizer now support case-insensitive log4j(2) prefixes only at the beginning of a property name.

Also adds a missing license header.


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/5cb84670
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/5cb84670
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/5cb84670

Branch: refs/heads/LOG4J2-1431
Commit: 5cb84670b2b6c3745dcd9c854a5d7477a3389348
Parents: a9bcf17
Author: Matt Sicker <bo...@gmail.com>
Authored: Sun Feb 5 15:29:58 2017 -0600
Committer: Matt Sicker <bo...@gmail.com>
Committed: Sun Feb 5 15:29:58 2017 -0600

----------------------------------------------------------------------
 .../logging/log4j/util/PropertySource.java      | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/5cb84670/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertySource.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertySource.java b/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertySource.java
index 4dd9cf3..a197aec 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertySource.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertySource.java
@@ -1,3 +1,19 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
 package org.apache.logging.log4j.util;
 
 import java.io.Serializable;
@@ -60,8 +76,8 @@ public interface PropertySource {
      * @since 2.9
      */
     final class Util {
-        private static final String PREFIXES = "(?:[Ll]og4j2?|org\\.apache\\.logging\\.log4j\\.)?";
-        private static final Pattern PROPERTY_TOKENIZER = Pattern.compile(PREFIXES + "([A-Z]*[a-z0-9]+)[-._/]?");
+        private static final String PREFIXES = "(?i:^log4j2?[-._/]?|^org\\.apache\\.logging\\.log4j\\.)?";
+        private static final Pattern PROPERTY_TOKENIZER = Pattern.compile(PREFIXES + "([A-Z]*[a-z0-9]+|[A-Z0-9]+)[-._/]?");
         private static final Map<CharSequence, List<CharSequence>> CACHE = new ConcurrentHashMap<>();
 
         /**


[2/2] logging-log4j2 git commit: Add unit tests for property sources and utilities

Posted by ma...@apache.org.
Add unit tests for property sources and utilities


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/7ae6b8a8
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/7ae6b8a8
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/7ae6b8a8

Branch: refs/heads/LOG4J2-1431
Commit: 7ae6b8a87dd5da4ea4e454356fe9401ecf1581d1
Parents: 5cb8467
Author: Matt Sicker <bo...@gmail.com>
Authored: Sun Feb 5 15:30:48 2017 -0600
Committer: Matt Sicker <bo...@gmail.com>
Committed: Sun Feb 5 15:30:48 2017 -0600

----------------------------------------------------------------------
 .../util/EnvironmentPropertySourceTest.java     | 58 ++++++++++++++++
 .../util/PropertiesPropertySourceTest.java      | 59 +++++++++++++++++
 .../log4j/util/PropertySourceCamelCaseTest.java | 57 ++++++++++++++++
 .../log4j/util/PropertySourceTokenizerTest.java | 69 ++++++++++++++++++++
 4 files changed, 243 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7ae6b8a8/log4j-api/src/test/java/org/apache/logging/log4j/util/EnvironmentPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/util/EnvironmentPropertySourceTest.java b/log4j-api/src/test/java/org/apache/logging/log4j/util/EnvironmentPropertySourceTest.java
new file mode 100644
index 0000000..3beea89
--- /dev/null
+++ b/log4j-api/src/test/java/org/apache/logging/log4j/util/EnvironmentPropertySourceTest.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.util;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ *
+ */
+@RunWith(Parameterized.class)
+public class EnvironmentPropertySourceTest {
+
+    private final PropertySource source = new EnvironmentPropertySource();
+    private final CharSequence expected;
+    private final List<? extends CharSequence> tokens;
+
+    public EnvironmentPropertySourceTest(final CharSequence expected, final List<? extends CharSequence> tokens) {
+        this.expected = expected;
+        this.tokens = tokens;
+    }
+
+    @Parameterized.Parameters(name = "{0}")
+    public static Object[][] data() {
+        return new Object[][]{
+            {"LOG4J_CONFIGURATION_FILE", Arrays.asList("configuration", "file")},
+            {"LOG4J_FOO_BAR_PROPERTY", Arrays.asList("foo", "bar", "property")},
+            {"LOG4J_EXACT", Collections.singletonList("EXACT")},
+            {"LOG4J_TEST_PROPERTY_NAME", PropertySource.Util.tokenize("Log4jTestPropertyName")},
+        };
+    }
+
+    @Test
+    public void testNormalFormFollowsEnvironmentVariableConventions() throws Exception {
+        assertEquals(expected, source.getNormalForm(tokens));
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7ae6b8a8/log4j-api/src/test/java/org/apache/logging/log4j/util/PropertiesPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/util/PropertiesPropertySourceTest.java b/log4j-api/src/test/java/org/apache/logging/log4j/util/PropertiesPropertySourceTest.java
new file mode 100644
index 0000000..2f07972
--- /dev/null
+++ b/log4j-api/src/test/java/org/apache/logging/log4j/util/PropertiesPropertySourceTest.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.util;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Properties;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ *
+ */
+@RunWith(Parameterized.class)
+public class PropertiesPropertySourceTest {
+
+    private final PropertySource source = new PropertiesPropertySource(new Properties());
+    private final CharSequence expected;
+    private final List<? extends CharSequence> tokens;
+
+    public PropertiesPropertySourceTest(final String expected, final List<CharSequence> tokens) {
+        this.expected = expected;
+        this.tokens = tokens;
+    }
+
+    @Parameterized.Parameters(name = "{0}")
+    public static Object[][] data() {
+        return new Object[][]{
+            {"log4j2.configurationFile", Arrays.asList("configuration", "file")},
+            {"log4j2.fooBarProperty", Arrays.asList("foo", "bar", "property")},
+            {"log4j2.EXACT", Collections.singletonList("EXACT")},
+            {"log4j2.testPropertyName", PropertySource.Util.tokenize("Log4jTestPropertyName")},
+        };
+    }
+
+    @Test
+    public void testNormalFormFollowsCamelCaseConventions() throws Exception {
+        assertEquals(expected, source.getNormalForm(tokens));
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7ae6b8a8/log4j-api/src/test/java/org/apache/logging/log4j/util/PropertySourceCamelCaseTest.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/util/PropertySourceCamelCaseTest.java b/log4j-api/src/test/java/org/apache/logging/log4j/util/PropertySourceCamelCaseTest.java
new file mode 100644
index 0000000..c746199
--- /dev/null
+++ b/log4j-api/src/test/java/org/apache/logging/log4j/util/PropertySourceCamelCaseTest.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.util;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ *
+ */
+@RunWith(Parameterized.class)
+public class PropertySourceCamelCaseTest {
+
+    private final CharSequence expected;
+    private final List<String> tokens;
+
+    public PropertySourceCamelCaseTest(final CharSequence expected, final List<String> tokens) {
+        this.expected = expected;
+        this.tokens = tokens;
+    }
+
+    @Parameterized.Parameters(name = "{0}")
+    public static Object[][] data() {
+        return new Object[][]{
+            {"", Collections.singletonList("")},
+            {"foo", Collections.singletonList("foo")},
+            {"fooBar", Arrays.asList("foo", "bar")},
+            {"oneTwoThree", Arrays.asList("one", "two", "three")},
+        };
+    }
+
+    @Test
+    public void testJoinAsCamelCase() throws Exception {
+        assertEquals(expected, PropertySource.Util.joinAsCamelCase(tokens));
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7ae6b8a8/log4j-api/src/test/java/org/apache/logging/log4j/util/PropertySourceTokenizerTest.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/util/PropertySourceTokenizerTest.java b/log4j-api/src/test/java/org/apache/logging/log4j/util/PropertySourceTokenizerTest.java
new file mode 100644
index 0000000..3b25af7
--- /dev/null
+++ b/log4j-api/src/test/java/org/apache/logging/log4j/util/PropertySourceTokenizerTest.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.util;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ *
+ */
+@RunWith(Parameterized.class)
+public class PropertySourceTokenizerTest {
+
+    private final CharSequence value;
+    private final List<CharSequence> expectedTokens;
+
+    public PropertySourceTokenizerTest(final CharSequence value, final List<CharSequence> expectedTokens) {
+        this.value = value;
+        this.expectedTokens = expectedTokens;
+    }
+
+    @Parameterized.Parameters(name = "{0}")
+    public static Object[][] data() {
+        return new Object[][]{
+            {"log4j.simple", Collections.singletonList("simple")},
+            {"log4j_simple", Collections.singletonList("simple")},
+            {"log4j-simple", Collections.singletonList("simple")},
+            {"log4j/simple", Collections.singletonList("simple")},
+            {"log4j2.simple", Collections.singletonList("simple")},
+            {"Log4jSimple", Collections.singletonList("simple")},
+            {"LOG4J_simple", Collections.singletonList("simple")},
+            {"org.apache.logging.log4j.simple", Collections.singletonList("simple")},
+            {"log4j.simpleProperty", Arrays.asList("simple", "property")},
+            {"log4j.simple_property", Arrays.asList("simple", "property")},
+            {"LOG4J_simple_property", Arrays.asList("simple", "property")},
+            {"LOG4J_SIMPLE_PROPERTY", Arrays.asList("simple", "property")},
+            {"log4j2-dashed-propertyName", Arrays.asList("dashed", "property", "name")},
+            {"Log4jProperty_with.all-the/separators", Arrays.asList("property", "with", "all", "the", "separators")},
+            {"org.apache.logging.log4j.config.property", Arrays.asList("config", "property")},
+        };
+    }
+
+    @Test
+    public void testTokenize() throws Exception {
+        List<CharSequence> tokens = PropertySource.Util.tokenize(value);
+        assertEquals(expectedTokens, tokens);
+    }
+}
\ No newline at end of file