You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2019/12/16 12:18:47 UTC

[tomcat] branch master updated: BZ64006: Provide default configuration source that "works"

This is an automated email from the ASF dual-hosted git repository.

remm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/master by this push:
     new f09d395  BZ64006: Provide default configuration source that "works"
f09d395 is described below

commit f09d395c46a3a806e435dbf25ddf2b0e5708e983
Author: remm <re...@apache.org>
AuthorDate: Mon Dec 16 13:18:35 2019 +0100

    BZ64006: Provide default configuration source that "works"
    
    Although this will likely be revisited in Tomcat 10, the plan of the
    configuration source was not to break existing Tomcat 9 code. As a
    result, use a default source based on the user folder when none is
    specified. Although it would be better to log this, extra logs like this
    are usually not well received so skip that as well for now.
---
 java/org/apache/catalina/startup/Tomcat.java       | 31 ++-----------------
 .../apache/tomcat/util/file/ConfigFileLoader.java  |  8 ++---
 .../tomcat/util/file/ConfigurationSource.java      | 31 +++++++++++++++++++
 .../tomcat/util/file/LocalStrings.properties       | 16 ----------
 .../tomcat/util/file/LocalStrings_de.properties    | 16 ----------
 .../tomcat/util/file/LocalStrings_fr.properties    | 16 ----------
 .../tomcat/util/file/LocalStrings_ja.properties    | 16 ----------
 .../tomcat/util/file/LocalStrings_ko.properties    | 16 ----------
 .../tomcat/util/file/LocalStrings_zh_CN.properties | 16 ----------
 .../catalina/users/MemoryUserDatabaseTests.java    | 35 ----------------------
 webapps/docs/changelog.xml                         |  5 ++++
 11 files changed, 40 insertions(+), 166 deletions(-)

diff --git a/java/org/apache/catalina/startup/Tomcat.java b/java/org/apache/catalina/startup/Tomcat.java
index 21b2223..7230d1e 100644
--- a/java/org/apache/catalina/startup/Tomcat.java
+++ b/java/org/apache/catalina/startup/Tomcat.java
@@ -18,13 +18,11 @@ package org.apache.catalina.startup;
 
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.net.MalformedURLException;
-import java.net.URI;
 import java.net.URL;
 import java.net.URLConnection;
 import java.security.Principal;
