diff --git a/core/pom.xml b/core/pom.xml index e039cc8f83d..bf6c74608fa 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -315,7 +315,6 @@ org/elasticsearch/search/MockSearchService.class org/elasticsearch/search/MockSearchService$*.class org/elasticsearch/cache/recycler/MockPageCacheRecycler.class - org/elasticsearch/cache/recycler/MockPageCacheRecycler$*.class org/elasticsearch/common/util/MockBigArrays.class org/elasticsearch/common/util/MockBigArrays$*.class org/elasticsearch/node/NodeMocksPlugin.class diff --git a/core/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java b/core/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java index d1143a54542..cc3aa5068db 100644 --- a/core/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java +++ b/core/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java @@ -192,7 +192,7 @@ public class Bootstrap { @SuppressForbidden(reason = "Exception#printStackTrace()") private static void setupLogging(Settings settings, Environment environment) { try { - Class.forName("org.apache.log4j.Logger"); + settings.getClassLoader().loadClass("org.apache.log4j.Logger"); LogConfigurator.configure(settings); } catch (ClassNotFoundException e) { // no log4j diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java b/core/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java index a1d9738552c..aa2fc96a9b5 100644 --- a/core/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java +++ b/core/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java @@ -23,7 +23,6 @@ import com.carrotsearch.hppc.cursors.ObjectCursor; import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableMap; -import org.elasticsearch.ElasticsearchException; import org.elasticsearch.Version; import org.elasticsearch.cluster.Diff; import org.elasticsearch.cluster.Diffable; @@ -252,12 +251,7 @@ public class IndexMetaData implements Diffable, FromXContentBuild if (hashFunction == null) { routingHashFunction = MURMUR3_HASH_FUNCTION; } else { - final Class hashFunctionClass; - try { - hashFunctionClass = (Class) getClass().getClassLoader().loadClass(hashFunction); - } catch (ClassNotFoundException|NoClassDefFoundError e) { - throw new ElasticsearchException("failed to load custom hash function [" + hashFunction + "]", e); - } + final Class hashFunctionClass = Classes.loadClass(getClass().getClassLoader(), hashFunction); try { routingHashFunction = hashFunctionClass.newInstance(); } catch (InstantiationException | IllegalAccessException e) { diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexUpgradeService.java b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexUpgradeService.java index fcbb0ade1d3..08f5dbe7e53 100644 --- a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexUpgradeService.java +++ b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexUpgradeService.java @@ -20,7 +20,6 @@ package org.elasticsearch.cluster.metadata; import com.carrotsearch.hppc.cursors.ObjectCursor; import org.apache.lucene.analysis.Analyzer; -import org.elasticsearch.ElasticsearchException; import org.elasticsearch.Version; import org.elasticsearch.cluster.routing.DjbHashFunction; import org.elasticsearch.cluster.routing.HashFunction; @@ -79,11 +78,7 @@ public class MetaDataIndexUpgradeService extends AbstractComponent { pre20HashFunction = DjbHashFunction.class; break; default: - try { - pre20HashFunction = (Class) getClass().getClassLoader().loadClass(pre20HashFunctionName); - } catch (ClassNotFoundException|NoClassDefFoundError e) { - throw new ElasticsearchException("failed to load custom hash function [" + pre20HashFunctionName + "]", e); - } + pre20HashFunction = Classes.loadClass(getClass().getClassLoader(), pre20HashFunctionName); } } else { pre20HashFunction = DjbHashFunction.class; diff --git a/core/src/main/java/org/elasticsearch/common/Classes.java b/core/src/main/java/org/elasticsearch/common/Classes.java index 4a73c0d8ae4..b9a508e94bd 100644 --- a/core/src/main/java/org/elasticsearch/common/Classes.java +++ b/core/src/main/java/org/elasticsearch/common/Classes.java @@ -19,7 +19,17 @@ package org.elasticsearch.common; +import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.bootstrap.Elasticsearch; +import org.elasticsearch.common.inject.Module; +import org.elasticsearch.common.settings.NoClassSettingsException; + import java.lang.reflect.Modifier; +import java.util.Arrays; +import java.util.Iterator; +import java.util.Locale; + +import static org.elasticsearch.common.Strings.toCamelCase; /** * @@ -31,6 +41,34 @@ public class Classes { */ private static final char PACKAGE_SEPARATOR = '.'; + /** + * Return the default ClassLoader to use: typically the thread context + * ClassLoader, if available; the ClassLoader that loaded the ClassUtils + * class will be used as fallback. + *

+ *

Call this method if you intend to use the thread context ClassLoader + * in a scenario where you absolutely need a non-null ClassLoader reference: + * for example, for class path resource loading (but not necessarily for + * Class.forName, which accepts a null ClassLoader + * reference as well). + * + * @return the default ClassLoader (never null) + * @see java.lang.Thread#getContextClassLoader() + */ + public static ClassLoader getDefaultClassLoader() { + ClassLoader cl = null; + try { + cl = Thread.currentThread().getContextClassLoader(); + } catch (Throwable ex) { + // Cannot access thread context ClassLoader - falling back to system class loader... + } + if (cl == null) { + // No thread context class loader -> use class loader of this class. + cl = Classes.class.getClassLoader(); + } + return cl; + } + /** * Determine the name of the package of the given class: * e.g. "java.lang" for the java.lang.String class. @@ -55,5 +93,13 @@ public class Classes { return !clazz.isInterface() && !Modifier.isAbstract(modifiers); } + public static Class loadClass(ClassLoader classLoader, String className) { + try { + return (Class) classLoader.loadClass(className); + } catch (ClassNotFoundException|NoClassDefFoundError e) { + throw new ElasticsearchException("failed to load class [" + className + "]", e); + } + } + private Classes() {} } diff --git a/core/src/main/java/org/elasticsearch/common/geo/ShapesAvailability.java b/core/src/main/java/org/elasticsearch/common/geo/ShapesAvailability.java index fce18337728..882bfcbf718 100644 --- a/core/src/main/java/org/elasticsearch/common/geo/ShapesAvailability.java +++ b/core/src/main/java/org/elasticsearch/common/geo/ShapesAvailability.java @@ -31,7 +31,7 @@ public class ShapesAvailability { static { boolean xSPATIAL4J_AVAILABLE; try { - Class.forName("com.spatial4j.core.shape.impl.PointImpl"); + Classes.getDefaultClassLoader().loadClass("com.spatial4j.core.shape.impl.PointImpl"); xSPATIAL4J_AVAILABLE = true; } catch (Throwable t) { xSPATIAL4J_AVAILABLE = false; @@ -40,7 +40,7 @@ public class ShapesAvailability { boolean xJTS_AVAILABLE; try { - Class.forName("com.vividsolutions.jts.geom.GeometryFactory"); + Classes.getDefaultClassLoader().loadClass("com.vividsolutions.jts.geom.GeometryFactory"); xJTS_AVAILABLE = true; } catch (Throwable t) { xJTS_AVAILABLE = false; diff --git a/core/src/main/java/org/elasticsearch/common/inject/Modules.java b/core/src/main/java/org/elasticsearch/common/inject/Modules.java index edb08dd183a..4e5ae23e05a 100644 --- a/core/src/main/java/org/elasticsearch/common/inject/Modules.java +++ b/core/src/main/java/org/elasticsearch/common/inject/Modules.java @@ -30,6 +30,10 @@ import java.lang.reflect.Constructor; */ public class Modules { + public static Module createModule(String moduleClass, Settings settings) throws ClassNotFoundException { + return createModule((Class) settings.getClassLoader().loadClass(moduleClass), settings); + } + public static Module createModule(Class moduleClass, @Nullable Settings settings) { Constructor constructor; try { diff --git a/core/src/main/java/org/elasticsearch/common/settings/Settings.java b/core/src/main/java/org/elasticsearch/common/settings/Settings.java index a448554c53f..4d422575480 100644 --- a/core/src/main/java/org/elasticsearch/common/settings/Settings.java +++ b/core/src/main/java/org/elasticsearch/common/settings/Settings.java @@ -81,7 +81,7 @@ public final class Settings implements ToXContent { private final ImmutableMap forcedUnderscoreSettings; private transient ClassLoader classLoader; - Settings(Map settings) { + Settings(Map settings, ClassLoader classLoader) { // we use a sorted map for consistent serialization when using getAsMap() // TODO: use Collections.unmodifiableMap with a TreeMap this.settings = ImmutableSortedMap.copyOf(settings); @@ -96,6 +96,7 @@ public final class Settings implements ToXContent { } } this.forcedUnderscoreSettings = forcedUnderscoreSettings == null ? ImmutableMap.of() : ImmutableMap.copyOf(forcedUnderscoreSettings); + this.classLoader = classLoader; } /** @@ -647,7 +648,7 @@ public final class Settings implements ToXContent { } Map retVal = new LinkedHashMap<>(); for (Map.Entry> entry : map.entrySet()) { - retVal.put(entry.getKey(), new Settings(Collections.unmodifiableMap(entry.getValue()))); + retVal.put(entry.getKey(), new Settings(Collections.unmodifiableMap(entry.getValue()), classLoader)); } return Collections.unmodifiableMap(retVal); } @@ -1117,6 +1118,23 @@ public final class Settings implements ToXContent { return this; } + /** + * Loads settings from classpath that represents them using the + * {@link SettingsLoaderFactory#loaderFromSource(String)}. + */ + public Builder loadFromClasspath(String resourceName) throws SettingsException { + ClassLoader classLoader = this.classLoader; + if (classLoader == null) { + classLoader = Classes.getDefaultClassLoader(); + } + InputStream is = classLoader.getResourceAsStream(resourceName); + if (is == null) { + throw new SettingsException("Failed to load settings from [" + resourceName + "]"); + } + + return loadFromStream(resourceName, is); + } + /** * Sets the class loader associated with the settings built. */ @@ -1252,7 +1270,7 @@ public final class Settings implements ToXContent { * set on this builder. */ public Settings build() { - return new Settings(Collections.unmodifiableMap(map)); + return new Settings(Collections.unmodifiableMap(map), classLoader); } } diff --git a/core/src/main/java/org/elasticsearch/env/Environment.java b/core/src/main/java/org/elasticsearch/env/Environment.java index aedc66095cc..c0e3bf4be7d 100644 --- a/core/src/main/java/org/elasticsearch/env/Environment.java +++ b/core/src/main/java/org/elasticsearch/env/Environment.java @@ -319,14 +319,13 @@ public class Environment { } } // try and load it from the classpath directly - // TODO: remove this, users can look up their own config on classpath - URL resource = getClass().getResource(path); + URL resource = settings.getClassLoader().getResource(path); if (resource != null) { return resource; } // try and load it from the classpath with config/ prefix if (!path.startsWith("config/")) { - resource = getClass().getResource("config/" + path); + resource = settings.getClassLoader().getResource("config/" + path); if (resource != null) { return resource; } diff --git a/core/src/main/java/org/elasticsearch/indices/IndicesService.java b/core/src/main/java/org/elasticsearch/indices/IndicesService.java index 022fbd997b6..d207e4b6618 100644 --- a/core/src/main/java/org/elasticsearch/indices/IndicesService.java +++ b/core/src/main/java/org/elasticsearch/indices/IndicesService.java @@ -300,6 +300,7 @@ public class IndicesService extends AbstractLifecycleComponent i Settings indexSettings = settingsBuilder() .put(this.settings) .put(settings) + .classLoader(settings.getClassLoader()) .build(); ModulesBuilder modules = new ModulesBuilder(); diff --git a/core/src/main/java/org/elasticsearch/script/ScriptModule.java b/core/src/main/java/org/elasticsearch/script/ScriptModule.java index f5de92f67d7..d6c52a6b130 100644 --- a/core/src/main/java/org/elasticsearch/script/ScriptModule.java +++ b/core/src/main/java/org/elasticsearch/script/ScriptModule.java @@ -79,21 +79,21 @@ public class ScriptModule extends AbstractModule { multibinder.addBinding().to(NativeScriptEngineService.class); try { - Class.forName("groovy.lang.GroovyClassLoader"); + settings.getClassLoader().loadClass("groovy.lang.GroovyClassLoader"); multibinder.addBinding().to(GroovyScriptEngineService.class).asEagerSingleton(); } catch (Throwable t) { Loggers.getLogger(ScriptService.class, settings).debug("failed to load groovy", t); } try { - Class.forName("com.github.mustachejava.Mustache"); + settings.getClassLoader().loadClass("com.github.mustachejava.Mustache"); multibinder.addBinding().to(MustacheScriptEngineService.class).asEagerSingleton(); } catch (Throwable t) { Loggers.getLogger(ScriptService.class, settings).debug("failed to load mustache", t); } try { - Class.forName("org.apache.lucene.expressions.Expression"); + settings.getClassLoader().loadClass("org.apache.lucene.expressions.Expression"); multibinder.addBinding().to(ExpressionScriptEngineService.class).asEagerSingleton(); } catch (Throwable t) { Loggers.getLogger(ScriptService.class, settings).debug("failed to load lucene expressions", t); diff --git a/core/src/main/java/org/elasticsearch/script/groovy/GroovyScriptEngineService.java b/core/src/main/java/org/elasticsearch/script/groovy/GroovyScriptEngineService.java index a74cdf94946..93f196f448e 100644 --- a/core/src/main/java/org/elasticsearch/script/groovy/GroovyScriptEngineService.java +++ b/core/src/main/java/org/elasticsearch/script/groovy/GroovyScriptEngineService.java @@ -70,7 +70,7 @@ public class GroovyScriptEngineService extends AbstractComponent implements Scri config.addCompilationCustomizers(imports); // Add BigDecimal -> Double transformer config.addCompilationCustomizers(new GroovyBigDecimalTransformer(CompilePhase.CONVERSION)); - this.loader = new GroovyClassLoader(getClass().getClassLoader(), config); + this.loader = new GroovyClassLoader(settings.getClassLoader(), config); } @Override diff --git a/core/src/test/java/org/elasticsearch/common/settings/loader/JsonSettingsLoaderTests.java b/core/src/test/java/org/elasticsearch/common/settings/loader/JsonSettingsLoaderTests.java index a7c4d167445..f4604d28d1a 100644 --- a/core/src/test/java/org/elasticsearch/common/settings/loader/JsonSettingsLoaderTests.java +++ b/core/src/test/java/org/elasticsearch/common/settings/loader/JsonSettingsLoaderTests.java @@ -34,9 +34,8 @@ public class JsonSettingsLoaderTests extends ESTestCase { @Test public void testSimpleJsonSettings() throws Exception { - String json = "org/elasticsearch/common/settings/loader/test-settings.json"; Settings settings = settingsBuilder() - .loadFromStream(json, getClass().getResourceAsStream(json)) + .loadFromClasspath("org/elasticsearch/common/settings/loader/test-settings.json") .build(); assertThat(settings.get("test1.value1"), equalTo("value1")); diff --git a/core/src/test/java/org/elasticsearch/common/settings/loader/YamlSettingsLoaderTests.java b/core/src/test/java/org/elasticsearch/common/settings/loader/YamlSettingsLoaderTests.java index 109dc71891c..362188ea03d 100644 --- a/core/src/test/java/org/elasticsearch/common/settings/loader/YamlSettingsLoaderTests.java +++ b/core/src/test/java/org/elasticsearch/common/settings/loader/YamlSettingsLoaderTests.java @@ -34,9 +34,8 @@ public class YamlSettingsLoaderTests extends ESTestCase { @Test public void testSimpleYamlSettings() throws Exception { - String yaml = "org/elasticsearch/common/settings/loader/test-settings.yml"; Settings settings = settingsBuilder() - .loadFromStream(yaml, getClass().getResourceAsStream(yaml)) + .loadFromClasspath("org/elasticsearch/common/settings/loader/test-settings.yml") .build(); assertThat(settings.get("test1.value1"), equalTo("value1")); @@ -53,17 +52,28 @@ public class YamlSettingsLoaderTests extends ESTestCase { @Test(expected = SettingsException.class) public void testIndentation() { - String yaml = "org/elasticsearch/common/settings/loader/indentation-settings.yml"; settingsBuilder() - .loadFromStream(yaml, getClass().getResourceAsStream(yaml)) - .build(); + .loadFromClasspath("org/elasticsearch/common/settings/loader/indentation-settings.yml") + .build(); } @Test(expected = SettingsException.class) public void testIndentationWithExplicitDocumentStart() { - String yaml = "org/elasticsearch/common/settings/loader/indentation-with-explicit-document-start-settings.yml"; settingsBuilder() - .loadFromStream(yaml, getClass().getResourceAsStream(yaml)) + .loadFromClasspath("org/elasticsearch/common/settings/loader/indentation-with-explicit-document-start-settings.yml") .build(); } + + + @Test + public void testYamlSettingsNoFile() throws Exception { + String invalidResourceName = "org/elasticsearch/common/settings/loader/no-test-settings.yml"; + try { + Settings defaultSettings = settingsBuilder().loadFromClasspath(invalidResourceName).build(); + fail("For a not exiting file an exception should be thrown."); + } catch (Exception e) { + assertTrue(e instanceof SettingsException); + assertThat(e.getMessage(), equalTo("Failed to load settings from [" + invalidResourceName + "]")); + } + } } \ No newline at end of file diff --git a/core/src/test/java/org/elasticsearch/index/analysis/AnalysisModuleTests.java b/core/src/test/java/org/elasticsearch/index/analysis/AnalysisModuleTests.java index ea27b5beeef..e667afaf5a3 100644 --- a/core/src/test/java/org/elasticsearch/index/analysis/AnalysisModuleTests.java +++ b/core/src/test/java/org/elasticsearch/index/analysis/AnalysisModuleTests.java @@ -79,7 +79,7 @@ public class AnalysisModuleTests extends ESTestCase { } private Settings loadFromClasspath(String path) { - return settingsBuilder().loadFromStream(path, getClass().getResourceAsStream(path)) + return settingsBuilder().loadFromClasspath(path) .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) .put("path.home", createTempDir().toString()) .build(); @@ -107,9 +107,8 @@ public class AnalysisModuleTests extends ESTestCase { @Test public void testVersionedAnalyzers() throws Exception { - String yaml = "org/elasticsearch/index/analysis/test1.yml"; Settings settings2 = settingsBuilder() - .loadFromStream(yaml, getClass().getResourceAsStream(yaml)) + .loadFromClasspath("org/elasticsearch/index/analysis/test1.yml") .put("path.home", createTempDir().toString()) .put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_0_90_0) .build(); diff --git a/core/src/test/java/org/elasticsearch/index/analysis/AnalysisTestsHelper.java b/core/src/test/java/org/elasticsearch/index/analysis/AnalysisTestsHelper.java index 74ff95d4a14..6f7581768f3 100644 --- a/core/src/test/java/org/elasticsearch/index/analysis/AnalysisTestsHelper.java +++ b/core/src/test/java/org/elasticsearch/index/analysis/AnalysisTestsHelper.java @@ -39,7 +39,7 @@ public class AnalysisTestsHelper { public static AnalysisService createAnalysisServiceFromClassPath(Path baseDir, String resource) { Settings settings = Settings.settingsBuilder() - .loadFromStream(resource, AnalysisTestsHelper.class.getResourceAsStream(resource)) + .loadFromClasspath(resource) .put("path.home", baseDir.toString()) .build(); diff --git a/core/src/test/java/org/elasticsearch/index/analysis/CompoundAnalysisTests.java b/core/src/test/java/org/elasticsearch/index/analysis/CompoundAnalysisTests.java index 7d51e4be74f..a259dc0d19e 100644 --- a/core/src/test/java/org/elasticsearch/index/analysis/CompoundAnalysisTests.java +++ b/core/src/test/java/org/elasticsearch/index/analysis/CompoundAnalysisTests.java @@ -115,18 +115,16 @@ public class CompoundAnalysisTests extends ESTestCase { } private Settings getJsonSettings() { - String json = "org/elasticsearch/index/analysis/test1.json"; return settingsBuilder() - .loadFromStream(json, getClass().getResourceAsStream(json)) + .loadFromClasspath("org/elasticsearch/index/analysis/test1.json") .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) .put("path.home", createTempDir().toString()) .build(); } private Settings getYamlSettings() { - String yaml = "org/elasticsearch/index/analysis/test1.yml"; return settingsBuilder() - .loadFromStream(yaml, getClass().getResourceAsStream(yaml)) + .loadFromClasspath("org/elasticsearch/index/analysis/test1.yml") .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) .put("path.home", createTempDir().toString()) .build(); diff --git a/core/src/test/java/org/elasticsearch/index/analysis/PatternCaptureTokenFilterTests.java b/core/src/test/java/org/elasticsearch/index/analysis/PatternCaptureTokenFilterTests.java index c177f8148d9..0a1d7e5e196 100644 --- a/core/src/test/java/org/elasticsearch/index/analysis/PatternCaptureTokenFilterTests.java +++ b/core/src/test/java/org/elasticsearch/index/analysis/PatternCaptureTokenFilterTests.java @@ -41,11 +41,10 @@ public class PatternCaptureTokenFilterTests extends ESTokenStreamTestCase { @Test public void testPatternCaptureTokenFilter() throws Exception { - String json = "org/elasticsearch/index/analysis/pattern_capture.json"; Index index = new Index("test"); Settings settings = settingsBuilder() .put("path.home", createTempDir()) - .loadFromStream(json, getClass().getResourceAsStream(json)) + .loadFromClasspath("org/elasticsearch/index/analysis/pattern_capture.json") .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) .build(); Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings), new EnvironmentModule(new Environment(settings)), new IndicesAnalysisModule()).createInjector(); diff --git a/core/src/test/java/org/elasticsearch/index/analysis/StopAnalyzerTests.java b/core/src/test/java/org/elasticsearch/index/analysis/StopAnalyzerTests.java index 5cc06b0a162..e520fd1c557 100644 --- a/core/src/test/java/org/elasticsearch/index/analysis/StopAnalyzerTests.java +++ b/core/src/test/java/org/elasticsearch/index/analysis/StopAnalyzerTests.java @@ -41,10 +41,9 @@ public class StopAnalyzerTests extends ESTokenStreamTestCase { @Test public void testDefaultsCompoundAnalysis() throws Exception { - String json = "org/elasticsearch/index/analysis/stop.json"; Index index = new Index("test"); Settings settings = settingsBuilder() - .loadFromStream(json, getClass().getResourceAsStream(json)) + .loadFromClasspath("org/elasticsearch/index/analysis/stop.json") .put("path.home", createTempDir().toString()) .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) .build(); diff --git a/core/src/test/java/org/elasticsearch/index/analysis/commongrams/CommonGramsTokenFilterFactoryTests.java b/core/src/test/java/org/elasticsearch/index/analysis/commongrams/CommonGramsTokenFilterFactoryTests.java index 8d19b9af1cd..6aadf4d1377 100644 --- a/core/src/test/java/org/elasticsearch/index/analysis/commongrams/CommonGramsTokenFilterFactoryTests.java +++ b/core/src/test/java/org/elasticsearch/index/analysis/commongrams/CommonGramsTokenFilterFactoryTests.java @@ -134,9 +134,8 @@ public class CommonGramsTokenFilterFactoryTests extends ESTokenStreamTestCase { @Test public void testCommonGramsAnalysis() throws IOException { - String json = "org/elasticsearch/index/analysis/commongrams/commongrams.json"; Settings settings = Settings.settingsBuilder() - .loadFromStream(json, getClass().getResourceAsStream(json)) + .loadFromClasspath("org/elasticsearch/index/analysis/commongrams/commongrams.json") .put("path.home", createTempDir().toString()) .build(); { @@ -219,9 +218,8 @@ public class CommonGramsTokenFilterFactoryTests extends ESTokenStreamTestCase { @Test public void testQueryModeCommonGramsAnalysis() throws IOException { - String json = "org/elasticsearch/index/analysis/commongrams/commongrams_query_mode.json"; Settings settings = Settings.settingsBuilder() - .loadFromStream(json, getClass().getResourceAsStream(json)) + .loadFromClasspath("org/elasticsearch/index/analysis/commongrams/commongrams_query_mode.json") .put("path.home", createTempDir().toString()) .build(); { diff --git a/core/src/test/java/org/elasticsearch/index/analysis/synonyms/SynonymsAnalysisTest.java b/core/src/test/java/org/elasticsearch/index/analysis/synonyms/SynonymsAnalysisTest.java index 0cd3ce2af0d..beb5ae3b51a 100644 --- a/core/src/test/java/org/elasticsearch/index/analysis/synonyms/SynonymsAnalysisTest.java +++ b/core/src/test/java/org/elasticsearch/index/analysis/synonyms/SynonymsAnalysisTest.java @@ -59,9 +59,8 @@ public class SynonymsAnalysisTest extends ESTestCase { @Test public void testSynonymsAnalysis() throws IOException { - String json = "org/elasticsearch/index/analysis/synonyms/synonyms.json"; Settings settings = settingsBuilder(). - loadFromStream(json, getClass().getResourceAsStream(json)) + loadFromClasspath("org/elasticsearch/index/analysis/synonyms/synonyms.json") .put("path.home", createTempDir().toString()) .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(); diff --git a/plugins/analysis-kuromoji/src/test/java/org/elasticsearch/index/analysis/KuromojiAnalysisTests.java b/plugins/analysis-kuromoji/src/test/java/org/elasticsearch/index/analysis/KuromojiAnalysisTests.java index b2721a7a1eb..3468a8e2bdc 100644 --- a/plugins/analysis-kuromoji/src/test/java/org/elasticsearch/index/analysis/KuromojiAnalysisTests.java +++ b/plugins/analysis-kuromoji/src/test/java/org/elasticsearch/index/analysis/KuromojiAnalysisTests.java @@ -191,10 +191,9 @@ public class KuromojiAnalysisTests extends ESTestCase { public AnalysisService createAnalysisService() { - String json = "org/elasticsearch/index/analysis/kuromoji_analysis.json"; Settings settings = Settings.settingsBuilder() .put("path.home", createTempDir()) - .loadFromStream(json, getClass().getResourceAsStream(json)) + .loadFromClasspath("org/elasticsearch/index/analysis/kuromoji_analysis.json") .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) .build(); diff --git a/plugins/analysis-phonetic/src/test/java/org/elasticsearch/index/analysis/SimplePhoneticAnalysisTests.java b/plugins/analysis-phonetic/src/test/java/org/elasticsearch/index/analysis/SimplePhoneticAnalysisTests.java index a81ab30decf..ed3da957571 100644 --- a/plugins/analysis-phonetic/src/test/java/org/elasticsearch/index/analysis/SimplePhoneticAnalysisTests.java +++ b/plugins/analysis-phonetic/src/test/java/org/elasticsearch/index/analysis/SimplePhoneticAnalysisTests.java @@ -45,8 +45,7 @@ public class SimplePhoneticAnalysisTests extends ESTestCase { @Test public void testPhoneticTokenFilterFactory() { - String yaml = "org/elasticsearch/index/analysis/phonetic-1.yml" - Settings settings = settingsBuilder().loadFromStream(yaml, getClass().getResourceAsStream(yaml)) + Settings settings = settingsBuilder().loadFromClasspath("org/elasticsearch/index/analysis/phonetic-1.yml") .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) .put("path.home", createTempDir()) .build();