Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-17548: Switch all public Java APIs from File to Path (#2907)

Matthew Biscochoae93adc62203
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 4b02920f9e0..1f72757e442 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -167,6 +167,8 @@ Other Changes
* SOLR-17579: Remove unused code and other refactorings in ReplicationHandler and tests. Removed unused public
LOCAL_ACTIVITY_DURING_REPLICATION variable. (Eric Pugh)
+* SOLR-17548: Switch all public Java APIs from File to Path. (Matthew Biscocho via Eric Pugh)
+
================== 9.8.0 ==================
New Features
---------------------
diff --git a/solr/benchmark/src/java/org/apache/solr/bench/MiniClusterState.java b/solr/benchmark/src/java/org/apache/solr/bench/MiniClusterState.java
index 34a970b3392..39c1745d387 100755
--- a/solr/benchmark/src/java/org/apache/solr/bench/MiniClusterState.java
+++ b/solr/benchmark/src/java/org/apache/solr/bench/MiniClusterState.java
@@ -267,7 +267,7 @@ public class MiniClusterState {
cluster =
new MiniSolrCloudCluster.Builder(nodeCount, miniClusterBaseDir)
.formatZkServer(false)
- .addConfig("conf", getFile("src/resources/configs/cloud-minimal/conf").toPath())
+ .addConfig("conf", getFile("src/resources/configs/cloud-minimal/conf"))
.configure();
} catch (Exception e) {
if (Files.exists(miniClusterBaseDir)) {
@@ -551,12 +551,12 @@ public class MiniClusterState {
* @param name the name
* @return the file
*/
- public static File getFile(String name) {
+ public static Path getFile(String name) {
final URL url =
MiniClusterState.class.getClassLoader().getResource(name.replace(File.separatorChar, '/'));
if (url != null) {
try {
- return new File(url.toURI());
+ return Path.of(url.toURI());
} catch (Exception e) {
throw new RuntimeException(
"Resource was found on classpath, but cannot be resolved to a "
@@ -564,12 +564,12 @@ public class MiniClusterState {
+ name);
}
}
- File file = new File(name);
- if (file.exists()) {
+ Path file = Path.of(name);
+ if (Files.exists(file)) {
return file;
} else {
- file = new File("../../../", name);
- if (file.exists()) {
+ file = Path.of("../../../", name);
+ if (Files.exists(file)) {
return file;
}
}
diff --git a/solr/core/src/java/org/apache/solr/cloud/SolrZkServer.java b/solr/core/src/java/org/apache/solr/cloud/SolrZkServer.java
index ee7a14733ed..b2f44c9a188 100644
--- a/solr/core/src/java/org/apache/solr/cloud/SolrZkServer.java
+++ b/solr/core/src/java/org/apache/solr/cloud/SolrZkServer.java
@@ -16,7 +16,6 @@
*/
package org.apache.solr.cloud;
-import java.io.File;
import java.io.IOException;
import java.io.Reader;
import java.lang.invoke.MethodHandles;
@@ -51,10 +50,10 @@ public class SolrZkServer {
private Thread zkThread; // the thread running a zookeeper server, only if zkRun is set
- private File dataHome; // o.a.zookeeper.**.QuorumPeerConfig needs a File not a Path
+ private Path dataHome; // o.a.zookeeper.**.QuorumPeerConfig needs a File not a Path
private String confHome;
- public SolrZkServer(String zkRun, String zkHost, File dataHome, String confHome, int solrPort) {
+ public SolrZkServer(String zkRun, String zkHost, Path dataHome, String confHome, int solrPort) {
this.zkRun = zkRun;
this.zkHost = zkHost;
this.dataHome = dataHome;
@@ -277,8 +276,8 @@ class SolrZkServerProps extends QuorumPeerConfig {
return false;
}
- public void setDataDir(File dataDir) {
- this.dataDir = dataDir;
+ public void setDataDir(Path dataDir) {
+ this.dataDir = dataDir.toFile();
}
/**
diff --git a/solr/core/src/java/org/apache/solr/core/DirectoryFactory.java b/solr/core/src/java/org/apache/solr/core/DirectoryFactory.java
index e1d22572bb5..aebbd64b7a1 100644
--- a/solr/core/src/java/org/apache/solr/core/DirectoryFactory.java
+++ b/solr/core/src/java/org/apache/solr/core/DirectoryFactory.java
@@ -339,6 +339,8 @@ public abstract class DirectoryFactory implements NamedListInitializedPlugin, Cl
public void cleanupOldIndexDirectories(
final String dataDirPath, final String currentIndexDirPath, boolean afterCoreReload) {
+
+ // TODO SOLR-8282 move to PATH
File dataDir = new File(dataDirPath);
if (!dataDir.isDirectory()) {
log.debug(
diff --git a/solr/core/src/java/org/apache/solr/core/SolrCore.java b/solr/core/src/java/org/apache/solr/core/SolrCore.java
index 6ac06ffa266..3611b943feb 100644
--- a/solr/core/src/java/org/apache/solr/core/SolrCore.java
+++ b/solr/core/src/java/org/apache/solr/core/SolrCore.java
@@ -1354,6 +1354,7 @@ public class SolrCore implements SolrInfoBean, Closeable {
Category.CORE.toString());
}
+ // TODO SOLR-8282 move to PATH
// initialize disk total / free metrics
Path dataDirPath = Paths.get(dataDir);
File dataDirFile = dataDirPath.toFile();
diff --git a/solr/core/src/java/org/apache/solr/core/SolrDeletionPolicy.java b/solr/core/src/java/org/apache/solr/core/SolrDeletionPolicy.java
index bf4f5072b8d..18043a389ad 100644
--- a/solr/core/src/java/org/apache/solr/core/SolrDeletionPolicy.java
+++ b/solr/core/src/java/org/apache/solr/core/SolrDeletionPolicy.java
@@ -16,9 +16,9 @@
*/
package org.apache.solr.core;
-import java.io.File;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
+import java.nio.file.Path;
import java.util.List;
import org.apache.lucene.index.IndexCommit;
import org.apache.lucene.index.IndexDeletionPolicy;
@@ -198,8 +198,8 @@ public class SolrDeletionPolicy extends IndexDeletionPolicy implements NamedList
// For anything persistent, make something that will
// be the same, regardless of the Directory instance.
if (dir instanceof FSDirectory fsd) {
- File fdir = fsd.getDirectory().toFile();
- sb.append(fdir.getPath());
+ Path fdir = fsd.getDirectory();
+ sb.append(fdir.toString());
} else {
sb.append(dir);
}
diff --git a/solr/core/src/java/org/apache/solr/core/StandardDirectoryFactory.java b/solr/core/src/java/org/apache/solr/core/StandardDirectoryFactory.java
index 2e53828ca78..5d02de67aa9 100644
--- a/solr/core/src/java/org/apache/solr/core/StandardDirectoryFactory.java
+++ b/solr/core/src/java/org/apache/solr/core/StandardDirectoryFactory.java
@@ -16,7 +16,6 @@
*/
package org.apache.solr.core;
-import java.io.File;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.nio.file.AtomicMoveNotSupportedException;
@@ -78,7 +77,7 @@ public class StandardDirectoryFactory extends CachingDirectoryFactory {
@Override
public String normalize(String path) throws IOException {
- return super.normalize(new File(path).getCanonicalPath());
+ return super.normalize(Path.of(path).toAbsolutePath().normalize().toString());
}
@Override
diff --git a/solr/core/src/java/org/apache/solr/core/ZkContainer.java b/solr/core/src/java/org/apache/solr/core/ZkContainer.java
index 3dbd1652993..a8c00bc7cd9 100644
--- a/solr/core/src/java/org/apache/solr/core/ZkContainer.java
+++ b/solr/core/src/java/org/apache/solr/core/ZkContainer.java
@@ -19,9 +19,9 @@ package org.apache.solr.core;
import static org.apache.solr.common.cloud.ZkStateReader.HTTPS;
import static org.apache.solr.common.cloud.ZkStateReader.HTTPS_PORT_PROP;
-import java.io.File;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
+import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeoutException;
@@ -96,7 +96,7 @@ public class ZkContainer {
new SolrZkServer(
stripChroot(zkRun),
stripChroot(config.getZkHost()),
- new File(zkDataHome),
+ Path.of(zkDataHome),
zkConfHome,
config.getSolrHostPort());
zkServer.parseConfig();
@@ -174,7 +174,7 @@ public class ZkContainer {
}
private String stripChroot(String zkRun) {
- if (zkRun == null || zkRun.trim().length() == 0 || zkRun.lastIndexOf('/') < 0) return zkRun;
+ if (zkRun == null || zkRun.trim().isEmpty() || zkRun.lastIndexOf('/') < 0) return zkRun;
return zkRun.substring(0, zkRun.lastIndexOf('/'));
}
diff --git a/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java b/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java
index d81af14d93a..a5a467386db 100644
--- a/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java
+++ b/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java
@@ -51,11 +51,9 @@ import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileStore;
-import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
-import java.nio.file.StandardCopyOption;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
@@ -124,7 +122,6 @@ import org.apache.solr.search.SolrIndexSearcher;
import org.apache.solr.security.AllowListUrlChecker;
import org.apache.solr.update.CommitUpdateCommand;
import org.apache.solr.update.UpdateShardHandler;
-import org.apache.solr.util.FileUtils;
import org.apache.solr.util.IndexOutputOutputStream;
import org.apache.solr.util.RTimer;
import org.apache.solr.util.RefCounted;
@@ -418,7 +415,7 @@ public class IndexFetcher {
Directory indexDir = null;
String indexDirPath;
boolean deleteTmpIdxDir = true;
- File tmpTlogDir = null;
+ Path tmpTlogDir = null;
if (!solrCore.getSolrCoreState().getLastReplicateIndexSuccess()) {
// if the last replication was not a success, we force a full replication
@@ -799,8 +796,9 @@ public class IndexFetcher {
Directory tmpIndexDir,
Directory indexDir,
boolean deleteTmpIdxDir,
- File tmpTlogDir,
- boolean successfulInstall) {
+ Path tmpTlogDir,
+ boolean successfulInstall)
+ throws IOException {
try {
if (!successfulInstall) {
try {
@@ -1068,6 +1066,7 @@ public class IndexFetcher {
confFilesDownloaded = Collections.synchronizedList(new ArrayList<>());
Path tmpConfPath =
solrCore.getResourceLoader().getConfigPath().resolve("conf." + getDateAsStr(new Date()));
+ // TODO SOLR-8282 move to PATH
File tmpconfDir = tmpConfPath.toFile();
try {
boolean status = tmpconfDir.mkdirs();
@@ -1079,7 +1078,8 @@ public class IndexFetcher {
for (Map<String, Object> file : confFilesToDownload) {
String saveAs = (String) (file.get(ALIAS) == null ? file.get(NAME) : file.get(ALIAS));
localFileFetcher =
- new LocalFsFileFetcher(tmpconfDir, file, saveAs, CONF_FILE_SHORT, latestGeneration);
+ new LocalFsFileFetcher(
+ tmpconfDir.toPath(), file, saveAs, CONF_FILE_SHORT, latestGeneration);
currentFile = file;
localFileFetcher.fetchFile();
confFilesDownloaded.add(new HashMap<>(file));
@@ -1089,7 +1089,7 @@ public class IndexFetcher {
terminateAndWaitFsyncService();
copyTmpConfFiles2Conf(tmpConfPath);
} finally {
- delTree(tmpconfDir);
+ delTree(tmpconfDir.toPath());
}
}
@@ -1156,6 +1156,7 @@ public class IndexFetcher {
alwaysDownload);
}
if (!compareResult.equal || downloadCompleteIndex || alwaysDownload) {
+ // TODO SOLR-8282 move to PATH
File localFile = new File(indexDirPath, filename);
if (downloadCompleteIndex
&& doDifferentialCopy
@@ -1203,15 +1204,15 @@ public class IndexFetcher {
private static Long getUsableSpace(String dir) {
try {
- File file = new File(dir);
- if (!file.exists()) {
- file = file.getParentFile();
+ Path file = Path.of(dir);
+ if (Files.notExists(file)) {
+ file = file.getParent();
// this is not a disk directory. so just pretend that there is enough space
- if (!file.exists()) {
+ if (Files.notExists(file)) {
return Long.MAX_VALUE;
}
}
- FileStore fileStore = Files.getFileStore(file.toPath());
+ FileStore fileStore = Files.getFileStore(file);
return fileStore.getUsableSpace();
} catch (IOException e) {
throw new SolrException(ErrorCode.SERVER_ERROR, "Could not free disk space", e);
@@ -1490,7 +1491,7 @@ public class IndexFetcher {
ErrorCode.SERVER_ERROR, "Unable to mkdirs: " + oldPath.getParent(), e);
}
if (Files.exists(oldPath)) {
- File oldFile = oldPath.toFile(); // TODO drop this
+ File oldFile = oldPath.toFile(); // TODO SOLR-8282 move to PATH
File backupFile =
new File(oldFile.getPath() + "." + getDateAsStr(new Date(oldFile.lastModified())));
if (!backupFile.getParentFile().exists()) {
@@ -1516,49 +1517,6 @@ public class IndexFetcher {
}
}
- /**
- * The tlog files are moved from the tmp dir to the tlog dir as an atomic filesystem operation. A
- * backup of the old directory is maintained. If the directory move fails, it will try to revert
- * the original tlog directory.
- */
- private boolean copyTmpTlogFiles2Tlog(File tmpTlogDir) {
- Path tlogDir =
- FileSystems.getDefault().getPath(solrCore.getUpdateHandler().getUpdateLog().getTlogDir());
- Path backupTlogDir =
- FileSystems.getDefault()
- .getPath(tlogDir.getParent().toAbsolutePath().toString(), tmpTlogDir.getName());
-
- try {
- Files.move(tlogDir, backupTlogDir, StandardCopyOption.ATOMIC_MOVE);
- } catch (IOException e) {
- log.error("Unable to rename: {} to: {}", tlogDir, backupTlogDir, e);
- return false;
- }
-
- Path src =
- FileSystems.getDefault()
- .getPath(backupTlogDir.toAbsolutePath().toString(), tmpTlogDir.getName());
- try {
- Files.move(src, tlogDir, StandardCopyOption.ATOMIC_MOVE);
- } catch (IOException e) {
- log.error("Unable to rename: {} to: {}", src, tlogDir, e);
-
- // In case of error, try to revert the original tlog directory
- try {
- Files.move(backupTlogDir, tlogDir, StandardCopyOption.ATOMIC_MOVE);
- } catch (IOException e2) {
- // bad, we were not able to revert the original tlog directory
- throw new SolrException(
- SolrException.ErrorCode.SERVER_ERROR,
- "Unable to rename: " + backupTlogDir + " to: " + tlogDir);
- }
-
- return false;
- }
-
- return true;
- }
-
private String getDateAsStr(Date d) {
return new SimpleDateFormat(SnapShooter.DATE_FMT, Locale.ROOT).format(d);
}
@@ -1601,9 +1559,9 @@ public class IndexFetcher {
return nameVsFile.isEmpty() ? Collections.emptyList() : nameVsFile.values();
}
- static boolean delTree(File dir) {
+ static boolean delTree(Path dir) {
try {
- org.apache.lucene.util.IOUtils.rm(dir.toPath());
+ org.apache.lucene.util.IOUtils.rm(dir);
return true;
} catch (IOException e) {
log.warn("Unable to delete directory : {}", dir, e);
@@ -2034,28 +1992,29 @@ public class IndexFetcher {
FileChannel fileChannel;
private FileOutputStream fileOutputStream;
- File file;
+ Path file;
- LocalFsFile(File dir, String saveAs) throws IOException {
+ LocalFsFile(Path dir, String saveAs) throws IOException {
+ this.file = dir.resolve(saveAs);
- this.file = new File(dir, saveAs);
-
- File parentDir = this.file.getParentFile();
- if (!parentDir.exists()) {
- if (!parentDir.mkdirs()) {
+ Path parentDir = this.file.getParent();
+ if (Files.notExists(parentDir)) {
+ try {
+ Files.createDirectories(parentDir);
+ } catch (Exception e) {
throw new SolrException(
SolrException.ErrorCode.SERVER_ERROR,
"Failed to create (sub)directory for file: " + saveAs);
}
}
- this.fileOutputStream = new FileOutputStream(file);
+ this.fileOutputStream = new FileOutputStream(file.toFile());
this.fileChannel = this.fileOutputStream.getChannel();
}
@Override
public void sync() throws IOException {
- FileUtils.sync(file);
+ org.apache.lucene.util.IOUtils.fsync(file, false);
}
@Override
@@ -2071,13 +2030,13 @@ public class IndexFetcher {
@Override
public void delete() throws Exception {
- Files.delete(file.toPath());
+ Files.delete(file);
}
}
protected class LocalFsFileFetcher extends FileFetcher {
LocalFsFileFetcher(
- File dir,
+ Path dir,
Map<String, Object> fileDetails,
String saveAs,
String solrParamOutput,
diff --git a/solr/core/src/java/org/apache/solr/handler/admin/ShowFileRequestHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/ShowFileRequestHandler.java
index e2d8b7715b8..1ec536f3c22 100644
--- a/solr/core/src/java/org/apache/solr/handler/admin/ShowFileRequestHandler.java
+++ b/solr/core/src/java/org/apache/solr/handler/admin/ShowFileRequestHandler.java
@@ -201,7 +201,7 @@ public class ShowFileRequestHandler extends RequestHandlerBase implements Permis
if (admin == null) { // exception already recorded
return;
}
-
+ // TODO SOLR-8282 move to PATH
File adminFile = admin.toFile();
// Make sure the file exists, is readable and is not a hidden file
if (!adminFile.exists()) {
@@ -252,7 +252,7 @@ public class ShowFileRequestHandler extends RequestHandlerBase implements Permis
params.set(CommonParams.WT, "raw");
req.setParams(params);
- ContentStreamBase content = new ContentStreamBase.FileStream(adminFile);
+ ContentStreamBase content = new ContentStreamBase.FileStream(adminFile.toPath());
content.setContentType(getSafeContentType(req.getParams().get(USE_CONTENT_TYPE)));
rsp.add(RawResponseWriter.CONTENT, content);
diff --git a/solr/core/src/java/org/apache/solr/handler/admin/SystemInfoHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/SystemInfoHandler.java
index f3988a6b725..cb5218bfa71 100644
--- a/solr/core/src/java/org/apache/solr/handler/admin/SystemInfoHandler.java
+++ b/solr/core/src/java/org/apache/solr/handler/admin/SystemInfoHandler.java
@@ -19,13 +19,13 @@ package org.apache.solr.handler.admin;
import static org.apache.solr.common.params.CommonParams.NAME;
import com.codahale.metrics.Gauge;
-import java.io.File;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.lang.management.ManagementFactory;
import java.lang.management.OperatingSystemMXBean;
import java.lang.management.RuntimeMXBean;
import java.net.InetAddress;
+import java.nio.file.Path;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.ArrayList;
@@ -193,7 +193,7 @@ public class SystemInfoHandler extends RequestHandlerBase {
// Solr Home
SimpleOrderedMap<Object> dirs = new SimpleOrderedMap<>();
- dirs.add("cwd", new File(System.getProperty("user.dir")).getAbsolutePath());
+ dirs.add("cwd", Path.of(System.getProperty("user.dir")).toAbsolutePath().toString());
dirs.add("instance", core.getInstancePath().toString());
try {
dirs.add("data", core.getDirectoryFactory().normalize(core.getDataDir()));
diff --git a/solr/core/src/java/org/apache/solr/rest/ManagedResourceStorage.java b/solr/core/src/java/org/apache/solr/rest/ManagedResourceStorage.java
index af04c36eaab..038b9c5f421 100644
--- a/solr/core/src/java/org/apache/solr/rest/ManagedResourceStorage.java
+++ b/solr/core/src/java/org/apache/solr/rest/ManagedResourceStorage.java
@@ -172,16 +172,23 @@ public abstract class ManagedResourceStorage {
throw new IllegalArgumentException(
"Required configuration parameter '" + STORAGE_DIR_INIT_ARG + "' not provided!");
- File dir = new File(storageDirArg);
- if (!dir.isDirectory()) dir.mkdirs();
+ Path dir = Path.of(storageDirArg);
+ if (!Files.isDirectory(dir)) {
+ try {
+ Files.createDirectories(dir);
+ } catch (IOException e) {
+ throw new SolrException(
+ SolrException.ErrorCode.SERVER_ERROR, "Unable to create storage directory " + dir, e);
+ }
+ }
- storageDir = dir.getAbsolutePath();
+ storageDir = dir.toAbsolutePath().toString();
log.info("File-based storage initialized to use dir: {}", storageDir);
}
@Override
public boolean exists(String storedResourceId) throws IOException {
- return (new File(storageDir, storedResourceId)).exists();
+ return Files.exists(Path.of(storageDir, storedResourceId));
}
@Override
@@ -196,18 +203,19 @@ public abstract class ManagedResourceStorage {
@Override
public boolean delete(String storedResourceId) throws IOException {
+ // TODO SOLR-8282 move to PATH
File storedFile = new File(storageDir, storedResourceId);
- return deleteIfFile(storedFile);
+ return deleteIfFile(storedFile.toPath());
}
// TODO: this interface should probably be changed, this simulates the old behavior,
// only throw security exception, just return false otherwise
- private boolean deleteIfFile(File f) {
- if (!f.isFile()) {
+ private boolean deleteIfFile(Path p) {
+ if (!Files.isRegularFile(p)) {
return false;
}
try {
- Files.delete(f.toPath());
+ Files.delete(p);
return true;
} catch (IOException cause) {
return false;
diff --git a/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchemaFactory.java b/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchemaFactory.java
index 55f4164551b..df44cda12e2 100644
--- a/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchemaFactory.java
+++ b/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchemaFactory.java
@@ -401,7 +401,8 @@ public class ManagedIndexSchemaFactory extends IndexSchemaFactory implements Sol
"On upgrading to managed schema, did not rename non-managed schema '{}' because it's the same as the managed schema's name.",
resourceName);
} else {
- final File nonManagedSchemaFile = locateConfigFile(resourceName);
+ // TODO SOLR-8282 move to PATH
+ final File nonManagedSchemaFile = locateConfigFile(resourceName).toFile();
if (null == nonManagedSchemaFile) {
// Don't throw an exception for failure to rename the non-managed schema
log.warn(
@@ -441,11 +442,11 @@ public class ManagedIndexSchemaFactory extends IndexSchemaFactory implements Sol
*
* @return the File for the named resource, or null if it can't be found
*/
- private File locateConfigFile(String resource) {
+ private Path locateConfigFile(String resource) {
String location = config.getResourceLoader().resourceLocation(resource);
if (location == null || location.equals(resource) || location.startsWith("classpath:"))
return null;
- return new File(location);
+ return Path.of(location);
}
/**
diff --git a/solr/core/src/java/org/apache/solr/servlet/SolrRequestParsers.java b/solr/core/src/java/org/apache/solr/servlet/SolrRequestParsers.java
index ee459c29231..8902acf51a3 100644
--- a/solr/core/src/java/org/apache/solr/servlet/SolrRequestParsers.java
+++ b/solr/core/src/java/org/apache/solr/servlet/SolrRequestParsers.java
@@ -19,7 +19,6 @@ package org.apache.solr.servlet;
import static org.apache.solr.common.params.CommonParams.PATH;
import java.io.ByteArrayOutputStream;
-import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.PushbackInputStream;
@@ -31,6 +30,7 @@ import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CodingErrorAction;
import java.nio.charset.StandardCharsets;
+import java.nio.file.Path;
import java.security.Principal;
import java.util.ArrayList;
import java.util.Arrays;
@@ -236,7 +236,7 @@ public class SolrRequestParsers {
"Remote Streaming is disabled. See https://solr.apache.org/guide/solr/latest/configuration-guide/requestdispatcher.html for help");
}
for (final String file : strs) {
- ContentStreamBase stream = new ContentStreamBase.FileStream(new File(file));
+ ContentStreamBase stream = new ContentStreamBase.FileStream(Path.of(file));
if (contentType != null) {
stream.setContentType(contentType);
}
diff --git a/solr/core/src/java/org/apache/solr/spelling/AbstractLuceneSpellChecker.java b/solr/core/src/java/org/apache/solr/spelling/AbstractLuceneSpellChecker.java
index a54ea8ab9e1..1c0e7006185 100644
--- a/solr/core/src/java/org/apache/solr/spelling/AbstractLuceneSpellChecker.java
+++ b/solr/core/src/java/org/apache/solr/spelling/AbstractLuceneSpellChecker.java
@@ -83,7 +83,7 @@ public abstract class AbstractLuceneSpellChecker extends SolrSpellChecker {
indexDir = (String) config.get(INDEX_DIR);
// If indexDir is relative then create index inside core.getDataDir()
if (indexDir != null) {
- if (!new File(indexDir).isAbsolute()) {
+ if (!Path.of(indexDir).isAbsolute()) {
indexDir = core.getDataDir() + File.separator + indexDir;
}
}
diff --git a/solr/core/src/java/org/apache/solr/spelling/suggest/fst/AnalyzingInfixLookupFactory.java b/solr/core/src/java/org/apache/solr/spelling/suggest/fst/AnalyzingInfixLookupFactory.java
index ead7cea97f7..682b9a81a29 100644
--- a/solr/core/src/java/org/apache/solr/spelling/suggest/fst/AnalyzingInfixLookupFactory.java
+++ b/solr/core/src/java/org/apache/solr/spelling/suggest/fst/AnalyzingInfixLookupFactory.java
@@ -18,6 +18,7 @@ package org.apache.solr.spelling.suggest.fst;
import java.io.File;
import java.io.IOException;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
@@ -87,7 +88,7 @@ public class AnalyzingInfixLookupFactory extends LookupFactory {
String indexPath =
params.get(INDEX_PATH) != null ? params.get(INDEX_PATH).toString() : DEFAULT_INDEX_PATH;
- if (new File(indexPath).isAbsolute() == false) {
+ if (!Path.of(indexPath).isAbsolute()) {
indexPath = core.getDataDir() + File.separator + indexPath;
}
@@ -108,7 +109,7 @@ public class AnalyzingInfixLookupFactory extends LookupFactory {
try {
return new AnalyzingInfixSuggester(
- FSDirectory.open(new File(indexPath).toPath()),
+ FSDirectory.open(Path.of(indexPath)),
indexAnalyzer,
queryAnalyzer,
minPrefixChars,
diff --git a/solr/core/src/java/org/apache/solr/spelling/suggest/fst/BlendedInfixLookupFactory.java b/solr/core/src/java/org/apache/solr/spelling/suggest/fst/BlendedInfixLookupFactory.java
index 7b11e8ed594..09a85917c94 100644
--- a/solr/core/src/java/org/apache/solr/spelling/suggest/fst/BlendedInfixLookupFactory.java
+++ b/solr/core/src/java/org/apache/solr/spelling/suggest/fst/BlendedInfixLookupFactory.java
@@ -18,6 +18,7 @@ package org.apache.solr.spelling.suggest.fst;
import java.io.File;
import java.io.IOException;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
@@ -78,7 +79,7 @@ public class BlendedInfixLookupFactory extends AnalyzingInfixLookupFactory {
String indexPath =
params.get(INDEX_PATH) != null ? params.get(INDEX_PATH).toString() : DEFAULT_INDEX_PATH;
- if (new File(indexPath).isAbsolute() == false) {
+ if (!Path.of(indexPath).isAbsolute()) {
indexPath = core.getDataDir() + File.separator + indexPath;
}
@@ -109,7 +110,7 @@ public class BlendedInfixLookupFactory extends AnalyzingInfixLookupFactory {
try {
return new BlendedInfixSuggester(
- FSDirectory.open(new File(indexPath).toPath()),
+ FSDirectory.open(Path.of(indexPath)),
indexAnalyzer,
queryAnalyzer,
minPrefixChars,
diff --git a/solr/core/src/java/org/apache/solr/update/UpdateLog.java b/solr/core/src/java/org/apache/solr/update/UpdateLog.java
index 60615a32f49..837f031ccec 100644
--- a/solr/core/src/java/org/apache/solr/update/UpdateLog.java
+++ b/solr/core/src/java/org/apache/solr/update/UpdateLog.java
@@ -24,8 +24,6 @@ import com.carrotsearch.hppc.LongSet;
import com.codahale.metrics.Gauge;
import com.codahale.metrics.Meter;
import java.io.Closeable;
-import java.io.File;
-import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.lang.invoke.MethodHandles;
@@ -581,7 +579,7 @@ public class UpdateLog implements PluginInfoInitialized, SolrMetricProducer {
} catch (IOException e) {
throw new SolrException(ErrorCode.SERVER_ERROR, "Could not set up tlogs", e);
}
- tlogFiles = getLogList(tlogDir.toFile());
+ tlogFiles = getLogList(tlogDir);
id = getLastLogId() + 1; // add 1 since we will create a new log for the next update
if (debug) {
@@ -732,14 +730,17 @@ public class UpdateLog implements PluginInfoInitialized, SolrMetricProducer {
return (cmd.getFlags() & UpdateCommand.REPLAY) != 0 && state == State.REPLAYING;
}
- public String[] getLogList(File directory) {
+ public String[] getLogList(Path directory) {
final String prefix = TLOG_NAME + '.';
- String[] names = directory.list((dir, name) -> name.startsWith(prefix));
- if (names == null) {
- throw new RuntimeException(new FileNotFoundException(directory.getAbsolutePath()));
+ try (Stream<Path> files = Files.list(directory)) {
+ return files
+ .map((file) -> file.getFileName().toString())
+ .filter((name) -> name.startsWith(prefix))
+ .sorted()
+ .toArray(String[]::new);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
}
- Arrays.sort(names);
- return names;
}
public long getLastLogId() {
diff --git a/solr/core/src/java/org/apache/solr/util/FileUtils.java b/solr/core/src/java/org/apache/solr/util/FileUtils.java
index b027d1e4d77..0b221aae025 100644
--- a/solr/core/src/java/org/apache/solr/util/FileUtils.java
+++ b/solr/core/src/java/org/apache/solr/util/FileUtils.java
@@ -16,13 +16,7 @@
*/
package org.apache.solr.util;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.RandomAccessFile;
-import java.nio.channels.FileChannel;
import java.nio.file.Files;
import java.nio.file.Path;
import org.apache.commons.io.FileExistsException;
@@ -30,60 +24,8 @@ import org.apache.commons.io.FileExistsException;
/** */
public class FileUtils {
- /**
- * Resolves a path relative a base directory.
- *
- * <p>This method does what "new File(base,path)" <b>Should</b> do, if it wasn't completely lame:
- * If path is absolute, then a File for that path is returned; if it's not absolute, then a File
- * is returned using "path" as a child of "base")
- */
- public static File resolvePath(File base, String path) {
- File r = new File(path);
- return r.isAbsolute() ? r : new File(base, path);
- }
-
- public static void copyFile(File src, File destination) throws IOException {
- try (FileChannel in = new FileInputStream(src).getChannel();
- FileChannel out = new FileOutputStream(destination).getChannel()) {
- in.transferTo(0, in.size(), out);
- }
- }
-
- /**
- * Copied from Lucene's FSDirectory.fsync(String)
- *
- * @param fullFile the File to be synced to disk
- * @throws IOException if the file could not be synced
- */
- public static void sync(File fullFile) throws IOException {
- if (fullFile == null || !fullFile.exists())
- throw new FileNotFoundException("File does not exist " + fullFile);
-
- boolean success = false;
- int retryCount = 0;
- IOException exc = null;
- while (!success && retryCount < 5) {
- retryCount++;
- try (RandomAccessFile file = new RandomAccessFile(fullFile, "rw")) {
- file.getFD().sync();
- success = true;
- } catch (IOException ioe) {
- if (exc == null) exc = ioe;
- try {
- // Pause 5 msec
- Thread.sleep(5);
- } catch (InterruptedException ie) {
- Thread.currentThread().interrupt();
- }
- }
- }
- if (!success)
- // Throw original exception
- throw exc;
- }
-
public static boolean fileExists(String filePathString) {
- return new File(filePathString).exists();
+ return Files.exists(Path.of(filePathString));
}
// Files.createDirectories has odd behavior if the path is a symlink and it already exists
diff --git a/solr/core/src/java/org/apache/solr/util/VersionedFile.java b/solr/core/src/java/org/apache/solr/util/VersionedFile.java
index a852f1fae26..12ffdb63b53 100644
--- a/solr/core/src/java/org/apache/solr/util/VersionedFile.java
+++ b/solr/core/src/java/org/apache/solr/util/VersionedFile.java
@@ -41,6 +41,7 @@ public class VersionedFile {
*/
public static InputStream getLatestFile(String dirName, String fileName)
throws FileNotFoundException {
+ // TODO SOLR-8282 move to PATH
Collection<File> oldFiles = null;
final String prefix = fileName + '.';
File f = new File(dirName, fileName);
diff --git a/solr/core/src/test/org/apache/solr/SolrTestCaseJ4Test.java b/solr/core/src/test/org/apache/solr/SolrTestCaseJ4Test.java
index 976eea1f0db..74d53019dbe 100644
--- a/solr/core/src/test/org/apache/solr/SolrTestCaseJ4Test.java
+++ b/solr/core/src/test/org/apache/solr/SolrTestCaseJ4Test.java
@@ -48,7 +48,7 @@ public class SolrTestCaseJ4Test extends SolrTestCaseJ4 {
FileUtils.touch(new File(tmpSolrHome, "core0/core.properties"));
FileUtils.touch(new File(tmpSolrHome, "core1/core.properties"));
- Files.copy(getFile("solr/solr.xml").toPath(), Path.of(tmpSolrHome, "solr.xml"));
+ Files.copy(getFile("solr/solr.xml"), Path.of(tmpSolrHome, "solr.xml"));
initCore("solrconfig-minimal.xml", "schema-tiny.xml", tmpSolrHome, "core1");
}
diff --git a/solr/core/src/test/org/apache/solr/cli/PostToolTest.java b/solr/core/src/test/org/apache/solr/cli/PostToolTest.java
index 425c9f495dd..758ae9ccd51 100644
--- a/solr/core/src/test/org/apache/solr/cli/PostToolTest.java
+++ b/solr/core/src/test/org/apache/solr/cli/PostToolTest.java
@@ -294,7 +294,8 @@ public class PostToolTest extends SolrCloudTestCase {
postTool.recursive = 0;
postTool.dryRun = true;
postTool.solrUpdateUrl = URI.create("http://localhost:8983/solr/fake/update");
- File dir = getFile("exampledocs");
+ // TODO SOLR-8282 move to PATH
+ File dir = getFile("exampledocs").toFile();
int num = postTool.postFiles(new String[] {dir.toString()}, 0, null, null);
assertEquals(2, num);
}
@@ -303,7 +304,7 @@ public class PostToolTest extends SolrCloudTestCase {
public void testDetectingIfRecursionPossibleInFilesMode() throws IOException {
PostTool postTool = new PostTool();
postTool.recursive = 1; // This is the default
- File dir = getFile("exampledocs");
+ File dir = getFile("exampledocs").toFile();
File doc = File.createTempFile("temp", ".json");
assertTrue(postTool.recursionPossible(new String[] {dir.toString()}));
assertFalse(postTool.recursionPossible(new String[] {doc.toString()}));
@@ -316,7 +317,8 @@ public class PostToolTest extends SolrCloudTestCase {
postTool.recursive = 1; // This is the default
postTool.dryRun = true;
postTool.solrUpdateUrl = URI.create("http://localhost:8983/solr/fake/update");
- File dir = getFile("exampledocs");
+ // TODO SOLR-8282 move to PATH
+ File dir = getFile("exampledocs").toFile();
int num = postTool.postFiles(new String[] {dir.toString()}, 0, null, null);
assertEquals(2, num);
}
diff --git a/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPI.java b/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPI.java
index 01614b7218e..886ffb6afca 100644
--- a/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPI.java
+++ b/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPI.java
@@ -287,7 +287,7 @@ public class TestConfigSetsAPI extends SolrCloudTestCase {
private void setupBaseConfigSet(String baseConfigSetName, Map<String, String> oldProps)
throws Exception {
- final Path configDir = getFile("solr").toPath().resolve("configsets/configset-2/conf");
+ final Path configDir = getFile("solr").resolve("configsets/configset-2/conf");
final Path tmpConfigDir = createTempDir();
tmpConfigDir.toFile().deleteOnExit();
PathUtils.copyDirectory(configDir, tmpConfigDir);
@@ -1518,7 +1518,7 @@ public class TestConfigSetsAPI extends SolrCloudTestCase {
// Read single file from sample configs. This should fail the unzipping
return uploadGivenConfigSet(
- SolrTestCaseJ4.getFile("solr/configsets/upload/regular/solrconfig.xml"),
+ SolrTestCaseJ4.getFile("solr/configsets/upload/regular/solrconfig.xml").toFile(),
configSetName,
suffix,
username,
@@ -1563,7 +1563,7 @@ public class TestConfigSetsAPI extends SolrCloudTestCase {
try {
return (new Upload())
.setConfigSetName(configSetName + suffix)
- .setUploadFile(file, "application/zip")
+ .setUploadFile(file.toPath(), "application/zip")
.setOverwrite(overwrite ? true : null) // expect server default to be 'false'
.setCleanup(cleanup ? true : null) // expect server default to be 'false'
.setBasicAuthCredentials(username, username) // for our MockAuthenticationPlugin
@@ -1587,7 +1587,7 @@ public class TestConfigSetsAPI extends SolrCloudTestCase {
boolean v2)
throws IOException {
// Read single file from sample configs
- final File file = SolrTestCaseJ4.getFile(localFilePath);
+ final File file = SolrTestCaseJ4.getFile(localFilePath).toFile();
if (v2) {
// TODO: switch to use V2Request
@@ -1620,7 +1620,7 @@ public class TestConfigSetsAPI extends SolrCloudTestCase {
.setConfigSetName(configSetName + suffix)
.setFilePath(uploadPath)
// NOTE: server doesn't actually care, and test plumbing doesn't tell us
- .setUploadFile(file, "application/octet-stream")
+ .setUploadFile(file.toPath(), "application/octet-stream")
.setOverwrite(overwrite ? true : null) // expect server default to be 'false'
.setCleanup(cleanup ? true : null) // expect server default to be 'false'
.setBasicAuthCredentials(username, username) // for our MockAuthenticationPlugin
@@ -1640,7 +1640,7 @@ public class TestConfigSetsAPI extends SolrCloudTestCase {
private File createTempZipFile(String directoryPath) {
try {
final File zipFile = createTempFile("configset", "zip").toFile();
- final File directory = SolrTestCaseJ4.getFile(directoryPath);
+ final File directory = SolrTestCaseJ4.getFile(directoryPath).toFile();
if (log.isInfoEnabled()) {
log.info("Directory: {}", directory.getAbsolutePath());
}
@@ -1661,7 +1661,7 @@ public class TestConfigSetsAPI extends SolrCloudTestCase {
private File createTempZipFileWithForbiddenTypes(String file) {
try {
final File zipFile = createTempFile("configset", "zip").toFile();
- final File directory = SolrTestCaseJ4.getFile(file);
+ final File directory = SolrTestCaseJ4.getFile(file).toFile();
if (log.isInfoEnabled()) {
log.info("Directory: {}", directory.getAbsolutePath());
}
@@ -1679,7 +1679,7 @@ public class TestConfigSetsAPI extends SolrCloudTestCase {
private File createTempZipFileWithForbiddenContent(String resourcePath) {
try {
final File zipFile = createTempFile("configset", "zip").toFile();
- final File directory = SolrTestCaseJ4.getFile(resourcePath);
+ final File directory = SolrTestCaseJ4.getFile(resourcePath).toFile();
if (log.isInfoEnabled()) {
log.info("Directory: {}", directory.getAbsolutePath());
}
@@ -1850,7 +1850,7 @@ public class TestConfigSetsAPI extends SolrCloudTestCase {
private byte[] readFile(String fname) throws IOException {
byte[] buf = null;
- try (FileInputStream fis = new FileInputStream(getFile(fname))) {
+ try (FileInputStream fis = new FileInputStream(getFile(fname).toFile())) {
buf = new byte[fis.available()];
fis.read(buf);
}
@@ -1861,7 +1861,7 @@ public class TestConfigSetsAPI extends SolrCloudTestCase {
public void testDeleteErrors() throws Exception {
final String baseUrl = cluster.getJettySolrRunners().get(0).getBaseUrl().toString();
final SolrClient solrClient = getHttpSolrClient(baseUrl);
- final Path configDir = getFile("solr").toPath().resolve("configsets/configset-2/conf");
+ final Path configDir = getFile("solr").resolve("configsets/configset-2/conf");
final Path tmpConfigDir = createTempDir();
tmpConfigDir.toFile().deleteOnExit();
// Ensure ConfigSet is immutable
diff --git a/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPIZkFailure.java b/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPIZkFailure.java
index 3afb80e9e03..bc644f1a362 100644
--- a/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPIZkFailure.java
+++ b/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPIZkFailure.java
@@ -141,7 +141,7 @@ public class TestConfigSetsAPIZkFailure extends SolrTestCaseJ4 {
private void setupBaseConfigSet(String baseConfigSetName, Map<String, String> oldProps)
throws Exception {
- final Path configDir = getFile("solr").toPath().resolve("configsets/configset-2/conf");
+ final Path configDir = getFile("solr").resolve("configsets/configset-2/conf");
final Path tmpConfigDir = createTempDir();
tmpConfigDir.toFile().deleteOnExit();
PathUtils.copyDirectory(configDir, tmpConfigDir);
diff --git a/solr/core/src/test/org/apache/solr/core/TestConfigSets.java b/solr/core/src/test/org/apache/solr/core/TestConfigSets.java
index df9d72cb508..8bec679b63d 100644
--- a/solr/core/src/test/org/apache/solr/core/TestConfigSets.java
+++ b/solr/core/src/test/org/apache/solr/core/TestConfigSets.java
@@ -91,7 +91,8 @@ public class TestConfigSets extends SolrTestCaseJ4 {
@Test
public void testNonExistentConfigSetThrowsException() {
- final CoreContainer container = setupContainer(getFile("solr/configsets").getAbsolutePath());
+ final CoreContainer container =
+ setupContainer(getFile("solr/configsets").toAbsolutePath().toString());
try {
Exception thrown =
expectThrows(
@@ -112,7 +113,7 @@ public class TestConfigSets extends SolrTestCaseJ4 {
Path testDirectory = createTempDir("core-reload");
Path configSetsDir = testDirectory.resolve("configsets");
- PathUtils.copyDirectory(getFile("solr/configsets").toPath(), configSetsDir);
+ PathUtils.copyDirectory(getFile("solr/configsets"), configSetsDir);
String csd = configSetsDir.toAbsolutePath().toString();
System.setProperty("configsets", csd);
@@ -129,7 +130,7 @@ public class TestConfigSets extends SolrTestCaseJ4 {
// Now copy in a config with a /dump handler and reload
Files.copy(
- getFile("solr/collection1/conf/solrconfig-withgethandler.xml").toPath(),
+ getFile("solr/collection1/conf/solrconfig-withgethandler.xml"),
configSetsDir.resolve("configset-2/conf").resolve("solrconfig.xml"),
StandardCopyOption.REPLACE_EXISTING);
container.reload("core1");
diff --git a/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java b/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java
index 4aaea27c857..bc93c3d6ad0 100644
--- a/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java
+++ b/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java
@@ -61,7 +61,7 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
@BeforeClass
public static void beforeClass() {
oldSolrHome = System.getProperty(SOLR_HOME_PROP);
- System.setProperty("configsets", getFile("solr/configsets").getAbsolutePath());
+ System.setProperty("configsets", getFile("solr/configsets").toAbsolutePath().toString());
}
@AfterClass
@@ -320,7 +320,7 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
MockCoresLocator cl = new MockCoresLocator();
Path solrHome = createTempDir();
- System.setProperty("configsets", getFile("solr/configsets").getAbsolutePath());
+ System.setProperty("configsets", getFile("solr/configsets").toAbsolutePath().toString());
final CoreContainer cc =
new CoreContainer(SolrXmlConfig.fromString(solrHome, CONFIGSETS_SOLR_XML), cl);
@@ -939,7 +939,7 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
Path solrHome = createTempDir();
- System.setProperty("configsets", getFile("solr/configsets").getAbsolutePath());
+ System.setProperty("configsets", getFile("solr/configsets").toAbsolutePath().toString());
final CoreContainer cc =
new CoreContainer(SolrXmlConfig.fromString(solrHome, CONFIGSETS_SOLR_XML), cl);
@@ -986,11 +986,11 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
Path confDir = Path.of(cc.getSolrHome(), "col_bad", "conf");
Files.createDirectories(confDir);
Files.copy(
- getFile("solr/collection1/conf/solrconfig-defaults.xml").toPath(),
+ getFile("solr/collection1/conf/solrconfig-defaults.xml"),
confDir.resolve("solrconfig.xml"),
StandardCopyOption.REPLACE_EXISTING);
Files.copy(
- getFile("solr/collection1/conf/schema-minimal.xml").toPath(),
+ getFile("solr/collection1/conf/schema-minimal.xml"),
confDir.resolve("schema.xml"),
StandardCopyOption.REPLACE_EXISTING);
cc.create("col_bad", Map.of());
@@ -1107,7 +1107,7 @@ public class TestCoreContainer extends SolrTestCaseJ4 {
// ----
// fix col_bad's config (again) and RELOAD to fix failure
Files.copy(
- getFile("solr/collection1/conf/solrconfig-defaults.xml").toPath(),
+ getFile("solr/collection1/conf/solrconfig-defaults.xml"),
confDir.resolve("solrconfig.xml"),
StandardCopyOption.REPLACE_EXISTING);
cc.reload("col_bad");
diff --git a/solr/core/src/test/org/apache/solr/core/TestSolrConfigHandler.java b/solr/core/src/test/org/apache/solr/core/TestSolrConfigHandler.java
index b34712c2969..7e4eb1db75f 100644
--- a/solr/core/src/test/org/apache/solr/core/TestSolrConfigHandler.java
+++ b/solr/core/src/test/org/apache/solr/core/TestSolrConfigHandler.java
@@ -78,7 +78,7 @@ public class TestSolrConfigHandler extends RestTestBase {
*/
public static ByteBuffer getFileContent(String f, boolean loadFromClassPath) throws IOException {
ByteBuffer jar;
- File file = loadFromClassPath ? getFile(f) : new File(f);
+ File file = loadFromClassPath ? getFile(f).toFile() : new File(f);
try (FileInputStream fis = new FileInputStream(file)) {
byte[] buf = new byte[fis.available()];
// TODO: This should check that we read the entire stream
diff --git a/solr/core/src/test/org/apache/solr/handler/ReplicationTestHelper.java b/solr/core/src/test/org/apache/solr/handler/ReplicationTestHelper.java
index 2e69ba4915a..2efe775a58d 100644
--- a/solr/core/src/test/org/apache/solr/handler/ReplicationTestHelper.java
+++ b/solr/core/src/test/org/apache/solr/handler/ReplicationTestHelper.java
@@ -26,6 +26,7 @@ import java.net.URI;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
@@ -42,7 +43,6 @@ import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.embedded.JettyConfig;
import org.apache.solr.embedded.JettySolrRunner;
-import org.apache.solr.util.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -54,9 +54,9 @@ public final class ReplicationTestHelper {
"solr" + File.separator + "collection1" + File.separator + "conf" + File.separator;
public static JettySolrRunner createAndStartJetty(SolrInstance instance) throws Exception {
- FileUtils.copyFile(
- new File(SolrTestCaseJ4.TEST_HOME(), "solr.xml"),
- new File(instance.getHomeDir(), "solr.xml"));
+ Files.copy(
+ Path.of(SolrTestCaseJ4.TEST_HOME(), "solr.xml"),
+ Path.of(instance.getHomeDir(), "solr.xml"));
Properties nodeProperties = new Properties();
nodeProperties.setProperty("solr.data.dir", instance.getDataDir());
JettyConfig jettyConfig = JettyConfig.builder().setPort(0).build();
@@ -96,9 +96,9 @@ public final class ReplicationTestHelper {
* character copy of file using UTF-8. If port is non-null, will be substituted any time
* "TEST_PORT" is found.
*/
- private static void copyFile(File src, File dst, Integer port, boolean internalCompression)
+ private static void copyFile(Path src, File dst, Integer port, boolean internalCompression)
throws IOException {
- try (BufferedReader in = Files.newBufferedReader(src.toPath(), StandardCharsets.UTF_8);
+ try (BufferedReader in = Files.newBufferedReader(src, StandardCharsets.UTF_8);
Writer out = Files.newBufferedWriter(dst.toPath(), StandardCharsets.UTF_8)) {
for (String line = in.readLine(); null != line; line = in.readLine()) {
if (null != port) {
diff --git a/solr/core/src/test/org/apache/solr/handler/TestCSVLoader.java b/solr/core/src/test/org/apache/solr/handler/TestCSVLoader.java
index bbff8694af3..2126747c19d 100644
--- a/solr/core/src/test/org/apache/solr/handler/TestCSVLoader.java
+++ b/solr/core/src/test/org/apache/solr/handler/TestCSVLoader.java
@@ -83,7 +83,7 @@ public class TestCSVLoader extends SolrTestCaseJ4 {
// TODO: stop using locally defined streams once stream.file and
// stream.body work everywhere
List<ContentStream> cs = new ArrayList<>(1);
- ContentStreamBase f = new ContentStreamBase.FileStream(new File(filename));
+ ContentStreamBase f = new ContentStreamBase.FileStream(Path.of(filename));
f.setContentType("text/csv");
cs.add(f);
req.setContentStreams(cs);
diff --git a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerBackup.java b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerBackup.java
index 032ae0c9c3e..83990058abc 100644
--- a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerBackup.java
+++ b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerBackup.java
@@ -46,7 +46,6 @@ import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.embedded.JettyConfig;
import org.apache.solr.embedded.JettySolrRunner;
-import org.apache.solr.util.FileUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -72,9 +71,9 @@ public class TestReplicationHandlerBackup extends SolrJettyTestBase {
private static JettySolrRunner createAndStartJetty(ReplicationTestHelper.SolrInstance instance)
throws Exception {
- FileUtils.copyFile(
- new File(SolrTestCaseJ4.TEST_HOME(), "solr.xml"),
- new File(instance.getHomeDir(), "solr.xml"));
+ Files.copy(
+ Path.of(SolrTestCaseJ4.TEST_HOME(), "solr.xml"),
+ Path.of(instance.getHomeDir(), "solr.xml"));
Properties nodeProperties = new Properties();
nodeProperties.setProperty("solr.data.dir", instance.getDataDir());
JettyConfig jettyConfig = JettyConfig.builder().setPort(0).build();
diff --git a/solr/core/src/test/org/apache/solr/handler/TestRestoreCore.java b/solr/core/src/test/org/apache/solr/handler/TestRestoreCore.java
index 593f0af7bd9..a4de0796d69 100644
--- a/solr/core/src/test/org/apache/solr/handler/TestRestoreCore.java
+++ b/solr/core/src/test/org/apache/solr/handler/TestRestoreCore.java
@@ -36,7 +36,6 @@ import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.embedded.JettyConfig;
import org.apache.solr.embedded.JettySolrRunner;
-import org.apache.solr.util.FileUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -57,9 +56,9 @@ public class TestRestoreCore extends SolrJettyTestBase {
private static JettySolrRunner createAndStartJetty(ReplicationTestHelper.SolrInstance instance)
throws Exception {
- FileUtils.copyFile(
- new File(SolrTestCaseJ4.TEST_HOME(), "solr.xml"),
- new File(instance.getHomeDir(), "solr.xml"));
+ Files.copy(
+ Path.of(SolrTestCaseJ4.TEST_HOME(), "solr.xml"),
+ Path.of(instance.getHomeDir(), "solr.xml"));
Properties nodeProperties = new Properties();
nodeProperties.setProperty("solr.data.dir", instance.getDataDir());
JettyConfig jettyConfig = JettyConfig.builder().setPort(0).build();
diff --git a/solr/core/src/test/org/apache/solr/handler/TestSampleDocumentsLoader.java b/solr/core/src/test/org/apache/solr/handler/TestSampleDocumentsLoader.java
index 6ecb27c7f02..7bd82ec60b1 100644
--- a/solr/core/src/test/org/apache/solr/handler/TestSampleDocumentsLoader.java
+++ b/solr/core/src/test/org/apache/solr/handler/TestSampleDocumentsLoader.java
@@ -109,12 +109,12 @@ public class TestSampleDocumentsLoader extends SolrTestCase {
return "application/octet-stream";
}
- protected ContentStream getContentStream(File file) {
+ protected ContentStream getContentStream(File file) throws IOException {
return getContentStream(file, guessContentTypeFromFilename(file.getName()));
}
- protected ContentStream getContentStream(File file, String contentType) {
- ContentStreamBase.FileStream stream = new ContentStreamBase.FileStream(file);
+ protected ContentStream getContentStream(File file, String contentType) throws IOException {
+ ContentStreamBase.FileStream stream = new ContentStreamBase.FileStream(file.toPath());
stream.setContentType(contentType);
return stream;
}
diff --git a/solr/core/src/test/org/apache/solr/handler/XmlUpdateRequestHandlerTest.java b/solr/core/src/test/org/apache/solr/handler/XmlUpdateRequestHandlerTest.java
index 0394018e0bf..8dcb465094a 100644
--- a/solr/core/src/test/org/apache/solr/handler/XmlUpdateRequestHandlerTest.java
+++ b/solr/core/src/test/org/apache/solr/handler/XmlUpdateRequestHandlerTest.java
@@ -105,7 +105,7 @@ public class XmlUpdateRequestHandlerTest extends SolrTestCaseJ4 {
@Test
public void testExternalEntities() throws Exception {
- String file = getFile("mailing_lists.pdf").toURI().toASCIIString();
+ String file = getFile("mailing_lists.pdf").toUri().toASCIIString();
String xml =
"<?xml version=\"1.0\"?>"
+
diff --git a/solr/core/src/test/org/apache/solr/handler/admin/MBeansHandlerTest.java b/solr/core/src/test/org/apache/solr/handler/admin/MBeansHandlerTest.java
index c4fa6c35e2e..05232b7f05e 100644
--- a/solr/core/src/test/org/apache/solr/handler/admin/MBeansHandlerTest.java
+++ b/solr/core/src/test/org/apache/solr/handler/admin/MBeansHandlerTest.java
@@ -130,7 +130,7 @@ public class MBeansHandlerTest extends SolrTestCaseJ4 {
@Test
public void testXMLDiffWithExternalEntity() {
- String file = getFile("mailing_lists.pdf").toURI().toASCIIString();
+ String file = getFile("mailing_lists.pdf").toUri().toASCIIString();
String xml =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<!DOCTYPE foo [<!ENTITY bar SYSTEM \""
diff --git a/solr/core/src/test/org/apache/solr/handler/designer/TestSchemaDesignerAPI.java b/solr/core/src/test/org/apache/solr/handler/designer/TestSchemaDesignerAPI.java
index f059acb8a6c..983d0fa3ab1 100644
--- a/solr/core/src/test/org/apache/solr/handler/designer/TestSchemaDesignerAPI.java
+++ b/solr/core/src/test/org/apache/solr/handler/designer/TestSchemaDesignerAPI.java
@@ -188,7 +188,7 @@ public class TestSchemaDesignerAPI extends SolrCloudTestCase implements SchemaDe
when(req.getParams()).thenReturn(reqParams);
// POST some sample JSON docs
- ContentStreamBase.FileStream stream = new ContentStreamBase.FileStream(next);
+ ContentStreamBase.FileStream stream = new ContentStreamBase.FileStream(next.toPath());
stream.setContentType(TestSampleDocumentsLoader.guessContentTypeFromFilename(next.getName()));
when(req.getContentStreams()).thenReturn(Collections.singletonList(stream));
@@ -300,7 +300,7 @@ public class TestSchemaDesignerAPI extends SolrCloudTestCase implements SchemaDe
when(req.getParams()).thenReturn(reqParams);
// POST some sample XML docs
- ContentStreamBase.FileStream stream = new ContentStreamBase.FileStream(filmsXml);
+ ContentStreamBase.FileStream stream = new ContentStreamBase.FileStream(filmsXml.toPath());
stream.setContentType("application/xml");
when(req.getContentStreams()).thenReturn(Collections.singletonList(stream));
@@ -354,7 +354,7 @@ public class TestSchemaDesignerAPI extends SolrCloudTestCase implements SchemaDe
// POST some sample JSON docs
File booksJson = new File(ExternalPaths.SOURCE_HOME, "example/exampledocs/books.json");
- ContentStreamBase.FileStream stream = new ContentStreamBase.FileStream(booksJson);
+ ContentStreamBase.FileStream stream = new ContentStreamBase.FileStream(booksJson.toPath());
stream.setContentType(JSON_MIME);
when(req.getContentStreams()).thenReturn(Collections.singletonList(stream));
diff --git a/solr/core/src/test/org/apache/solr/pkg/PackageStoreSchemaPluginsTest.java b/solr/core/src/test/org/apache/solr/pkg/PackageStoreSchemaPluginsTest.java
index 0d94bcf1f5a..26d8261c07f 100644
--- a/solr/core/src/test/org/apache/solr/pkg/PackageStoreSchemaPluginsTest.java
+++ b/solr/core/src/test/org/apache/solr/pkg/PackageStoreSchemaPluginsTest.java
@@ -51,8 +51,8 @@ public class PackageStoreSchemaPluginsTest extends SolrCloudTestCase {
}
}
- private final Path pluginJarPath = getFile("runtimecode/schema-plugins.jar.bin").toPath();
- private final Path bogusJarPath = getFile("runtimecode/runtimelibs.jar.bin").toPath();
+ private final Path pluginJarPath = getFile("runtimecode/schema-plugins.jar.bin");
+ private final Path bogusJarPath = getFile("runtimecode/runtimelibs.jar.bin");
private SolrClient client;
diff --git a/solr/core/src/test/org/apache/solr/rest/TestRestManager.java b/solr/core/src/test/org/apache/solr/rest/TestRestManager.java
index a95bd3d3edd..b8ef9b0de84 100644
--- a/solr/core/src/test/org/apache/solr/rest/TestRestManager.java
+++ b/solr/core/src/test/org/apache/solr/rest/TestRestManager.java
@@ -17,6 +17,7 @@
package org.apache.solr.rest;
import java.io.File;
+import java.io.IOException;
import java.nio.file.Paths;
import java.util.Arrays;
import org.apache.solr.common.util.NamedList;
@@ -120,7 +121,7 @@ public class TestRestManager extends SolrRestletTestBase {
}
@Test
- public void testReloadFromPersistentStorage() {
+ public void testReloadFromPersistentStorage() throws IOException {
SolrResourceLoader loader = new SolrResourceLoader(Paths.get("./"));
File unitTestStorageDir = createTempDir("testRestManager").toFile();
assertTrue(
diff --git a/solr/core/src/test/org/apache/solr/schema/ExternalFileFieldSortTest.java b/solr/core/src/test/org/apache/solr/schema/ExternalFileFieldSortTest.java
index 1a554d551b5..23a1152c3eb 100644
--- a/solr/core/src/test/org/apache/solr/schema/ExternalFileFieldSortTest.java
+++ b/solr/core/src/test/org/apache/solr/schema/ExternalFileFieldSortTest.java
@@ -26,9 +26,9 @@ import org.junit.Test;
public class ExternalFileFieldSortTest extends SolrTestCaseJ4 {
static void updateExternalFile() throws IOException {
- final String testHome = SolrTestCaseJ4.getFile("solr/collection1").getParent();
+ final Path testHome = SolrTestCaseJ4.getFile("solr/collection1").getParent();
String filename = "external_eff";
- Files.copy(Path.of(testHome, filename), Path.of(h.getCore().getDataDir(), filename));
+ Files.copy(testHome.resolve(filename), Path.of(h.getCore().getDataDir(), filename));
}
private void addDocuments() {
diff --git a/solr/core/src/test/org/apache/solr/schema/TestCollationField.java b/solr/core/src/test/org/apache/solr/schema/TestCollationField.java
index 0ac2d36e4bb..437c397ea59 100644
--- a/solr/core/src/test/org/apache/solr/schema/TestCollationField.java
+++ b/solr/core/src/test/org/apache/solr/schema/TestCollationField.java
@@ -64,14 +64,11 @@ public class TestCollationField extends SolrTestCaseJ4 {
// copy over configuration files
Files.copy(
- getFile("solr/collection1/conf/solrconfig-basic.xml").toPath(),
- confDir.resolve("solrconfig.xml"));
+ getFile("solr/collection1/conf/solrconfig-basic.xml"), confDir.resolve("solrconfig.xml"));
Files.copy(
- getFile("solr/collection1/conf/solrconfig.snippet.randomindexconfig.xml").toPath(),
+ getFile("solr/collection1/conf/solrconfig.snippet.randomindexconfig.xml"),
confDir.resolve("solrconfig.snippet.randomindexconfig.xml"));
- Files.copy(
- getFile("solr/collection1/conf/schema-collate.xml").toPath(),
- confDir.resolve("schema.xml"));
+ Files.copy(getFile("solr/collection1/conf/schema-collate.xml"), confDir.resolve("schema.xml"));
// generate custom collation rules (DIN 5007-2), saving to customrules.dat
RuleBasedCollator baseCollator =
diff --git a/solr/core/src/test/org/apache/solr/schema/TestCollationFieldDocValues.java b/solr/core/src/test/org/apache/solr/schema/TestCollationFieldDocValues.java
index b38b65f81fc..1443d2f1f90 100644
--- a/solr/core/src/test/org/apache/solr/schema/TestCollationFieldDocValues.java
+++ b/solr/core/src/test/org/apache/solr/schema/TestCollationFieldDocValues.java
@@ -64,14 +64,12 @@ public class TestCollationFieldDocValues extends SolrTestCaseJ4 {
// copy over configuration files
Files.copy(
- getFile("solr/collection1/conf/solrconfig-basic.xml").toPath(),
- confDir.resolve("solrconfig.xml"));
+ getFile("solr/collection1/conf/solrconfig-basic.xml"), confDir.resolve("solrconfig.xml"));
Files.copy(
- getFile("solr/collection1/conf/solrconfig.snippet.randomindexconfig.xml").toPath(),
+ getFile("solr/collection1/conf/solrconfig.snippet.randomindexconfig.xml"),
confDir.resolve("solrconfig.snippet.randomindexconfig.xml"));
Files.copy(
- getFile("solr/collection1/conf/schema-collate-dv.xml").toPath(),
- confDir.resolve("schema.xml"));
+ getFile("solr/collection1/conf/schema-collate-dv.xml"), confDir.resolve("schema.xml"));
// generate custom collation rules (DIN 5007-2), saving to customrules.dat
RuleBasedCollator baseCollator =
diff --git a/solr/core/src/test/org/apache/solr/search/TestRecovery.java b/solr/core/src/test/org/apache/solr/search/TestRecovery.java
index 6cb6747c716..36e33b772e2 100644
--- a/solr/core/src/test/org/apache/solr/search/TestRecovery.java
+++ b/solr/core/src/test/org/apache/solr/search/TestRecovery.java
@@ -1386,12 +1386,12 @@ public class TestRecovery extends SolrTestCaseJ4 {
h.close();
- String[] files = ulog.getLogList(logDir);
+ String[] files = ulog.getLogList(logDir.toPath());
for (String file : files) {
Files.delete(new File(logDir, file).toPath());
}
- assertEquals(0, ulog.getLogList(logDir).length);
+ assertEquals(0, ulog.getLogList(logDir.toPath()).length);
createCore();
@@ -1422,7 +1422,8 @@ public class TestRecovery extends SolrTestCaseJ4 {
assertJQ(
req("qt", "/get", "getVersions", "" + maxReq),
"/versions==" + versions.subList(0, Math.min(maxReq, versExpected)));
- assertEquals(Math.min(i, ulog.getMaxNumLogsToKeep()), ulog.getLogList(logDir).length);
+ assertEquals(
+ Math.min(i, ulog.getMaxNumLogsToKeep()), ulog.getLogList(logDir.toPath()).length);
}
docsPerBatch = ulog.getNumRecordsToKeep() + 20;
@@ -1443,7 +1444,7 @@ public class TestRecovery extends SolrTestCaseJ4 {
"/versions==" + versions.subList(0, Math.min(maxReq, versExpected)));
// previous logs should be gone now
- assertEquals(1, ulog.getLogList(logDir).length);
+ assertEquals(1, ulog.getLogList(logDir.toPath()).length);
addDocs(1, numIndexed, versions);
numIndexed += 1;
@@ -1480,7 +1481,7 @@ public class TestRecovery extends SolrTestCaseJ4 {
"/versions==" + versions.subList(0, Math.min(maxReq, expectedToRetain)));
// previous logs should be gone now
- assertEquals(1, ulog.getLogList(logDir).length);
+ assertEquals(1, ulog.getLogList(logDir.toPath()).length);
//
// test that a corrupt tlog file doesn't stop us from coming up, or seeing versions before
@@ -1492,7 +1493,7 @@ public class TestRecovery extends SolrTestCaseJ4 {
new LinkedList<
Long>()); // don't add this to the versions list because we are going to lose it...
h.close();
- files = ulog.getLogList(logDir);
+ files = ulog.getLogList(logDir.toPath());
Arrays.sort(files);
try (RandomAccessFile raf =
new RandomAccessFile(new File(logDir, files[files.length - 1]), "rw")) {
@@ -1548,7 +1549,7 @@ public class TestRecovery extends SolrTestCaseJ4 {
assertU(adoc("id", "F3"));
h.close();
- String[] files = ulog.getLogList(logDir);
+ String[] files = ulog.getLogList(logDir.toPath());
Arrays.sort(files);
try (RandomAccessFile raf =
new RandomAccessFile(new File(logDir, files[files.length - 1]), "rw")) {
@@ -1615,7 +1616,7 @@ public class TestRecovery extends SolrTestCaseJ4 {
h.close();
- String[] files = ulog.getLogList(logDir);
+ String[] files = ulog.getLogList(logDir.toPath());
Arrays.sort(files);
try (RandomAccessFile raf =
new RandomAccessFile(new File(logDir, files[files.length - 1]), "rw")) {
@@ -1698,7 +1699,7 @@ public class TestRecovery extends SolrTestCaseJ4 {
assertU(adoc("id", "CCCCCC"));
h.close();
- String[] files = ulog.getLogList(logDir);
+ String[] files = ulog.getLogList(logDir.toPath());
Arrays.sort(files);
String fname = files[files.length - 1];
byte[] content;
@@ -1925,12 +1926,12 @@ public class TestRecovery extends SolrTestCaseJ4 {
h.close();
try {
- String[] files = ulog.getLogList(logDir);
+ String[] files = ulog.getLogList(logDir.toPath());
for (String file : files) {
Files.delete(new File(logDir, file).toPath());
}
- assertEquals(0, ulog.getLogList(logDir).length);
+ assertEquals(0, ulog.getLogList(logDir.toPath()).length);
} finally {
// make sure we create the core again, even if the assert operation fails, so it won't mess
// up the next test.
diff --git a/solr/core/src/test/org/apache/solr/servlet/SolrRequestParserTest.java b/solr/core/src/test/org/apache/solr/servlet/SolrRequestParserTest.java
index e86e6c12c4b..f2634411e90 100644
--- a/solr/core/src/test/org/apache/solr/servlet/SolrRequestParserTest.java
+++ b/solr/core/src/test/org/apache/solr/servlet/SolrRequestParserTest.java
@@ -162,7 +162,7 @@ public class SolrRequestParserTest extends SolrTestCaseJ4 {
@Test
@SuppressWarnings({"try"})
public void testStreamFile() throws Exception {
- Path file = getFile("README").toPath();
+ Path file = getFile("README");
byte[] bytes = Files.readAllBytes(file);
diff --git a/solr/core/src/test/org/apache/solr/util/FileUtilsTest.java b/solr/core/src/test/org/apache/solr/util/FileUtilsTest.java
index 0dfeff109a3..e6e96380026 100644
--- a/solr/core/src/test/org/apache/solr/util/FileUtilsTest.java
+++ b/solr/core/src/test/org/apache/solr/util/FileUtilsTest.java
@@ -23,15 +23,6 @@ import org.junit.Test;
public class FileUtilsTest extends SolrTestCase {
- @Test
- public void testResolve() {
- String cwd = new File(".").getAbsolutePath();
- assertEquals(new File("conf/data"), FileUtils.resolvePath(new File("conf"), "data"));
- assertEquals(
- new File(cwd + "/conf/data"), FileUtils.resolvePath(new File(cwd + "/conf"), "data"));
- assertEquals(new File(cwd + "/data"), FileUtils.resolvePath(new File("conf"), cwd + "/data"));
- }
-
@Test
public void testDetectsPathEscape() {
final var parent = Path.of(".");
diff --git a/solr/core/src/test/org/apache/solr/util/TestSystemIdResolver.java b/solr/core/src/test/org/apache/solr/util/TestSystemIdResolver.java
index 71ba80b4bd1..8aea4ba8178 100644
--- a/solr/core/src/test/org/apache/solr/util/TestSystemIdResolver.java
+++ b/solr/core/src/test/org/apache/solr/util/TestSystemIdResolver.java
@@ -46,7 +46,7 @@ public class TestSystemIdResolver extends SolrTestCaseJ4 {
}
public void testResolving() throws Exception {
- final Path testHome = SolrTestCaseJ4.getFile("solr/collection1").getParentFile().toPath();
+ final Path testHome = SolrTestCaseJ4.getFile("solr/collection1").getParent();
final ResourceLoader loader =
new SolrResourceLoader(testHome.resolve("collection1"), this.getClass().getClassLoader());
final SystemIdResolver resolver = new SystemIdResolver(loader);
@@ -131,7 +131,7 @@ public class TestSystemIdResolver extends SolrTestCaseJ4 {
public void testUnsafeResolving() throws Exception {
System.setProperty(SolrResourceLoader.SOLR_ALLOW_UNSAFE_RESOURCELOADING_PARAM, "true");
- final Path testHome = SolrTestCaseJ4.getFile("solr/collection1").getParentFile().toPath();
+ final Path testHome = SolrTestCaseJ4.getFile("solr/collection1").getParent();
final ResourceLoader loader =
new SolrResourceLoader(testHome.resolve("collection1"), this.getClass().getClassLoader());
final SystemIdResolver resolver = new SystemIdResolver(loader);
diff --git a/solr/cross-dc-manager/src/test/org/apache/solr/crossdc/manager/DeleteByQueryToIdTest.java b/solr/cross-dc-manager/src/test/org/apache/solr/crossdc/manager/DeleteByQueryToIdTest.java
index ff13f34e301..475b9f0b73f 100644
--- a/solr/cross-dc-manager/src/test/org/apache/solr/crossdc/manager/DeleteByQueryToIdTest.java
+++ b/solr/cross-dc-manager/src/test/org/apache/solr/crossdc/manager/DeleteByQueryToIdTest.java
@@ -108,9 +108,8 @@ public class DeleteByQueryToIdTest extends SolrCloudTestCase {
solrCluster1 =
SolrCloudTestCase.configureCluster(1)
- .addConfig("conf", getFile("configs/cloud-minimal/conf").toPath().toAbsolutePath())
- .addConfig(
- "confNoDbq", getFile("configs/cloud-minimal-no-dbq/conf").toPath().toAbsolutePath())
+ .addConfig("conf", getFile("configs/cloud-minimal/conf").toAbsolutePath())
+ .addConfig("confNoDbq", getFile("configs/cloud-minimal-no-dbq/conf").toAbsolutePath())
.configure();
props.setProperty("solr.crossdc.topicName", TOPIC);
@@ -132,8 +131,8 @@ public class DeleteByQueryToIdTest extends SolrCloudTestCase {
solrCluster2 =
SolrCloudTestCase.configureCluster(1)
- .addConfig("conf", getFile("configs/cloud-minimal/conf").toPath())
- .addConfig("confNoDbq", getFile("configs/cloud-minimal-no-dbq/conf").toPath())
+ .addConfig("conf", getFile("configs/cloud-minimal/conf"))
+ .addConfig("confNoDbq", getFile("configs/cloud-minimal-no-dbq/conf"))
.configure();
solrCluster2.getZkClient().makePath("/crossdc.properties", data, true);
diff --git a/solr/cross-dc-manager/src/test/org/apache/solr/crossdc/manager/RetryQueueIntegrationTest.java b/solr/cross-dc-manager/src/test/org/apache/solr/crossdc/manager/RetryQueueIntegrationTest.java
index 147a7673df7..c654fc99187 100644
--- a/solr/cross-dc-manager/src/test/org/apache/solr/crossdc/manager/RetryQueueIntegrationTest.java
+++ b/solr/cross-dc-manager/src/test/org/apache/solr/crossdc/manager/RetryQueueIntegrationTest.java
@@ -157,7 +157,7 @@ public class RetryQueueIntegrationTest extends SolrTestCaseJ4 {
// new SolrCloudTestCase.Builder(1, baseDir).addConfig("conf",
// getFile("configs/cloud-minimal/conf").toPath()).configure();
- cluster.uploadConfigSet(getFile("configs/cloud-minimal/conf").toPath(), "conf");
+ cluster.uploadConfigSet(getFile("configs/cloud-minimal/conf"), "conf");
CollectionAdminRequest.Create create2 =
CollectionAdminRequest.createCollection(COLLECTION, "conf", 1, 1);
diff --git a/solr/cross-dc-manager/src/test/org/apache/solr/crossdc/manager/SolrAndKafkaIntegrationTest.java b/solr/cross-dc-manager/src/test/org/apache/solr/crossdc/manager/SolrAndKafkaIntegrationTest.java
index af65035258e..65fe1aeb55b 100644
--- a/solr/cross-dc-manager/src/test/org/apache/solr/crossdc/manager/SolrAndKafkaIntegrationTest.java
+++ b/solr/cross-dc-manager/src/test/org/apache/solr/crossdc/manager/SolrAndKafkaIntegrationTest.java
@@ -121,9 +121,7 @@ public class SolrAndKafkaIntegrationTest extends SolrCloudTestCase {
System.setProperty(INDEX_UNMIRRORABLE_DOCS, "false");
solrCluster1 =
- configureCluster(1)
- .addConfig("conf", getFile("configs/cloud-minimal/conf").toPath())
- .configure();
+ configureCluster(1).addConfig("conf", getFile("configs/cloud-minimal/conf")).configure();
CollectionAdminRequest.Create create =
CollectionAdminRequest.createCollection(COLLECTION, "conf", 1, 1);
@@ -131,9 +129,7 @@ public class SolrAndKafkaIntegrationTest extends SolrCloudTestCase {
solrCluster1.waitForActiveCollection(COLLECTION, 1, 1);
solrCluster2 =
- configureCluster(1)
- .addConfig("conf", getFile("configs/cloud-minimal/conf").toPath())
- .configure();
+ configureCluster(1).addConfig("conf", getFile("configs/cloud-minimal/conf")).configure();
CollectionAdminRequest.Create create2 =
CollectionAdminRequest.createCollection(COLLECTION, "conf", 1, 1);
diff --git a/solr/cross-dc-manager/src/test/org/apache/solr/crossdc/manager/SolrAndKafkaMultiCollectionIntegrationTest.java b/solr/cross-dc-manager/src/test/org/apache/solr/crossdc/manager/SolrAndKafkaMultiCollectionIntegrationTest.java
index 26ecfd34e25..de942eb980e 100644
--- a/solr/cross-dc-manager/src/test/org/apache/solr/crossdc/manager/SolrAndKafkaMultiCollectionIntegrationTest.java
+++ b/solr/cross-dc-manager/src/test/org/apache/solr/crossdc/manager/SolrAndKafkaMultiCollectionIntegrationTest.java
@@ -117,9 +117,7 @@ public class SolrAndKafkaMultiCollectionIntegrationTest extends SolrCloudTestCas
System.setProperty(INDEX_UNMIRRORABLE_DOCS, "false");
solrCluster1 =
- configureCluster(1)
- .addConfig("conf", getFile("configs/cloud-minimal/conf").toPath())
- .configure();
+ configureCluster(1).addConfig("conf", getFile("configs/cloud-minimal/conf")).configure();
CollectionAdminRequest.Create create =
CollectionAdminRequest.createCollection(COLLECTION, "conf", 1, 1);
@@ -127,9 +125,7 @@ public class SolrAndKafkaMultiCollectionIntegrationTest extends SolrCloudTestCas
solrCluster1.waitForActiveCollection(COLLECTION, 1, 1);
solrCluster2 =
- configureCluster(1)
- .addConfig("conf", getFile("configs/cloud-minimal/conf").toPath())
- .configure();
+ configureCluster(1).addConfig("conf", getFile("configs/cloud-minimal/conf")).configure();
CollectionAdminRequest.Create create2 =
CollectionAdminRequest.createCollection(COLLECTION, "conf", 1, 1);
diff --git a/solr/cross-dc-manager/src/test/org/apache/solr/crossdc/manager/SolrAndKafkaReindexTest.java b/solr/cross-dc-manager/src/test/org/apache/solr/crossdc/manager/SolrAndKafkaReindexTest.java
index 5aa7c1ddf51..7a955fb6519 100644
--- a/solr/cross-dc-manager/src/test/org/apache/solr/crossdc/manager/SolrAndKafkaReindexTest.java
+++ b/solr/cross-dc-manager/src/test/org/apache/solr/crossdc/manager/SolrAndKafkaReindexTest.java
@@ -98,9 +98,7 @@ public class SolrAndKafkaReindexTest extends SolrCloudTestCase {
System.setProperty("solr.crossdc.bootstrapServers", kafkaCluster.bootstrapServers());
solrCluster1 =
- configureCluster(3)
- .addConfig("conf", getFile("configs/cloud-minimal/conf").toPath())
- .configure();
+ configureCluster(3).addConfig("conf", getFile("configs/cloud-minimal/conf")).configure();
CollectionAdminRequest.Create create =
CollectionAdminRequest.createCollection(COLLECTION, "conf", 3, 2);
@@ -108,9 +106,7 @@ public class SolrAndKafkaReindexTest extends SolrCloudTestCase {
solrCluster1.waitForActiveCollection(COLLECTION, 3, 6);
solrCluster2 =
- configureCluster(3)
- .addConfig("conf", getFile("configs/cloud-minimal/conf").toPath())
- .configure();
+ configureCluster(3).addConfig("conf", getFile("configs/cloud-minimal/conf")).configure();
CollectionAdminRequest.Create create2 =
CollectionAdminRequest.createCollection(COLLECTION, "conf", 2, 3);
diff --git a/solr/cross-dc-manager/src/test/org/apache/solr/crossdc/manager/ZkConfigIntegrationTest.java b/solr/cross-dc-manager/src/test/org/apache/solr/crossdc/manager/ZkConfigIntegrationTest.java
index f926e9178ea..a3c0f2b9626 100644
--- a/solr/cross-dc-manager/src/test/org/apache/solr/crossdc/manager/ZkConfigIntegrationTest.java
+++ b/solr/cross-dc-manager/src/test/org/apache/solr/crossdc/manager/ZkConfigIntegrationTest.java
@@ -102,9 +102,7 @@ public class ZkConfigIntegrationTest extends SolrCloudTestCase {
Properties props = new Properties();
solrCluster1 =
- configureCluster(1)
- .addConfig("conf", getFile("configs/cloud-minimal/conf").toPath())
- .configure();
+ configureCluster(1).addConfig("conf", getFile("configs/cloud-minimal/conf")).configure();
props.setProperty(KafkaCrossDcConf.TOPIC_NAME, TOPIC2);
props.setProperty(KafkaCrossDcConf.BOOTSTRAP_SERVERS, kafkaCluster.bootstrapServers());
@@ -123,9 +121,7 @@ public class ZkConfigIntegrationTest extends SolrCloudTestCase {
solrCluster1.waitForActiveCollection(COLLECTION, 1, 1);
solrCluster2 =
- configureCluster(1)
- .addConfig("conf", getFile("configs/cloud-minimal/conf").toPath())
- .configure();
+ configureCluster(1).addConfig("conf", getFile("configs/cloud-minimal/conf")).configure();
CollectionAdminRequest.Create create2 =
CollectionAdminRequest.createCollection(COLLECTION, "conf", 1, 1);
diff --git a/solr/modules/analysis-extras/src/test/org/apache/solr/analysis/TestFoldingMultitermExtrasQuery.java b/solr/modules/analysis-extras/src/test/org/apache/solr/analysis/TestFoldingMultitermExtrasQuery.java
index f6138cdde1a..e5b066263a5 100644
--- a/solr/modules/analysis-extras/src/test/org/apache/solr/analysis/TestFoldingMultitermExtrasQuery.java
+++ b/solr/modules/analysis-extras/src/test/org/apache/solr/analysis/TestFoldingMultitermExtrasQuery.java
@@ -16,8 +16,8 @@
*/
package org.apache.solr.analysis;
-import java.io.File;
-import org.apache.commons.io.FileUtils;
+import java.nio.file.Path;
+import org.apache.commons.io.file.PathUtils;
import org.apache.solr.SolrTestCaseJ4;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -32,9 +32,12 @@ public class TestFoldingMultitermExtrasQuery extends SolrTestCaseJ4 {
@BeforeClass
public static void beforeTests() throws Exception {
- File testHome = createTempDir().toFile();
- FileUtils.copyDirectory(getFile("analysis-extras/solr"), testHome);
- initCore("solrconfig-icucollate.xml", "schema-folding-extra.xml", testHome.getAbsolutePath());
+ Path testHome = createTempDir();
+ PathUtils.copyDirectory(getFile("analysis-extras/solr"), testHome);
+ initCore(
+ "solrconfig-icucollate.xml",
+ "schema-folding-extra.xml",
+ testHome.toAbsolutePath().toString());
int idx = 1;
// ICUFoldingFilterFactory
diff --git a/solr/modules/analysis-extras/src/test/org/apache/solr/schema/TestICUCollationField.java b/solr/modules/analysis-extras/src/test/org/apache/solr/schema/TestICUCollationField.java
index 7193d9f706a..d66f959c799 100644
--- a/solr/modules/analysis-extras/src/test/org/apache/solr/schema/TestICUCollationField.java
+++ b/solr/modules/analysis-extras/src/test/org/apache/solr/schema/TestICUCollationField.java
@@ -66,10 +66,10 @@ public class TestICUCollationField extends SolrTestCaseJ4 {
// copy over configuration files
Files.copy(
- getFile("analysis-extras/solr/collection1/conf/solrconfig-icucollate.xml").toPath(),
+ getFile("analysis-extras/solr/collection1/conf/solrconfig-icucollate.xml"),
confDir.resolve("solrconfig.xml"));
Files.copy(
- getFile("analysis-extras/solr/collection1/conf/schema-icucollate.xml").toPath(),
+ getFile("analysis-extras/solr/collection1/conf/schema-icucollate.xml"),
confDir.resolve("schema.xml"));
// generate custom collation rules (DIN 5007-2), saving to customrules.dat
diff --git a/solr/modules/analysis-extras/src/test/org/apache/solr/schema/TestICUCollationFieldDocValues.java b/solr/modules/analysis-extras/src/test/org/apache/solr/schema/TestICUCollationFieldDocValues.java
index 2b14bd8a5c6..37c85d9392b 100644
--- a/solr/modules/analysis-extras/src/test/org/apache/solr/schema/TestICUCollationFieldDocValues.java
+++ b/solr/modules/analysis-extras/src/test/org/apache/solr/schema/TestICUCollationFieldDocValues.java
@@ -63,10 +63,10 @@ public class TestICUCollationFieldDocValues extends SolrTestCaseJ4 {
// copy over configuration files
Files.copy(
- getFile("analysis-extras/solr/collection1/conf/solrconfig-icucollate.xml").toPath(),
+ getFile("analysis-extras/solr/collection1/conf/solrconfig-icucollate.xml"),
confDir.resolve("solrconfig.xml"));
Files.copy(
- getFile("analysis-extras/solr/collection1/conf/schema-icucollate-dv.xml").toPath(),
+ getFile("analysis-extras/solr/collection1/conf/schema-icucollate-dv.xml"),
confDir.resolve("schema.xml"));
// generate custom collation rules (DIN 5007-2), saving to customrules.dat
diff --git a/solr/modules/analysis-extras/src/test/org/apache/solr/schema/TestICUCollationFieldOptions.java b/solr/modules/analysis-extras/src/test/org/apache/solr/schema/TestICUCollationFieldOptions.java
index 63f8b00b0d3..62f1cbea550 100644
--- a/solr/modules/analysis-extras/src/test/org/apache/solr/schema/TestICUCollationFieldOptions.java
+++ b/solr/modules/analysis-extras/src/test/org/apache/solr/schema/TestICUCollationFieldOptions.java
@@ -16,8 +16,8 @@
*/
package org.apache.solr.schema;
-import java.io.File;
-import org.apache.commons.io.FileUtils;
+import java.nio.file.Path;
+import org.apache.commons.io.file.PathUtils;
import org.apache.solr.SolrTestCaseJ4;
import org.junit.BeforeClass;
@@ -25,10 +25,12 @@ import org.junit.BeforeClass;
public class TestICUCollationFieldOptions extends SolrTestCaseJ4 {
@BeforeClass
public static void beforeClass() throws Exception {
- File testHome = createTempDir().toFile();
- FileUtils.copyDirectory(getFile("analysis-extras/solr"), testHome);
+ Path testHome = createTempDir();
+ PathUtils.copyDirectory(getFile("analysis-extras/solr"), testHome);
initCore(
- "solrconfig-icucollate.xml", "schema-icucollateoptions.xml", testHome.getAbsolutePath());
+ "solrconfig-icucollate.xml",
+ "schema-icucollateoptions.xml",
+ testHome.toAbsolutePath().toString());
// add some docs
assertU(adoc("id", "1", "text", "foo-bar"));
assertU(adoc("id", "2", "text", "foo bar"));
diff --git a/solr/modules/analysis-extras/src/test/org/apache/solr/update/processor/TestOpenNLPExtractNamedEntitiesUpdateProcessorFactory.java b/solr/modules/analysis-extras/src/test/org/apache/solr/update/processor/TestOpenNLPExtractNamedEntitiesUpdateProcessorFactory.java
index 46b219dedde..8144bba6cd5 100644
--- a/solr/modules/analysis-extras/src/test/org/apache/solr/update/processor/TestOpenNLPExtractNamedEntitiesUpdateProcessorFactory.java
+++ b/solr/modules/analysis-extras/src/test/org/apache/solr/update/processor/TestOpenNLPExtractNamedEntitiesUpdateProcessorFactory.java
@@ -17,9 +17,9 @@
package org.apache.solr.update.processor;
-import java.io.File;
+import java.nio.file.Path;
import java.util.List;
-import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.file.PathUtils;
import org.apache.solr.common.SolrInputDocument;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -28,10 +28,12 @@ public class TestOpenNLPExtractNamedEntitiesUpdateProcessorFactory extends Updat
@BeforeClass
public static void beforeClass() throws Exception {
- File testHome = createTempDir().toFile();
- FileUtils.copyDirectory(getFile("analysis-extras/solr"), testHome);
+ Path testHome = createTempDir();
+ PathUtils.copyDirectory(getFile("analysis-extras/solr"), testHome);
initCore(
- "solrconfig-opennlp-extract.xml", "schema-opennlp-extract.xml", testHome.getAbsolutePath());
+ "solrconfig-opennlp-extract.xml",
+ "schema-opennlp-extract.xml",
+ testHome.toAbsolutePath().toString());
}
@Test
diff --git a/solr/modules/clustering/src/test/org/apache/solr/handler/clustering/ClusteringComponentDistributedTest.java b/solr/modules/clustering/src/test/org/apache/solr/handler/clustering/ClusteringComponentDistributedTest.java
index e427e8840f9..003276312e3 100644
--- a/solr/modules/clustering/src/test/org/apache/solr/handler/clustering/ClusteringComponentDistributedTest.java
+++ b/solr/modules/clustering/src/test/org/apache/solr/handler/clustering/ClusteringComponentDistributedTest.java
@@ -36,7 +36,7 @@ public class ClusteringComponentDistributedTest extends BaseDistributedSearchTes
@Override
public String getSolrHome() {
- return getFile("clustering/solr/collection1").getParent();
+ return getFile("clustering/solr/collection1").getParent().toString();
}
@Before
diff --git a/solr/modules/clustering/src/test/org/apache/solr/handler/clustering/ClusteringComponentTest.java b/solr/modules/clustering/src/test/org/apache/solr/handler/clustering/ClusteringComponentTest.java
index 32422d78c3d..6ff1c63a859 100644
--- a/solr/modules/clustering/src/test/org/apache/solr/handler/clustering/ClusteringComponentTest.java
+++ b/solr/modules/clustering/src/test/org/apache/solr/handler/clustering/ClusteringComponentTest.java
@@ -17,10 +17,10 @@
package org.apache.solr.handler.clustering;
import com.carrotsearch.randomizedtesting.RandomizedContext;
-import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
+import java.nio.file.Path;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -30,7 +30,7 @@ import java.util.Objects;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
-import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.file.PathUtils;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.response.ClusteringResponse;
import org.apache.solr.common.SolrDocument;
@@ -55,9 +55,9 @@ public class ClusteringComponentTest extends SolrTestCaseJ4 {
@BeforeClass
public static void beforeClass() throws Exception {
- File testHome = createTempDir().toFile();
- FileUtils.copyDirectory(getFile("clustering/solr"), testHome);
- initCore("solrconfig.xml", "schema.xml", testHome.getAbsolutePath());
+ Path testHome = createTempDir();
+ PathUtils.copyDirectory(getFile("clustering/solr"), testHome);
+ initCore("solrconfig.xml", "schema.xml", testHome.toAbsolutePath().toString());
String[] languages = {
"English", "French", "German", "Unknown",
diff --git a/solr/modules/cross-dc/src/test/org/apache/solr/crossdc/CrossDCProducerSolrStandaloneTest.java b/solr/modules/cross-dc/src/test/org/apache/solr/crossdc/CrossDCProducerSolrStandaloneTest.java
index d8d91832efa..c35adbc17ed 100644
--- a/solr/modules/cross-dc/src/test/org/apache/solr/crossdc/CrossDCProducerSolrStandaloneTest.java
+++ b/solr/modules/cross-dc/src/test/org/apache/solr/crossdc/CrossDCProducerSolrStandaloneTest.java
@@ -120,12 +120,12 @@ public class CrossDCProducerSolrStandaloneTest extends SolrTestCaseJ4 {
Files.createFile(coreDirectory.resolve("core.properties"));
// Copy "schema.xml" from the source location to the "conf" subdirectory
- File sourceSchemaFile = getFile(Path.of(sourceLocation, "schema.xml").toString());
+ File sourceSchemaFile = getFile(Path.of(sourceLocation, "schema.xml").toString()).toFile();
Path targetSchemaPath = subHome.resolve("schema.xml");
Files.copy(sourceSchemaFile.toPath(), targetSchemaPath, StandardCopyOption.REPLACE_EXISTING);
// Copy solr config file from the source location to the "conf" subdirectory
- File sourceConfigFile = getFile(Path.of(sourceLocation, solrConfigName).toString());
+ File sourceConfigFile = getFile(Path.of(sourceLocation, solrConfigName).toString()).toFile();
Path targetConfigPath = subHome.resolve("solrconfig.xml");
Files.copy(sourceConfigFile.toPath(), targetConfigPath, StandardCopyOption.REPLACE_EXISTING);
}
diff --git a/solr/modules/extraction/src/test/org/apache/solr/handler/extraction/ExtractingRequestHandlerTest.java b/solr/modules/extraction/src/test/org/apache/solr/handler/extraction/ExtractingRequestHandlerTest.java
index ede60a108d3..7ad7ef1dc70 100644
--- a/solr/modules/extraction/src/test/org/apache/solr/handler/extraction/ExtractingRequestHandlerTest.java
+++ b/solr/modules/extraction/src/test/org/apache/solr/handler/extraction/ExtractingRequestHandlerTest.java
@@ -52,7 +52,8 @@ public class ExtractingRequestHandlerTest extends SolrTestCaseJ4 {
false);
}
- initCore("solrconfig.xml", "schema.xml", getFile("extraction/solr").getAbsolutePath());
+ initCore(
+ "solrconfig.xml", "schema.xml", getFile("extraction/solr").toAbsolutePath().toString());
}
@Override
diff --git a/solr/modules/extraction/src/test/org/apache/solr/handler/extraction/TestXLSXResponseWriter.java b/solr/modules/extraction/src/test/org/apache/solr/handler/extraction/TestXLSXResponseWriter.java
index 1c95280cac6..4aa5f9eb09f 100644
--- a/solr/modules/extraction/src/test/org/apache/solr/handler/extraction/TestXLSXResponseWriter.java
+++ b/solr/modules/extraction/src/test/org/apache/solr/handler/extraction/TestXLSXResponseWriter.java
@@ -47,7 +47,8 @@ public class TestXLSXResponseWriter extends SolrTestCaseJ4 {
@BeforeClass
public static void beforeClass() throws Exception {
System.setProperty("enable.update.log", "false");
- initCore("solrconfig.xml", "schema.xml", getFile("extraction/solr").getAbsolutePath());
+ initCore(
+ "solrconfig.xml", "schema.xml", getFile("extraction/solr").toAbsolutePath().toString());
createIndex();
// find a reference to the default response writer so we can redirect its output later
SolrCore testCore = h.getCore();
diff --git a/solr/modules/gcs-repository/src/test/org/apache/solr/gcs/GCSIncrementalBackupTest.java b/solr/modules/gcs-repository/src/test/org/apache/solr/gcs/GCSIncrementalBackupTest.java
index 4b145c601b4..e8300147322 100644
--- a/solr/modules/gcs-repository/src/test/org/apache/solr/gcs/GCSIncrementalBackupTest.java
+++ b/solr/modules/gcs-repository/src/test/org/apache/solr/gcs/GCSIncrementalBackupTest.java
@@ -73,7 +73,7 @@ public class GCSIncrementalBackupTest extends AbstractIncrementalBackupTest {
public static void setupClass() throws Exception {
configureCluster(NUM_NODES) // nodes
- .addConfig("conf1", getFile("conf/solrconfig.xml").getParentFile().toPath())
+ .addConfig("conf1", getFile("conf/solrconfig.xml").getParent())
.withSolrXml(SOLR_XML)
.configure();
}
diff --git a/solr/modules/gcs-repository/src/test/org/apache/solr/gcs/GCSInstallShardTest.java b/solr/modules/gcs-repository/src/test/org/apache/solr/gcs/GCSInstallShardTest.java
index 3d0d30262ed..ecb08fa0192 100644
--- a/solr/modules/gcs-repository/src/test/org/apache/solr/gcs/GCSInstallShardTest.java
+++ b/solr/modules/gcs-repository/src/test/org/apache/solr/gcs/GCSInstallShardTest.java
@@ -52,7 +52,7 @@ public class GCSInstallShardTest extends AbstractInstallShardTest {
public static void setupClass() throws Exception {
configureCluster(1) // nodes
- .addConfig("conf1", getFile("conf/solrconfig.xml").getParentFile().toPath())
+ .addConfig("conf1", getFile("conf/solrconfig.xml").getParent())
.withSolrXml(SOLR_XML)
.configure();
diff --git a/solr/modules/jwt-auth/src/test/org/apache/solr/security/jwt/JWTAuthPluginTest.java b/solr/modules/jwt-auth/src/test/org/apache/solr/security/jwt/JWTAuthPluginTest.java
index a5642b9f6cd..0d6cc759cb2 100644
--- a/solr/modules/jwt-auth/src/test/org/apache/solr/security/jwt/JWTAuthPluginTest.java
+++ b/solr/modules/jwt-auth/src/test/org/apache/solr/security/jwt/JWTAuthPluginTest.java
@@ -73,7 +73,7 @@ public class JWTAuthPluginTest extends SolrTestCaseJ4 {
static HashMap<String, Object> testJwk;
public static Path JWT_TEST_PATH() {
- return getFile("solr/security").getParentFile().toPath();
+ return getFile("solr/security").getParent();
}
static {
diff --git a/solr/modules/langid/src/test/org/apache/solr/update/processor/LanguageIdentifierUpdateProcessorFactoryTestCase.java b/solr/modules/langid/src/test/org/apache/solr/update/processor/LanguageIdentifierUpdateProcessorFactoryTestCase.java
index 15e62d11a50..4690fc1569c 100644
--- a/solr/modules/langid/src/test/org/apache/solr/update/processor/LanguageIdentifierUpdateProcessorFactoryTestCase.java
+++ b/solr/modules/langid/src/test/org/apache/solr/update/processor/LanguageIdentifierUpdateProcessorFactoryTestCase.java
@@ -40,7 +40,7 @@ public abstract class LanguageIdentifierUpdateProcessorFactoryTestCase extends S
initCore(
"solrconfig-languageidentifier.xml",
"schema.xml",
- getFile("langid/solr").getAbsolutePath());
+ getFile("langid/solr").toAbsolutePath().toString());
SolrCore core = h.getCore();
UpdateRequestProcessorChain chained = core.getUpdateProcessingChain("lang_id_tika");
assertNotNull(chained);
diff --git a/solr/modules/s3-repository/src/test/org/apache/solr/s3/S3IncrementalBackupTest.java b/solr/modules/s3-repository/src/test/org/apache/solr/s3/S3IncrementalBackupTest.java
index d10322253cd..7825c33afc1 100644
--- a/solr/modules/s3-repository/src/test/org/apache/solr/s3/S3IncrementalBackupTest.java
+++ b/solr/modules/s3-repository/src/test/org/apache/solr/s3/S3IncrementalBackupTest.java
@@ -95,7 +95,7 @@ public class S3IncrementalBackupTest extends AbstractIncrementalBackupTest {
AbstractS3ClientTest.setS3ConfFile();
configureCluster(NUM_NODES) // nodes
- .addConfig("conf1", getFile("conf/solrconfig.xml").getParentFile().toPath())
+ .addConfig("conf1", getFile("conf/solrconfig.xml").getParent())
.withSolrXml(
SOLR_XML
.replace("BUCKET", BUCKET_NAME)
diff --git a/solr/modules/s3-repository/src/test/org/apache/solr/s3/S3InstallShardTest.java b/solr/modules/s3-repository/src/test/org/apache/solr/s3/S3InstallShardTest.java
index ea21cb58877..19c88caa089 100644
--- a/solr/modules/s3-repository/src/test/org/apache/solr/s3/S3InstallShardTest.java
+++ b/solr/modules/s3-repository/src/test/org/apache/solr/s3/S3InstallShardTest.java
@@ -69,7 +69,7 @@ public class S3InstallShardTest extends AbstractInstallShardTest {
AbstractS3ClientTest.setS3ConfFile();
configureCluster(1) // nodes
- .addConfig("conf1", getFile("conf/solrconfig.xml").getParentFile().toPath())
+ .addConfig("conf1", getFile("conf/solrconfig.xml").getParent())
.withSolrXml(
SOLR_XML
.replace("BUCKET", BUCKET_NAME)
diff --git a/solr/modules/scripting/src/test/org/apache/solr/scripting/update/ScriptUpdateProcessorFactoryTest.java b/solr/modules/scripting/src/test/org/apache/solr/scripting/update/ScriptUpdateProcessorFactoryTest.java
index 3e8bfa9a055..0433440cb25 100644
--- a/solr/modules/scripting/src/test/org/apache/solr/scripting/update/ScriptUpdateProcessorFactoryTest.java
+++ b/solr/modules/scripting/src/test/org/apache/solr/scripting/update/ScriptUpdateProcessorFactoryTest.java
@@ -44,7 +44,7 @@ public class ScriptUpdateProcessorFactoryTest extends UpdateProcessorTestBase {
initCore(
"solrconfig-script-updateprocessor.xml",
"schema.xml",
- getFile("scripting/solr").getAbsolutePath());
+ getFile("scripting/solr").toAbsolutePath().toString());
}
/**
diff --git a/solr/modules/scripting/src/test/org/apache/solr/scripting/update/TestBadScriptingUpdateProcessorConfig.java b/solr/modules/scripting/src/test/org/apache/solr/scripting/update/TestBadScriptingUpdateProcessorConfig.java
index 750ae4094bb..c20ef78b620 100644
--- a/solr/modules/scripting/src/test/org/apache/solr/scripting/update/TestBadScriptingUpdateProcessorConfig.java
+++ b/solr/modules/scripting/src/test/org/apache/solr/scripting/update/TestBadScriptingUpdateProcessorConfig.java
@@ -32,7 +32,7 @@ public class TestBadScriptingUpdateProcessorConfig extends SolrTestCaseJ4 {
assertConfigs(
"bad-solrconfig-bogus-scriptengine-name.xml",
"schema.xml",
- getFile("scripting/solr/collection1").getParent(),
+ getFile("scripting/solr/collection1").getParent().toString(),
"giberish");
}
@@ -42,7 +42,7 @@ public class TestBadScriptingUpdateProcessorConfig extends SolrTestCaseJ4 {
assertConfigs(
"bad-solrconfig-missing-scriptfile.xml",
"schema.xml",
- getFile("scripting/solr/collection1").getParent(),
+ getFile("scripting/solr/collection1").getParent().toString(),
"a-file-name-that-does-not-exist.js");
}
@@ -52,7 +52,7 @@ public class TestBadScriptingUpdateProcessorConfig extends SolrTestCaseJ4 {
assertConfigs(
"bad-solrconfig-invalid-scriptfile.xml",
"schema.xml",
- getFile("scripting/solr/collection1").getParent(),
+ getFile("scripting/solr/collection1").getParent().toString(),
"invalid.script.xml");
}
diff --git a/solr/modules/scripting/src/test/org/apache/solr/scripting/xslt/XSLTOutputWriterTest.java b/solr/modules/scripting/src/test/org/apache/solr/scripting/xslt/XSLTOutputWriterTest.java
index 06122b2f212..f0dd2d85d9d 100644
--- a/solr/modules/scripting/src/test/org/apache/solr/scripting/xslt/XSLTOutputWriterTest.java
+++ b/solr/modules/scripting/src/test/org/apache/solr/scripting/xslt/XSLTOutputWriterTest.java
@@ -30,7 +30,7 @@ public class XSLTOutputWriterTest extends SolrTestCaseJ4 {
@BeforeClass
public static void beforeClass() throws Exception {
- initCore("solrconfig.xml", "schema.xml", getFile("scripting/solr").getAbsolutePath());
+ initCore("solrconfig.xml", "schema.xml", getFile("scripting/solr").toAbsolutePath().toString());
}
@Test
diff --git a/solr/modules/scripting/src/test/org/apache/solr/scripting/xslt/XSLTUpdateRequestHandlerTest.java b/solr/modules/scripting/src/test/org/apache/solr/scripting/xslt/XSLTUpdateRequestHandlerTest.java
index c6a2a876b4c..af61f99e860 100644
--- a/solr/modules/scripting/src/test/org/apache/solr/scripting/xslt/XSLTUpdateRequestHandlerTest.java
+++ b/solr/modules/scripting/src/test/org/apache/solr/scripting/xslt/XSLTUpdateRequestHandlerTest.java
@@ -42,7 +42,7 @@ public class XSLTUpdateRequestHandlerTest extends SolrTestCaseJ4 {
@BeforeClass
public static void beforeTests() throws Exception {
- initCore("solrconfig.xml", "schema.xml", getFile("scripting/solr").getAbsolutePath());
+ initCore("solrconfig.xml", "schema.xml", getFile("scripting/solr").toAbsolutePath().toString());
}
@Override
@@ -98,7 +98,7 @@ public class XSLTUpdateRequestHandlerTest extends SolrTestCaseJ4 {
@Test
public void testEntities() throws Exception {
// use a binary file, so when it's loaded fail with XML error:
- String file = getFile("mailing_lists.pdf").toURI().toASCIIString();
+ String file = getFile("mailing_lists.pdf").toUri().toASCIIString();
String xml =
"<?xml version=\"1.0\"?>"
+ "<!DOCTYPE foo ["
diff --git a/solr/prometheus-exporter/src/test/org/apache/solr/prometheus/PrometheusExporterTestBase.java b/solr/prometheus-exporter/src/test/org/apache/solr/prometheus/PrometheusExporterTestBase.java
index 0b0e826c31d..93ab8b347b8 100644
--- a/solr/prometheus-exporter/src/test/org/apache/solr/prometheus/PrometheusExporterTestBase.java
+++ b/solr/prometheus-exporter/src/test/org/apache/solr/prometheus/PrometheusExporterTestBase.java
@@ -28,7 +28,8 @@ public class PrometheusExporterTestBase extends SolrCloudTestCase {
public static final String COLLECTION = "collection1";
public static final String CONF_NAME = COLLECTION + "_config";
- public static final String CONF_DIR = getFile("solr/" + COLLECTION + "/conf").getAbsolutePath();
+ public static final String CONF_DIR =
+ getFile("solr/" + COLLECTION + "/conf").toAbsolutePath().toString();
public static final int NUM_SHARDS = 2;
public static final int NUM_REPLICAS = 2;
public static final int NUM_NODES = NUM_SHARDS * NUM_REPLICAS;
@@ -60,7 +61,7 @@ public class PrometheusExporterTestBase extends SolrCloudTestCase {
@BeforeClass
public static void setupCluster() throws Exception {
System.setProperty("metricsEnabled", "true");
- configureCluster(NUM_NODES).addConfig(CONF_NAME, getFile(CONF_DIR).toPath()).configure();
+ configureCluster(NUM_NODES).addConfig(CONF_NAME, getFile(CONF_DIR)).configure();
CollectionAdminRequest.createCollection(COLLECTION, CONF_NAME, NUM_SHARDS, NUM_REPLICAS)
.process(cluster.getSolrClient());
diff --git a/solr/prometheus-exporter/src/test/org/apache/solr/prometheus/exporter/MetricsQueryTemplateTest.java b/solr/prometheus-exporter/src/test/org/apache/solr/prometheus/exporter/MetricsQueryTemplateTest.java
index 9a23a1f19d8..115ae677eb2 100644
--- a/solr/prometheus-exporter/src/test/org/apache/solr/prometheus/exporter/MetricsQueryTemplateTest.java
+++ b/solr/prometheus-exporter/src/test/org/apache/solr/prometheus/exporter/MetricsQueryTemplateTest.java
@@ -83,7 +83,7 @@ public class MetricsQueryTemplateTest extends SolrTestCaseJ4 {
Document config =
DocumentBuilderFactory.newInstance()
.newDocumentBuilder()
- .parse(SolrTestCaseJ4.getFile("conf/test-config-with-templates.xml"));
+ .parse(SolrTestCaseJ4.getFile("conf/test-config-with-templates.xml").toFile());
NodeList jqTemplates =
(NodeList)
(xpathFactory.newXPath())
@@ -95,7 +95,8 @@ public class MetricsQueryTemplateTest extends SolrTestCaseJ4 {
assertNotNull(coreQueryTemplate);
ObjectMapper objectMapper = new ObjectMapper();
- JsonNode parsedMetrics = objectMapper.readTree(SolrTestCaseJ4.getFile("query-metrics.json"));
+ JsonNode parsedMetrics =
+ objectMapper.readTree(SolrTestCaseJ4.getFile("query-metrics.json").toFile());
final String[] queryMetrics =
new String[] {
"$jq:core-query(1minRate, select(.key | endswith(\".distrib.requestTimes\")), 1minRate)",
diff --git a/solr/prometheus-exporter/src/test/org/apache/solr/prometheus/utils/Helpers.java b/solr/prometheus-exporter/src/test/org/apache/solr/prometheus/utils/Helpers.java
index b0acf4ef7a8..6c78149f817 100644
--- a/solr/prometheus-exporter/src/test/org/apache/solr/prometheus/utils/Helpers.java
+++ b/solr/prometheus-exporter/src/test/org/apache/solr/prometheus/utils/Helpers.java
@@ -31,16 +31,17 @@ import org.apache.solr.prometheus.exporter.MetricsConfiguration;
public class Helpers {
public static MetricsConfiguration loadConfiguration(String pathRsrc) throws Exception {
- return MetricsConfiguration.from(SolrTestCaseJ4.getFile(pathRsrc).getPath());
+ return MetricsConfiguration.from(SolrTestCaseJ4.getFile(pathRsrc).toString());
}
public static void indexAllDocs(SolrClient client) throws IOException, SolrServerException {
- File exampleDocsDir = new File(SolrTestCaseJ4.getFile("exampledocs").getAbsolutePath());
+ File exampleDocsDir =
+ new File(SolrTestCaseJ4.getFile("exampledocs").toAbsolutePath().toString());
File[] xmlFiles =
Objects.requireNonNull(exampleDocsDir.listFiles((dir, name) -> name.endsWith(".xml")));
for (File xml : xmlFiles) {
ContentStreamUpdateRequest req = new ContentStreamUpdateRequest("/update");
- req.addFile(xml, "application/xml");
+ req.addFile(xml.toPath(), "application/xml");
client.request(req, PrometheusExporterTestBase.COLLECTION);
}
client.commit(PrometheusExporterTestBase.COLLECTION);
diff --git a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/SolrClientCacheTest.java b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/SolrClientCacheTest.java
index 1f7ee0cffbf..91b5364ed7f 100644
--- a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/SolrClientCacheTest.java
+++ b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/SolrClientCacheTest.java
@@ -47,7 +47,7 @@ public class SolrClientCacheTest extends SolrCloudTestCase {
sysProps.forEach(System::setProperty);
configureCluster(1)
.formatZkServer(true)
- .addConfig("config", getFile("solrj/solr/configsets/streaming/conf").toPath())
+ .addConfig("config", getFile("solrj/solr/configsets/streaming/conf"))
.configure();
}
diff --git a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/graph/GraphExpressionTest.java b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/graph/GraphExpressionTest.java
index 6aef7412c9f..487dec09b6f 100644
--- a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/graph/GraphExpressionTest.java
+++ b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/graph/GraphExpressionTest.java
@@ -81,7 +81,6 @@ public class GraphExpressionTest extends SolrCloudTestCase {
.addConfig(
"conf",
getFile("solrj")
- .toPath()
.resolve("solr")
.resolve("configsets")
.resolve("streaming")
diff --git a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/graph/GraphTest.java b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/graph/GraphTest.java
index 55dfec4f7a2..e16c2692fc0 100644
--- a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/graph/GraphTest.java
+++ b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/graph/GraphTest.java
@@ -52,7 +52,6 @@ public class GraphTest extends SolrCloudTestCase {
.addConfig(
"conf",
getFile("solrj")
- .toPath()
.resolve("solr")
.resolve("configsets")
.resolve("streaming")
diff --git a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/sql/JdbcTest.java b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/sql/JdbcTest.java
index 12b9f807847..1a182667a2e 100644
--- a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/sql/JdbcTest.java
+++ b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/sql/JdbcTest.java
@@ -62,7 +62,6 @@ public class JdbcTest extends SolrCloudTestCase {
.addConfig(
"conf",
getFile("solrj")
- .toPath()
.resolve("solr")
.resolve("configsets")
.resolve("streaming")
diff --git a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/BadClusterTest.java b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/BadClusterTest.java
index b7c8b8a836c..7f7ce1feeb3 100644
--- a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/BadClusterTest.java
+++ b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/BadClusterTest.java
@@ -53,7 +53,6 @@ public class BadClusterTest extends SolrCloudTestCase {
.addConfig(
"conf",
getFile("solrj")
- .toPath()
.resolve("solr")
.resolve("configsets")
.resolve("streaming")
diff --git a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/JDBCStreamTest.java b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/JDBCStreamTest.java
index 3a2e028130d..b8e200da234 100644
--- a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/JDBCStreamTest.java
+++ b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/JDBCStreamTest.java
@@ -65,7 +65,6 @@ public class JDBCStreamTest extends SolrCloudTestCase {
.addConfig(
"conf",
getFile("solrj")
- .toPath()
.resolve("solr")
.resolve("configsets")
.resolve("streaming")
diff --git a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/MathExpressionTest.java b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/MathExpressionTest.java
index 1d35aa2e353..9b598c42755 100644
--- a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/MathExpressionTest.java
+++ b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/MathExpressionTest.java
@@ -56,19 +56,13 @@ public class MathExpressionTest extends SolrCloudTestCase {
.addConfig(
"conf",
getFile("solrj")
- .toPath()
.resolve("solr")
.resolve("configsets")
.resolve("streaming")
.resolve("conf"))
.addConfig(
"ml",
- getFile("solrj")
- .toPath()
- .resolve("solr")
- .resolve("configsets")
- .resolve("ml")
- .resolve("conf"))
+ getFile("solrj").resolve("solr").resolve("configsets").resolve("ml").resolve("conf"))
.configure();
String collection;
diff --git a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/ParallelFacetStreamOverAliasTest.java b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/ParallelFacetStreamOverAliasTest.java
index 347894bae42..53f293cc5a0 100644
--- a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/ParallelFacetStreamOverAliasTest.java
+++ b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/ParallelFacetStreamOverAliasTest.java
@@ -88,7 +88,6 @@ public class ParallelFacetStreamOverAliasTest extends SolrCloudTestCase {
.addConfig(
"conf",
getFile("solrj")
- .toPath()
.resolve("solr")
.resolve("configsets")
.resolve("streaming")
diff --git a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/SelectWithEvaluatorsTest.java b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/SelectWithEvaluatorsTest.java
index ac4a4102e55..2abfa0fad3d 100644
--- a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/SelectWithEvaluatorsTest.java
+++ b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/SelectWithEvaluatorsTest.java
@@ -52,19 +52,13 @@ public class SelectWithEvaluatorsTest extends SolrCloudTestCase {
.addConfig(
"conf",
getFile("solrj")
- .toPath()
.resolve("solr")
.resolve("configsets")
.resolve("streaming")
.resolve("conf"))
.addConfig(
"ml",
- getFile("solrj")
- .toPath()
- .resolve("solr")
- .resolve("configsets")
- .resolve("ml")
- .resolve("conf"))
+ getFile("solrj").resolve("solr").resolve("configsets").resolve("ml").resolve("conf"))
.configure();
String collection;
diff --git a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/StreamDecoratorTest.java b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/StreamDecoratorTest.java
index 2b19742ae6f..85407c78737 100644
--- a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/StreamDecoratorTest.java
+++ b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/StreamDecoratorTest.java
@@ -87,19 +87,13 @@ public class StreamDecoratorTest extends SolrCloudTestCase {
.addConfig(
"conf",
getFile("solrj")
- .toPath()
.resolve("solr")
.resolve("configsets")
.resolve("streaming")
.resolve("conf"))
.addConfig(
"ml",
- getFile("solrj")
- .toPath()
- .resolve("solr")
- .resolve("configsets")
- .resolve("ml")
- .resolve("conf"))
+ getFile("solrj").resolve("solr").resolve("configsets").resolve("ml").resolve("conf"))
.configure();
String collection;
diff --git a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionTest.java b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionTest.java
index 1541312d02e..2433164e365 100644
--- a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionTest.java
+++ b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionTest.java
@@ -83,19 +83,13 @@ public class StreamExpressionTest extends SolrCloudTestCase {
.addConfig(
"conf",
getFile("solrj")
- .toPath()
.resolve("solr")
.resolve("configsets")
.resolve("streaming")
.resolve("conf"))
.addConfig(
"ml",
- getFile("solrj")
- .toPath()
- .resolve("solr")
- .resolve("configsets")
- .resolve("ml")
- .resolve("conf"))
+ getFile("solrj").resolve("solr").resolve("configsets").resolve("ml").resolve("conf"))
.configure();
String collection;
diff --git a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/StreamingTest.java b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/StreamingTest.java
index 5eadc7ed727..8be2fcd8059 100644
--- a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/StreamingTest.java
+++ b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/StreamingTest.java
@@ -100,7 +100,6 @@ public class StreamingTest extends SolrCloudTestCase {
.addConfig(
"conf",
getFile("solrj")
- .toPath()
.resolve("solr")
.resolve("configsets")
.resolve("streaming")
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/request/ConfigSetAdminRequest.java b/solr/solrj/src/java/org/apache/solr/client/solrj/request/ConfigSetAdminRequest.java
index 4c21ce6c776..6743cc09711 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/request/ConfigSetAdminRequest.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/request/ConfigSetAdminRequest.java
@@ -18,9 +18,9 @@ package org.apache.solr.client.solrj.request;
import static org.apache.solr.common.params.CommonParams.NAME;
-import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
+import java.nio.file.Path;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
@@ -160,7 +160,8 @@ public abstract class ConfigSetAdminRequest<
*
* @see #setUploadStream
*/
- public final Upload setUploadFile(final File file, final String contentType) {
+ public final Upload setUploadFile(final Path file, final String contentType)
+ throws IOException {
final FileStream fileStream = new FileStream(file);
fileStream.setContentType(contentType);
return setUploadStream(fileStream);
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/request/ContentStreamUpdateRequest.java b/solr/solrj/src/java/org/apache/solr/client/solrj/request/ContentStreamUpdateRequest.java
index dfeccc49284..9c19dfa64af 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/request/ContentStreamUpdateRequest.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/request/ContentStreamUpdateRequest.java
@@ -16,9 +16,9 @@
*/
package org.apache.solr.client.solrj.request;
-import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@@ -76,7 +76,7 @@ public class ContentStreamUpdateRequest extends AbstractUpdateRequest {
* @see #getContentStreams()
* @see org.apache.solr.common.util.ContentStreamBase.FileStream
*/
- public void addFile(File file, String contentType) throws IOException {
+ public void addFile(Path file, String contentType) throws IOException {
ContentStreamBase cs = new ContentStreamBase.FileStream(file);
cs.setContentType(contentType);
addContentStream(cs);
diff --git a/solr/solrj/src/java/org/apache/solr/common/util/ContentStreamBase.java b/solr/solrj/src/java/org/apache/solr/common/util/ContentStreamBase.java
index 321b08a0f24..ee46e6ddded 100644
--- a/solr/solrj/src/java/org/apache/solr/common/util/ContentStreamBase.java
+++ b/solr/solrj/src/java/org/apache/solr/common/util/ContentStreamBase.java
@@ -18,7 +18,6 @@ package org.apache.solr.common.util;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -29,6 +28,8 @@ import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
@@ -36,6 +37,7 @@ import java.util.function.Predicate;
import java.util.zip.GZIPInputStream;
import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.request.RequestWriter;
+import org.apache.solr.common.SolrException;
/**
* Three concrete implementations for ContentStream - one for File/URL/String
@@ -165,15 +167,20 @@ public abstract class ContentStreamBase implements ContentStream {
/** Construct a <code>ContentStream</code> from a <code>File</code> */
public static class FileStream extends ContentStreamBase {
- private final File file;
+ private final Path file;
- public FileStream(File f) {
+ public FileStream(Path f) {
file = f;
contentType = null; // ??
- name = file.getName();
- size = file.length();
- sourceInfo = file.toURI().toString();
+ name = file.getFileName().toString();
+ try {
+ size = Files.size(file);
+ } catch (IOException e) {
+ throw new SolrException(
+ SolrException.ErrorCode.SERVER_ERROR, "Unable to read file size " + file, e);
+ }
+ sourceInfo = file.toUri().toString();
}
@Override
@@ -186,7 +193,7 @@ public abstract class ContentStreamBase implements ContentStream {
@Override
public InputStream getStream() throws IOException {
- InputStream is = new FileInputStream(file);
+ InputStream is = new FileInputStream(file.toFile());
String lowerName = name.toLowerCase(Locale.ROOT);
if (lowerName.endsWith(".gz") || lowerName.endsWith(".gzip")) {
is = new GZIPInputStream(is);
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/MergeIndexesExampleTestBase.java b/solr/solrj/src/test/org/apache/solr/client/solrj/MergeIndexesExampleTestBase.java
index 04e0d5aacf9..660aa53080b 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/MergeIndexesExampleTestBase.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/MergeIndexesExampleTestBase.java
@@ -49,7 +49,7 @@ public abstract class MergeIndexesExampleTestBase extends SolrTestCaseJ4 {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
static Path getSolrHome() {
- return SolrTestCaseJ4.getFile("solrj/solr/multicore").toPath();
+ return SolrTestCaseJ4.getFile("solrj/solr/multicore");
}
protected void setupCoreContainer() {
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java
index 3e762175b28..cc7f52b4c34 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java
@@ -936,7 +936,7 @@ public abstract class SolrExampleTests extends SolrExampleTestsBase {
assertEquals(0, rsp.getResults().getNumFound());
ContentStreamUpdateRequest up = new ContentStreamUpdateRequest("/update");
- File file = getFile("solrj/books.csv");
+ File file = getFile("solrj/books.csv").toFile();
final int opened[] = new int[] {0};
final int closed[] = new int[] {0};
@@ -960,7 +960,7 @@ public abstract class SolrExampleTests extends SolrExampleTestsBase {
};
up.addContentStream(contentStreamMock);
} else {
- up.addFile(file, "application/csv");
+ up.addFile(file.toPath(), "application/csv");
}
up.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
@@ -985,8 +985,7 @@ public abstract class SolrExampleTests extends SolrExampleTestsBase {
assertEquals(0, rsp.getResults().getNumFound());
NamedList<Object> result =
client.request(
- new StreamingUpdateRequest(
- "/update", getFile("solrj/books.csv").toPath(), "application/csv")
+ new StreamingUpdateRequest("/update", getFile("solrj/books.csv"), "application/csv")
.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true));
assertNotNull("Couldn't upload books.csv", result);
rsp = client.query(new SolrQuery("*:*"));
@@ -1019,7 +1018,7 @@ public abstract class SolrExampleTests extends SolrExampleTestsBase {
}
private ByteBuffer getFileContent(NamedList<?> nl, String name) throws IOException {
- try (InputStream is = new FileInputStream(getFile(name))) {
+ try (InputStream is = new FileInputStream(getFile(name).toFile())) {
return MultiContentWriterRequest.readByteBuffer(is);
}
}
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/TestLBHttpSolrClient.java b/solr/solrj/src/test/org/apache/solr/client/solrj/TestLBHttpSolrClient.java
index 331330e3fdb..ec26de0af05 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/TestLBHttpSolrClient.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/TestLBHttpSolrClient.java
@@ -316,13 +316,12 @@ public class TestLBHttpSolrClient extends SolrTestCaseJ4 {
dataDir.mkdirs();
confDir.mkdirs();
- Files.copy(
- SolrTestCaseJ4.getFile(getSolrXmlFile()).toPath(), homeDir.toPath().resolve("solr.xml"));
+ Files.copy(SolrTestCaseJ4.getFile(getSolrXmlFile()), homeDir.toPath().resolve("solr.xml"));
Path f = confDir.toPath().resolve("solrconfig.xml");
- Files.copy(SolrTestCaseJ4.getFile(getSolrConfigFile()).toPath(), f);
+ Files.copy(SolrTestCaseJ4.getFile(getSolrConfigFile()), f);
f = confDir.toPath().resolve("schema.xml");
- Files.copy(SolrTestCaseJ4.getFile(getSchemaFile()).toPath(), f);
+ Files.copy(SolrTestCaseJ4.getFile(getSchemaFile()), f);
Files.createFile(homeDir.toPath().resolve("collection1/core.properties"));
}
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/AbstractEmbeddedSolrServerTestCase.java b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/AbstractEmbeddedSolrServerTestCase.java
index 15027618384..98841227f73 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/AbstractEmbeddedSolrServerTestCase.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/AbstractEmbeddedSolrServerTestCase.java
@@ -47,7 +47,7 @@ public abstract class AbstractEmbeddedSolrServerTestCase extends SolrTestCaseJ4
@BeforeClass
public static void setUpHome() throws IOException {
- CONFIG_HOME = getFile("solrj/solr/shared").toPath().toAbsolutePath();
+ CONFIG_HOME = getFile("solrj/solr/shared").toAbsolutePath();
SOLR_HOME = createTempDir("solrHome");
FileUtils.copyDirectory(CONFIG_HOME.toFile(), SOLR_HOME.toFile());
}
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientBuilderTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientBuilderTest.java
index 01f57970e99..0846dfefc6c 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientBuilderTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientBuilderTest.java
@@ -44,7 +44,6 @@ public class CloudHttp2SolrClientBuilderTest extends SolrCloudTestCase {
.addConfig(
"conf",
getFile("solrj")
- .toPath()
.resolve("solr")
.resolve("configsets")
.resolve("configset-1")
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientRetryTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientRetryTest.java
index d9b5074402c..505210c94df 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientRetryTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientRetryTest.java
@@ -41,7 +41,6 @@ public class CloudHttp2SolrClientRetryTest extends SolrCloudTestCase {
.addConfig(
"conf",
getFile("solrj")
- .toPath()
.resolve("solr")
.resolve("configsets")
.resolve("streaming")
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientTest.java
index 47c3a6c5086..c98d75268f6 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientTest.java
@@ -99,7 +99,6 @@ public class CloudHttp2SolrClientTest extends SolrCloudTestCase {
.addConfig(
"conf",
getFile("solrj")
- .toPath()
.resolve("solr")
.resolve("configsets")
.resolve("streaming")
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientRetryTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientRetryTest.java
index 8576e10e562..9f4fbb85b61 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientRetryTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientRetryTest.java
@@ -39,7 +39,6 @@ public class CloudSolrClientRetryTest extends SolrCloudTestCase {
.addConfig(
"conf",
getFile("solrj")
- .toPath()
.resolve("solr")
.resolve("configsets")
.resolve("streaming")
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientRoutingTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientRoutingTest.java
index f2824b9e550..00774305dcc 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientRoutingTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientRoutingTest.java
@@ -42,7 +42,7 @@ public final class CloudSolrClientRoutingTest extends SolrCloudTestCase {
public static void setupCluster() throws Exception {
// configset("cloud-minimal");
configureCluster(1)
- .addConfig("conf", getFile("solrj/solr/configsets/streaming/conf").toPath())
+ .addConfig("conf", getFile("solrj/solr/configsets/streaming/conf"))
.configure();
CollectionAdminRequest.Create create =
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.java
index e6160bc8421..cb1b015d7e9 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.java
@@ -103,7 +103,6 @@ public class CloudSolrClientTest extends SolrCloudTestCase {
.addConfig(
"conf",
getFile("solrj")
- .toPath()
.resolve("solr")
.resolve("configsets")
.resolve("streaming")
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/ClusterStateProviderTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/ClusterStateProviderTest.java
index ea8225307da..707313efec4 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/ClusterStateProviderTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/ClusterStateProviderTest.java
@@ -46,7 +46,6 @@ public class ClusterStateProviderTest extends SolrCloudTestCase {
.addConfig(
"conf",
getFile("solrj")
- .toPath()
.resolve("solr")
.resolve("configsets")
.resolve("streaming")
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/HttpClusterStateSSLTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/HttpClusterStateSSLTest.java
index 1242cde9945..24e005c28c7 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/HttpClusterStateSSLTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/HttpClusterStateSSLTest.java
@@ -40,7 +40,6 @@ public class HttpClusterStateSSLTest extends SolrCloudTestCase {
.addConfig(
"conf",
getFile("solrj")
- .toPath()
.resolve("solr")
.resolve("configsets")
.resolve("streaming")
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/LBHttp2SolrClientIntegrationTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/LBHttp2SolrClientIntegrationTest.java
index 7653731b511..61504a052b8 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/LBHttp2SolrClientIntegrationTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/LBHttp2SolrClientIntegrationTest.java
@@ -282,13 +282,12 @@ public class LBHttp2SolrClientIntegrationTest extends SolrTestCaseJ4 {
dataDir.mkdirs();
confDir.mkdirs();
- Files.copy(
- SolrTestCaseJ4.getFile(getSolrXmlFile()).toPath(), homeDir.toPath().resolve("solr.xml"));
+ Files.copy(SolrTestCaseJ4.getFile(getSolrXmlFile()), homeDir.toPath().resolve("solr.xml"));
Path f = confDir.toPath().resolve("solrconfig.xml");
- Files.copy(SolrTestCaseJ4.getFile(getSolrConfigFile()).toPath(), f);
+ Files.copy(SolrTestCaseJ4.getFile(getSolrConfigFile()), f);
f = confDir.toPath().resolve("schema.xml");
- Files.copy(SolrTestCaseJ4.getFile(getSchemaFile()).toPath(), f);
+ Files.copy(SolrTestCaseJ4.getFile(getSchemaFile()), f);
Files.createFile(homeDir.toPath().resolve("collection1/core.properties"));
}
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/SendUpdatesToLeadersOverrideTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/SendUpdatesToLeadersOverrideTest.java
index 7c716070b1d..91ad98170f1 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/SendUpdatesToLeadersOverrideTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/SendUpdatesToLeadersOverrideTest.java
@@ -83,12 +83,7 @@ public class SendUpdatesToLeadersOverrideTest extends SolrCloudTestCase {
configureCluster(numNodes)
.addConfig(
CONFIG,
- getFile("solrj")
- .toPath()
- .resolve("solr")
- .resolve("configsets")
- .resolve(CONFIG)
- .resolve("conf"))
+ getFile("solrj").resolve("solr").resolve("configsets").resolve(CONFIG).resolve("conf"))
.configure();
// create 2 shard collection with 1 NRT (leader) and 1 PULL replica
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/TestCloudSolrClientConnections.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/TestCloudSolrClientConnections.java
index a7c0cb76156..2f1641d5859 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/TestCloudSolrClientConnections.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/TestCloudSolrClientConnections.java
@@ -60,7 +60,7 @@ public class TestCloudSolrClientConnections extends SolrTestCaseJ4 {
@Test
public void testCloudClientUploads() throws Exception {
- Path configPath = getFile("solrj").toPath().resolve("solr/configsets/configset-2/conf");
+ Path configPath = getFile("solrj").resolve("solr/configsets/configset-2/conf");
MiniSolrCloudCluster cluster =
new MiniSolrCloudCluster(0, createTempDir(), JettyConfig.builder().build());
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/request/SchemaTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/request/SchemaTest.java
index dd89fb97cbb..d3169ace898 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/request/SchemaTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/request/SchemaTest.java
@@ -112,7 +112,8 @@ public class SchemaTest extends RestTestBase {
public void init() throws Exception {
File tmpSolrHome = createTempDir().toFile();
FileUtils.copyDirectory(
- new File(getFile("solrj/solr/collection1").getParent()), tmpSolrHome.getAbsoluteFile());
+ new File(getFile("solrj/solr/collection1").getParent().toString()),
+ tmpSolrHome.getAbsoluteFile());
final SortedMap<ServletHolder, String> extraServlets = new TreeMap<>();
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/request/SolrPingTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/request/SolrPingTest.java
index d00e6fc404e..6679a825137 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/request/SolrPingTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/request/SolrPingTest.java
@@ -30,7 +30,7 @@ public class SolrPingTest extends EmbeddedSolrServerTestBase {
@BeforeClass
public static void beforeClass() throws Exception {
- solrClientTestRule.startSolr(SolrTestCaseJ4.getFile("solrj/solr").toPath());
+ solrClientTestRule.startSolr(SolrTestCaseJ4.getFile("solrj/solr"));
SolrTestCaseJ4.newRandomConfig();
solrClientTestRule.newCollection().withConfigSet("../collection1").create();
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestConfigSetAdminRequest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestConfigSetAdminRequest.java
index 794129d34b4..bb685b6756c 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestConfigSetAdminRequest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestConfigSetAdminRequest.java
@@ -16,7 +16,7 @@
*/
package org.apache.solr.client.solrj.request;
-import java.io.File;
+import java.nio.file.Path;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.response.ConfigSetAdminResponse;
@@ -34,7 +34,7 @@ public class TestConfigSetAdminRequest extends SolrTestCaseJ4 {
@Test
public void testUpload() throws Exception {
- final File tmpFile = createTempFile().toFile();
+ final Path tmpFile = createTempFile();
ConfigSetAdminRequest.Upload upload = new ConfigSetAdminRequest.Upload();
verifyException(upload, "ConfigSet");
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestV2Request.java b/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestV2Request.java
index bec4705eb1e..63456df22cc 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestV2Request.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestV2Request.java
@@ -43,7 +43,7 @@ public class TestV2Request extends SolrCloudTestCase {
public void setupCluster() throws Exception {
configureCluster(4)
.withJettyConfig(jettyCfg -> jettyCfg.enableV2(true))
- .addConfig("config", getFile("solrj/solr/collection1/conf").toPath())
+ .addConfig("config", getFile("solrj/solr/collection1/conf"))
.configure();
}
diff --git a/solr/solrj/src/test/org/apache/solr/common/cloud/PerReplicaStatesIntegrationTest.java b/solr/solrj/src/test/org/apache/solr/common/cloud/PerReplicaStatesIntegrationTest.java
index 71336a8088d..ac7f4840734 100644
--- a/solr/solrj/src/test/org/apache/solr/common/cloud/PerReplicaStatesIntegrationTest.java
+++ b/solr/solrj/src/test/org/apache/solr/common/cloud/PerReplicaStatesIntegrationTest.java
@@ -65,7 +65,6 @@ public class PerReplicaStatesIntegrationTest extends SolrCloudTestCase {
.addConfig(
"conf",
getFile("solrj")
- .toPath()
.resolve("solr")
.resolve("configsets")
.resolve("streaming")
@@ -133,7 +132,6 @@ public class PerReplicaStatesIntegrationTest extends SolrCloudTestCase {
.addConfig(
"conf",
getFile("solrj")
- .toPath()
.resolve("solr")
.resolve("configsets")
.resolve("streaming")
@@ -242,7 +240,6 @@ public class PerReplicaStatesIntegrationTest extends SolrCloudTestCase {
.addConfig(
"conf",
getFile("solrj")
- .toPath()
.resolve("solr")
.resolve("configsets")
.resolve("streaming")
@@ -307,7 +304,6 @@ public class PerReplicaStatesIntegrationTest extends SolrCloudTestCase {
.addConfig(
"conf",
getFile("solrj")
- .toPath()
.resolve("solr")
.resolve("configsets")
.resolve("streaming")
diff --git a/solr/solrj/src/test/org/apache/solr/common/cloud/TestCloudCollectionsListeners.java b/solr/solrj/src/test/org/apache/solr/common/cloud/TestCloudCollectionsListeners.java
index 822ca00b8b6..97014c458d6 100644
--- a/solr/solrj/src/test/org/apache/solr/common/cloud/TestCloudCollectionsListeners.java
+++ b/solr/solrj/src/test/org/apache/solr/common/cloud/TestCloudCollectionsListeners.java
@@ -53,7 +53,7 @@ public class TestCloudCollectionsListeners extends SolrCloudTestCase {
@Before
public void prepareCluster() throws Exception {
configureCluster(CLUSTER_SIZE)
- .addConfig("config", getFile("solrj/solr/collection1/conf").toPath())
+ .addConfig("config", getFile("solrj/solr/collection1/conf"))
.configure();
int missingServers = CLUSTER_SIZE - cluster.getJettySolrRunners().size();
diff --git a/solr/solrj/src/test/org/apache/solr/common/cloud/TestCollectionStateWatchers.java b/solr/solrj/src/test/org/apache/solr/common/cloud/TestCollectionStateWatchers.java
index 13532e8ef5e..9e7960b8c01 100644
--- a/solr/solrj/src/test/org/apache/solr/common/cloud/TestCollectionStateWatchers.java
+++ b/solr/solrj/src/test/org/apache/solr/common/cloud/TestCollectionStateWatchers.java
@@ -53,7 +53,7 @@ public class TestCollectionStateWatchers extends SolrCloudTestCase {
@Before
public void prepareCluster() throws Exception {
configureCluster(CLUSTER_SIZE)
- .addConfig("config", getFile("solrj/solr/collection1/conf").toPath())
+ .addConfig("config", getFile("solrj/solr/collection1/conf"))
.configure();
executor = ExecutorUtil.newMDCAwareCachedThreadPool("backgroundWatchers");
}
diff --git a/solr/solrj/src/test/org/apache/solr/common/cloud/TestDocCollectionWatcher.java b/solr/solrj/src/test/org/apache/solr/common/cloud/TestDocCollectionWatcher.java
index 4cc96202254..23839d13d97 100644
--- a/solr/solrj/src/test/org/apache/solr/common/cloud/TestDocCollectionWatcher.java
+++ b/solr/solrj/src/test/org/apache/solr/common/cloud/TestDocCollectionWatcher.java
@@ -54,7 +54,7 @@ public class TestDocCollectionWatcher extends SolrCloudTestCase {
@Before
public void prepareCluster() throws Exception {
configureCluster(CLUSTER_SIZE)
- .addConfig("config", getFile("solrj/solr/collection1/conf").toPath())
+ .addConfig("config", getFile("solrj/solr/collection1/conf"))
.configure();
executor = ExecutorUtil.newMDCAwareCachedThreadPool("backgroundWatchers");
}
diff --git a/solr/solrj/src/test/org/apache/solr/common/cloud/TestNodesSysPropsCacher.java b/solr/solrj/src/test/org/apache/solr/common/cloud/TestNodesSysPropsCacher.java
index a78f2b3bde3..489de336a89 100644
--- a/solr/solrj/src/test/org/apache/solr/common/cloud/TestNodesSysPropsCacher.java
+++ b/solr/solrj/src/test/org/apache/solr/common/cloud/TestNodesSysPropsCacher.java
@@ -33,7 +33,7 @@ public class TestNodesSysPropsCacher extends SolrCloudTestCase {
MiniSolrCloudCluster cluster =
configureCluster(4)
.withJettyConfig(jetty -> jetty.enableV2(true))
- .addConfig("config", getFile("solrj/solr/collection1/conf").toPath())
+ .addConfig("config", getFile("solrj/solr/collection1/conf"))
.configure();
System.clearProperty("metricsEnabled");
diff --git a/solr/solrj/src/test/org/apache/solr/common/util/ContentStreamTest.java b/solr/solrj/src/test/org/apache/solr/common/util/ContentStreamTest.java
index 019e00d675f..884ebfe1ff0 100644
--- a/solr/solrj/src/test/org/apache/solr/common/util/ContentStreamTest.java
+++ b/solr/solrj/src/test/org/apache/solr/common/util/ContentStreamTest.java
@@ -51,7 +51,7 @@ public class ContentStreamTest extends SolrTestCaseJ4 {
is.transferTo(os);
}
- ContentStreamBase stream = new ContentStreamBase.FileStream(file);
+ ContentStreamBase stream = new ContentStreamBase.FileStream(file.toPath());
try (InputStream s = stream.getStream();
FileInputStream fis = new FileInputStream(file);
InputStreamReader isr =
@@ -75,7 +75,7 @@ public class ContentStreamTest extends SolrTestCaseJ4 {
is.transferTo(zos);
}
- ContentStreamBase stream = new ContentStreamBase.FileStream(file);
+ ContentStreamBase stream = new ContentStreamBase.FileStream(file.toPath());
try (InputStream s = stream.getStream();
FileInputStream fis = new FileInputStream(file);
GZIPInputStream zis = new GZIPInputStream(fis);
diff --git a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
index d7d67f05ef1..d5d630333a4 100644
--- a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
+++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
@@ -2127,16 +2127,16 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
}
/**
- * Gets a resource from the context classloader as {@link File}. This method should only be used,
+ * Gets a resource from the context classloader as {@link Path}. This method should only be used,
* if a real file is needed. To get a stream, code should prefer {@link Class#getResourceAsStream}
* using {@code this.getClass()}.
*/
- public static File getFile(String name) {
+ public static Path getFile(String name) {
final URL url =
SolrTestCaseJ4.class.getClassLoader().getResource(name.replace(File.separatorChar, '/'));
if (url != null) {
try {
- return new File(url.toURI());
+ return Path.of(url.toURI());
} catch (Exception e) {
throw new RuntimeException(
"Resource was found on classpath, but cannot be resolved to a "
@@ -2144,8 +2144,8 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
+ name);
}
}
- final File file = new File(name);
- if (file.exists()) {
+ final Path file = Path.of(name);
+ if (Files.exists(file)) {
return file;
}
throw new RuntimeException(
@@ -2154,11 +2154,11 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
}
public static String TEST_HOME() {
- return getFile("solr/collection1").getParent();
+ return getFile("solr/collection1").getParent().toString();
}
public static Path TEST_PATH() {
- return getFile("solr/collection1").getParentFile().toPath();
+ return getFile("solr/collection1").getParent();
}
public static Path TEST_COLL1_CONF() {
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractBasicDistributedZkTestBase.java b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractBasicDistributedZkTestBase.java
index 91fe79b6c73..0cf43b7bf8f 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractBasicDistributedZkTestBase.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractBasicDistributedZkTestBase.java
@@ -1265,7 +1265,7 @@ public abstract class AbstractBasicDistributedZkTestBase extends AbstractFullDis
.get(0)
.request(
new StreamingUpdateRequest(
- "/update", getFile("books_numeric_ids.csv").toPath(), "application/csv")
+ "/update", getFile("books_numeric_ids.csv"), "application/csv")
.setCommitWithin(900000)
.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true));