From 467faeaae08773a2f4b1e6d29fd349ead693f7be Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Fri, 27 Jul 2012 12:15:03 +0000 Subject: [PATCH] LUCENE-4260: factor subPackages out of the resourceloader interface git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1366360 13f79535-47bb-0310-9956-ffa450edef68 --- .../util/ResourceAsStreamResourceLoader.java | 3 +-- .../lucene/analysis/util/ResourceLoader.java | 3 ++- .../TestSnowballPorterFilterFactory.java | 20 ------------------- .../util/StringMockResourceLoader.java | 3 +-- .../analysis/ja/StringMockResourceLoader.java | 3 +-- .../apache/solr/core/SolrResourceLoader.java | 6 ++++++ .../solr/schema/FieldTypePluginLoader.java | 2 +- .../org/apache/solr/schema/IndexSchema.java | 2 +- .../util/plugin/AbstractPluginLoader.java | 8 ++++---- .../StringMockSolrResourceLoader.java | 2 +- 10 files changed, 18 insertions(+), 34 deletions(-) diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/util/ResourceAsStreamResourceLoader.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/util/ResourceAsStreamResourceLoader.java index 103b0140429..94d5fc89b86 100644 --- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/util/ResourceAsStreamResourceLoader.java +++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/util/ResourceAsStreamResourceLoader.java @@ -36,9 +36,8 @@ public class ResourceAsStreamResourceLoader implements ResourceLoader { return clazz.getResourceAsStream(resource); } - // TODO: do this subpackages thing... wtf is that? @Override - public T newInstance(String cname, Class expectedType, String... subpackages) { + public T newInstance(String cname, Class expectedType) { try { Class clazz = Class.forName(cname).asSubclass(expectedType); return clazz.newInstance(); diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/util/ResourceLoader.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/util/ResourceLoader.java index 1de426de58b..3a484352b2d 100644 --- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/util/ResourceLoader.java +++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/util/ResourceLoader.java @@ -33,5 +33,6 @@ public interface ResourceLoader { /** * Creates a class of the name and expected type */ - public T newInstance(String cname, Class expectedType, String ... subpackages); + // TODO: fix exception handling + public T newInstance(String cname, Class expectedType); } \ No newline at end of file diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/snowball/TestSnowballPorterFilterFactory.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/snowball/TestSnowballPorterFilterFactory.java index df5c291c804..574b02af36b 100644 --- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/snowball/TestSnowballPorterFilterFactory.java +++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/snowball/TestSnowballPorterFilterFactory.java @@ -67,26 +67,6 @@ public class TestSnowballPorterFilterFactory extends BaseTokenStreamTestCase { } return sb.toString(); } - - class LinesMockSolrResourceLoader implements ResourceLoader { - List lines; - - LinesMockSolrResourceLoader(List lines) { - this.lines = lines; - } - - public List getLines(String resource) throws IOException { - return lines; - } - - public T newInstance(String cname, Class expectedType, String... subpackages) { - return null; - } - - public InputStream openResource(String resource) throws IOException { - return null; - } - } /** * Test the protected words mechanism of SnowballPorterFilterFactory diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/util/StringMockResourceLoader.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/util/StringMockResourceLoader.java index 067925f70a0..6ab8a1f35aa 100644 --- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/util/StringMockResourceLoader.java +++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/util/StringMockResourceLoader.java @@ -29,8 +29,7 @@ public class StringMockResourceLoader implements ResourceLoader { this.text = text; } - // TODO: do this subpackages thing... wtf is that? - public T newInstance(String cname, Class expectedType, String... subpackages) { + public T newInstance(String cname, Class expectedType) { try { Class clazz = Class.forName(cname).asSubclass(expectedType); return clazz.newInstance(); diff --git a/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/StringMockResourceLoader.java b/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/StringMockResourceLoader.java index c2b2a75f2c1..03191c45dae 100644 --- a/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/StringMockResourceLoader.java +++ b/lucene/analysis/kuromoji/src/test/org/apache/lucene/analysis/ja/StringMockResourceLoader.java @@ -33,8 +33,7 @@ class StringMockResourceLoader implements ResourceLoader { this.text = text; } - // TODO: do this subpackages thing... wtf is that? - public T newInstance(String cname, Class expectedType, String... subpackages) { + public T newInstance(String cname, Class expectedType) { try { Class clazz = Class.forName(cname).asSubclass(expectedType); return clazz.newInstance(); diff --git a/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java b/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java index 85aa8c34bae..8180d411f97 100644 --- a/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java +++ b/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java @@ -448,6 +448,12 @@ public class SolrResourceLoader implements ResourceLoader } } } + + static final String empty[] = new String[0]; + + public T newInstance(String name, Class expectedType) { + return newInstance(name, expectedType, empty); + } public T newInstance(String cname, Class expectedType, String ... subpackages) { Class clazz = findClass(cname, expectedType, subpackages); diff --git a/solr/core/src/java/org/apache/solr/schema/FieldTypePluginLoader.java b/solr/core/src/java/org/apache/solr/schema/FieldTypePluginLoader.java index 5c2073ff16f..23d32452260 100644 --- a/solr/core/src/java/org/apache/solr/schema/FieldTypePluginLoader.java +++ b/solr/core/src/java/org/apache/solr/schema/FieldTypePluginLoader.java @@ -73,7 +73,7 @@ public final class FieldTypePluginLoader @Override - protected FieldType create( ResourceLoader loader, + protected FieldType create( SolrResourceLoader loader, String name, String className, Node node ) throws Exception { diff --git a/solr/core/src/java/org/apache/solr/schema/IndexSchema.java b/solr/core/src/java/org/apache/solr/schema/IndexSchema.java index 417a8a70162..320902a70db 100644 --- a/solr/core/src/java/org/apache/solr/schema/IndexSchema.java +++ b/solr/core/src/java/org/apache/solr/schema/IndexSchema.java @@ -698,7 +698,7 @@ public final class IndexSchema { return newArr; } - static SimilarityFactory readSimilarity(ResourceLoader loader, Node node) { + static SimilarityFactory readSimilarity(SolrResourceLoader loader, Node node) { if (node==null) { return null; } else { diff --git a/solr/core/src/java/org/apache/solr/util/plugin/AbstractPluginLoader.java b/solr/core/src/java/org/apache/solr/util/plugin/AbstractPluginLoader.java index 47a59b8570c..91e23f6e8d3 100644 --- a/solr/core/src/java/org/apache/solr/util/plugin/AbstractPluginLoader.java +++ b/solr/core/src/java/org/apache/solr/util/plugin/AbstractPluginLoader.java @@ -22,11 +22,11 @@ import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.apache.lucene.analysis.util.ResourceLoader; import org.apache.solr.common.SolrException; import org.apache.solr.common.SolrException.ErrorCode; import org.apache.solr.util.DOMUtil; import org.apache.solr.core.SolrConfig; +import org.apache.solr.core.SolrResourceLoader; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -81,7 +81,7 @@ public abstract class AbstractPluginLoader * @param node - the XML node defining this plugin */ @SuppressWarnings("unchecked") - protected T create( ResourceLoader loader, String name, String className, Node node ) throws Exception + protected T create( SolrResourceLoader loader, String name, String className, Node node ) throws Exception { return loader.newInstance(className, pluginClassType, getDefaultPackages()); } @@ -124,7 +124,7 @@ public abstract class AbstractPluginLoader * If a default element is defined, it will be returned from this function. * */ - public T load( ResourceLoader loader, NodeList nodes ) + public T load( SolrResourceLoader loader, NodeList nodes ) { List info = new ArrayList(); T defaultPlugin = null; @@ -204,7 +204,7 @@ public abstract class AbstractPluginLoader * The created class for the plugin will be returned from this function. * */ - public T loadSingle(ResourceLoader loader, Node node) { + public T loadSingle(SolrResourceLoader loader, Node node) { List info = new ArrayList(); T plugin = null; diff --git a/solr/test-framework/src/java/org/apache/solr/analysis/StringMockSolrResourceLoader.java b/solr/test-framework/src/java/org/apache/solr/analysis/StringMockSolrResourceLoader.java index a161bf5c2fb..2185a89b7d0 100644 --- a/solr/test-framework/src/java/org/apache/solr/analysis/StringMockSolrResourceLoader.java +++ b/solr/test-framework/src/java/org/apache/solr/analysis/StringMockSolrResourceLoader.java @@ -32,7 +32,7 @@ class StringMockSolrResourceLoader implements ResourceLoader { this.text = text; } - public T newInstance(String cname, Class expectedType, String... subpackages) { + public T newInstance(String cname, Class expectedType) { return null; }