logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rpo...@apache.org
Subject svn commit: r1555352 - in /logging/log4j/log4j2/trunk: log4j-core/src/main/java/org/apache/logging/log4j/core/helpers/ log4j-core/src/test/java/org/apache/logging/log4j/core/helpers/ log4j-core/src/test/resources/ src/changes/
Date Sat, 04 Jan 2014 14:50:10 GMT
Author: rpopma
Date: Sat Jan  4 14:50:09 2014
New Revision: 1555352

URL: http://svn.apache.org/r1555352
Log:
LOG4J2-466 fix for config files with a '+' character in their path

Added:
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/helpers/FileUtilsTest.java
  (with props)
    logging/log4j/log4j2/trunk/log4j-core/src/test/resources/log4j+config+with+plus+characters.xml
  (with props)
Modified:
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/helpers/FileUtils.java
    logging/log4j/log4j2/trunk/src/changes/changes.xml

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/helpers/FileUtils.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/helpers/FileUtils.java?rev=1555352&r1=1555351&r2=1555352&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/helpers/FileUtils.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/helpers/FileUtils.java
Sat Jan  4 14:50:09 2014
@@ -63,7 +63,11 @@ public final class FileUtils {
             }
         }
         try {
-            return new File(URLDecoder.decode(uri.toURL().getFile(), "UTF8"));
+            String fileName = uri.toURL().getFile();
+            if (new File(fileName).exists()) {
+                return new File(fileName);
+            }
+            return new File(URLDecoder.decode(fileName, "UTF8"));
         } catch (final MalformedURLException ex) {
             LOGGER.warn("Invalid URL " + uri, ex);
         } catch (final UnsupportedEncodingException uee) {

Added: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/helpers/FileUtilsTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/helpers/FileUtilsTest.java?rev=1555352&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/helpers/FileUtilsTest.java
(added)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/helpers/FileUtilsTest.java
Sat Jan  4 14:50:09 2014
@@ -0,0 +1,50 @@
+/*
+ * 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.core.helpers;
+
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.net.URI;
+
+import org.junit.Test;
+
+/**
+ * Tests the FileUtils class.
+ */
+public class FileUtilsTest {
+
+    @Test
+    public void testFileFromUriWithPlusCharactersInName() throws Exception {
+        String CONFIG = "target/test-classes/log4j+config+with+plus+characters.xml";
+        URI uri = new URI(CONFIG);
+        File file = FileUtils.fileFromURI(uri);
+        assertEquals("log4j+config+with+plus+characters.xml", file.getName());
+        assertTrue("file exists", file.exists());
+    }
+
+    @Test
+    public void testFileFromUriWithPlusCharactersConvertedToSpacesIfFileDoesNotExist()
+            throws Exception {
+        String CONFIG = "NON-EXISTING-PATH/this+file+does+not+exist.xml";
+        URI uri = new URI(CONFIG);
+        File file = FileUtils.fileFromURI(uri);
+        assertEquals("this file does not exist.xml", file.getName());
+        assertFalse("file does not exist", file.exists());
+    }
+}

Propchange: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/helpers/FileUtilsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: logging/log4j/log4j2/trunk/log4j-core/src/test/resources/log4j+config+with+plus+characters.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/resources/log4j%2Bconfig%2Bwith%2Bplus%2Bcharacters.xml?rev=1555352&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/resources/log4j+config+with+plus+characters.xml
(added)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/resources/log4j+config+with+plus+characters.xml
Sat Jan  4 14:50:09 2014
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+
+-->
+<Configuration status="ERROR" name="XMLConfigTest" packages="org.apache.logging.log4j.test">
+
+  <Appenders>
+    <List name="List">
+    </List>
+  </Appenders>
+  <Loggers>
+    <Root level="trace">
+      <AppenderRef ref="List"/>
+    </Root>
+  </Loggers>
+
+</Configuration>
\ No newline at end of file

Propchange: logging/log4j/log4j2/trunk/log4j-core/src/test/resources/log4j+config+with+plus+characters.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1555352&r1=1555351&r2=1555352&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Sat Jan  4 14:50:09 2014
@@ -21,6 +21,9 @@
   </properties>
   <body>
     <release version="2.0-RC1" date="2013-MM-DD" description="Bug fixes and enhancements">
+      <action issue="LOG4J2-466" dev="rpopma" type="fix" due-to="Jan Tepke">
+        Cannot load log4j2 config file if path contains plus '+' characters.
+      </action>
       <action issue="LOG4J2-462" dev="rpopma" type="fix" due-to="Daisuke Baba">
         Fix LogEvent to never return null Level, fixes LevelPatternConverter.format may throw
NPE.
       </action>



Mime
View raw message