lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From uschind...@apache.org
Subject svn commit: r1457695 - in /lucene/dev/branches/lucene_solr_4_2: ./ lucene/ lucene/analysis/ lucene/analysis/common/src/java/org/apache/lucene/analysis/util/ lucene/core/ lucene/core/src/java/org/apache/lucene/util/
Date Mon, 18 Mar 2013 10:12:03 GMT
Author: uschindler
Date: Mon Mar 18 10:12:02 2013
New Revision: 1457695

URL: http://svn.apache.org/r1457695
Log:
Merged revision(s) 1455863 from lucene/dev/branches/branch_4x:
LUCENE-4713: The SPI components used to load custom codecs or analysis components were fixed
to also scan the Lucene ClassLoader in addition to the context ClassLoader, so Lucene is always
able to find its own codecs. The special case of a null context ClassLoader is now also supported.

Modified:
    lucene/dev/branches/lucene_solr_4_2/   (props changed)
    lucene/dev/branches/lucene_solr_4_2/lucene/   (props changed)
    lucene/dev/branches/lucene_solr_4_2/lucene/CHANGES.txt   (contents, props changed)
    lucene/dev/branches/lucene_solr_4_2/lucene/analysis/   (props changed)
    lucene/dev/branches/lucene_solr_4_2/lucene/analysis/common/src/java/org/apache/lucene/analysis/util/AnalysisSPILoader.java
    lucene/dev/branches/lucene_solr_4_2/lucene/core/   (props changed)
    lucene/dev/branches/lucene_solr_4_2/lucene/core/src/java/org/apache/lucene/util/NamedSPILoader.java
    lucene/dev/branches/lucene_solr_4_2/lucene/core/src/java/org/apache/lucene/util/SPIClassIterator.java

Modified: lucene/dev/branches/lucene_solr_4_2/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_2/lucene/CHANGES.txt?rev=1457695&r1=1457694&r2=1457695&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_2/lucene/CHANGES.txt (original)
+++ lucene/dev/branches/lucene_solr_4_2/lucene/CHANGES.txt Mon Mar 18 10:12:02 2013
@@ -6,7 +6,13 @@ http://s.apache.org/luceneversions
 
 ======================= Lucene 4.2.1 =======================
 
-(No Changes)
+Bug Fixes
+
+* LUCENE-4713: The SPI components used to load custom codecs or analysis
+  components were fixed to also scan the Lucene ClassLoader in addition
+  to the context ClassLoader, so Lucene is always able to find its own
+  codecs. The special case of a null context ClassLoader is now also
+  supported.  (Christian Kohlschütter, Uwe Schindler)
 
 ======================= Lucene 4.2.0 =======================
 

Modified: lucene/dev/branches/lucene_solr_4_2/lucene/analysis/common/src/java/org/apache/lucene/analysis/util/AnalysisSPILoader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_2/lucene/analysis/common/src/java/org/apache/lucene/analysis/util/AnalysisSPILoader.java?rev=1457695&r1=1457694&r2=1457695&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_2/lucene/analysis/common/src/java/org/apache/lucene/analysis/util/AnalysisSPILoader.java
(original)
+++ lucene/dev/branches/lucene_solr_4_2/lucene/analysis/common/src/java/org/apache/lucene/analysis/util/AnalysisSPILoader.java
Mon Mar 18 10:12:02 2013
@@ -52,6 +52,11 @@ final class AnalysisSPILoader<S extends 
   public AnalysisSPILoader(Class<S> clazz, String[] suffixes, ClassLoader classloader)
{
     this.clazz = clazz;
     this.suffixes = suffixes;
+    // if clazz' classloader is not a parent of the given one, we scan clazz's classloader,
too:
+    final ClassLoader clazzClassloader = clazz.getClassLoader();
+    if (clazzClassloader != null && !SPIClassIterator.isParentClassLoader(clazzClassloader,
classloader)) {
+      reload(clazzClassloader);
+    }
     reload(classloader);
   }
   

Modified: lucene/dev/branches/lucene_solr_4_2/lucene/core/src/java/org/apache/lucene/util/NamedSPILoader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_2/lucene/core/src/java/org/apache/lucene/util/NamedSPILoader.java?rev=1457695&r1=1457694&r2=1457695&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_2/lucene/core/src/java/org/apache/lucene/util/NamedSPILoader.java
(original)
+++ lucene/dev/branches/lucene_solr_4_2/lucene/core/src/java/org/apache/lucene/util/NamedSPILoader.java
Mon Mar 18 10:12:02 2013
@@ -39,6 +39,11 @@ public final class NamedSPILoader<S exte
   
   public NamedSPILoader(Class<S> clazz, ClassLoader classloader) {
     this.clazz = clazz;
+    // if clazz' classloader is not a parent of the given one, we scan clazz's classloader,
too:
+    final ClassLoader clazzClassloader = clazz.getClassLoader();
+    if (clazzClassloader != null && !SPIClassIterator.isParentClassLoader(clazzClassloader,
classloader)) {
+      reload(clazzClassloader);
+    }
     reload(classloader);
   }
   

Modified: lucene/dev/branches/lucene_solr_4_2/lucene/core/src/java/org/apache/lucene/util/SPIClassIterator.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_2/lucene/core/src/java/org/apache/lucene/util/SPIClassIterator.java?rev=1457695&r1=1457694&r2=1457695&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_2/lucene/core/src/java/org/apache/lucene/util/SPIClassIterator.java
(original)
+++ lucene/dev/branches/lucene_solr_4_2/lucene/core/src/java/org/apache/lucene/util/SPIClassIterator.java
Mon Mar 18 10:12:02 2013
@@ -54,16 +54,27 @@ public final class SPIClassIterator<S> i
     return new SPIClassIterator<S>(clazz, loader);
   }
   
+  /** Utility method to check if some class loader is a (grand-)parent of or the same as
another one.
+   * This means the child will be able to load all classes from the parent, too. */
+  public static boolean isParentClassLoader(final ClassLoader parent, ClassLoader child)
{
+    while (child != null) {
+      if (child == parent) {
+        return true;
+      }
+      child = child.getParent();
+    }
+    return false;
+  }
+  
   private SPIClassIterator(Class<S> clazz, ClassLoader loader) {
-    if (loader == null)
-      throw new IllegalArgumentException("You must provide a ClassLoader.");
     this.clazz = clazz;
-    this.loader = loader;
     try {
-      this.profilesEnum = loader.getResources(META_INF_SERVICES + clazz.getName());
+      final String fullName = META_INF_SERVICES + clazz.getName();
+      this.profilesEnum = (loader == null) ? ClassLoader.getSystemResources(fullName) : loader.getResources(fullName);
     } catch (IOException ioe) {
       throw new ServiceConfigurationError("Error loading SPI profiles for type " + clazz.getName()
+ " from classpath", ioe);
     }
+    this.loader = (loader == null) ? ClassLoader.getSystemClassLoader() : loader;
     this.linesIterator = Collections.<String>emptySet().iterator();
   }
   



Mime
View raw message