@@ -1415,33 +1413,8 @@ public class Tomcat {
         org.apache.catalina.startup.Tomcat tomcat = new org.apache.catalina.startup.Tomcat();
         // Create a Catalina instance and let it parse the configuration files
         // It will also set a shutdown hook to stop the Server when needed
-        tomcat.init(new ConfigurationSource() {
-            protected final File userDir = new File(System.getProperty("user.dir"));
-            protected final URI userDirUri = userDir.toURI();
-            @Override
-            public Resource getResource(String name) throws IOException {
-                File f = new File(name);
-                if (!f.isAbsolute()) {
-                    f = new File(userDir, name);
-                }
-                if (f.isFile()) {
-                    return new Resource(new FileInputStream(f), f.toURI());
-                } else {
-                    throw new FileNotFoundException(name);
-                }
-            }
-            @Override
-            public URI getURI(String name) {
-                File f = new File(name);
-                if (!f.isAbsolute()) {
-                    f = new File(userDir, name);
-                }
-                if (f.isFile()) {
-                    return f.toURI();
-                }
-                return userDirUri.resolve(name);
-            }
-        });
+        // Use the default configuration source
+        tomcat.init(null);
         boolean await = false;
         String path = "";
         // Process command line parameters
diff --git a/java/org/apache/tomcat/util/file/ConfigFileLoader.java b/java/org/apache/tomcat/util/file/ConfigFileLoader.java
index febf827..ce0f5ee 100644
--- a/java/org/apache/tomcat/util/file/ConfigFileLoader.java
+++ b/java/org/apache/tomcat/util/file/ConfigFileLoader.java
@@ -21,8 +21,6 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.net.URI;
 
-import org.apache.tomcat.util.res.StringManager;
-
 /**
  * This class is used to obtain {@link InputStream}s for configuration files
  * from a given location String. This allows greater flexibility than these
@@ -30,14 +28,12 @@ import org.apache.tomcat.util.res.StringManager;
  */
 public class ConfigFileLoader {
 
-    private static final StringManager sm = StringManager.getManager(ConfigFileLoader.class
-            .getPackage().getName());
-
     private static ConfigurationSource source;
 
     public static final ConfigurationSource getSource() {
         if (ConfigFileLoader.source == null) {
-            throw new IllegalStateException(sm.getString("configFileLoader.noConfigurationSource"));
+            // TODO: Add logging in Tomcat 10 when the default is silently used, or remove the default
+            return ConfigurationSource.DEFAULT;
         }
         return source;
     }
diff --git a/java/org/apache/tomcat/util/file/ConfigurationSource.java b/java/org/apache/tomcat/util/file/ConfigurationSource.java
index ca8e2ce..43d5a25 100644
--- a/java/org/apache/tomcat/util/file/ConfigurationSource.java
+++ b/java/org/apache/tomcat/util/file/ConfigurationSource.java
@@ -16,6 +16,9 @@
  */
 package org.apache.tomcat.util.file;
 
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.MalformedURLException;
@@ -30,6 +33,34 @@ import java.net.URI;
  */
 public interface ConfigurationSource {
 
+    public static final ConfigurationSource DEFAULT = new ConfigurationSource() {
+        protected final File userDir = new File(System.getProperty("user.dir"));
+        protected final URI userDirUri = userDir.toURI();
+        @Override
+        public Resource getResource(String name) throws IOException {
+            File f = new File(name);
+            if (!f.isAbsolute()) {
+                f = new File(userDir, name);
+            }
+            if (f.isFile()) {
+                return new Resource(new FileInputStream(f), f.toURI());
+            } else {
+                throw new FileNotFoundException(name);
+            }
+        }
+        @Override
+        public URI getURI(String name) {
+            File f = new File(name);
+            if (!f.isAbsolute()) {
+                f = new File(userDir, name);
+            }
+            if (f.isFile()) {
+                return f.toURI();
+            }
+            return userDirUri.resolve(name);
+        }
+    };
+
     /**
      * Represents a resource: a stream to the resource associated with
      * its URI.
diff --git a/java/org/apache/tomcat/util/file/LocalStrings.properties b/java/org/apache/tomcat/util/file/LocalStrings.properties
deleted file mode 100644
index 017a560..0000000
--- a/java/org/apache/tomcat/util/file/LocalStrings.properties
+++ /dev/null
@@ -1,16 +0,0 @@
-# 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.
-
-configFileLoader.noConfigurationSource=No configuration source has been set using ConfigFileLoader.setSource.
diff --git a/java/org/apache/tomcat/util/file/LocalStrings_de.properties b/java/org/apache/tomcat/util/file/LocalStrings_de.properties
deleted file mode 100644
index a14023b..0000000
--- a/java/org/apache/tomcat/util/file/LocalStrings_de.properties
+++ /dev/null
@@ -1,16 +0,0 @@
-# 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.
-
-configFileLoader.noConfigurationSource=Es wurde keine Konfigurationsquelle per ConfigFileLoader.setSource gesetzt.
diff --git a/java/org/apache/tomcat/util/file/LocalStrings_fr.properties b/java/org/apache/tomcat/util/file/LocalStrings_fr.properties
deleted file mode 100644
index 51a0a8e..0000000
--- a/java/org/apache/tomcat/util/file/LocalStrings_fr.properties
+++ /dev/null
@@ -1,16 +0,0 @@
-# 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.
-
-configFileLoader.noConfigurationSource=Aucune source de configuration n'a été définie par ConfigFileLoader.setSource.
diff --git a/java/org/apache/tomcat/util/file/LocalStrings_ja.properties b/java/org/apache/tomcat/util/file/LocalStrings_ja.properties
deleted file mode 100644
index 010117c..0000000
--- a/java/org/apache/tomcat/util/file/LocalStrings_ja.properties
+++ /dev/null
@@ -1,16 +0,0 @@
-# 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.
-
-configFileLoader.noConfigurationSource=ConfigFileLoader.setSourceを使用して設定ソースが設定されていません。
diff --git a/java/org/apache/tomcat/util/file/LocalStrings_ko.properties b/java/org/apache/tomcat/util/file/LocalStrings_ko.properties
deleted file mode 100644
index cc5f9fb..0000000
--- a/java/org/apache/tomcat/util/file/LocalStrings_ko.properties
+++ /dev/null
@@ -1,16 +0,0 @@
-# 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.
-
-configFileLoader.noConfigurationSource=ConfigFileLoader.setSource를 사용하여, 설정 원본이 설정되지 않았습니다.
diff --git a/java/org/apache/tomcat/util/file/LocalStrings_zh_CN.properties b/java/org/apache/tomcat/util/file/LocalStrings_zh_CN.properties
deleted file mode 100644
index 31a7253..0000000
--- a/java/org/apache/tomcat/util/file/LocalStrings_zh_CN.properties
+++ /dev/null
@@ -1,16 +0,0 @@
-# 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.
-
-configFileLoader.noConfigurationSource=没有配置源时,采用ConfigFileLoader.setSource 配置
diff --git a/test/org/apache/catalina/users/MemoryUserDatabaseTests.java b/test/org/apache/catalina/users/MemoryUserDatabaseTests.java
index 98e10b5..97ec3fa 100644
--- a/test/org/apache/catalina/users/MemoryUserDatabaseTests.java
+++ b/test/org/apache/catalina/users/MemoryUserDatabaseTests.java
@@ -19,11 +19,7 @@ package org.apache.catalina.users;
 
 import java.io.BufferedWriter;
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.FileWriter;
-import java.io.IOException;
-import java.net.URI;
 import java.security.Principal;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -34,8 +30,6 @@ import org.junit.BeforeClass;
 import org.junit.Test;
 
 import org.apache.catalina.User;
-import org.apache.tomcat.util.file.ConfigFileLoader;
-import org.apache.tomcat.util.file.ConfigurationSource;
 
 public class MemoryUserDatabaseTests {
     private static File TEST_FILE = new File(System.getProperty("java.io.tmpdir"), "tomcat-users.xml");
@@ -58,35 +52,6 @@ public class MemoryUserDatabaseTests {
                     + "</tomcat-users>");
         }
 
-        // MemoryUserDatabase requires the use of ConfigFileLoader/ConfigurationSource
-        ConfigFileLoader.setSource(new ConfigurationSource() {
-            protected final File userDir = new File(System.getProperty("java.io.tmpdir"));
-            protected final URI userDirUri = userDir.toURI();
-            @Override
-            public Resource getResource(String name) throws IOException {
-                File f = new File(name);
-                if (!f.isAbsolute()) {
-                    f = new File(userDir, name);
-                }
-                if (f.isFile()) {
-                    return new Resource(new FileInputStream(f), f.toURI());
-                } else {
-                    throw new FileNotFoundException(name);
-                }
-            }
-            @Override
-            public URI getURI(String name) {
-                File f = new File(name);
-                if (!f.isAbsolute()) {
-                    f = new File(userDir, name);
-                }
-                if (f.isFile()) {
-                    return f.toURI();
-                }
-                return userDirUri.resolve(name);
-            }
-        });
-
         db = new MemoryUserDatabase();
         db.setPathname(TEST_FILE.getAbsolutePath());
         db.open();
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index c4d600a..e75c7d3 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -55,6 +55,11 @@
         Avoid useless environment restore when not using GSSCredential
         in JNDIRealm. (remm)
       </fix>
+      <fix>
+        <bug>64006</bug>: Provide default configuration source based on the
+        current directory if none has been set, for full compatibility with
+        existing code. (remm)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Coyote">


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org