diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index a24233f23a4..0580d2fa105 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -156,6 +156,9 @@ Optimizations Other Changes ---------------------- +* SOLR-4653: Solr configuration should log inaccessible/ non-existent relative paths in lib + dir=... (Dawid Weiss) + * SOLR-4317: SolrTestCaseJ4: Can't avoid "collection1" convention (Tricia Jenkins, via Erick Erickson) * SOLR-4571: SolrZkClient#setData should return Stat object. (Mark Miller) diff --git a/solr/core/src/java/org/apache/solr/core/SolrConfig.java b/solr/core/src/java/org/apache/solr/core/SolrConfig.java index 69b32558bd4..90be8f04d8b 100644 --- a/solr/core/src/java/org/apache/solr/core/SolrConfig.java +++ b/solr/core/src/java/org/apache/solr/core/SolrConfig.java @@ -462,10 +462,10 @@ public class SolrConfig extends Config { String baseDir = DOMUtil.getAttr(node, "dir"); String path = DOMUtil.getAttr(node, "path"); if (null != baseDir) { - // :TODO: add support for a simpler 'glob' mutually eclusive of regex + // :TODO: add support for a simpler 'glob' mutually exclusive of regex String regex = DOMUtil.getAttr(node, "regex"); FileFilter filter = (null == regex) ? null : new RegexFileFilter(regex); - getResourceLoader().addToClassLoader(baseDir, filter); + getResourceLoader().addToClassLoader(baseDir, filter, false); } else if (null != path) { getResourceLoader().addToClassLoader(path); } else { 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 283c0ceb8c5..0a9aaef4ada 100644 --- a/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java +++ b/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java @@ -111,7 +111,7 @@ public class SolrResourceLoader implements ResourceLoader } this.classLoader = createClassLoader(null, parent); - addToClassLoader("./lib/", null); + addToClassLoader("./lib/", null, true); reloadLuceneSPI(); this.coreProperties = coreProperties; } @@ -135,17 +135,35 @@ public class SolrResourceLoader implements ResourceLoader * only be called prior to using this ResourceLoader to get any resources, otherwise * it's behavior will be non-deterministic. You also have to {link @reloadLuceneSPI} * before using this ResourceLoader. + * + *

This method will quietly ignore missing or non-directory baseDir + * folder. * * @param baseDir base directory whose children (either jars or directories of * classes) will be in the classpath, will be resolved relative * the instance dir. * @param filter The filter files must satisfy, if null all files will be accepted. + * @param quiet Be quiet if baseDir does not point to a directory or if no file is + * left after applying the filter. */ - void addToClassLoader(final String baseDir, final FileFilter filter) { + void addToClassLoader(final String baseDir, final FileFilter filter, boolean quiet) { File base = FileUtils.resolvePath(new File(getInstanceDir()), baseDir); - this.classLoader = replaceClassLoader(classLoader, base, filter); + if (base != null && base.exists() && base.isDirectory()) { + File[] files = base.listFiles(filter); + if (!quiet && (files == null || files.length == 0)) { + log.warn("No files added to classloader from lib: " + + baseDir + " (resolved as: " + base.getAbsolutePath() + ")."); + } else { + this.classLoader = replaceClassLoader(classLoader, base, filter); + } + } else { + if (!quiet) { + log.warn("Can't find (or read) directory to add to classloader: " + + baseDir + " (resolved as: " + base.getAbsolutePath() + ")."); + } + } } - + /** * Adds the specific file/dir specified to the ClassLoader used by this * ResourceLoader. This method MUST @@ -174,7 +192,7 @@ public class SolrResourceLoader implements ResourceLoader /** * Reloads all Lucene SPI implementations using the new classloader. * This method must be called after {@link #addToClassLoader(String)} - * and {@link #addToClassLoader(String,FileFilter)} before using + * and {@link #addToClassLoader(String,FileFilter,boolean)} before using * this ResourceLoader. */ void reloadLuceneSPI() { diff --git a/solr/example/solr/collection1/conf/solrconfig.xml b/solr/example/solr/collection1/conf/solrconfig.xml index cccf0b865ae..1e6b1b670d9 100755 --- a/solr/example/solr/collection1/conf/solrconfig.xml +++ b/solr/example/solr/collection1/conf/solrconfig.xml @@ -82,9 +82,9 @@ - +