From 48098e25e7814d36ca7c56dd0131cf91174edd9b Mon Sep 17 00:00:00 2001 From: "Chris M. Hostetter" Date: Tue, 17 Mar 2009 06:18:06 +0000 Subject: [PATCH] SOLR-1072: absolute paths used in sharedLib now work. new FileUtils method added for dealing with this kind of path resolution git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@755130 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 4 ++ .../apache/solr/common/util/FileUtils.java | 43 +++++++++++++++++++ .../org/apache/solr/core/CoreContainer.java | 5 +-- .../solr/common/util/FileUtilsTest.java | 32 ++++++++++++++ 4 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 src/common/org/apache/solr/common/util/FileUtils.java create mode 100644 src/test/org/apache/solr/common/util/FileUtilsTest.java diff --git a/CHANGES.txt b/CHANGES.txt index 14d979ea2d7..a34fa6e4ddd 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -304,6 +304,10 @@ Bug Fixes 34. SOLR-1064: registry.jsp incorrectly displaying info for last core initialized regardless 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.java new file mode 100644 index 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. + * + *

+ * This method does what "new File(base,path)" Should 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") + *

+ */ + 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.java index 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 CoreContainer managementPath = 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.java new file mode 100644 index 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")); + } +}