From a7d16a1dd18faca475a24dfc161e527cb371a946 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Wed, 29 Apr 2015 09:10:19 -0400 Subject: [PATCH] first strike against crazy CWD usages --- .../org/elasticsearch/env/Environment.java | 25 +++++-------------- .../indices/analysis/HunspellService.java | 6 ++--- .../elasticsearch/bootstrap/security.policy | 5 ++-- .../indices/analyze/HunspellServiceTests.java | 11 -------- .../test/InternalTestCluster.java | 24 ++++-------------- 5 files changed, 17 insertions(+), 54 deletions(-) diff --git a/src/main/java/org/elasticsearch/env/Environment.java b/src/main/java/org/elasticsearch/env/Environment.java index cab04792b5d..2c95e092bc9 100644 --- a/src/main/java/org/elasticsearch/env/Environment.java +++ b/src/main/java/org/elasticsearch/env/Environment.java @@ -175,26 +175,13 @@ public class Environment { } public URL resolveConfig(String path) throws FailedToResolveConfigException { - String origPath = path; - // first, try it as a path on the file system - Path f1 = PathUtils.get(path); - if (Files.exists(f1)) { + // first, try it as a path in the config directory + Path f = configFile.resolve(path); + if (Files.exists(f)) { try { - return f1.toUri().toURL(); + return f.toUri().toURL(); } catch (MalformedURLException e) { - throw new FailedToResolveConfigException("Failed to resolve path [" + f1 + "]", e); - } - } - if (path.startsWith("/")) { - path = path.substring(1); - } - // next, try it relative to the config location - Path f2 = configFile.resolve(path); - if (Files.exists(f2)) { - try { - return f2.toUri().toURL(); - } catch (MalformedURLException e) { - throw new FailedToResolveConfigException("Failed to resolve path [" + f1 + "]", e); + throw new FailedToResolveConfigException("Failed to resolve path [" + f + "]", e); } } // try and load it from the classpath directly @@ -209,6 +196,6 @@ public class Environment { return resource; } } - throw new FailedToResolveConfigException("Failed to resolve config path [" + origPath + "], tried file path [" + f1 + "], path file [" + f2 + "], and classpath"); + throw new FailedToResolveConfigException("Failed to resolve config path [" + path + "], tried config path [" + f + "] and classpath"); } } diff --git a/src/main/java/org/elasticsearch/indices/analysis/HunspellService.java b/src/main/java/org/elasticsearch/indices/analysis/HunspellService.java index ccb49a6fd2a..83b9a51b0c8 100644 --- a/src/main/java/org/elasticsearch/indices/analysis/HunspellService.java +++ b/src/main/java/org/elasticsearch/indices/analysis/HunspellService.java @@ -74,7 +74,7 @@ public class HunspellService extends AbstractComponent { public final static String HUNSPELL_LAZY_LOAD = "indices.analysis.hunspell.dictionary.lazy"; public final static String HUNSPELL_IGNORE_CASE = "indices.analysis.hunspell.dictionary.ignore_case"; - public final static String HUNSPELL_LOCATION = "indices.analysis.hunspell.dictionary.location"; + private final static String OLD_HUNSPELL_LOCATION = "indices.analysis.hunspell.dictionary.location"; private final LoadingCache dictionaries; private final Map knownDictionaries; @@ -116,9 +116,9 @@ public class HunspellService extends AbstractComponent { } private Path resolveHunspellDirectory(Settings settings, Environment env) { - String location = settings.get(HUNSPELL_LOCATION, null); + String location = settings.get(OLD_HUNSPELL_LOCATION, null); if (location != null) { - return PathUtils.get(location); + throw new IllegalArgumentException("please, put your hunspell dictionaries under config/hunspell !"); } return env.configFile().resolve("hunspell"); } diff --git a/src/main/resources/org/elasticsearch/bootstrap/security.policy b/src/main/resources/org/elasticsearch/bootstrap/security.policy index 44b89c47c58..771c95d44d0 100644 --- a/src/main/resources/org/elasticsearch/bootstrap/security.policy +++ b/src/main/resources/org/elasticsearch/bootstrap/security.policy @@ -31,8 +31,9 @@ grant { permission java.io.FilePermission "${java.io.tmpdir}${/}-", "read,write,delete"; // paths used for running tests - // project base directory - permission java.io.FilePermission "${project.basedir}${/}target${/}-", "read"; + // compiled classes + permission java.io.FilePermission "${project.basedir}${/}target${/}classes${/}-", "read"; + permission java.io.FilePermission "${project.basedir}${/}target${/}test-classes${/}-", "read"; // read permission for lib sigar permission java.io.FilePermission "${project.basedir}${/}lib/sigar{/}-", "read"; // mvn custom ./m2/repository for dependency jars diff --git a/src/test/java/org/elasticsearch/indices/analyze/HunspellServiceTests.java b/src/test/java/org/elasticsearch/indices/analyze/HunspellServiceTests.java index 304940e8141..742f5d1615e 100644 --- a/src/test/java/org/elasticsearch/indices/analyze/HunspellServiceTests.java +++ b/src/test/java/org/elasticsearch/indices/analyze/HunspellServiceTests.java @@ -79,17 +79,6 @@ public class HunspellServiceTests extends ElasticsearchIntegrationTest { assertIgnoreCase(true, dictionary); } - @Test - public void testCustomizeLocaleDirectory() throws Exception { - Settings settings = ImmutableSettings.settingsBuilder() - .put(HUNSPELL_LOCATION, getDataPath("/indices/analyze/conf_dir/hunspell")) - .build(); - - internalCluster().startNode(settings); - Dictionary dictionary = internalCluster().getInstance(HunspellService.class).getDictionary("en_US"); - assertThat(dictionary, notNullValue()); - } - @Test public void testDicWithNoAff() throws Exception { Settings settings = ImmutableSettings.settingsBuilder() diff --git a/src/test/java/org/elasticsearch/test/InternalTestCluster.java b/src/test/java/org/elasticsearch/test/InternalTestCluster.java index 660d228a43e..8eac41a29b2 100644 --- a/src/test/java/org/elasticsearch/test/InternalTestCluster.java +++ b/src/test/java/org/elasticsearch/test/InternalTestCluster.java @@ -805,7 +805,7 @@ public final class InternalTestCluster extends TestCluster { /* no sniff client for now - doesn't work will all tests since it might throw NoNodeAvailableException if nodes are shut down. * we first need support of transportClientRatio as annotations or so */ - return transportClient = TransportClientFactory.noSniff(settingsSource.transportClient()).client(node, clusterName); + return transportClient = new TransportClientFactory(false, settingsSource.transportClient(), baseDir).client(node, clusterName); } void resetClient() throws IOException { @@ -859,29 +859,14 @@ public final class InternalTestCluster extends TestCluster { public static final String TRANSPORT_CLIENT_PREFIX = "transport_client_"; static class TransportClientFactory { - private static TransportClientFactory NO_SNIFF_CLIENT_FACTORY = new TransportClientFactory(false, ImmutableSettings.EMPTY); - private static TransportClientFactory SNIFF_CLIENT_FACTORY = new TransportClientFactory(true, ImmutableSettings.EMPTY); - private final boolean sniff; private final Settings settings; + private final Path baseDir; - public static TransportClientFactory noSniff(Settings settings) { - if (settings == null || settings.names().isEmpty()) { - return NO_SNIFF_CLIENT_FACTORY; - } - return new TransportClientFactory(false, settings); - } - - public static TransportClientFactory sniff(Settings settings) { - if (settings == null || settings.names().isEmpty()) { - return SNIFF_CLIENT_FACTORY; - } - return new TransportClientFactory(true, settings); - } - - TransportClientFactory(boolean sniff, Settings settings) { + TransportClientFactory(boolean sniff, Settings settings, Path baseDir) { this.sniff = sniff; this.settings = settings != null ? settings : ImmutableSettings.EMPTY; + this.baseDir = baseDir; } public Client client(Node node, String clusterName) { @@ -889,6 +874,7 @@ public final class InternalTestCluster extends TestCluster { Settings nodeSettings = node.settings(); Builder builder = settingsBuilder() .put("client.transport.nodes_sampler_interval", "1s") + .put("path.home", baseDir) .put("name", TRANSPORT_CLIENT_PREFIX + node.settings().get("name")) .put("plugins." + PluginsService.LOAD_PLUGIN_FROM_CLASSPATH, false) .put(ClusterName.SETTING, clusterName).put("client.transport.sniff", sniff)