Apache Lucene open-source search software
SOLR-1072: absolute paths used in sharedLib now work. new FileUtils method added for dealing with this kind of path resolution
Chris M. Hostetter48098e25e781
diff --git a/CHANGES.txt b/CHANGES.txtindex 14d979ea2d7..a34fa6e4ddd 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -304,6 +304,10 @@ Bug Fixes34. SOLR-1064: registry.jsp incorrectly displaying info for last core initializedregardless of what the current core is. (hossman)+35. SOLR-1072: absolute paths used in sharedLib attribute were+ incorrectly treated as relative paths. (hossman)++Other Changes----------------------1. Upgraded to Lucene 2.4.0 (yonik)diff --git a/src/common/org/apache/solr/common/util/FileUtils.java b/src/common/org/apache/solr/common/util/FileUtils.javanew file mode 100644index 00000000000..b138310a9b5--- /dev/null+++ b/src/common/org/apache/solr/common/util/FileUtils.java@@ -0,0 +1,43 @@+/**+ * 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.solr.common.util;++import java.io.File;+import java.io.IOException;++/**+ * @version $Id$+ */+public class FileUtils {++ /**+ * Resolves a path relative a base directory.+ *+ * <p>+ * This method does what "new File(base,path)" <b>Should</b> do, it it wasn't+ * completley lame: If path is absolute, then a File for that path is returned;+ * if it's not absoluve, then a File is returnd using "path" as a child+ * of "base")+ * </p>+ */+ public static File resolvePath(File base, String path) throws IOException {+ File r = new File(path);+ return r.isAbsolute() ? r : new File(base, path);+ }++}diff --git a/src/java/org/apache/solr/core/CoreContainer.java b/src/java/org/apache/solr/core/CoreContainer.javaindex e989f809aa5..42808f77920 100644--- a/src/java/org/apache/solr/core/CoreContainer.java+++ b/src/java/org/apache/solr/core/CoreContainer.java@@ -39,6 +39,7 @@ import org.apache.solr.common.params.CoreAdminParams;import org.apache.solr.common.util.DOMUtil;import org.apache.solr.common.util.XML;import org.apache.solr.common.util.StrUtils;+import org.apache.solr.common.util.FileUtils;import org.apache.solr.handler.admin.CoreAdminHandler;import org.apache.solr.schema.IndexSchema;import org.w3c.dom.Node;@@ -176,9 +177,7 @@ public class CoreContainermanagementPath = cfg.get("solr/cores/@managementPath", null );if (libDir != null) {- // relative dir to conf- File f = new File(dir, libDir);- libDir = f.getPath();+ File f = FileUtils.resolvePath(new File(dir), libDir);log.info( "loading shared library: "+f.getAbsolutePath() );libLoader = SolrResourceLoader.createClassLoader(f, null);}diff --git a/src/test/org/apache/solr/common/util/FileUtilsTest.java b/src/test/org/apache/solr/common/util/FileUtilsTest.javanew file mode 100644index 00000000000..2d27d8572a8--- /dev/null+++ b/src/test/org/apache/solr/common/util/FileUtilsTest.java@@ -0,0 +1,32 @@+/**+ * 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.solr.common.util;++import java.io.File;+import java.io.IOException;++import junit.framework.TestCase;++public class FileUtilsTest extends TestCase {++ public void testResolve() throws IOException {+ assertEquals(new File("conf/data"), FileUtils.resolvePath(new File("conf"), "data"));+ assertEquals(new File("/conf/data"), FileUtils.resolvePath(new File("/conf"), "data"));+ assertEquals(new File("/data"), FileUtils.resolvePath(new File("conf"), "/data"));+ }+}