You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by ho...@apache.org on 2009/03/17 07:18:06 UTC

svn commit: r755130 - in /lucene/solr/trunk: CHANGES.txt src/common/org/apache/solr/common/util/FileUtils.java src/java/org/apache/solr/core/CoreContainer.java src/test/org/apache/solr/common/util/FileUtilsTest.java

Author: hossman
Date: Tue Mar 17 06:18:06 2009
New Revision: 755130

URL: http://svn.apache.org/viewvc?rev=755130&view=rev
Log:
SOLR-1072: absolute paths used in sharedLib now work.  new FileUtils method added for dealing with this kind of path resolution

Added:
    lucene/solr/trunk/src/common/org/apache/solr/common/util/FileUtils.java   (with props)
    lucene/solr/trunk/src/test/org/apache/solr/common/util/FileUtilsTest.java   (with props)
Modified:
    lucene/solr/trunk/CHANGES.txt
    lucene/solr/trunk/src/java/org/apache/solr/core/CoreContainer.java

Modified: lucene/solr/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/CHANGES.txt?rev=755130&r1=755129&r2=755130&view=diff
==============================================================================
--- lucene/solr/trunk/CHANGES.txt (original)
+++ lucene/solr/trunk/CHANGES.txt Tue Mar 17 06:18:06 2009
@@ -304,6 +304,10 @@
 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)

Added: lucene/solr/trunk/src/common/org/apache/solr/common/util/FileUtils.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/common/org/apache/solr/common/util/FileUtils.java?rev=755130&view=auto
==============================================================================
--- lucene/solr/trunk/src/common/org/apache/solr/common/util/FileUtils.java (added)
+++ lucene/solr/trunk/src/common/org/apache/solr/common/util/FileUtils.java Tue Mar 17 06:18:06 2009
@@ -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);
+  }
+
+}

Propchange: lucene/solr/trunk/src/common/org/apache/solr/common/util/FileUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: lucene/solr/trunk/src/common/org/apache/solr/common/util/FileUtils.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: lucene/solr/trunk/src/java/org/apache/solr/core/CoreContainer.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/core/CoreContainer.java?rev=755130&r1=755129&r2=755130&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/core/CoreContainer.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/core/CoreContainer.java Tue Mar 17 06:18:06 2009
@@ -39,6 +39,7 @@
 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 @@
       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);
       }

Added: lucene/solr/trunk/src/test/org/apache/solr/common/util/FileUtilsTest.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/test/org/apache/solr/common/util/FileUtilsTest.java?rev=755130&view=auto
==============================================================================
--- lucene/solr/trunk/src/test/org/apache/solr/common/util/FileUtilsTest.java (added)
+++ lucene/solr/trunk/src/test/org/apache/solr/common/util/FileUtilsTest.java Tue Mar 17 06:18:06 2009
@@ -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"));
+  }
+}

Propchange: lucene/solr/trunk/src/test/org/apache/solr/common/util/FileUtilsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: lucene/solr/trunk/src/test/org/apache/solr/common/util/FileUtilsTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL