SOLR-4653: Solr configuration should log inaccessible/ non-existent relative paths in lib dir=...

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1463836 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dawid Weiss 2013-04-03 06:40:59 +00:00
parent e529be4006
commit 160cec5c95
4 changed files with 30 additions and 9 deletions

View File

@ -156,6 +156,9 @@ Optimizations
Other Changes 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-4317: SolrTestCaseJ4: Can't avoid "collection1" convention (Tricia Jenkins, via Erick Erickson)
* SOLR-4571: SolrZkClient#setData should return Stat object. (Mark Miller) * SOLR-4571: SolrZkClient#setData should return Stat object. (Mark Miller)

View File

@ -462,10 +462,10 @@ public class SolrConfig extends Config {
String baseDir = DOMUtil.getAttr(node, "dir"); String baseDir = DOMUtil.getAttr(node, "dir");
String path = DOMUtil.getAttr(node, "path"); String path = DOMUtil.getAttr(node, "path");
if (null != baseDir) { 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"); String regex = DOMUtil.getAttr(node, "regex");
FileFilter filter = (null == regex) ? null : new RegexFileFilter(regex); FileFilter filter = (null == regex) ? null : new RegexFileFilter(regex);
getResourceLoader().addToClassLoader(baseDir, filter); getResourceLoader().addToClassLoader(baseDir, filter, false);
} else if (null != path) { } else if (null != path) {
getResourceLoader().addToClassLoader(path); getResourceLoader().addToClassLoader(path);
} else { } else {

View File

@ -111,7 +111,7 @@ public class SolrResourceLoader implements ResourceLoader
} }
this.classLoader = createClassLoader(null, parent); this.classLoader = createClassLoader(null, parent);
addToClassLoader("./lib/", null); addToClassLoader("./lib/", null, true);
reloadLuceneSPI(); reloadLuceneSPI();
this.coreProperties = coreProperties; this.coreProperties = coreProperties;
} }
@ -136,15 +136,33 @@ public class SolrResourceLoader implements ResourceLoader
* it's behavior will be non-deterministic. You also have to {link @reloadLuceneSPI} * it's behavior will be non-deterministic. You also have to {link @reloadLuceneSPI}
* before using this ResourceLoader. * before using this ResourceLoader.
* *
* <p>This method will quietly ignore missing or non-directory <code>baseDir</code>
* folder.
*
* @param baseDir base directory whose children (either jars or directories of * @param baseDir base directory whose children (either jars or directories of
* classes) will be in the classpath, will be resolved relative * classes) will be in the classpath, will be resolved relative
* the instance dir. * the instance dir.
* @param filter The filter files must satisfy, if null all files will be accepted. * @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); File base = FileUtils.resolvePath(new File(getInstanceDir()), baseDir);
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); 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 * Adds the specific file/dir specified to the ClassLoader used by this
@ -174,7 +192,7 @@ public class SolrResourceLoader implements ResourceLoader
/** /**
* Reloads all Lucene SPI implementations using the new classloader. * Reloads all Lucene SPI implementations using the new classloader.
* This method must be called after {@link #addToClassLoader(String)} * 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. * this ResourceLoader.
*/ */
void reloadLuceneSPI() { void reloadLuceneSPI() {

View File

@ -82,9 +82,9 @@
<lib dir="../../../dist/" regex="solr-velocity-\d.*\.jar" /> <lib dir="../../../dist/" regex="solr-velocity-\d.*\.jar" />
<!-- If a 'dir' option (with or without a regex) is used and nothing <!-- If a 'dir' option (with or without a regex) is used and nothing
is found that matches, it will be ignored is found that matches, a warning will be logged.
--> -->
<lib dir="/total/crap/dir/ignored" /> <lib dir="/non/existent/dir/yields/warning" />
<!-- an exact 'path' can be used instead of a 'dir' to specify a <!-- an exact 'path' can be used instead of a 'dir' to specify a
specific jar file. This will cause a serious error to be logged specific jar file. This will cause a serious error to be logged