diff --git a/dev-tools/forbidden/all-signatures.txt b/dev-tools/forbidden/all-signatures.txt index e8494c2721e..5e893e537f3 100644 --- a/dev-tools/forbidden/all-signatures.txt +++ b/dev-tools/forbidden/all-signatures.txt @@ -33,3 +33,6 @@ java.nio.file.Path#toFile() @defaultMessage Don't use deprecated lucene apis org.apache.lucene.index.DocsEnum org.apache.lucene.index.DocsAndPositionsEnum + +java.nio.file.Paths @ Use PathUtils.get instead. +java.nio.file.FileSystems#getDefault() @ use PathUtils.getDefault instead. diff --git a/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java b/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java index 47288a667b0..9020d115a8b 100644 --- a/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java +++ b/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java @@ -26,6 +26,8 @@ import org.elasticsearch.common.SuppressForbidden; import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.inject.CreationException; import org.elasticsearch.common.inject.spi.Message; +import org.elasticsearch.common.io.FileSystemUtils; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.jna.Natives; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; @@ -153,7 +155,7 @@ public class Bootstrap { if (pidFile != null) { try { - PidFile.create(Paths.get(pidFile), true); + PidFile.create(PathUtils.get(pidFile), true); } catch (Exception e) { String errorMessage = buildErrorMessage("pid", e); sysError(errorMessage, true); diff --git a/src/main/java/org/elasticsearch/common/io/FileSystemUtils.java b/src/main/java/org/elasticsearch/common/io/FileSystemUtils.java index 12440352be8..a0a7f50de4f 100644 --- a/src/main/java/org/elasticsearch/common/io/FileSystemUtils.java +++ b/src/main/java/org/elasticsearch/common/io/FileSystemUtils.java @@ -208,7 +208,7 @@ public final class FileSystemUtils { } else if (suffix != null) { if (!isSameFile(file, path)) { // If it already exists we try to copy this new version appending suffix to its name - path = Paths.get(path.toString().concat(suffix)); + path = path.resolveSibling(path.getFileName().toString().concat(suffix)); // We just move the file to new dir but with a new name (appended with suffix) Files.move(file, path, StandardCopyOption.REPLACE_EXISTING); } diff --git a/src/main/java/org/elasticsearch/common/io/PathUtils.java b/src/main/java/org/elasticsearch/common/io/PathUtils.java new file mode 100644 index 00000000000..a896e82f0e5 --- /dev/null +++ b/src/main/java/org/elasticsearch/common/io/PathUtils.java @@ -0,0 +1,81 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.common.io; + +import org.elasticsearch.common.SuppressForbidden; + +import java.net.URI; +import java.nio.file.FileSystem; +import java.nio.file.FileSystems; +import java.nio.file.Path; +import java.nio.file.Paths; + +/** + * Utilities for creating a Path from names, + * or accessing the default FileSystem. + *

+ * This class allows the default filesystem to + * be changed during tests. + */ +@SuppressForbidden(reason = "accesses the default filesystem by design") +public final class PathUtils { + /** no instantiation */ + private PathUtils() {} + + /** can be changed by tests */ + static FileSystem DEFAULT = FileSystems.getDefault(); + + /** + * Returns a {@code Path} from name components. + *

+ * This works just like {@code Paths.get()}. + * Remember: just like {@code Paths.get()} this is NOT A STRING CONCATENATION + * UTILITY FUNCTION. + *

+ * Remember: this should almost never be used. Usually resolve + * a path against an existing one! + */ + public static Path get(String first, String... more) { + return DEFAULT.getPath(first, more); + } + + /** + * Returns a {@code Path} from a URI + *

+ * This works just like {@code Paths.get()}. + *

+ * Remember: this should almost never be used. Usually resolve + * a path against an existing one! + */ + public static Path get(URI uri) { + if (uri.getScheme().equalsIgnoreCase("file")) { + return DEFAULT.provider().getPath(uri); + } else { + return Paths.get(uri); + } + } + + /** + * Returns the default FileSystem. + */ + public static FileSystem getDefaultFileSystem() { + return DEFAULT; + } +} diff --git a/src/main/java/org/elasticsearch/env/Environment.java b/src/main/java/org/elasticsearch/env/Environment.java index 62f09d72d04..87a356774f1 100644 --- a/src/main/java/org/elasticsearch/env/Environment.java +++ b/src/main/java/org/elasticsearch/env/Environment.java @@ -20,6 +20,8 @@ package org.elasticsearch.env; import org.elasticsearch.cluster.ClusterName; +import org.elasticsearch.common.io.FileSystemUtils; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.io.Streams; import org.elasticsearch.common.settings.Settings; @@ -68,25 +70,25 @@ public class Environment { public Environment(Settings settings) { this.settings = settings; if (settings.get("path.home") != null) { - homeFile = Paths.get(cleanPath(settings.get("path.home"))); + homeFile = PathUtils.get(cleanPath(settings.get("path.home"))); } else { - homeFile = Paths.get(System.getProperty("user.dir")); + homeFile = PathUtils.get(System.getProperty("user.dir")); } if (settings.get("path.conf") != null) { - configFile = Paths.get(cleanPath(settings.get("path.conf"))); + configFile = PathUtils.get(cleanPath(settings.get("path.conf"))); } else { configFile = homeFile.resolve("config"); } if (settings.get("path.plugins") != null) { - pluginsFile = Paths.get(cleanPath(settings.get("path.plugins"))); + pluginsFile = PathUtils.get(cleanPath(settings.get("path.plugins"))); } else { pluginsFile = homeFile.resolve("plugins"); } if (settings.get("path.work") != null) { - workFile = Paths.get(cleanPath(settings.get("path.work"))); + workFile = PathUtils.get(cleanPath(settings.get("path.work"))); } else { workFile = homeFile.resolve("work"); } @@ -97,7 +99,7 @@ public class Environment { dataFiles = new Path[dataPaths.length]; dataWithClusterFiles = new Path[dataPaths.length]; for (int i = 0; i < dataPaths.length; i++) { - dataFiles[i] = Paths.get(dataPaths[i]); + dataFiles[i] = PathUtils.get(dataPaths[i]); dataWithClusterFiles[i] = dataFiles[i].resolve(ClusterName.clusterNameFromSettings(settings).value()); } } else { @@ -106,7 +108,7 @@ public class Environment { } if (settings.get("path.logs") != null) { - logsFile = Paths.get(cleanPath(settings.get("path.logs"))); + logsFile = PathUtils.get(cleanPath(settings.get("path.logs"))); } else { logsFile = homeFile.resolve("logs"); } @@ -178,7 +180,7 @@ 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 = Paths.get(path); + Path f1 = PathUtils.get(path); if (Files.exists(f1)) { try { return f1.toUri().toURL(); diff --git a/src/main/java/org/elasticsearch/env/NodeEnvironment.java b/src/main/java/org/elasticsearch/env/NodeEnvironment.java index 201fe226af6..458acf5e935 100644 --- a/src/main/java/org/elasticsearch/env/NodeEnvironment.java +++ b/src/main/java/org/elasticsearch/env/NodeEnvironment.java @@ -22,6 +22,7 @@ package org.elasticsearch.env; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; import com.google.common.primitives.Ints; + import org.apache.lucene.store.*; import org.apache.lucene.util.Constants; import org.apache.lucene.util.IOUtils; @@ -33,6 +34,7 @@ import org.elasticsearch.common.Nullable; import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.io.FileSystemUtils; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.ByteSizeValue; @@ -128,7 +130,8 @@ public class NodeEnvironment extends AbstractComponent implements Closeable { int maxLocalStorageNodes = settings.getAsInt("node.max_local_storage_nodes", 50); for (int possibleLockId = 0; possibleLockId < maxLocalStorageNodes; possibleLockId++) { for (int dirIndex = 0; dirIndex < environment.dataWithClusterFiles().length; dirIndex++) { - Path dir = environment.dataWithClusterFiles()[dirIndex].resolve(Paths.get(NODES_FOLDER, Integer.toString(possibleLockId))); + // TODO: wtf with resolve(get()) + Path dir = environment.dataWithClusterFiles()[dirIndex].resolve(PathUtils.get(NODES_FOLDER, Integer.toString(possibleLockId))); Files.createDirectories(dir); try (Directory luceneDir = FSDirectory.open(dir, NativeFSLockFactory.INSTANCE)) { @@ -616,7 +619,8 @@ public class NodeEnvironment extends AbstractComponent implements Closeable { final NodePath[] nodePaths = nodePaths(); final Path[] shardLocations = new Path[nodePaths.length]; for (int i = 0; i < nodePaths.length; i++) { - shardLocations[i] = nodePaths[i].path.resolve(Paths.get(INDICES_FOLDER, + // TODO: wtf with resolve(get()) + shardLocations[i] = nodePaths[i].path.resolve(PathUtils.get(INDICES_FOLDER, shardId.index().name(), Integer.toString(shardId.id()))); } @@ -730,9 +734,9 @@ public class NodeEnvironment extends AbstractComponent implements Closeable { // This assert is because this should be caught by MetaDataCreateIndexService assert customPathsEnabled; if (addNodeId) { - return Paths.get(customDataDir, Integer.toString(this.localNodeId)); + return PathUtils.get(customDataDir, Integer.toString(this.localNodeId)); } else { - return Paths.get(customDataDir); + return PathUtils.get(customDataDir); } } else { throw new ElasticsearchIllegalArgumentException("no custom " + IndexMetaData.SETTING_DATA_PATH + " setting available"); diff --git a/src/main/java/org/elasticsearch/http/HttpServer.java b/src/main/java/org/elasticsearch/http/HttpServer.java index b4a26ba8c57..6d43053e408 100644 --- a/src/main/java/org/elasticsearch/http/HttpServer.java +++ b/src/main/java/org/elasticsearch/http/HttpServer.java @@ -25,6 +25,7 @@ import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.component.AbstractLifecycleComponent; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.io.FileSystemUtils; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; import org.elasticsearch.node.service.NodeService; @@ -175,7 +176,7 @@ public class HttpServer extends AbstractLifecycleComponent { // Convert file separators. sitePath = sitePath.replace("/", separator); // this is a plugin provided site, serve it as static files from the plugin location - Path file = FileSystemUtils.append(siteFile, Paths.get(sitePath), 0); + Path file = FileSystemUtils.append(siteFile, PathUtils.get(sitePath), 0); if (!Files.exists(file) || Files.isHidden(file)) { channel.sendResponse(new BytesRestResponse(NOT_FOUND)); return; diff --git a/src/main/java/org/elasticsearch/index/mapper/MapperService.java b/src/main/java/org/elasticsearch/index/mapper/MapperService.java index 697d2488bd3..e7629f51035 100755 --- a/src/main/java/org/elasticsearch/index/mapper/MapperService.java +++ b/src/main/java/org/elasticsearch/index/mapper/MapperService.java @@ -45,6 +45,7 @@ import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.compress.CompressedString; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.io.FileSystemUtils; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.io.Streams; import org.elasticsearch.common.lucene.search.AndFilter; import org.elasticsearch.common.lucene.search.NotFilter; @@ -180,7 +181,7 @@ public class MapperService extends AbstractIndexComponent { } catch (FailedToResolveConfigException e) { // not there, default to the built in one try { - percolatorMappingUrl = Paths.get(percolatorMappingLocation).toUri().toURL(); + percolatorMappingUrl = PathUtils.get(percolatorMappingLocation).toUri().toURL(); } catch (MalformedURLException e1) { throw new FailedToResolveConfigException("Failed to resolve default percolator mapping location [" + percolatorMappingLocation + "]"); } @@ -231,7 +232,7 @@ public class MapperService extends AbstractIndexComponent { } catch (FailedToResolveConfigException e) { // not there, default to the built in one try { - mappingUrl = Paths.get(mappingLocation).toUri().toURL(); + mappingUrl = PathUtils.get(mappingLocation).toUri().toURL(); } catch (MalformedURLException e1) { throw new FailedToResolveConfigException("Failed to resolve dynamic mapping location [" + mappingLocation + "]"); } diff --git a/src/main/java/org/elasticsearch/index/translog/Translog.java b/src/main/java/org/elasticsearch/index/translog/Translog.java index ac993dedac7..2424b02c763 100644 --- a/src/main/java/org/elasticsearch/index/translog/Translog.java +++ b/src/main/java/org/elasticsearch/index/translog/Translog.java @@ -146,9 +146,9 @@ public interface Translog extends IndexShardComponent, Closeable, Accountable { /** * Returns the translog file with the given id as a Path. This - * will return a relative path. + * will return a filename. */ - Path getPath(long translogId); + String getPath(long translogId); /** * return stats diff --git a/src/main/java/org/elasticsearch/index/translog/fs/FsTranslog.java b/src/main/java/org/elasticsearch/index/translog/fs/FsTranslog.java index 85164fda6fb..b816f884bfc 100644 --- a/src/main/java/org/elasticsearch/index/translog/fs/FsTranslog.java +++ b/src/main/java/org/elasticsearch/index/translog/fs/FsTranslog.java @@ -431,8 +431,8 @@ public class FsTranslog extends AbstractIndexShardComponent implements Translog } @Override - public Path getPath(long translogId) { - return Paths.get(TRANSLOG_FILE_PREFIX + translogId); + public String getPath(long translogId) { + return TRANSLOG_FILE_PREFIX + translogId; } @Override @@ -473,14 +473,14 @@ public class FsTranslog extends AbstractIndexShardComponent implements Translog @Override public OperationIterator openIterator(long translogId) throws IOException { - final Path translogName = getPath(translogId); + final String translogName = getPath(translogId); Path recoveringTranslogFile = null; logger.trace("try open translog file {} locations: {}", translogName, Arrays.toString(locations())); OUTER: for (Path translogLocation : locations()) { // we have to support .recovering since it's a leftover from previous version but might still be on the filesystem // we used to rename the foo into foo.recovering since foo was reused / overwritten but we fixed that in 2.0 - for (Path recoveryFiles : FileSystemUtils.files(translogLocation, translogName.getFileName() + "{.recovering,}")) { + for (Path recoveryFiles : FileSystemUtils.files(translogLocation, translogName + "{.recovering,}")) { logger.trace("translog file found in {}", recoveryFiles); recoveringTranslogFile = recoveryFiles; break OUTER; diff --git a/src/main/java/org/elasticsearch/indices/analysis/HunspellService.java b/src/main/java/org/elasticsearch/indices/analysis/HunspellService.java index b5628fcf370..ccb49a6fd2a 100644 --- a/src/main/java/org/elasticsearch/indices/analysis/HunspellService.java +++ b/src/main/java/org/elasticsearch/indices/analysis/HunspellService.java @@ -22,11 +22,13 @@ import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; import com.google.common.util.concurrent.UncheckedExecutionException; + import org.apache.lucene.analysis.hunspell.Dictionary; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.io.FileSystemUtils; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; @@ -116,7 +118,7 @@ public class HunspellService extends AbstractComponent { private Path resolveHunspellDirectory(Settings settings, Environment env) { String location = settings.get(HUNSPELL_LOCATION, null); if (location != null) { - return Paths.get(location); + return PathUtils.get(location); } return env.configFile().resolve("hunspell"); } diff --git a/src/main/java/org/elasticsearch/plugins/PluginsService.java b/src/main/java/org/elasticsearch/plugins/PluginsService.java index 87420fc7184..7a7c569acbe 100644 --- a/src/main/java/org/elasticsearch/plugins/PluginsService.java +++ b/src/main/java/org/elasticsearch/plugins/PluginsService.java @@ -21,6 +21,7 @@ package org.elasticsearch.plugins; import com.google.common.base.Charsets; import com.google.common.collect.*; + import org.apache.lucene.util.Constants; import org.apache.lucene.util.IOUtils; import org.elasticsearch.ElasticsearchException; @@ -35,6 +36,7 @@ import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.component.LifecycleComponent; import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.io.FileSystemUtils; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.settings.ImmutableSettings; @@ -61,7 +63,7 @@ public class PluginsService extends AbstractComponent { public static final String ES_PLUGIN_PROPERTIES = "es-plugin.properties"; public static final String LOAD_PLUGIN_FROM_CLASSPATH = "plugins.load_classpath_plugins"; - private static final PathMatcher PLUGIN_LIB_MATCHER = FileSystems.getDefault().getPathMatcher("glob:**.{jar,zip}"); + static final String PLUGIN_LIB_PATTERN = "glob:**.{jar,zip}"; public static final String PLUGINS_CHECK_LUCENE_KEY = "plugins.check_lucene"; public static final String PLUGINS_INFO_REFRESH_INTERVAL_KEY = "plugins.info_refresh_interval"; @@ -393,9 +395,11 @@ public class PluginsService extends AbstractComponent { libFiles.addAll(Arrays.asList(files(libLocation))); } + PathMatcher matcher = PathUtils.getDefaultFileSystem().getPathMatcher(PLUGIN_LIB_PATTERN); + // if there are jars in it, add it as well for (Path libFile : libFiles) { - if (!hasLibExtension(libFile)) { + if (!matcher.matches(libFile)) { continue; } addURL.invoke(classLoader, libFile.toUri().toURL()); @@ -407,10 +411,6 @@ public class PluginsService extends AbstractComponent { } } - protected static boolean hasLibExtension(Path lib) { - return PLUGIN_LIB_MATCHER.matches(lib); - } - private Path[] files(Path from) throws IOException { try (DirectoryStream stream = Files.newDirectoryStream(from)) { return Iterators.toArray(stream.iterator(), Path.class); diff --git a/src/main/java/org/elasticsearch/repositories/fs/FsRepository.java b/src/main/java/org/elasticsearch/repositories/fs/FsRepository.java index aa65f6983da..49c783b56ae 100644 --- a/src/main/java/org/elasticsearch/repositories/fs/FsRepository.java +++ b/src/main/java/org/elasticsearch/repositories/fs/FsRepository.java @@ -23,6 +23,8 @@ import org.elasticsearch.common.blobstore.BlobPath; import org.elasticsearch.common.blobstore.BlobStore; import org.elasticsearch.common.blobstore.fs.FsBlobStore; import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.io.FileSystemUtils; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.index.snapshots.IndexShardRepository; import org.elasticsearch.repositories.RepositoryException; @@ -74,7 +76,7 @@ public class FsRepository extends BlobStoreRepository { logger.warn("using local fs location for gateway, should be changed to be a shared location across nodes"); throw new RepositoryException(name.name(), "missing location"); } else { - locationFile = Paths.get(location); + locationFile = PathUtils.get(location); } blobStore = new FsBlobStore(settings, locationFile); this.chunkSize = repositorySettings.settings().getAsBytesSize("chunk_size", settings.getAsBytesSize("repositories.fs.chunk_size", null)); diff --git a/src/test/java/org/apache/lucene/util/AbstractRandomizedTest.java b/src/test/java/org/apache/lucene/util/AbstractRandomizedTest.java index d5cbdf8b076..696b34d0b04 100644 --- a/src/test/java/org/apache/lucene/util/AbstractRandomizedTest.java +++ b/src/test/java/org/apache/lucene/util/AbstractRandomizedTest.java @@ -27,7 +27,9 @@ import com.carrotsearch.randomizedtesting.rules.NoClassHooksShadowingRule; import com.carrotsearch.randomizedtesting.rules.NoInstanceHooksOverridesRule; import com.carrotsearch.randomizedtesting.rules.StaticFieldsInvariantRule; import com.carrotsearch.randomizedtesting.rules.SystemPropertiesInvariantRule; + import org.apache.lucene.util.LuceneTestCase.SuppressCodecs; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.util.concurrent.EsExecutors; @@ -190,7 +192,7 @@ public abstract class AbstractRandomizedTest extends RandomizedTest { String s = System.getProperty("tempDir", System.getProperty("java.io.tmpdir")); if (s == null) throw new RuntimeException("To run tests, you need to define system property 'tempDir' or 'java.io.tmpdir'."); - TEMP_DIR = Paths.get(s); + TEMP_DIR = PathUtils.get(s); try { Files.createDirectories(TEMP_DIR); } catch (IOException e) { diff --git a/src/test/java/org/elasticsearch/NamingConventionTests.java b/src/test/java/org/elasticsearch/NamingConventionTests.java index 3a792c35e41..549a367c548 100644 --- a/src/test/java/org/elasticsearch/NamingConventionTests.java +++ b/src/test/java/org/elasticsearch/NamingConventionTests.java @@ -20,8 +20,11 @@ package org.elasticsearch; import com.google.common.base.Joiner; import com.google.common.collect.Sets; + import junit.framework.TestCase; + import org.apache.lucene.util.LuceneTestCase; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.test.ElasticsearchLuceneTestCase; import org.elasticsearch.test.ElasticsearchTestCase; import org.elasticsearch.test.ElasticsearchTokenStreamTestCase; @@ -51,10 +54,10 @@ public class NamingConventionTests extends ElasticsearchTestCase { String[] packages = {"org.elasticsearch", "org.apache.lucene"}; for (final String packageName : packages) { final String path = "/" + packageName.replace('.', '/'); - final Path startPath = Paths.get(NamingConventionTests.class.getResource(path).toURI()); - final Set ignore = Sets.newHashSet(Paths.get("/org/elasticsearch/stresstest"), Paths.get("/org/elasticsearch/benchmark/stress")); + final Path startPath = PathUtils.get(NamingConventionTests.class.getResource(path).toURI()); + final Set ignore = Sets.newHashSet(PathUtils.get("/org/elasticsearch/stresstest"), PathUtils.get("/org/elasticsearch/benchmark/stress")); Files.walkFileTree(startPath, new FileVisitor() { - private Path pkgPrefix = Paths.get(path).getParent(); + private Path pkgPrefix = PathUtils.get(path).getParent(); @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { Path next = pkgPrefix.resolve(dir.getFileName()); diff --git a/src/test/java/org/elasticsearch/benchmark/common/lucene/uidscan/LuceneUidScanBenchmark.java b/src/test/java/org/elasticsearch/benchmark/common/lucene/uidscan/LuceneUidScanBenchmark.java index 41ddbc20c59..fe548b9ee4c 100644 --- a/src/test/java/org/elasticsearch/benchmark/common/lucene/uidscan/LuceneUidScanBenchmark.java +++ b/src/test/java/org/elasticsearch/benchmark/common/lucene/uidscan/LuceneUidScanBenchmark.java @@ -25,6 +25,7 @@ import org.apache.lucene.document.StringField; import org.apache.lucene.index.*; import org.apache.lucene.store.FSDirectory; import org.elasticsearch.common.StopWatch; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.lucene.uid.Versions; import org.elasticsearch.common.unit.SizeValue; @@ -40,7 +41,7 @@ public class LuceneUidScanBenchmark { public static void main(String[] args) throws Exception { - FSDirectory dir = FSDirectory.open(Paths.get("work/test")); + FSDirectory dir = FSDirectory.open(PathUtils.get("work/test")); IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(Lucene.STANDARD_ANALYZER)); final int NUMBER_OF_THREADS = 2; diff --git a/src/test/java/org/elasticsearch/benchmark/fs/FsAppendBenchmark.java b/src/test/java/org/elasticsearch/benchmark/fs/FsAppendBenchmark.java index 99bb5375c55..7dd6481a0c9 100644 --- a/src/test/java/org/elasticsearch/benchmark/fs/FsAppendBenchmark.java +++ b/src/test/java/org/elasticsearch/benchmark/fs/FsAppendBenchmark.java @@ -20,6 +20,7 @@ package org.elasticsearch.benchmark.fs; import org.apache.lucene.util.IOUtils; import org.elasticsearch.common.StopWatch; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.unit.ByteSizeValue; import java.nio.ByteBuffer; @@ -35,7 +36,7 @@ import java.util.Random; public class FsAppendBenchmark { public static void main(String[] args) throws Exception { - Path path = Paths.get("work/test.log"); + Path path = PathUtils.get("work/test.log"); IOUtils.deleteFilesIgnoringExceptions(path); int CHUNK = (int) ByteSizeValue.parseBytesSizeValue("1k").bytes(); diff --git a/src/test/java/org/elasticsearch/benchmark/scripts/score/BasicScriptBenchmark.java b/src/test/java/org/elasticsearch/benchmark/scripts/score/BasicScriptBenchmark.java index 59683666aa4..79b009e2010 100644 --- a/src/test/java/org/elasticsearch/benchmark/scripts/score/BasicScriptBenchmark.java +++ b/src/test/java/org/elasticsearch/benchmark/scripts/score/BasicScriptBenchmark.java @@ -25,6 +25,7 @@ import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchType; import org.elasticsearch.client.Client; import org.elasticsearch.common.StopWatch; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.lucene.search.function.CombineFunction; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -150,7 +151,7 @@ public class BasicScriptBenchmark { } public static void writeHelperFunction() throws IOException { - try (BufferedWriter out = Files.newBufferedWriter(Paths.get("addToPlot.m"), StandardCharsets.UTF_8)) { + try (BufferedWriter out = Files.newBufferedWriter(PathUtils.get("addToPlot.m"), StandardCharsets.UTF_8)) { out.write("function handle = addToPlot(numTerms, perDoc, color, linestyle, linewidth)\n" + "handle = line(numTerms, perDoc);\n" + "set(handle, 'color', color);\n" + "set(handle, 'linestyle',linestyle);\n" + "set(handle, 'LineWidth',linewidth);\n" + "end\n"); @@ -161,7 +162,7 @@ public class BasicScriptBenchmark { if (args.length == 0) { return; } - try (BufferedWriter out = Files.newBufferedWriter(Paths.get(args[0]), StandardCharsets.UTF_8)) { + try (BufferedWriter out = Files.newBufferedWriter(PathUtils.get(args[0]), StandardCharsets.UTF_8)) { out.write("#! /usr/local/bin/octave -qf"); out.write("\n\n\n\n"); out.write("######################################\n"); diff --git a/src/test/java/org/elasticsearch/bwcompat/OldIndexBackwardsCompatibilityTests.java b/src/test/java/org/elasticsearch/bwcompat/OldIndexBackwardsCompatibilityTests.java index 497d497847d..ba719d064b5 100644 --- a/src/test/java/org/elasticsearch/bwcompat/OldIndexBackwardsCompatibilityTests.java +++ b/src/test/java/org/elasticsearch/bwcompat/OldIndexBackwardsCompatibilityTests.java @@ -21,6 +21,7 @@ package org.elasticsearch.bwcompat; import com.carrotsearch.randomizedtesting.LifecycleScope; import com.google.common.util.concurrent.ListenableFuture; + import org.apache.lucene.index.IndexWriter; import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.TestUtil; @@ -30,6 +31,7 @@ import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.action.search.SearchRequestBuilder; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.common.io.FileSystemUtils; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; @@ -88,7 +90,7 @@ public class OldIndexBackwardsCompatibilityTests extends ElasticsearchIntegratio public static void initIndexesList() throws Exception { indexes = new ArrayList<>(); URL dirUrl = OldIndexBackwardsCompatibilityTests.class.getResource("."); - Path dir = Paths.get(dirUrl.toURI()); + Path dir = PathUtils.get(dirUrl.toURI()); try (DirectoryStream stream = Files.newDirectoryStream(dir, "index-*.zip")) { for (Path path : stream) { indexes.add(path.getFileName().toString()); @@ -157,7 +159,7 @@ public class OldIndexBackwardsCompatibilityTests extends ElasticsearchIntegratio String indexName = indexFile.replace(".zip", "").toLowerCase(Locale.ROOT); // decompress the index - Path backwardsIndex = Paths.get(getClass().getResource(indexFile).toURI()); + Path backwardsIndex = PathUtils.get(getClass().getResource(indexFile).toURI()); try (InputStream stream = Files.newInputStream(backwardsIndex)) { TestUtil.unzip(stream, unzipDir); } diff --git a/src/test/java/org/elasticsearch/bwcompat/RestoreBackwardsCompatTests.java b/src/test/java/org/elasticsearch/bwcompat/RestoreBackwardsCompatTests.java index fce98bb7c22..f61cf9b3db8 100644 --- a/src/test/java/org/elasticsearch/bwcompat/RestoreBackwardsCompatTests.java +++ b/src/test/java/org/elasticsearch/bwcompat/RestoreBackwardsCompatTests.java @@ -26,6 +26,7 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.IndexTemplateMetaData; import org.elasticsearch.cluster.routing.allocation.decider.FilterAllocationDecider; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.snapshots.AbstractSnapshotTests; @@ -94,7 +95,7 @@ public class RestoreBackwardsCompatTests extends AbstractSnapshotTests { public static List repoVersions() throws Exception { List repoVersions = newArrayList(); - Path repoFiles = Paths.get(RestoreBackwardsCompatTests.class.getResource(".").toURI()); + Path repoFiles = PathUtils.get(RestoreBackwardsCompatTests.class.getResource(".").toURI()); try (DirectoryStream stream = Files.newDirectoryStream(repoFiles, "repo-*.zip")) { for (Path entry : stream) { String fileName = entry.getFileName().toString(); diff --git a/src/test/java/org/elasticsearch/cluster/routing/RoutingBackwardCompatibilityUponUpgradeTests.java b/src/test/java/org/elasticsearch/cluster/routing/RoutingBackwardCompatibilityUponUpgradeTests.java index 145fe5ca2c0..15c6954ef38 100644 --- a/src/test/java/org/elasticsearch/cluster/routing/RoutingBackwardCompatibilityUponUpgradeTests.java +++ b/src/test/java/org/elasticsearch/cluster/routing/RoutingBackwardCompatibilityUponUpgradeTests.java @@ -24,6 +24,7 @@ import org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse; import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.cluster.metadata.IndexMetaData; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.node.Node; @@ -48,7 +49,7 @@ public class RoutingBackwardCompatibilityUponUpgradeTests extends ElasticsearchI } private void test(String name, Class expectedHashFunction, boolean expectedUseType) throws Exception { - Path zippedIndexDir = Paths.get(getClass().getResource("/org/elasticsearch/cluster/routing/" + name + ".zip").toURI()); + Path zippedIndexDir = PathUtils.get(getClass().getResource("/org/elasticsearch/cluster/routing/" + name + ".zip").toURI()); Settings baseSettings = prepareBackwardsDataDir(zippedIndexDir); internalCluster().startNode(ImmutableSettings.builder() .put(baseSettings) diff --git a/src/test/java/org/elasticsearch/common/io/FileSystemUtilsTests.java b/src/test/java/org/elasticsearch/common/io/FileSystemUtilsTests.java index 6f75150f1ed..13c90112be4 100644 --- a/src/test/java/org/elasticsearch/common/io/FileSystemUtilsTests.java +++ b/src/test/java/org/elasticsearch/common/io/FileSystemUtilsTests.java @@ -53,7 +53,7 @@ public class FileSystemUtilsTests extends ElasticsearchTestCase { // We first copy sources test files from src/test/resources // Because after when the test runs, src files are moved to their destination - final Path path = Paths.get(FileSystemUtilsTests.class.getResource("/org/elasticsearch/common/io/copyappend").toURI()); + final Path path = PathUtils.get(FileSystemUtilsTests.class.getResource("/org/elasticsearch/common/io/copyappend").toURI()); FileSystemUtils.copyDirectoryRecursively(path, src); } @@ -161,13 +161,13 @@ public class FileSystemUtilsTests extends ElasticsearchTestCase { @Test public void testAppend() { - assertEquals(FileSystemUtils.append(Paths.get("/foo/bar"), Paths.get("/hello/world/this_is/awesome"), 0), - Paths.get("/foo/bar/hello/world/this_is/awesome")); + assertEquals(FileSystemUtils.append(PathUtils.get("/foo/bar"), PathUtils.get("/hello/world/this_is/awesome"), 0), + PathUtils.get("/foo/bar/hello/world/this_is/awesome")); - assertEquals(FileSystemUtils.append(Paths.get("/foo/bar"), Paths.get("/hello/world/this_is/awesome"), 2), - Paths.get("/foo/bar/this_is/awesome")); + assertEquals(FileSystemUtils.append(PathUtils.get("/foo/bar"), PathUtils.get("/hello/world/this_is/awesome"), 2), + PathUtils.get("/foo/bar/this_is/awesome")); - assertEquals(FileSystemUtils.append(Paths.get("/foo/bar"), Paths.get("/hello/world/this_is/awesome"), 1), - Paths.get("/foo/bar/world/this_is/awesome")); + assertEquals(FileSystemUtils.append(PathUtils.get("/foo/bar"), PathUtils.get("/hello/world/this_is/awesome"), 1), + PathUtils.get("/foo/bar/world/this_is/awesome")); } } diff --git a/src/test/java/org/elasticsearch/common/logging/log4j/Log4jESLoggerTests.java b/src/test/java/org/elasticsearch/common/logging/log4j/Log4jESLoggerTests.java index cb55da1be98..c3513822781 100644 --- a/src/test/java/org/elasticsearch/common/logging/log4j/Log4jESLoggerTests.java +++ b/src/test/java/org/elasticsearch/common/logging/log4j/Log4jESLoggerTests.java @@ -24,6 +24,7 @@ import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.apache.log4j.spi.LocationInfo; import org.apache.log4j.spi.LoggingEvent; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; @@ -129,7 +130,7 @@ public class Log4jESLoggerTests extends ElasticsearchTestCase { private static Path resolveConfigDir() throws Exception { URL url = Log4jESLoggerTests.class.getResource("config"); - return Paths.get(url.toURI()); + return PathUtils.get(url.toURI()); } private static class TestAppender extends AppenderSkeleton { diff --git a/src/test/java/org/elasticsearch/common/logging/log4j/LoggingConfigurationTests.java b/src/test/java/org/elasticsearch/common/logging/log4j/LoggingConfigurationTests.java index 264b82a287d..ac72682a2c9 100644 --- a/src/test/java/org/elasticsearch/common/logging/log4j/LoggingConfigurationTests.java +++ b/src/test/java/org/elasticsearch/common/logging/log4j/LoggingConfigurationTests.java @@ -21,6 +21,7 @@ package org.elasticsearch.common.logging.log4j; import org.apache.log4j.Appender; import org.apache.log4j.Logger; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.ImmutableSettings; @@ -145,7 +146,7 @@ public class LoggingConfigurationTests extends ElasticsearchTestCase { private static Path resolveConfigDir() throws Exception { URL url = LoggingConfigurationTests.class.getResource("config"); - return Paths.get(url.toURI()); + return PathUtils.get(url.toURI()); } private static String loggingConfiguration(String suffix) { diff --git a/src/test/java/org/elasticsearch/env/NodeEnvironmentTests.java b/src/test/java/org/elasticsearch/env/NodeEnvironmentTests.java index 5e63bcdac9d..e216f30f910 100644 --- a/src/test/java/org/elasticsearch/env/NodeEnvironmentTests.java +++ b/src/test/java/org/elasticsearch/env/NodeEnvironmentTests.java @@ -22,6 +22,7 @@ import org.apache.lucene.store.LockObtainFailedException; import org.apache.lucene.util.IOUtils; import org.elasticsearch.ElasticsearchIllegalStateException; import org.elasticsearch.cluster.metadata.IndexMetaData; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.AbstractRunnable; @@ -69,7 +70,7 @@ public class NodeEnvironmentTests extends ElasticsearchTestCase { assertEquals(env.nodeDataPaths().length, dataPaths.length); for (int i = 0; i < dataPaths.length; i++) { - assertTrue(env.nodeDataPaths()[i].startsWith(Paths.get(dataPaths[i]))); + assertTrue(env.nodeDataPaths()[i].startsWith(PathUtils.get(dataPaths[i]))); } env.close(); assertTrue("LockedShards: " + env.lockedShards(), env.lockedShards().isEmpty()); @@ -312,7 +313,7 @@ public class NodeEnvironmentTests extends ElasticsearchTestCase { assertTrue("settings with path_data should have a custom data path", NodeEnvironment.hasCustomDataPath(s2)); assertThat(env.shardDataPaths(sid, s1), equalTo(env.shardPaths(sid))); - assertThat(env.shardDataPaths(sid, s2), equalTo(new Path[] {Paths.get("/tmp/foo/0/myindex/0")})); + assertThat(env.shardDataPaths(sid, s2), equalTo(new Path[] {PathUtils.get("/tmp/foo/0/myindex/0")})); assertThat("shard paths with a custom data_path should contain only regular paths", env.shardPaths(sid), @@ -326,7 +327,7 @@ public class NodeEnvironmentTests extends ElasticsearchTestCase { ImmutableSettings.builder().put(NodeEnvironment.ADD_NODE_ID_TO_CUSTOM_PATH, false).build()); assertThat(env2.shardDataPaths(sid, s1), equalTo(env2.shardPaths(sid))); - assertThat(env2.shardDataPaths(sid, s2), equalTo(new Path[] {Paths.get("/tmp/foo/myindex/0")})); + assertThat(env2.shardDataPaths(sid, s2), equalTo(new Path[] {PathUtils.get("/tmp/foo/myindex/0")})); assertThat("shard paths with a custom data_path should contain only regular paths", env2.shardPaths(sid), @@ -342,7 +343,7 @@ public class NodeEnvironmentTests extends ElasticsearchTestCase { private Path[] stringsToPaths(String[] strings, String additional) { Path[] locations = new Path[strings.length]; for (int i = 0; i < strings.length; i++) { - locations[i] = Paths.get(strings[i], additional); + locations[i] = PathUtils.get(strings[i], additional); } return locations; } diff --git a/src/test/java/org/elasticsearch/index/store/CorruptedFileTest.java b/src/test/java/org/elasticsearch/index/store/CorruptedFileTest.java index 0c793981395..2763b6264ad 100644 --- a/src/test/java/org/elasticsearch/index/store/CorruptedFileTest.java +++ b/src/test/java/org/elasticsearch/index/store/CorruptedFileTest.java @@ -23,6 +23,7 @@ import com.carrotsearch.randomizedtesting.LifecycleScope; import com.carrotsearch.randomizedtesting.generators.RandomPicks; import com.google.common.base.Charsets; import com.google.common.base.Predicate; + import org.apache.lucene.codecs.CodecUtil; import org.apache.lucene.index.CheckIndex; import org.apache.lucene.index.IndexFileNames; @@ -45,6 +46,7 @@ import org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDeci import org.elasticsearch.cluster.routing.allocation.decider.ThrottlingAllocationDecider; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.bytes.BytesArray; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.settings.ImmutableSettings; @@ -528,7 +530,7 @@ public class CorruptedFileTest extends ElasticsearchIntegrationTest { for (FsStats.Info info : nodeStatses.getNodes()[0].getFs()) { String path = info.getPath(); final String relativeDataLocationPath = "indices/test/" + Integer.toString(shardRouting.getId()) + "/index"; - Path file = Paths.get(path).resolve(relativeDataLocationPath); + Path file = PathUtils.get(path).resolve(relativeDataLocationPath); try (DirectoryStream stream = Files.newDirectoryStream(file)) { for (Path item : stream) { if (Files.isRegularFile(item) && "write.lock".equals(item.getFileName().toString()) == false) { @@ -637,7 +639,7 @@ public class CorruptedFileTest extends ElasticsearchIntegrationTest { List files = new ArrayList<>(); for (FsStats.Info info : nodeStatses.getNodes()[0].getFs()) { String path = info.getPath(); - Path file = Paths.get(path).resolve("indices/test/" + Integer.toString(routing.getId()) + "/index"); + Path file = PathUtils.get(path).resolve("indices/test/" + Integer.toString(routing.getId()) + "/index"); try (DirectoryStream stream = Files.newDirectoryStream(file)) { for (Path item : stream) { files.add(item); diff --git a/src/test/java/org/elasticsearch/index/store/CorruptedTranslogTests.java b/src/test/java/org/elasticsearch/index/store/CorruptedTranslogTests.java index 992359fbf0d..775e22859b8 100644 --- a/src/test/java/org/elasticsearch/index/store/CorruptedTranslogTests.java +++ b/src/test/java/org/elasticsearch/index/store/CorruptedTranslogTests.java @@ -21,6 +21,7 @@ package org.elasticsearch.index.store; import com.carrotsearch.ant.tasks.junit4.dependencies.com.google.common.collect.Lists; import com.carrotsearch.randomizedtesting.generators.RandomPicks; + import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse; import org.elasticsearch.action.index.IndexRequestBuilder; import org.elasticsearch.action.search.SearchPhaseExecutionException; @@ -28,6 +29,7 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.routing.GroupShardsIterator; import org.elasticsearch.cluster.routing.ShardIterator; import org.elasticsearch.cluster.routing.ShardRouting; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.shard.IndexShard; @@ -125,7 +127,7 @@ public class CorruptedTranslogTests extends ElasticsearchIntegrationTest { for (FsStats.Info info : nodeStatses.getNodes()[0].getFs()) { String path = info.getPath(); final String relativeDataLocationPath = "indices/test/" + Integer.toString(shardRouting.getId()) + "/translog"; - Path file = Paths.get(path).resolve(relativeDataLocationPath); + Path file = PathUtils.get(path).resolve(relativeDataLocationPath); logger.info("--> path: {}", file); try (DirectoryStream stream = Files.newDirectoryStream(file)) { for (Path item : stream) { diff --git a/src/test/java/org/elasticsearch/indices/IndicesCustomDataPathTests.java b/src/test/java/org/elasticsearch/indices/IndicesCustomDataPathTests.java index 1f235bb38b0..a14024d807c 100644 --- a/src/test/java/org/elasticsearch/indices/IndicesCustomDataPathTests.java +++ b/src/test/java/org/elasticsearch/indices/IndicesCustomDataPathTests.java @@ -23,6 +23,7 @@ import org.apache.lucene.util.IOUtils; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.cluster.metadata.IndexMetaData; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.test.ElasticsearchIntegrationTest; import org.elasticsearch.test.junit.annotations.TestLogging; @@ -53,7 +54,7 @@ public class IndicesCustomDataPathTests extends ElasticsearchIntegrationTest { @After public void teardown() throws Exception { - IOUtils.deleteFilesIgnoringExceptions(Paths.get(path)); + IOUtils.deleteFilesIgnoringExceptions(PathUtils.get(path)); } @Test diff --git a/src/test/java/org/elasticsearch/nodesinfo/SimpleNodesInfoTests.java b/src/test/java/org/elasticsearch/nodesinfo/SimpleNodesInfoTests.java index bc4433b299a..dfd50b2e327 100644 --- a/src/test/java/org/elasticsearch/nodesinfo/SimpleNodesInfoTests.java +++ b/src/test/java/org/elasticsearch/nodesinfo/SimpleNodesInfoTests.java @@ -25,6 +25,7 @@ import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse; import org.elasticsearch.action.admin.cluster.node.info.PluginInfo; import org.elasticsearch.cluster.ClusterService; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.nodesinfo.plugin.dummy1.TestPlugin; @@ -162,7 +163,7 @@ public class SimpleNodesInfoTests extends ElasticsearchIntegrationTest { ImmutableSettings.Builder settings = settingsBuilder(); settings.put(nodeSettings); if (resource != null) { - settings.put("path.plugins", Paths.get(resource.toURI()).toAbsolutePath()); + settings.put("path.plugins", PathUtils.get(resource.toURI()).toAbsolutePath()); } if (pluginClassNames.length > 0) { diff --git a/src/test/java/org/elasticsearch/plugins/PluginServiceTests.java b/src/test/java/org/elasticsearch/plugins/PluginServiceTests.java index 00ffaf73c2c..9b4581e2348 100644 --- a/src/test/java/org/elasticsearch/plugins/PluginServiceTests.java +++ b/src/test/java/org/elasticsearch/plugins/PluginServiceTests.java @@ -20,8 +20,10 @@ package org.elasticsearch.plugins; import com.google.common.collect.ImmutableList; + import org.elasticsearch.action.admin.cluster.node.info.PluginInfo; import org.elasticsearch.common.collect.Tuple; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.nodesinfo.SimpleNodesInfoTests; import org.elasticsearch.plugins.loading.classpath.InClassPathPlugin; @@ -31,6 +33,7 @@ import org.junit.Test; import java.net.URISyntaxException; import java.nio.file.Path; +import java.nio.file.PathMatcher; import java.nio.file.Paths; import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder; @@ -71,17 +74,19 @@ public class PluginServiceTests extends ElasticsearchIntegrationTest { @Test public void testHasLibExtension() { - Path p = Paths.get("path", "to", "plugin.jar"); - assertTrue(PluginsService.hasLibExtension(p)); + PathMatcher matcher = PathUtils.getDefaultFileSystem().getPathMatcher(PluginsService.PLUGIN_LIB_PATTERN); - p = Paths.get("path", "to", "plugin.zip"); - assertTrue(PluginsService.hasLibExtension(p)); + Path p = PathUtils.get("path", "to", "plugin.jar"); + assertTrue(matcher.matches(p)); - p = Paths.get("path", "to", "plugin.tar.gz"); - assertFalse(PluginsService.hasLibExtension(p)); + p = PathUtils.get("path", "to", "plugin.zip"); + assertTrue(matcher.matches(p)); - p = Paths.get("path", "to", "plugin"); - assertFalse(PluginsService.hasLibExtension(p)); + p = PathUtils.get("path", "to", "plugin.tar.gz"); + assertFalse(matcher.matches(p)); + + p = PathUtils.get("path", "to", "plugin"); + assertFalse(matcher.matches(p)); } private Plugin getPlugin(String pluginName) { diff --git a/src/test/java/org/elasticsearch/plugins/SitePluginTests.java b/src/test/java/org/elasticsearch/plugins/SitePluginTests.java index 83e0e46695d..eeec0c685d7 100644 --- a/src/test/java/org/elasticsearch/plugins/SitePluginTests.java +++ b/src/test/java/org/elasticsearch/plugins/SitePluginTests.java @@ -21,6 +21,7 @@ package org.elasticsearch.plugins; import org.apache.http.client.config.RequestConfig; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.http.HttpServerTransport; import org.elasticsearch.rest.RestStatus; @@ -49,7 +50,7 @@ public class SitePluginTests extends ElasticsearchIntegrationTest { @Override protected Settings nodeSettings(int nodeOrdinal) { try { - Path pluginDir = Paths.get(SitePluginTests.class.getResource("/org/elasticsearch/plugins").toURI()); + Path pluginDir = PathUtils.get(SitePluginTests.class.getResource("/org/elasticsearch/plugins").toURI()); return settingsBuilder() .put(super.nodeSettings(nodeOrdinal)) .put("path.plugins", pluginDir.toAbsolutePath()) diff --git a/src/test/java/org/elasticsearch/snapshots/mockstore/MockRepository.java b/src/test/java/org/elasticsearch/snapshots/mockstore/MockRepository.java index b44b69f5e4e..fe2eb17f654 100644 --- a/src/test/java/org/elasticsearch/snapshots/mockstore/MockRepository.java +++ b/src/test/java/org/elasticsearch/snapshots/mockstore/MockRepository.java @@ -21,6 +21,7 @@ package org.elasticsearch.snapshots.mockstore; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; + import org.elasticsearch.ElasticsearchException; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.metadata.MetaData; @@ -30,6 +31,7 @@ import org.elasticsearch.common.blobstore.BlobMetaData; import org.elasticsearch.common.blobstore.BlobPath; import org.elasticsearch.common.blobstore.BlobStore; import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.snapshots.IndexShardRepository; import org.elasticsearch.repositories.RepositoryName; @@ -111,7 +113,7 @@ public class MockRepository extends FsRepository { } private static Settings localizeLocation(Settings settings, ClusterService clusterService) { - Path location = Paths.get(settings.get("location")); + Path location = PathUtils.get(settings.get("location")); location = location.resolve(clusterService.localNode().getId()); return settingsBuilder().put(settings).put("location", location.toAbsolutePath()).build(); } diff --git a/src/test/java/org/elasticsearch/test/ElasticsearchBackwardsCompatIntegrationTest.java b/src/test/java/org/elasticsearch/test/ElasticsearchBackwardsCompatIntegrationTest.java index efc629facf8..b6cb3d6aada 100644 --- a/src/test/java/org/elasticsearch/test/ElasticsearchBackwardsCompatIntegrationTest.java +++ b/src/test/java/org/elasticsearch/test/ElasticsearchBackwardsCompatIntegrationTest.java @@ -24,6 +24,7 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.routing.IndexRoutingTable; import org.elasticsearch.cluster.routing.IndexShardRoutingTable; import org.elasticsearch.cluster.routing.ShardRouting; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.regex.Regex; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; @@ -99,7 +100,7 @@ public abstract class ElasticsearchBackwardsCompatIntegrationTest extends Elasti throw new IllegalArgumentException("Backcompat elasticsearch version must be same major version as current. " + "backcompat: " + version + ", current: " + Version.CURRENT.toString()); } - Path file = Paths.get(path, "elasticsearch-" + version); + Path file = PathUtils.get(path, "elasticsearch-" + version); if (!Files.exists(file)) { throw new IllegalArgumentException("Backwards tests location is missing: " + file.toAbsolutePath()); } diff --git a/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java b/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java index b35ef5e696f..315b5749e66 100644 --- a/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java +++ b/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java @@ -26,6 +26,7 @@ import com.carrotsearch.randomizedtesting.generators.RandomPicks; import com.google.common.base.Joiner; import com.google.common.base.Predicate; import com.google.common.collect.Lists; + import org.apache.http.impl.client.HttpClients; import org.apache.lucene.store.StoreRateLimiting; import org.apache.lucene.util.AbstractRandomizedTest; @@ -76,6 +77,7 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.io.FileSystemUtils; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.regex.Regex; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; @@ -1838,7 +1840,7 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase * Asserts that there are no files in the specified path */ public void assertPathHasBeenCleared(String path) throws Exception { - assertPathHasBeenCleared(Paths.get(path)); + assertPathHasBeenCleared(PathUtils.get(path)); } /** diff --git a/src/test/java/org/elasticsearch/test/ElasticsearchTestCase.java b/src/test/java/org/elasticsearch/test/ElasticsearchTestCase.java index db3e021f945..469e1bcd656 100644 --- a/src/test/java/org/elasticsearch/test/ElasticsearchTestCase.java +++ b/src/test/java/org/elasticsearch/test/ElasticsearchTestCase.java @@ -34,6 +34,7 @@ import org.elasticsearch.client.Requests; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.routing.DjbHashFunction; import org.elasticsearch.common.Strings; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.ImmutableSettings; @@ -200,7 +201,7 @@ public abstract class ElasticsearchTestCase extends AbstractRandomizedTest { */ public Path getResourcePath(String relativePath) { URI uri = URI.create(getClass().getResource(relativePath).toString()); - return Paths.get(uri); + return PathUtils.get(uri); } @After diff --git a/src/test/java/org/elasticsearch/test/ExternalNode.java b/src/test/java/org/elasticsearch/test/ExternalNode.java index 69d7e886b3f..705f07d3e2a 100644 --- a/src/test/java/org/elasticsearch/test/ExternalNode.java +++ b/src/test/java/org/elasticsearch/test/ExternalNode.java @@ -27,6 +27,7 @@ import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse; import org.elasticsearch.client.Client; import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.cluster.ClusterName; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.ImmutableSettings; @@ -127,7 +128,7 @@ final class ExternalNode implements Closeable { params.add("-Des." + entry.getKey() + "=" + entry.getValue()); } - params.add("-Des.path.home=" + Paths.get(".").toAbsolutePath()); + params.add("-Des.path.home=" + PathUtils.get(".").toAbsolutePath()); params.add("-Des.path.conf=" + path + "/config"); ProcessBuilder builder = new ProcessBuilder(params); diff --git a/src/test/java/org/elasticsearch/test/rest/ElasticsearchRestTests.java b/src/test/java/org/elasticsearch/test/rest/ElasticsearchRestTests.java index 0267b3d9cc8..4c35c08030d 100644 --- a/src/test/java/org/elasticsearch/test/rest/ElasticsearchRestTests.java +++ b/src/test/java/org/elasticsearch/test/rest/ElasticsearchRestTests.java @@ -25,9 +25,11 @@ import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; import com.carrotsearch.randomizedtesting.annotations.TestGroup; import com.carrotsearch.randomizedtesting.annotations.TimeoutSuite; import com.google.common.collect.Lists; + import org.apache.lucene.util.AbstractRandomizedTest; import org.apache.lucene.util.TimeUnits; import org.elasticsearch.common.Strings; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.node.Node; @@ -46,10 +48,8 @@ import org.junit.BeforeClass; import org.junit.Test; import java.io.IOException; -import java.nio.file.FileSystems; import java.nio.file.Path; import java.nio.file.PathMatcher; -import java.nio.file.Paths; import java.util.*; /** @@ -102,7 +102,7 @@ public class ElasticsearchRestTests extends ElasticsearchIntegrationTest { blacklistPathMatchers = new PathMatcher[blacklist.length]; int i = 0; for (String glob : blacklist) { - blacklistPathMatchers[i++] = FileSystems.getDefault().getPathMatcher("glob:" + glob); + blacklistPathMatchers[i++] = PathUtils.getDefaultFileSystem().getPathMatcher("glob:" + glob); } } else { blacklistPathMatchers = new PathMatcher[0]; @@ -251,7 +251,7 @@ public class ElasticsearchRestTests extends ElasticsearchIntegrationTest { //we need to replace a few characters otherwise the test section name can't be parsed as a path on windows String testSection = testCandidate.getTestSection().getName().replace("*", "").replace("\\", "/").replaceAll("\\s+/", "/").trim(); String testPath = testCandidate.getSuitePath() + "/" + testSection; - assumeFalse("[" + testCandidate.getTestPath() + "] skipped, reason: blacklisted", blacklistedPathMatcher.matches(Paths.get(testPath))); + assumeFalse("[" + testCandidate.getTestPath() + "] skipped, reason: blacklisted", blacklistedPathMatcher.matches(PathUtils.get(testPath))); } //The client needs non static info to get initialized, therefore it can't be initialized in the before class restTestExecutionContext.initClient(cluster().httpAddresses(), restClientSettings()); diff --git a/src/test/java/org/elasticsearch/test/rest/support/FileUtils.java b/src/test/java/org/elasticsearch/test/rest/support/FileUtils.java index 922cd625d8a..3fdebc94258 100644 --- a/src/test/java/org/elasticsearch/test/rest/support/FileUtils.java +++ b/src/test/java/org/elasticsearch/test/rest/support/FileUtils.java @@ -22,6 +22,7 @@ import com.google.common.collect.Maps; import com.google.common.collect.Sets; import org.elasticsearch.common.Strings; +import org.elasticsearch.common.io.PathUtils; import java.io.IOException; import java.net.URI; @@ -106,7 +107,7 @@ public final class FileUtils { } } - return Paths.get(URI.create(resource.toString())); + return PathUtils.get(URI.create(resource.toString())); } private static URL findResource(String path, String optionalFileSuffix) { @@ -121,9 +122,9 @@ public final class FileUtils { } private static Path findFile(String path, String optionalFileSuffix) { - Path file = Paths.get(path); + Path file = PathUtils.get(path); if (!Files.exists(file)) { - file = Paths.get(path + optionalFileSuffix); + file = PathUtils.get(path + optionalFileSuffix); } return file; } diff --git a/src/test/java/org/elasticsearch/tribe/TribeUnitTests.java b/src/test/java/org/elasticsearch/tribe/TribeUnitTests.java index b7524dfc8a7..058c7b6d679 100644 --- a/src/test/java/org/elasticsearch/tribe/TribeUnitTests.java +++ b/src/test/java/org/elasticsearch/tribe/TribeUnitTests.java @@ -20,9 +20,11 @@ package org.elasticsearch.tribe; import com.carrotsearch.randomizedtesting.LifecycleScope; + import org.elasticsearch.client.Client; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.node.Node; @@ -88,7 +90,7 @@ public class TribeUnitTests extends ElasticsearchTestCase { @Test public void testThatTribeClientsIgnoreGlobalConfig() throws Exception { - Path pathConf = Paths.get(TribeUnitTests.class.getResource("elasticsearch.yml").toURI()).getParent(); + Path pathConf = PathUtils.get(TribeUnitTests.class.getResource("elasticsearch.yml").toURI()).getParent(); Settings settings = ImmutableSettings.builder().put("config.ignore_system_properties", true).put("path.conf", pathConf).build(); assertTribeNodeSuccesfullyCreated(settings); }