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
This commit is contained in:
Chris M. Hostetter 2009-03-17 06:18:06 +00:00
parent f1a4aba6be
commit 48098e25e7
4 changed files with 81 additions and 3 deletions

View File

@ -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)

View File

@ -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);
}
}

View File

@ -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);
}

View File

@ -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"));
}
}