Use URI vs URL accessing File from classpath.

URL escapes special characters such as spaces which
causes the resource to not be found when used to create
a File object.  Use URI.

Closes #5915
This commit is contained in:
Matt Weber 2014-04-26 15:16:43 -07:00 committed by Luca Cavanna
parent 51ba3ca220
commit 4df4506875
3 changed files with 9 additions and 11 deletions

View File

@ -55,7 +55,7 @@ import java.io.IOException;
/**
* Test parsing and executing a template request.
* */
*/
public class TemplateQueryParserTest extends ElasticsearchTestCase {
private Injector injector;
@ -63,8 +63,7 @@ public class TemplateQueryParserTest extends ElasticsearchTestCase {
@Before
public void setup() throws IOException {
String scriptPath = this.getClass().getResource("config").getPath();
Settings settings = ImmutableSettings.settingsBuilder().put("path.conf", scriptPath).build();
Settings settings = ImmutableSettings.settingsBuilder().put("path.conf", this.getResource("config").getPath()).build();
Index index = new Index("test");
injector = new ModulesBuilder().add(

View File

@ -24,8 +24,6 @@ import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.test.ElasticsearchIntegrationTest;
import org.junit.Before;
import org.junit.Test;
@ -43,7 +41,7 @@ import static org.hamcrest.Matchers.is;
/**
* Full integration test of the template query plugin.
* */
*/
@ElasticsearchIntegrationTest.ClusterScope(scope = ElasticsearchIntegrationTest.Scope.SUITE)
public class TemplateQueryTest extends ElasticsearchIntegrationTest {
@ -59,8 +57,7 @@ public class TemplateQueryTest extends ElasticsearchIntegrationTest {
@Override
public Settings nodeSettings(int nodeOrdinal) {
String scriptPath = this.getClass().getResource("config").getPath();
return settingsBuilder().put("path.conf", scriptPath).build();
return settingsBuilder().put("path.conf", this.getResource("config").getPath()).build();
}
@Test

View File

@ -25,6 +25,7 @@ import org.elasticsearch.common.Strings;
import java.io.File;
import java.io.FileFilter;
import java.io.FileNotFoundException;
import java.net.URI;
import java.net.URL;
import java.util.Map;
import java.util.Set;
@ -92,7 +93,8 @@ public final class FileUtils {
return file;
}
}
return new File(resource.getFile());
return new File(URI.create(resource.toString()));
}
private static URL findResource(String path, String optionalFileSuffix) {