From e1295dc3d84e390fdbde410e729b623ff3600c34 Mon Sep 17 00:00:00 2001 From: Uwe Schindler Date: Mon, 13 Aug 2012 00:01:59 +0000 Subject: [PATCH] Fix test failure caused in Maven, because test-framework classes are packaged in JAR. git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1372218 13f79535-47bb-0310-9956-ffa450edef68 --- .../core/TestAllAnalyzersHaveFactories.java | 3 +-- .../analysis/core/TestRandomChains.java | 21 ++++++++++++++----- .../org/apache/solr/SolrInfoMBeanTest.java | 7 ++++++- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/TestAllAnalyzersHaveFactories.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/TestAllAnalyzersHaveFactories.java index e88881905bf..9cf616cd5c8 100644 --- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/TestAllAnalyzersHaveFactories.java +++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/TestAllAnalyzersHaveFactories.java @@ -100,8 +100,7 @@ public class TestAllAnalyzersHaveFactories extends LuceneTestCase { private static final ResourceLoader loader = new StringMockResourceLoader(""); public void test() throws Exception { - List> analysisClasses = new ArrayList>(); - TestRandomChains.getClassesForPackage("org.apache.lucene.analysis", analysisClasses); + List> analysisClasses = TestRandomChains.getClassesForPackage("org.apache.lucene.analysis"); for (final Class c : analysisClasses) { final int modifiers = c.getModifiers(); diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/TestRandomChains.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/TestRandomChains.java index ff3e9eb70bb..587f1568bb6 100644 --- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/TestRandomChains.java +++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/TestRandomChains.java @@ -25,6 +25,7 @@ import java.io.StringReader; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Modifier; +import java.net.URI; import java.net.URL; import java.nio.CharBuffer; import java.util.ArrayList; @@ -165,8 +166,7 @@ public class TestRandomChains extends BaseTokenStreamTestCase { @BeforeClass public static void beforeClass() throws Exception { - List> analysisClasses = new ArrayList>(); - getClassesForPackage("org.apache.lucene.analysis", analysisClasses); + List> analysisClasses = getClassesForPackage("org.apache.lucene.analysis"); tokenizers = new ArrayList>(); tokenfilters = new ArrayList>(); charfilters = new ArrayList>(); @@ -235,19 +235,30 @@ public class TestRandomChains extends BaseTokenStreamTestCase { private static Constructor castConstructor(Class instanceClazz, Constructor ctor) { return (Constructor) ctor; } - static void getClassesForPackage(String pckgname, List> classes) throws Exception { + + public static List> getClassesForPackage(String pckgname) throws Exception { + final List> classes = new ArrayList>(); + collectClassesForPackage(pckgname, classes); + assertFalse("No classes found in package '"+pckgname+"'; maybe your test classes are packaged as JAR file?", classes.isEmpty()); + return classes; + } + + private static void collectClassesForPackage(String pckgname, List> classes) throws Exception { final ClassLoader cld = TestRandomChains.class.getClassLoader(); final String path = pckgname.replace('.', '/'); final Enumeration resources = cld.getResources(path); while (resources.hasMoreElements()) { - final File directory = new File(resources.nextElement().toURI()); + final URI uri = resources.nextElement().toURI(); + if (!"file".equalsIgnoreCase(uri.getScheme())) + continue; + final File directory = new File(uri); if (directory.exists()) { String[] files = directory.list(); for (String file : files) { if (new File(directory, file).isDirectory()) { // recurse String subPackage = pckgname + "." + file; - getClassesForPackage(subPackage, classes); + collectClassesForPackage(subPackage, classes); } if (file.endsWith(".class")) { String clazzName = file.substring(0, file.length() - 6); diff --git a/solr/core/src/test/org/apache/solr/SolrInfoMBeanTest.java b/solr/core/src/test/org/apache/solr/SolrInfoMBeanTest.java index 8d51177d395..40f4fb7a7e8 100644 --- a/solr/core/src/test/org/apache/solr/SolrInfoMBeanTest.java +++ b/solr/core/src/test/org/apache/solr/SolrInfoMBeanTest.java @@ -25,6 +25,7 @@ import org.apache.solr.highlight.DefaultSolrHighlighter; import org.apache.solr.search.LRUCache; import org.junit.BeforeClass; import java.io.File; +import java.net.URI; import java.net.URL; import java.util.ArrayList; import java.util.Enumeration; @@ -94,7 +95,10 @@ public class SolrInfoMBeanTest extends SolrTestCaseJ4 String path = pckgname.replace('.', '/'); Enumeration resources = cld.getResources(path); while (resources.hasMoreElements()) { - final File f = new File(resources.nextElement().toURI()); + final URI uri = resources.nextElement().toURI(); + if (!"file".equalsIgnoreCase(uri.getScheme())) + continue; + final File f = new File(uri); directories.add(f); } @@ -114,6 +118,7 @@ public class SolrInfoMBeanTest extends SolrTestCaseJ4 } } } + assertFalse("No classes found in package '"+pckgname+"'; maybe your test classes are packaged as JAR file?", classes.isEmpty()); return classes; } }