From 1ee430d345dc9b65248299904337299548696186 Mon Sep 17 00:00:00 2001 From: Matthew Biscocho Date: Thu, 12 Dec 2024 16:29:09 -0500 Subject: [PATCH 01/10] Move public Java APIs from File to Path --- .../apache/solr/bench/MiniClusterState.java | 10 +-- .../org/apache/solr/cloud/SolrZkServer.java | 9 ++- .../solr/cloud/ZkSolrResourceLoader.java | 2 +- .../solr/core/CachingDirectoryFactory.java | 2 +- .../org/apache/solr/core/CoreDescriptor.java | 2 +- .../apache/solr/core/DirectoryFactory.java | 4 +- .../java/org/apache/solr/core/SolrCore.java | 5 +- .../apache/solr/core/SolrDeletionPolicy.java | 6 +- .../apache/solr/core/SolrResourceLoader.java | 2 +- .../solr/core/StandardDirectoryFactory.java | 3 +- .../org/apache/solr/core/ZkContainer.java | 5 +- .../solr/core/backup/BackupManager.java | 2 +- .../org/apache/solr/handler/IndexFetcher.java | 66 +++++++++++-------- .../solr/handler/admin/CoreAdminHandler.java | 2 +- .../handler/admin/ShowFileRequestHandler.java | 8 +-- .../solr/handler/admin/SystemInfoHandler.java | 4 +- .../solr/rest/ManagedResourceStorage.java | 28 ++++---- .../schema/ManagedIndexSchemaFactory.java | 9 +-- .../solr/servlet/SolrRequestParsers.java | 4 +- .../spelling/AbstractLuceneSpellChecker.java | 4 +- .../fst/AnalyzingInfixLookupFactory.java | 7 +- .../fst/BlendedInfixLookupFactory.java | 7 +- .../org/apache/solr/update/UpdateLog.java | 9 ++- .../java/org/apache/solr/util/FileUtils.java | 21 +++--- .../org/apache/solr/util/RegexFileFilter.java | 2 +- .../apache/solr/util/SystemIdResolver.java | 2 +- .../org/apache/solr/util/VersionedFile.java | 1 + .../solrj/request/ConfigSetAdminRequest.java | 5 +- .../request/ContentStreamUpdateRequest.java | 4 +- .../solr/common/util/ContentStreamBase.java | 15 +++-- 30 files changed, 133 insertions(+), 117 deletions(-) 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..607cda932be 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 void startMiniCluster(int nodeCount) { 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 static ModifiableSolrParams params(ModifiableSolrParams params, String... * @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 new File(url.toURI()).toPath(); } catch (Exception e) { throw new RuntimeException( "Resource was found on classpath, but cannot be resolved to a " @@ -566,11 +566,11 @@ public static File getFile(String name) { } File file = new File(name); if (file.exists()) { - return file; + return file.toPath(); } else { file = new File("../../../", name); if (file.exists()) { - return file; + return file.toPath(); } } throw new RuntimeException( 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 @@ public static boolean hasServers(Properties props) { 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/cloud/ZkSolrResourceLoader.java b/solr/core/src/java/org/apache/solr/cloud/ZkSolrResourceLoader.java index 68654851d5b..2490290cff4 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ZkSolrResourceLoader.java +++ b/solr/core/src/java/org/apache/solr/cloud/ZkSolrResourceLoader.java @@ -17,7 +17,7 @@ package org.apache.solr.cloud; import java.io.ByteArrayInputStream; -import java.io.File; +import java.io.File; // ALLOWED import java.io.IOException; import java.io.InputStream; import java.lang.invoke.MethodHandles; diff --git a/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.java b/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.java index dfe9487809e..72254d4586d 100644 --- a/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.java +++ b/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.java @@ -16,7 +16,7 @@ */ package org.apache.solr.core; -import java.io.File; +import java.io.File; // ALLOWED import java.io.IOException; import java.lang.invoke.MethodHandles; import java.nio.file.DirectoryStream; diff --git a/solr/core/src/java/org/apache/solr/core/CoreDescriptor.java b/solr/core/src/java/org/apache/solr/core/CoreDescriptor.java index 6109b2f860b..c4757e6b830 100644 --- a/solr/core/src/java/org/apache/solr/core/CoreDescriptor.java +++ b/solr/core/src/java/org/apache/solr/core/CoreDescriptor.java @@ -16,7 +16,7 @@ */ package org.apache.solr.core; -import java.io.File; +import java.io.File; // ALLOWED import java.io.IOException; import java.io.Reader; import java.lang.invoke.MethodHandles; 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..51daea31dd7 100644 --- a/solr/core/src/java/org/apache/solr/core/DirectoryFactory.java +++ b/solr/core/src/java/org/apache/solr/core/DirectoryFactory.java @@ -17,7 +17,7 @@ package org.apache.solr.core; import java.io.Closeable; -import java.io.File; +import java.io.File; // ALLOWED import java.io.FileFilter; import java.io.FileNotFoundException; import java.io.IOException; @@ -339,6 +339,8 @@ public String getDataHome(CoreDescriptor cd) throws IOException { 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..a78dffc3afc 100644 --- a/solr/core/src/java/org/apache/solr/core/SolrCore.java +++ b/solr/core/src/java/org/apache/solr/core/SolrCore.java @@ -22,7 +22,7 @@ import com.codahale.metrics.Counter; import com.codahale.metrics.Timer; import java.io.Closeable; -import java.io.File; +import java.io.File; // ALLOWED import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; @@ -1354,6 +1354,7 @@ public void initializeMetrics(SolrMetricsContext parentContext, String scope) { Category.CORE.toString()); } + // TODO SOLR-8282 move to PATH // initialize disk total / free metrics Path dataDirPath = Paths.get(dataDir); File dataDirFile = dataDirPath.toFile(); @@ -3202,7 +3203,7 @@ public ValueSourceParser getValueSourceParser(String parserName) { * stopwords to ZooKeeper if running in SolrCloud mode. */ @SuppressWarnings({"unchecked", "rawtypes"}) - protected RestManager initRestManager() throws SolrException { + protected RestManager initRestManager() throws SolrException, IOException { PluginInfo restManagerPluginInfo = getSolrConfig().getPluginInfo(RestManager.class.getName()); 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 @@ private String getId(IndexCommit commit) { // 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/SolrResourceLoader.java b/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java index 11f61a12ae2..d6174c334db 100644 --- a/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java +++ b/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java @@ -18,7 +18,7 @@ import com.google.common.annotations.VisibleForTesting; import java.io.Closeable; -import java.io.File; +import java.io.File; // ALLOWED import java.io.FilterInputStream; import java.io.IOException; import java.io.InputStream; 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..611240273eb 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 @@ protected LockFactory createLockFactory(String rawLockType) throws IOException { @Override public String normalize(String path) throws IOException { - return super.normalize(new File(path).getCanonicalPath()); + return super.normalize(Path.of(path).toAbsolutePath().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 6dd7b2d571d..8e2a8dd597f 100644 --- a/solr/core/src/java/org/apache/solr/core/ZkContainer.java +++ b/solr/core/src/java/org/apache/solr/core/ZkContainer.java @@ -19,7 +19,6 @@ 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.Paths; @@ -99,7 +98,7 @@ public void initZooKeeper(final CoreContainer cc, CloudConfig config) { new SolrZkServer( stripChroot(zkRun), stripChroot(config.getZkHost()), - new File(zkDataHome), + Paths.get(zkDataHome), zkConfHome, config.getSolrHostPort()); zkServer.parseConfig(); @@ -184,7 +183,7 @@ public SolrMetricsContext getSolrMetricsContext() { } 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/core/backup/BackupManager.java b/solr/core/src/java/org/apache/solr/core/backup/BackupManager.java index df3353a7b31..1f2b4b75720 100644 --- a/solr/core/src/java/org/apache/solr/core/backup/BackupManager.java +++ b/solr/core/src/java/org/apache/solr/core/backup/BackupManager.java @@ -16,7 +16,7 @@ */ package org.apache.solr.core.backup; -import java.io.File; +import java.io.File; // ALLOWED import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; 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 a933bb6e1d6..5ebb3809d51 100644 --- a/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java +++ b/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java @@ -37,7 +37,7 @@ import static org.apache.solr.handler.admin.api.ReplicationAPIBase.GENERATION; import static org.apache.solr.handler.admin.api.ReplicationAPIBase.OFFSET; -import java.io.File; +import java.io.File; // ALLOWED import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; @@ -422,7 +422,7 @@ IndexFetchResult fetchLatestIndex(boolean forceReplication, boolean forceCoreRel 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 @@ -797,7 +797,7 @@ private void cleanup( Directory tmpIndexDir, Directory indexDir, boolean deleteTmpIdxDir, - File tmpTlogDir, + Path tmpTlogDir, boolean successfulInstall) throws IOException { try { @@ -1065,6 +1065,7 @@ private void downloadConfFiles( 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(); @@ -1076,7 +1077,8 @@ private void downloadConfFiles( for (Map 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)); @@ -1086,7 +1088,7 @@ private void downloadConfFiles( terminateAndWaitFsyncService(); copyTmpConfFiles2Conf(tmpConfPath); } finally { - delTree(tmpconfDir); + delTree(tmpconfDir.toPath()); } } @@ -1153,6 +1155,7 @@ private long downloadIndexFiles( alwaysDownload); } if (!compareResult.equal || downloadCompleteIndex || alwaysDownload) { + // TODO SOLR-8282 move to PATH File localFile = new File(indexDirPath, filename); if (downloadCompleteIndex && doDifferentialCopy @@ -1200,15 +1203,15 @@ private long downloadIndexFiles( 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.exists(file)) { + file = file.getParent(); // this is not a disk directory. so just pretend that there is enough space - if (!file.exists()) { + if (Files.exists(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); @@ -1474,7 +1477,7 @@ private List makeTmpConfDirFileList(Path dir) { * The conf files are copied to the tmp dir to the conf dir. A backup of the old file is * maintained */ - private void copyTmpConfFiles2Conf(Path tmpconfDir) { + private void copyTmpConfFiles2Conf(Path tmpconfDir) throws IOException { boolean status = false; Path confPath = solrCore.getResourceLoader().getConfigPath(); int numTempPathElements = tmpconfDir.getNameCount(); @@ -1487,7 +1490,7 @@ private void copyTmpConfFiles2Conf(Path tmpconfDir) { 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()) { @@ -1518,12 +1521,14 @@ private void copyTmpConfFiles2Conf(Path tmpconfDir) { * backup of the old directory is maintained. If the directory move fails, it will try to revert * back the original tlog directory. */ - private boolean copyTmpTlogFiles2Tlog(File tmpTlogDir) { + private boolean copyTmpTlogFiles2Tlog(Path tmpTlogDir) { Path tlogDir = FileSystems.getDefault().getPath(solrCore.getUpdateHandler().getUpdateLog().getTlogDir()); Path backupTlogDir = FileSystems.getDefault() - .getPath(tlogDir.getParent().toAbsolutePath().toString(), tmpTlogDir.getName()); + .getPath( + tlogDir.getParent().toAbsolutePath().toString(), + tmpTlogDir.getFileName().toString()); try { Files.move(tlogDir, backupTlogDir, StandardCopyOption.ATOMIC_MOVE); @@ -1534,7 +1539,8 @@ private boolean copyTmpTlogFiles2Tlog(File tmpTlogDir) { Path src = FileSystems.getDefault() - .getPath(backupTlogDir.toAbsolutePath().toString(), tmpTlogDir.getName()); + .getPath( + backupTlogDir.toAbsolutePath().toString(), tmpTlogDir.getFileName().toString()); try { Files.move(src, tlogDir, StandardCopyOption.ATOMIC_MOVE); } catch (IOException e) { @@ -1604,9 +1610,9 @@ private Collection> getModifiedConfFiles( * SecurityException, otherwise returns Throwable preventing deletion (instead of false), for * additional information. */ - static Throwable delete(File file) { + static Throwable delete(Path file) { try { - Files.delete(file.toPath()); + Files.delete(file); return null; } catch (SecurityException e) { throw e; @@ -1615,9 +1621,9 @@ static Throwable delete(File file) { } } - 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); @@ -2046,27 +2052,29 @@ protected class DirectoryFileFetcher extends FileFetcher { } private static class LocalFsFile implements FileInterface { - private File copy2Dir; + private Path copy2Dir; FileChannel fileChannel; private FileOutputStream fileOutputStream; - File file; + Path file; - LocalFsFile(File dir, String saveAs) throws IOException { + LocalFsFile(Path dir, String saveAs) throws IOException { this.copy2Dir = dir; - this.file = new File(copy2Dir, saveAs); + this.file = Path.of(copy2Dir.toString(), 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(); } @@ -2088,13 +2096,13 @@ public void close() throws Exception { @Override public void delete() throws Exception { - Files.delete(file.toPath()); + Files.delete(file); } } protected class LocalFsFileFetcher extends FileFetcher { LocalFsFileFetcher( - File dir, + Path dir, Map fileDetails, String saveAs, String solrParamOutput, diff --git a/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java index c35117fb088..1b66683a143 100644 --- a/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java +++ b/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java @@ -25,7 +25,7 @@ import com.github.benmanes.caffeine.cache.Caffeine; import com.github.benmanes.caffeine.cache.Expiry; import com.github.benmanes.caffeine.cache.Ticker; -import java.io.File; +import java.io.File; // ALLOWED import java.lang.invoke.MethodHandles; import java.util.ArrayList; import java.util.Collection; 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..c2cf54396ef 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 @@ -16,7 +16,7 @@ */ package org.apache.solr.handler.admin; -import java.io.File; +import java.io.File; // ALLOWED import java.io.IOException; import java.io.UnsupportedEncodingException; import java.lang.invoke.MethodHandles; @@ -195,13 +195,13 @@ private void showFromZooKeeper( } // Return the file indicated (or the directory listing) from the local file system. - private void showFromFileSystem(SolrQueryRequest req, SolrQueryResponse rsp) { + private void showFromFileSystem(SolrQueryRequest req, SolrQueryResponse rsp) throws IOException { Path admin = getAdminFileFromFileSystem(req, rsp, hiddenFiles); 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 @@ private void showFromFileSystem(SolrQueryRequest req, SolrQueryResponse rsp) { 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 @@ 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 @@ private SimpleOrderedMap getCoreInfo(SolrCore core, IndexSchema schema) // Solr Home SimpleOrderedMap 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..1b921804da9 100644 --- a/solr/core/src/java/org/apache/solr/rest/ManagedResourceStorage.java +++ b/solr/core/src/java/org/apache/solr/rest/ManagedResourceStorage.java @@ -20,7 +20,7 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; -import java.io.File; +import java.io.File; // ALLOWED import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; @@ -69,7 +69,8 @@ public abstract class ManagedResourceStorage { public static interface StorageIO { String getInfo(); - void configure(SolrResourceLoader loader, NamedList initArgs) throws SolrException; + void configure(SolrResourceLoader loader, NamedList initArgs) + throws SolrException, IOException; boolean exists(String storedResourceId) throws IOException; @@ -88,7 +89,8 @@ public static interface StorageIO { * running in cloud mode as well as initArgs. */ public static StorageIO newStorageIO( - String collection, SolrResourceLoader resourceLoader, NamedList initArgs) { + String collection, SolrResourceLoader resourceLoader, NamedList initArgs) + throws IOException { StorageIO storageIO; SolrZkClient zkClient = null; @@ -165,23 +167,23 @@ public static class FileStorageIO implements StorageIO { @Override public void configure(SolrResourceLoader loader, NamedList initArgs) - throws SolrException { + throws SolrException, IOException { String storageDirArg = initArgs.get(STORAGE_DIR_INIT_ARG); if (storageDirArg == null || storageDirArg.trim().length() == 0) 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)) Files.createDirectories(dir); - 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 +198,20 @@ public OutputStream openOutputStream(String storedResourceId) throws IOException @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) { + // File f = p.toFile(); + 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..cbffdf11934 100644 --- a/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchemaFactory.java +++ b/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchemaFactory.java @@ -17,7 +17,7 @@ package org.apache.solr.schema; import java.io.ByteArrayInputStream; -import java.io.File; +import java.io.File; // ALLOWED import java.io.IOException; import java.io.InputStream; import java.lang.invoke.MethodHandles; @@ -401,7 +401,8 @@ private void upgradeToManagedSchema() { "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 @@ private void upgradeToManagedSchema() { * * @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 @@ 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.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 @@ private SolrQueryRequest buildRequestFrom( "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..864b0dc26cb 100644 --- a/solr/core/src/java/org/apache/solr/spelling/AbstractLuceneSpellChecker.java +++ b/solr/core/src/java/org/apache/solr/spelling/AbstractLuceneSpellChecker.java @@ -16,7 +16,7 @@ */ package org.apache.solr.spelling; -import java.io.File; +import java.io.File; // ALLOWED import java.io.IOException; import java.nio.file.Path; import java.util.Arrays; @@ -83,7 +83,7 @@ public String init(NamedList config, SolrCore core) { 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..fdae92015cb 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 @@ -16,8 +16,9 @@ */ package org.apache.solr.spelling.suggest.fst; -import java.io.File; +import java.io.File; // ALLOWED 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 Lookup create(NamedList params, SolrCore core) { 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 Lookup create(NamedList params, SolrCore core) { 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..1ed9f0cb735 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 @@ -16,8 +16,9 @@ */ package org.apache.solr.spelling.suggest.fst; -import java.io.File; +import java.io.File; // ALLOWED 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 Lookup create(NamedList params, SolrCore core) { 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 Lookup create(NamedList params, SolrCore core) { 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 8e0126073d2..03cc5e12aaa 100644 --- a/solr/core/src/java/org/apache/solr/update/UpdateLog.java +++ b/solr/core/src/java/org/apache/solr/update/UpdateLog.java @@ -24,7 +24,6 @@ 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; @@ -580,7 +579,7 @@ protected void initTlogDir(SolrCore core) { } 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) { @@ -731,11 +730,11 @@ private boolean updateFromOldTlogs(UpdateCommand cmd) { 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)); + String[] names = directory.toFile().list((dir, name) -> name.startsWith(prefix)); if (names == null) { - throw new RuntimeException(new FileNotFoundException(directory.getAbsolutePath())); + throw new RuntimeException(new FileNotFoundException(directory.toFile().getAbsolutePath())); } Arrays.sort(names); return names; 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..a63d0c43274 100644 --- a/solr/core/src/java/org/apache/solr/util/FileUtils.java +++ b/solr/core/src/java/org/apache/solr/util/FileUtils.java @@ -16,7 +16,6 @@ */ package org.apache.solr.util; -import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; @@ -37,14 +36,14 @@ public class FileUtils { * 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 Path resolvePath(Path base, String path) { + Path r = Path.of(path); + return r.isAbsolute() ? r : Path.of(base.toString(), path); } - public static void copyFile(File src, File destination) throws IOException { - try (FileChannel in = new FileInputStream(src).getChannel(); - FileChannel out = new FileOutputStream(destination).getChannel()) { + public static void copyFile(Path src, Path destination) throws IOException { + try (FileChannel in = new FileInputStream(src.toFile()).getChannel(); + FileChannel out = new FileOutputStream(destination.toFile()).getChannel()) { in.transferTo(0, in.size(), out); } } @@ -55,8 +54,8 @@ public static void copyFile(File src, File destination) throws IOException { * @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()) + public static void sync(Path fullFile) throws IOException { + if (fullFile == null || !Files.exists(fullFile)) throw new FileNotFoundException("File does not exist " + fullFile); boolean success = false; @@ -64,7 +63,7 @@ public static void sync(File fullFile) throws IOException { IOException exc = null; while (!success && retryCount < 5) { retryCount++; - try (RandomAccessFile file = new RandomAccessFile(fullFile, "rw")) { + try (RandomAccessFile file = new RandomAccessFile(fullFile.toFile(), "rw")) { file.getFD().sync(); success = true; } catch (IOException ioe) { @@ -83,7 +82,7 @@ public static void sync(File fullFile) throws IOException { } 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/RegexFileFilter.java b/solr/core/src/java/org/apache/solr/util/RegexFileFilter.java index 3ed84d93c20..20d3cdf34f5 100644 --- a/solr/core/src/java/org/apache/solr/util/RegexFileFilter.java +++ b/solr/core/src/java/org/apache/solr/util/RegexFileFilter.java @@ -16,7 +16,7 @@ */ package org.apache.solr.util; -import java.io.File; +import java.io.File; // ALLOWED import java.io.FileFilter; import java.util.regex.Pattern; diff --git a/solr/core/src/java/org/apache/solr/util/SystemIdResolver.java b/solr/core/src/java/org/apache/solr/util/SystemIdResolver.java index 6d1267d76f4..d9701fdf246 100644 --- a/solr/core/src/java/org/apache/solr/util/SystemIdResolver.java +++ b/solr/core/src/java/org/apache/solr/util/SystemIdResolver.java @@ -16,7 +16,7 @@ */ package org.apache.solr.util; -import java.io.File; +import java.io.File; // ALLOWED import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; 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 oldFiles = null; final String prefix = fileName + '.'; File f = new File(dirName, fileName); 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 @@ 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 final String getFilePath() { * * @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 String getContentType() { * @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..823fafdf1c3 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 @@ 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.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; @@ -165,15 +166,15 @@ public InputStream getStream() throws IOException { /** Construct a ContentStream from a File */ public static class FileStream extends ContentStreamBase { - private final File file; + private final Path file; - public FileStream(File f) { + public FileStream(Path f) throws IOException { file = f; contentType = null; // ?? - name = file.getName(); - size = file.length(); - sourceInfo = file.toURI().toString(); + name = file.getFileName().toString(); + size = Files.size(file); + sourceInfo = file.toUri().toString(); } @Override @@ -186,7 +187,7 @@ public String getContentType() { @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); From ac5f63edccfb7b4e927f8173785c25a115dc8042 Mon Sep 17 00:00:00 2001 From: Matthew Biscocho Date: Thu, 12 Dec 2024 16:53:11 -0500 Subject: [PATCH 02/10] Move File objects to toPath() --- .../solr/cloud/ZkSolrResourceLoader.java | 2 +- .../solr/core/CachingDirectoryFactory.java | 2 +- .../org/apache/solr/core/CoreDescriptor.java | 2 +- .../apache/solr/core/DirectoryFactory.java | 2 +- .../java/org/apache/solr/core/SolrCore.java | 2 +- .../apache/solr/core/SolrResourceLoader.java | 2 +- .../solr/core/backup/BackupManager.java | 2 +- .../org/apache/solr/handler/IndexFetcher.java | 2 +- .../solr/handler/admin/CoreAdminHandler.java | 2 +- .../handler/admin/ShowFileRequestHandler.java | 2 +- .../solr/rest/ManagedResourceStorage.java | 2 +- .../schema/ManagedIndexSchemaFactory.java | 2 +- .../spelling/AbstractLuceneSpellChecker.java | 2 +- .../fst/AnalyzingInfixLookupFactory.java | 2 +- .../fst/BlendedInfixLookupFactory.java | 2 +- .../org/apache/solr/util/RegexFileFilter.java | 2 +- .../apache/solr/util/SystemIdResolver.java | 2 +- .../apache/solr/cloud/TestConfigSetsAPI.java | 4 +-- .../solr/handler/ReplicationTestHelper.java | 5 ++-- .../apache/solr/handler/TestCSVLoader.java | 2 +- .../handler/TestReplicationHandlerBackup.java | 4 +-- .../apache/solr/handler/TestRestoreCore.java | 4 +-- .../handler/TestSampleDocumentsLoader.java | 6 ++--- .../designer/TestSchemaDesignerAPI.java | 25 +++++++++++-------- .../org/apache/solr/rest/TestRestManager.java | 3 ++- .../org/apache/solr/search/TestRecovery.java | 23 +++++++++-------- .../org/apache/solr/util/FileUtilsTest.java | 6 ++--- .../ExtractingRequestHandlerTest.java | 4 +-- .../apache/solr/prometheus/utils/Helpers.java | 2 +- .../examples/JsonRequestApiTest.java | 2 +- .../solr/client/solrj/SolrExampleTests.java | 6 ++--- .../request/TestConfigSetAdminRequest.java | 4 +-- ...tJsonQueryRequestFacetingEmbeddedTest.java | 2 +- ...onQueryRequestFacetingIntegrationTest.java | 2 +- ...onQueryRequestFacetingIntegrationTest.java | 2 +- .../json/JsonQueryRequestIntegrationTest.java | 2 +- .../solr/common/util/ContentStreamTest.java | 4 +-- 37 files changed, 77 insertions(+), 69 deletions(-) diff --git a/solr/core/src/java/org/apache/solr/cloud/ZkSolrResourceLoader.java b/solr/core/src/java/org/apache/solr/cloud/ZkSolrResourceLoader.java index 2490290cff4..68654851d5b 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ZkSolrResourceLoader.java +++ b/solr/core/src/java/org/apache/solr/cloud/ZkSolrResourceLoader.java @@ -17,7 +17,7 @@ package org.apache.solr.cloud; import java.io.ByteArrayInputStream; -import java.io.File; // ALLOWED +import java.io.File; import java.io.IOException; import java.io.InputStream; import java.lang.invoke.MethodHandles; diff --git a/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.java b/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.java index 72254d4586d..dfe9487809e 100644 --- a/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.java +++ b/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.java @@ -16,7 +16,7 @@ */ package org.apache.solr.core; -import java.io.File; // ALLOWED +import java.io.File; import java.io.IOException; import java.lang.invoke.MethodHandles; import java.nio.file.DirectoryStream; diff --git a/solr/core/src/java/org/apache/solr/core/CoreDescriptor.java b/solr/core/src/java/org/apache/solr/core/CoreDescriptor.java index c4757e6b830..6109b2f860b 100644 --- a/solr/core/src/java/org/apache/solr/core/CoreDescriptor.java +++ b/solr/core/src/java/org/apache/solr/core/CoreDescriptor.java @@ -16,7 +16,7 @@ */ package org.apache.solr.core; -import java.io.File; // ALLOWED +import java.io.File; import java.io.IOException; import java.io.Reader; import java.lang.invoke.MethodHandles; 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 51daea31dd7..aebbd64b7a1 100644 --- a/solr/core/src/java/org/apache/solr/core/DirectoryFactory.java +++ b/solr/core/src/java/org/apache/solr/core/DirectoryFactory.java @@ -17,7 +17,7 @@ package org.apache.solr.core; import java.io.Closeable; -import java.io.File; // ALLOWED +import java.io.File; import java.io.FileFilter; import java.io.FileNotFoundException; import java.io.IOException; 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 a78dffc3afc..318834ffd6e 100644 --- a/solr/core/src/java/org/apache/solr/core/SolrCore.java +++ b/solr/core/src/java/org/apache/solr/core/SolrCore.java @@ -22,7 +22,7 @@ import com.codahale.metrics.Counter; import com.codahale.metrics.Timer; import java.io.Closeable; -import java.io.File; // ALLOWED +import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; diff --git a/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java b/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java index d6174c334db..11f61a12ae2 100644 --- a/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java +++ b/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java @@ -18,7 +18,7 @@ import com.google.common.annotations.VisibleForTesting; import java.io.Closeable; -import java.io.File; // ALLOWED +import java.io.File; import java.io.FilterInputStream; import java.io.IOException; import java.io.InputStream; diff --git a/solr/core/src/java/org/apache/solr/core/backup/BackupManager.java b/solr/core/src/java/org/apache/solr/core/backup/BackupManager.java index 1f2b4b75720..df3353a7b31 100644 --- a/solr/core/src/java/org/apache/solr/core/backup/BackupManager.java +++ b/solr/core/src/java/org/apache/solr/core/backup/BackupManager.java @@ -16,7 +16,7 @@ */ package org.apache.solr.core.backup; -import java.io.File; // ALLOWED +import java.io.File; import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; 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 5ebb3809d51..26880ea6f46 100644 --- a/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java +++ b/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java @@ -37,7 +37,7 @@ import static org.apache.solr.handler.admin.api.ReplicationAPIBase.GENERATION; import static org.apache.solr.handler.admin.api.ReplicationAPIBase.OFFSET; -import java.io.File; // ALLOWED +import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; diff --git a/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java index 1b66683a143..c35117fb088 100644 --- a/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java +++ b/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java @@ -25,7 +25,7 @@ import com.github.benmanes.caffeine.cache.Caffeine; import com.github.benmanes.caffeine.cache.Expiry; import com.github.benmanes.caffeine.cache.Ticker; -import java.io.File; // ALLOWED +import java.io.File; import java.lang.invoke.MethodHandles; import java.util.ArrayList; import java.util.Collection; 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 c2cf54396ef..918257e975d 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 @@ -16,7 +16,7 @@ */ package org.apache.solr.handler.admin; -import java.io.File; // ALLOWED +import java.io.File; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.lang.invoke.MethodHandles; 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 1b921804da9..3942835a1a0 100644 --- a/solr/core/src/java/org/apache/solr/rest/ManagedResourceStorage.java +++ b/solr/core/src/java/org/apache/solr/rest/ManagedResourceStorage.java @@ -20,7 +20,7 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; -import java.io.File; // ALLOWED +import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; 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 cbffdf11934..df44cda12e2 100644 --- a/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchemaFactory.java +++ b/solr/core/src/java/org/apache/solr/schema/ManagedIndexSchemaFactory.java @@ -17,7 +17,7 @@ package org.apache.solr.schema; import java.io.ByteArrayInputStream; -import java.io.File; // ALLOWED +import java.io.File; import java.io.IOException; import java.io.InputStream; import java.lang.invoke.MethodHandles; 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 864b0dc26cb..1c0e7006185 100644 --- a/solr/core/src/java/org/apache/solr/spelling/AbstractLuceneSpellChecker.java +++ b/solr/core/src/java/org/apache/solr/spelling/AbstractLuceneSpellChecker.java @@ -16,7 +16,7 @@ */ package org.apache.solr.spelling; -import java.io.File; // ALLOWED +import java.io.File; import java.io.IOException; import java.nio.file.Path; import java.util.Arrays; 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 fdae92015cb..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 @@ -16,7 +16,7 @@ */ package org.apache.solr.spelling.suggest.fst; -import java.io.File; // ALLOWED +import java.io.File; import java.io.IOException; import java.nio.file.Path; import java.util.ArrayList; 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 1ed9f0cb735..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 @@ -16,7 +16,7 @@ */ package org.apache.solr.spelling.suggest.fst; -import java.io.File; // ALLOWED +import java.io.File; import java.io.IOException; import java.nio.file.Path; import java.util.ArrayList; diff --git a/solr/core/src/java/org/apache/solr/util/RegexFileFilter.java b/solr/core/src/java/org/apache/solr/util/RegexFileFilter.java index 20d3cdf34f5..3ed84d93c20 100644 --- a/solr/core/src/java/org/apache/solr/util/RegexFileFilter.java +++ b/solr/core/src/java/org/apache/solr/util/RegexFileFilter.java @@ -16,7 +16,7 @@ */ package org.apache.solr.util; -import java.io.File; // ALLOWED +import java.io.File; import java.io.FileFilter; import java.util.regex.Pattern; diff --git a/solr/core/src/java/org/apache/solr/util/SystemIdResolver.java b/solr/core/src/java/org/apache/solr/util/SystemIdResolver.java index d9701fdf246..6d1267d76f4 100644 --- a/solr/core/src/java/org/apache/solr/util/SystemIdResolver.java +++ b/solr/core/src/java/org/apache/solr/util/SystemIdResolver.java @@ -16,7 +16,7 @@ */ package org.apache.solr.util; -import java.io.File; // ALLOWED +import java.io.File; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; 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..8ed3d93b492 100644 --- a/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPI.java +++ b/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPI.java @@ -1563,7 +1563,7 @@ private long uploadGivenConfigSet( 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 @@ -1620,7 +1620,7 @@ private long uploadSingleConfigSetFile( .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 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..9016b1b46d8 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.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; @@ -55,8 +56,8 @@ public final class ReplicationTestHelper { public static JettySolrRunner createAndStartJetty(SolrInstance instance) throws Exception { FileUtils.copyFile( - new File(SolrTestCaseJ4.TEST_HOME(), "solr.xml"), - new File(instance.getHomeDir(), "solr.xml")); + 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/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 @@ void loadLocal(String... args) throws Exception { // TODO: stop using locally defined streams once stream.file and // stream.body work everywhere List 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 418ce1d6551..453aa736425 100644 --- a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerBackup.java +++ b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerBackup.java @@ -73,8 +73,8 @@ 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")); + 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..8c2d4390c5a 100644 --- a/solr/core/src/test/org/apache/solr/handler/TestRestoreCore.java +++ b/solr/core/src/test/org/apache/solr/handler/TestRestoreCore.java @@ -58,8 +58,8 @@ 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")); + 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 static String guessContentTypeFromFilename(String name) { 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/designer/TestSchemaDesignerAPI.java b/solr/core/src/test/org/apache/solr/handler/designer/TestSchemaDesignerAPI.java index f059acb8a6c..4ec87f1094c 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 void testAddTechproductsProgressively() throws Exception { 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 void testSuggestFilmsXml() throws Exception { 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 void testBasicUserWorkflow() throws Exception { // 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)); @@ -553,7 +553,8 @@ public void testBasicUserWorkflow() throws Exception { req = mock(SolrQueryRequest.class); when(req.getParams()).thenReturn(reqParams); - stream = new ContentStreamBase.FileStream(getFile("schema-designer/add-new-field.json")); + stream = + new ContentStreamBase.FileStream(getFile("schema-designer/add-new-field.json").toPath()); stream.setContentType(JSON_MIME); when(req.getContentStreams()).thenReturn(Collections.singletonList(stream)); rsp = new SolrQueryResponse(); @@ -574,7 +575,9 @@ public void testBasicUserWorkflow() throws Exception { when(req.getParams()).thenReturn(reqParams); // switch a single-valued field to a multi-valued field, which triggers a full rebuild of the // "temp" collection - stream = new ContentStreamBase.FileStream(getFile("schema-designer/update-author-field.json")); + stream = + new ContentStreamBase.FileStream( + getFile("schema-designer/update-author-field.json").toPath()); stream.setContentType(JSON_MIME); when(req.getContentStreams()).thenReturn(Collections.singletonList(stream)); @@ -592,7 +595,8 @@ public void testBasicUserWorkflow() throws Exception { req = mock(SolrQueryRequest.class); when(req.getParams()).thenReturn(reqParams); - stream = new ContentStreamBase.FileStream(getFile("schema-designer/add-new-type.json")); + stream = + new ContentStreamBase.FileStream(getFile("schema-designer/add-new-type.json").toPath()); stream.setContentType(JSON_MIME); when(req.getContentStreams()).thenReturn(Collections.singletonList(stream)); rsp = new SolrQueryResponse(); @@ -618,7 +622,7 @@ public void testBasicUserWorkflow() throws Exception { req = mock(SolrQueryRequest.class); when(req.getParams()).thenReturn(reqParams); - stream = new ContentStreamBase.FileStream(getFile("schema-designer/update-type.json")); + stream = new ContentStreamBase.FileStream(getFile("schema-designer/update-type.json").toPath()); stream.setContentType(JSON_MIME); when(req.getContentStreams()).thenReturn(Collections.singletonList(stream)); rsp = new SolrQueryResponse(); @@ -714,7 +718,7 @@ public void testFieldUpdates() throws Exception { req = mock(SolrQueryRequest.class); when(req.getParams()).thenReturn(reqParams); ContentStreamBase.FileStream stream = - new ContentStreamBase.FileStream(getFile("schema-designer/add-new-field.json")); + new ContentStreamBase.FileStream(getFile("schema-designer/add-new-field.json").toPath()); stream.setContentType(JSON_MIME); when(req.getContentStreams()).thenReturn(Collections.singletonList(stream)); rsp = new SolrQueryResponse(); @@ -860,7 +864,7 @@ public void testSchemaDiffEndpoint() throws Exception { Integer schemaVersion = rsp.getValues().toSolrParams().getInt(SCHEMA_VERSION_PARAM); reqParams.set(SCHEMA_VERSION_PARAM, schemaVersion); ContentStreamBase.FileStream fileStream = - new ContentStreamBase.FileStream(getFile("schema-designer/add-new-field.json")); + new ContentStreamBase.FileStream(getFile("schema-designer/add-new-field.json").toPath()); fileStream.setContentType(JSON_MIME); when(req.getContentStreams()).thenReturn(Collections.singletonList(fileStream)); rsp = new SolrQueryResponse(); @@ -871,7 +875,8 @@ public void testSchemaDiffEndpoint() throws Exception { // Add a new field type schemaVersion = rsp.getValues().toSolrParams().getInt(SCHEMA_VERSION_PARAM); reqParams.set(SCHEMA_VERSION_PARAM, schemaVersion); - fileStream = new ContentStreamBase.FileStream(getFile("schema-designer/add-new-type.json")); + fileStream = + new ContentStreamBase.FileStream(getFile("schema-designer/add-new-type.json").toPath()); fileStream.setContentType(JSON_MIME); when(req.getContentStreams()).thenReturn(Collections.singletonList(fileStream)); rsp = new SolrQueryResponse(); 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 void testRestManagerEndpoints() throws Exception { } @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/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 void testRemoveOldLogs() throws Exception { 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 void testRemoveOldLogs() throws Exception { 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 void testRemoveOldLogs() throws Exception { "/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 void testRemoveOldLogs() throws Exception { "/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 void testRemoveOldLogs() throws Exception { 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 void testTruncatedLog() throws Exception { 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 void testCorruptLog() throws Exception { 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 void testRecoveryMultipleLogs() throws Exception { 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 @@ void deleteLogs() throws Exception { 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/util/FileUtilsTest.java b/solr/core/src/test/org/apache/solr/util/FileUtilsTest.java index 0dfeff109a3..98e363fae26 100644 --- a/solr/core/src/test/org/apache/solr/util/FileUtilsTest.java +++ b/solr/core/src/test/org/apache/solr/util/FileUtilsTest.java @@ -26,10 +26,10 @@ 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("conf/data"), FileUtils.resolvePath(Path.of("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")); + new File(cwd + "/conf/data"), FileUtils.resolvePath(Path.of(cwd + "/conf"), "data")); + assertEquals(new File(cwd + "/data"), FileUtils.resolvePath(Path.of("conf"), cwd + "/data")); } @Test 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..e7b535a2341 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 @@ -663,7 +663,7 @@ public void testCommitWithin() throws Exception { ExtractingDocumentLoader loader = (ExtractingDocumentLoader) handler.newLoader(req, p); loader.load( - req, rsp, new ContentStreamBase.FileStream(getFile("extraction/version_control.txt")), p); + req, rsp, new ContentStreamBase.FileStream(getFile("extraction/version_control.txt").toPath()), p); AddUpdateCommand add = p.addCommands.get(0); assertEquals(200, add.commitWithin); @@ -1134,7 +1134,7 @@ SolrQueryResponse loadLocalFromHandler(String handler, String filename, String.. // TODO: stop using locally defined streams once stream.file and // stream.body work everywhere List cs = new ArrayList<>(); - cs.add(new ContentStreamBase.FileStream(getFile(filename))); + cs.add(new ContentStreamBase.FileStream(getFile(filename).toPath())); req.setContentStreams(cs); return h.queryAndResponse(handler, req); } finally { 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..db1421a8d97 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 @@ -40,7 +40,7 @@ public static void indexAllDocs(SolrClient client) throws IOException, SolrServe 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/solr-ref-guide/modules/query-guide/examples/JsonRequestApiTest.java b/solr/solr-ref-guide/modules/query-guide/examples/JsonRequestApiTest.java index 0f3091838a1..104bdda783d 100644 --- a/solr/solr-ref-guide/modules/query-guide/examples/JsonRequestApiTest.java +++ b/solr/solr-ref-guide/modules/query-guide/examples/JsonRequestApiTest.java @@ -66,7 +66,7 @@ public static void setupCluster() throws Exception { ContentStreamUpdateRequest up = new ContentStreamUpdateRequest("/update"); up.setParam("collection", COLLECTION_NAME); - up.addFile(getFile("solrj/techproducts.xml"), "application/xml"); + up.addFile(getFile("solrj/techproducts.xml").toPath(), "application/xml"); up.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true); UpdateResponse updateResponse = up.process(cluster.getSolrClient()); assertEquals(0, updateResponse.getStatus()); 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..4386d723581 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 @@ -960,7 +960,7 @@ public void close() throws IOException { }; up.addContentStream(contentStreamMock); } else { - up.addFile(file, "application/csv"); + up.addFile(file.toPath(), "application/csv"); } up.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true); @@ -1033,8 +1033,8 @@ public void testMultiContentStreamRequest() throws Exception { assertEquals(0, rsp.getResults().getNumFound()); ContentStreamUpdateRequest up = new ContentStreamUpdateRequest("/update"); - up.addFile(getFile("solrj/docs1.xml"), "application/xml"); // 2 - up.addFile(getFile("solrj/docs2.xml"), "application/xml"); // 3 + up.addFile(getFile("solrj/docs1.xml").toPath(), "application/xml"); // 2 + up.addFile(getFile("solrj/docs2.xml").toPath(), "application/xml"); // 3 up.setParam("a", "\u1234"); up.setParam(CommonParams.HEADER_ECHO_PARAMS, CommonParams.EchoParamStyle.ALL.toString()); up.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true); 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..eb88caee5ae 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 @@ -41,7 +41,7 @@ public void testUpload() throws Exception { upload.setConfigSetName("name"); verifyException(upload, "There must be a ContentStream"); - upload.setUploadFile(tmpFile, "application/zip"); + upload.setUploadFile(tmpFile.toPath(), "application/zip"); assertEquals(1, upload.getContentStreams().size()); assertEquals( @@ -52,7 +52,7 @@ public void testUpload() throws Exception { assertNull(upload.getParams().get(ConfigSetParams.CLEANUP)); upload - .setUploadFile(tmpFile, "application/xml") + .setUploadFile(tmpFile.toPath(), "application/xml") .setFilePath("solrconfig.xml") .setOverwrite(true); diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/DirectJsonQueryRequestFacetingEmbeddedTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/DirectJsonQueryRequestFacetingEmbeddedTest.java index 8103dda8e19..b009cb15333 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/DirectJsonQueryRequestFacetingEmbeddedTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/DirectJsonQueryRequestFacetingEmbeddedTest.java @@ -62,7 +62,7 @@ public static void beforeClass() throws Exception { ContentStreamUpdateRequest up = new ContentStreamUpdateRequest("/update"); up.setParam("collection", COLLECTION_NAME); - up.addFile(getFile("solrj/techproducts.xml"), "application/xml"); + up.addFile(getFile("solrj/techproducts.xml").toPath(), "application/xml"); up.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true); UpdateResponse updateResponse = up.process(client); assertEquals(0, updateResponse.getStatus()); diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/DirectJsonQueryRequestFacetingIntegrationTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/DirectJsonQueryRequestFacetingIntegrationTest.java index 7663e44852d..361b541b9fc 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/DirectJsonQueryRequestFacetingIntegrationTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/DirectJsonQueryRequestFacetingIntegrationTest.java @@ -56,7 +56,7 @@ public static void setupCluster() throws Exception { ContentStreamUpdateRequest up = new ContentStreamUpdateRequest("/update"); up.setParam("collection", COLLECTION_NAME); - up.addFile(getFile("solrj/techproducts.xml"), "application/xml"); + up.addFile(getFile("solrj/techproducts.xml").toPath(), "application/xml"); up.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true); UpdateResponse updateResponse = up.process(cluster.getSolrClient()); assertEquals(0, updateResponse.getStatus()); diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/JsonQueryRequestFacetingIntegrationTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/JsonQueryRequestFacetingIntegrationTest.java index bb66ef233a1..7912ed858bb 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/JsonQueryRequestFacetingIntegrationTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/JsonQueryRequestFacetingIntegrationTest.java @@ -63,7 +63,7 @@ public static void setupCluster() throws Exception { ContentStreamUpdateRequest up = new ContentStreamUpdateRequest("/update"); up.setParam("collection", COLLECTION_NAME); - up.addFile(getFile("solrj/techproducts.xml"), "application/xml"); + up.addFile(getFile("solrj/techproducts.xml").toPath(), "application/xml"); up.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true); UpdateResponse updateResponse = up.process(cluster.getSolrClient()); assertEquals(0, updateResponse.getStatus()); diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/JsonQueryRequestIntegrationTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/JsonQueryRequestIntegrationTest.java index 203f69189ce..beea0ae76d7 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/JsonQueryRequestIntegrationTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/JsonQueryRequestIntegrationTest.java @@ -58,7 +58,7 @@ public static void setupCluster() throws Exception { ContentStreamUpdateRequest up = new ContentStreamUpdateRequest("/update"); up.setParam("collection", COLLECTION_NAME); - up.addFile(getFile("solrj/books.csv"), "application/csv"); + up.addFile(getFile("solrj/books.csv").toPath(), "application/csv"); up.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true); UpdateResponse updateResponse = up.process(cluster.getSolrClient()); assertEquals(0, updateResponse.getStatus()); 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 void testFileStream() throws IOException { 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 void testFileStreamGZIP() throws IOException { 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); From 58d52b787f77f1e733b37d3bd7979984ba784745 Mon Sep 17 00:00:00 2001 From: Matthew Biscocho Date: Thu, 12 Dec 2024 17:39:55 -0500 Subject: [PATCH 03/10] SolrTestCaseJ4 getFile() returns Path instead --- .../org/apache/solr/SolrTestCaseJ4Test.java | 2 +- .../org/apache/solr/cli/PostToolTest.java | 6 +++--- .../apache/solr/cloud/TestConfigSetsAPI.java | 16 ++++++++-------- .../cloud/TestConfigSetsAPIZkFailure.java | 2 +- .../org/apache/solr/core/TestConfigSets.java | 7 ++++--- .../apache/solr/core/TestCoreContainer.java | 12 ++++++------ .../solr/core/TestSolrConfigHandler.java | 2 +- .../solr/handler/ReplicationTestHelper.java | 4 ++-- .../handler/XmlUpdateRequestHandlerTest.java | 2 +- .../solr/handler/admin/MBeansHandlerTest.java | 2 +- .../designer/TestSchemaDesignerAPI.java | 19 +++++++------------ .../pkg/PackageStoreSchemaPluginsTest.java | 4 ++-- .../schema/ExternalFileFieldSortTest.java | 2 +- .../solr/schema/TestCollationField.java | 9 +++------ .../schema/TestCollationFieldDocValues.java | 8 +++----- .../solr/servlet/SolrRequestParserTest.java | 2 +- .../solr/util/TestSystemIdResolver.java | 4 ++-- .../manager/DeleteByQueryToIdTest.java | 9 ++++----- .../manager/RetryQueueIntegrationTest.java | 2 +- .../manager/SolrAndKafkaIntegrationTest.java | 8 ++------ ...ndKafkaMultiCollectionIntegrationTest.java | 8 ++------ .../manager/SolrAndKafkaReindexTest.java | 8 ++------ .../manager/ZkConfigIntegrationTest.java | 8 ++------ .../TestFoldingMultitermExtrasQuery.java | 2 +- .../solr/schema/TestICUCollationField.java | 4 ++-- .../TestICUCollationFieldDocValues.java | 4 ++-- .../schema/TestICUCollationFieldOptions.java | 2 +- ...ctNamedEntitiesUpdateProcessorFactory.java | 2 +- .../ClusteringComponentDistributedTest.java | 2 +- .../clustering/ClusteringComponentTest.java | 2 +- .../CrossDCProducerSolrStandaloneTest.java | 4 ++-- .../ExtractingRequestHandlerTest.java | 7 ++++--- .../extraction/TestXLSXResponseWriter.java | 3 ++- .../solr/gcs/GCSIncrementalBackupTest.java | 2 +- .../apache/solr/gcs/GCSInstallShardTest.java | 2 +- .../solr/security/jwt/JWTAuthPluginTest.java | 2 +- ...ntifierUpdateProcessorFactoryTestCase.java | 2 +- .../solr/s3/S3IncrementalBackupTest.java | 2 +- .../apache/solr/s3/S3InstallShardTest.java | 2 +- .../ScriptUpdateProcessorFactoryTest.java | 2 +- ...TestBadScriptingUpdateProcessorConfig.java | 6 +++--- .../scripting/xslt/XSLTOutputWriterTest.java | 2 +- .../xslt/XSLTUpdateRequestHandlerTest.java | 4 ++-- .../PrometheusExporterTestBase.java | 5 +++-- .../exporter/MetricsQueryTemplateTest.java | 5 +++-- .../apache/solr/prometheus/utils/Helpers.java | 5 +++-- .../examples/JsonRequestApiTest.java | 2 +- .../client/solrj/io/SolrClientCacheTest.java | 2 +- .../solrj/io/graph/GraphExpressionTest.java | 1 - .../solr/client/solrj/io/graph/GraphTest.java | 1 - .../solr/client/solrj/io/sql/JdbcTest.java | 1 - .../solrj/io/stream/BadClusterTest.java | 1 - .../solrj/io/stream/JDBCStreamTest.java | 1 - .../solrj/io/stream/MathExpressionTest.java | 8 +------- .../ParallelFacetStreamOverAliasTest.java | 1 - .../io/stream/SelectWithEvaluatorsTest.java | 8 +------- .../solrj/io/stream/StreamDecoratorTest.java | 8 +------- .../solrj/io/stream/StreamExpressionTest.java | 8 +------- .../client/solrj/io/stream/StreamingTest.java | 1 - ...onQueryRequestFacetingIntegrationTest.java | 2 +- .../java/org/apache/solr/SolrTestCaseJ4.java | 14 +++++++------- .../AbstractBasicDistributedZkTestBase.java | 2 +- 62 files changed, 114 insertions(+), 166 deletions(-) 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 static void beforeClass() throws Exception { 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..da4fce970aa 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,7 @@ public void testDoFilesMode() throws IOException { postTool.recursive = 0; postTool.dryRun = true; postTool.solrUpdateUrl = URI.create("http://localhost:8983/solr/fake/update"); - File dir = getFile("exampledocs"); + File dir = getFile("exampledocs").toFile(); int num = postTool.postFiles(new String[] {dir.toString()}, 0, null, null); assertEquals(2, num); } @@ -303,7 +303,7 @@ public void testDoFilesMode() throws IOException { 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 +316,7 @@ public void testRecursionAppliesToFilesMode() throws IOException { postTool.recursive = 1; // This is the default postTool.dryRun = true; postTool.solrUpdateUrl = URI.create("http://localhost:8983/solr/fake/update"); - File dir = getFile("exampledocs"); + 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 8ed3d93b492..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 void testCreateWithTrust() throws Exception { private void setupBaseConfigSet(String baseConfigSetName, Map 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 @@ private long uploadBadConfigSet(String configSetName, String suffix, String user // 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, @@ -1587,7 +1587,7 @@ private long uploadSingleConfigSetFile( 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 @@ -1640,7 +1640,7 @@ private long uploadSingleConfigSetFile( 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 @@ private File createTempZipFile(String directoryPath) { 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 @@ private File createTempZipFileWithForbiddenTypes(String file) { 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 @@ private static Object getObjectByPath(Map root, List hierarchy) { 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 @@ private byte[] readFile(String fname) throws IOException { 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 void testCreateZkFailure() throws Exception { private void setupBaseConfigSet(String baseConfigSetName, Map 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 void testConfigSetServiceFindsConfigSets() { @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 void testConfigSetOnCoreReload() throws IOException { 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 void testConfigSetOnCoreReload() throws IOException { // 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 void testDeleteBadCores() { 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 void testCoreInitFailuresOnReload() throws Exception { 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 void testCoreInitFailuresOnReload() throws Exception { 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 void testCoreInitFailuresOnReload() throws Exception { // ---- // 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 static ByteBuffer getFileContent(String f) throws IOException { */ 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 9016b1b46d8..72276aaffd0 100644 --- a/solr/core/src/test/org/apache/solr/handler/ReplicationTestHelper.java +++ b/solr/core/src/test/org/apache/solr/handler/ReplicationTestHelper.java @@ -97,9 +97,9 @@ public static int index(SolrClient s, Object... fields) throws Exception { * 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/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 void testRequestParams() throws Exception { @Test public void testExternalEntities() throws Exception { - String file = getFile("mailing_lists.pdf").toURI().toASCIIString(); + String file = getFile("mailing_lists.pdf").toUri().toASCIIString(); String xml = "" + 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 void testAddedMBeanDiff() throws Exception { @Test public void testXMLDiffWithExternalEntity() { - String file = getFile("mailing_lists.pdf").toURI().toASCIIString(); + String file = getFile("mailing_lists.pdf").toUri().toASCIIString(); String xml = "\n" + " cs = new ArrayList<>(); - cs.add(new ContentStreamBase.FileStream(getFile(filename).toPath())); + cs.add(new ContentStreamBase.FileStream(getFile(filename))); req.setContentStreams(cs); return h.queryAndResponse(handler, req); } finally { 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 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 static void beforeClass() throws Exception { 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 static void setupClass() throws Exception { 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..590fafdb8a7 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 static void setupClass() throws Exception { AbstractS3ClientTest.setS3ConfFile(); configureCluster(1) // nodes - .addConfig("conf1", getFile("conf/solrconfig.xml").getParentFile().toPath()) + .addConfig("conf1", getFile("conf/solrconfig.xml").toAbsolutePath()) .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 static void beforeClass() throws Exception { 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 void testBogusScriptEngine() throws Exception { 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 void testMissingScriptFile() throws Exception { 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 void testInvalidScriptFile() throws Exception { 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 void testUpdate() throws Exception { @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 = "" + " name.endsWith(".xml"))); for (File xml : xmlFiles) { diff --git a/solr/solr-ref-guide/modules/query-guide/examples/JsonRequestApiTest.java b/solr/solr-ref-guide/modules/query-guide/examples/JsonRequestApiTest.java index 104bdda783d..0f3091838a1 100644 --- a/solr/solr-ref-guide/modules/query-guide/examples/JsonRequestApiTest.java +++ b/solr/solr-ref-guide/modules/query-guide/examples/JsonRequestApiTest.java @@ -66,7 +66,7 @@ public static void setupCluster() throws Exception { ContentStreamUpdateRequest up = new ContentStreamUpdateRequest("/update"); up.setParam("collection", COLLECTION_NAME); - up.addFile(getFile("solrj/techproducts.xml").toPath(), "application/xml"); + up.addFile(getFile("solrj/techproducts.xml"), "application/xml"); up.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true); UpdateResponse updateResponse = up.process(cluster.getSolrClient()); assertEquals(0, updateResponse.getStatus()); 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 static void before() throws Exception { 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 static void setupCluster() throws Exception { .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 static void setupCluster() throws Exception { .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 static void setupCluster() throws Exception { .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 static void configureCluster() throws Exception { .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 static void setupCluster() throws Exception { .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 static void setupCluster() throws Exception { .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 static void setupCluster() throws Exception { .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 static void setupCluster() throws Exception { .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 static void setupCluster() throws Exception { .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 static void setupCluster() throws Exception { .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 static void configureCluster() throws Exception { .addConfig( "conf", getFile("solrj") - .toPath() .resolve("solr") .resolve("configsets") .resolve("streaming") diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/JsonQueryRequestFacetingIntegrationTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/JsonQueryRequestFacetingIntegrationTest.java index 7912ed858bb..bb66ef233a1 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/JsonQueryRequestFacetingIntegrationTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/JsonQueryRequestFacetingIntegrationTest.java @@ -63,7 +63,7 @@ public static void setupCluster() throws Exception { ContentStreamUpdateRequest up = new ContentStreamUpdateRequest("/update"); up.setParam("collection", COLLECTION_NAME); - up.addFile(getFile("solrj/techproducts.xml").toPath(), "application/xml"); + up.addFile(getFile("solrj/techproducts.xml"), "application/xml"); up.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true); UpdateResponse updateResponse = up.process(cluster.getSolrClient()); assertEquals(0, updateResponse.getStatus()); 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..3bc9910819b 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 Map> invertField(Map model, } /** - * 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 static File getFile(String name) { + 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 static File getFile(String name) { } 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"); } 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 @@ private void testNumberOfCommitsWithCommitAfterAdd() throws SolrServerException, .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)); From 45b27123418d536ee8e3f99eff6cbb0d8e945c0a Mon Sep 17 00:00:00 2001 From: Matthew Biscocho Date: Fri, 13 Dec 2024 08:49:35 -0500 Subject: [PATCH 04/10] More cleanup on toPath() --- .../java/org/apache/solr/core/SolrCore.java | 2 +- .../java/org/apache/solr/core/ZkContainer.java | 3 ++- .../org/apache/solr/handler/IndexFetcher.java | 2 +- .../handler/admin/ShowFileRequestHandler.java | 2 +- .../solr/rest/ManagedResourceStorage.java | 18 +++++++++++------- .../java/org/apache/solr/util/FileUtils.java | 2 +- .../solr/common/util/ContentStreamBase.java | 10 ++++++++-- .../solr/client/solrj/SolrExampleTests.java | 11 +++++------ .../impl/CloudHttp2SolrClientRetryTest.java | 1 - .../impl/TestCloudSolrClientConnections.java | 2 +- .../cloud/PerReplicaStatesIntegrationTest.java | 4 ---- .../cloud/TestCloudCollectionsListeners.java | 2 +- .../cloud/TestCollectionStateWatchers.java | 2 +- .../common/cloud/TestDocCollectionWatcher.java | 2 +- .../common/cloud/TestNodesSysPropsCacher.java | 2 +- .../java/org/apache/solr/SolrTestCaseJ4.java | 2 +- 16 files changed, 36 insertions(+), 31 deletions(-) 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 318834ffd6e..3611b943feb 100644 --- a/solr/core/src/java/org/apache/solr/core/SolrCore.java +++ b/solr/core/src/java/org/apache/solr/core/SolrCore.java @@ -3203,7 +3203,7 @@ public ValueSourceParser getValueSourceParser(String parserName) { * stopwords to ZooKeeper if running in SolrCloud mode. */ @SuppressWarnings({"unchecked", "rawtypes"}) - protected RestManager initRestManager() throws SolrException, IOException { + protected RestManager initRestManager() throws SolrException { PluginInfo restManagerPluginInfo = getSolrConfig().getPluginInfo(RestManager.class.getName()); 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 8e2a8dd597f..94ee58e8610 100644 --- a/solr/core/src/java/org/apache/solr/core/ZkContainer.java +++ b/solr/core/src/java/org/apache/solr/core/ZkContainer.java @@ -21,6 +21,7 @@ import java.io.IOException; import java.lang.invoke.MethodHandles; +import java.nio.file.Path; import java.nio.file.Paths; import java.util.List; import java.util.concurrent.ExecutorService; @@ -98,7 +99,7 @@ public void initZooKeeper(final CoreContainer cc, CloudConfig config) { new SolrZkServer( stripChroot(zkRun), stripChroot(config.getZkHost()), - Paths.get(zkDataHome), + Path.of(zkDataHome), zkConfHome, config.getSolrHostPort()); zkServer.parseConfig(); 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 26880ea6f46..f970726ab7d 100644 --- a/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java +++ b/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java @@ -1477,7 +1477,7 @@ private List makeTmpConfDirFileList(Path dir) { * The conf files are copied to the tmp dir to the conf dir. A backup of the old file is * maintained */ - private void copyTmpConfFiles2Conf(Path tmpconfDir) throws IOException { + private void copyTmpConfFiles2Conf(Path tmpconfDir) { boolean status = false; Path confPath = solrCore.getResourceLoader().getConfigPath(); int numTempPathElements = tmpconfDir.getNameCount(); 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 918257e975d..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 @@ -195,7 +195,7 @@ private void showFromZooKeeper( } // Return the file indicated (or the directory listing) from the local file system. - private void showFromFileSystem(SolrQueryRequest req, SolrQueryResponse rsp) throws IOException { + private void showFromFileSystem(SolrQueryRequest req, SolrQueryResponse rsp) { Path admin = getAdminFileFromFileSystem(req, rsp, hiddenFiles); if (admin == null) { // exception already recorded 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 3942835a1a0..19d7e6f4731 100644 --- a/solr/core/src/java/org/apache/solr/rest/ManagedResourceStorage.java +++ b/solr/core/src/java/org/apache/solr/rest/ManagedResourceStorage.java @@ -69,8 +69,7 @@ public abstract class ManagedResourceStorage { public static interface StorageIO { String getInfo(); - void configure(SolrResourceLoader loader, NamedList initArgs) - throws SolrException, IOException; + void configure(SolrResourceLoader loader, NamedList initArgs) throws SolrException; boolean exists(String storedResourceId) throws IOException; @@ -89,8 +88,7 @@ void configure(SolrResourceLoader loader, NamedList initArgs) * running in cloud mode as well as initArgs. */ public static StorageIO newStorageIO( - String collection, SolrResourceLoader resourceLoader, NamedList initArgs) - throws IOException { + String collection, SolrResourceLoader resourceLoader, NamedList initArgs) { StorageIO storageIO; SolrZkClient zkClient = null; @@ -167,7 +165,7 @@ public static class FileStorageIO implements StorageIO { @Override public void configure(SolrResourceLoader loader, NamedList initArgs) - throws SolrException, IOException { + throws SolrException { String storageDirArg = initArgs.get(STORAGE_DIR_INIT_ARG); if (storageDirArg == null || storageDirArg.trim().length() == 0) @@ -175,7 +173,14 @@ public void configure(SolrResourceLoader loader, NamedList initArgs) "Required configuration parameter '" + STORAGE_DIR_INIT_ARG + "' not provided!"); Path dir = Path.of(storageDirArg); - if (Files.isDirectory(dir)) Files.createDirectories(dir); + 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.toAbsolutePath().toString(); log.info("File-based storage initialized to use dir: {}", storageDir); @@ -206,7 +211,6 @@ public boolean delete(String storedResourceId) throws IOException { // TODO: this interface should probably be changed, this simulates the old behavior, // only throw security exception, just return false otherwise private boolean deleteIfFile(Path p) { - // File f = p.toFile(); if (!Files.isRegularFile(p)) { return false; } 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 a63d0c43274..ca3e12487de 100644 --- a/solr/core/src/java/org/apache/solr/util/FileUtils.java +++ b/solr/core/src/java/org/apache/solr/util/FileUtils.java @@ -55,7 +55,7 @@ public static void copyFile(Path src, Path destination) throws IOException { * @throws IOException if the file could not be synced */ public static void sync(Path fullFile) throws IOException { - if (fullFile == null || !Files.exists(fullFile)) + if (fullFile == null || Files.notExists(fullFile)) throw new FileNotFoundException("File does not exist " + fullFile); boolean success = false; 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 823fafdf1c3..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 @@ -37,6 +37,7 @@ 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 @@ -168,12 +169,17 @@ public InputStream getStream() throws IOException { public static class FileStream extends ContentStreamBase { private final Path file; - public FileStream(Path f) throws IOException { + public FileStream(Path f) { file = f; contentType = null; // ?? name = file.getFileName().toString(); - size = Files.size(file); + 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(); } 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 4386d723581..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 void testContentStreamRequest() throws Exception { 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}; @@ -985,8 +985,7 @@ public void testStreamingRequest() throws Exception { assertEquals(0, rsp.getResults().getNumFound()); NamedList 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 void testMultiContentWriterRequest() throws Exception { } 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); } } @@ -1033,8 +1032,8 @@ public void testMultiContentStreamRequest() throws Exception { assertEquals(0, rsp.getResults().getNumFound()); ContentStreamUpdateRequest up = new ContentStreamUpdateRequest("/update"); - up.addFile(getFile("solrj/docs1.xml").toPath(), "application/xml"); // 2 - up.addFile(getFile("solrj/docs2.xml").toPath(), "application/xml"); // 3 + up.addFile(getFile("solrj/docs1.xml"), "application/xml"); // 2 + up.addFile(getFile("solrj/docs2.xml"), "application/xml"); // 3 up.setParam("a", "\u1234"); up.setParam(CommonParams.HEADER_ECHO_PARAMS, CommonParams.EchoParamStyle.ALL.toString()); up.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true); 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 static void setupCluster() throws Exception { .addConfig( "conf", getFile("solrj") - .toPath() .resolve("solr") .resolve("configsets") .resolve("streaming") 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 void testCloudClientCanConnectAfterClusterComesUp() throws Exception { @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/common/cloud/PerReplicaStatesIntegrationTest.java b/solr/solrj/src/test/org/apache/solr/common/cloud/PerReplicaStatesIntegrationTest.java index 21a5307eb67..31ae432dcf8 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 void testPerReplicaStateCollection() throws Exception { .addConfig( "conf", getFile("solrj") - .toPath() .resolve("solr") .resolve("configsets") .resolve("streaming") @@ -133,7 +132,6 @@ public void testRestart() throws Exception { .addConfig( "conf", getFile("solrj") - .toPath() .resolve("solr") .resolve("configsets") .resolve("streaming") @@ -242,7 +240,6 @@ public void testMultipleTransitions() throws Exception { .addConfig( "conf", getFile("solrj") - .toPath() .resolve("solr") .resolve("configsets") .resolve("streaming") @@ -307,7 +304,6 @@ public void testZkNodeVersions() throws Exception { .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 static void shutdownBackgroundExecutors() { @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 void testSysProps() throws Exception { 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/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java index 3bc9910819b..d5d630333a4 100644 --- a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java +++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java @@ -2158,7 +2158,7 @@ public static String TEST_HOME() { } public static Path TEST_PATH() { - return getFile("solr/collection1"); + return getFile("solr/collection1").getParent(); } public static Path TEST_COLL1_CONF() { From f851b1f7c2b9c1fe7fd2e0536bbbd16658357b94 Mon Sep 17 00:00:00 2001 From: Matthew Biscocho Date: Fri, 13 Dec 2024 09:45:37 -0500 Subject: [PATCH 05/10] Fixed tests from wrong Path conversion logic --- .../src/java/org/apache/solr/handler/IndexFetcher.java | 4 ++-- .../java/org/apache/solr/rest/ManagedResourceStorage.java | 2 +- .../core/src/test/org/apache/solr/util/FileUtilsTest.java | 8 ++++---- .../solr/client/solrj/MergeIndexesExampleTestBase.java | 2 +- .../apache/solr/client/solrj/TestLBHttpSolrClient.java | 7 +++---- .../embedded/AbstractEmbeddedSolrServerTestCase.java | 2 +- .../solrj/impl/CloudHttp2SolrClientBuilderTest.java | 1 - .../solr/client/solrj/impl/CloudHttp2SolrClientTest.java | 1 - .../solr/client/solrj/impl/CloudSolrClientRetryTest.java | 1 - .../client/solrj/impl/CloudSolrClientRoutingTest.java | 2 +- .../solr/client/solrj/impl/CloudSolrClientTest.java | 1 - .../solr/client/solrj/impl/ClusterStateProviderTest.java | 1 - .../solr/client/solrj/impl/HttpClusterStateSSLTest.java | 1 - .../solrj/impl/LBHttp2SolrClientIntegrationTest.java | 7 +++---- .../solrj/impl/SendUpdatesToLeadersOverrideTest.java | 7 +------ .../org/apache/solr/client/solrj/request/SchemaTest.java | 3 ++- .../apache/solr/client/solrj/request/SolrPingTest.java | 2 +- .../apache/solr/client/solrj/request/TestV2Request.java | 2 +- .../json/DirectJsonQueryRequestFacetingEmbeddedTest.java | 2 +- .../DirectJsonQueryRequestFacetingIntegrationTest.java | 2 +- .../request/json/JsonQueryRequestIntegrationTest.java | 2 +- 21 files changed, 24 insertions(+), 36 deletions(-) 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 f970726ab7d..0edb777d1fd 100644 --- a/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java +++ b/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java @@ -1204,10 +1204,10 @@ private long downloadIndexFiles( private static Long getUsableSpace(String dir) { try { Path file = Path.of(dir); - if (Files.exists(file)) { + if (Files.notExists(file)) { file = file.getParent(); // this is not a disk directory. so just pretend that there is enough space - if (Files.exists(file)) { + if (Files.notExists(file)) { return Long.MAX_VALUE; } } 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 19d7e6f4731..46b5a2a23d4 100644 --- a/solr/core/src/java/org/apache/solr/rest/ManagedResourceStorage.java +++ b/solr/core/src/java/org/apache/solr/rest/ManagedResourceStorage.java @@ -173,7 +173,7 @@ public void configure(SolrResourceLoader loader, NamedList initArgs) "Required configuration parameter '" + STORAGE_DIR_INIT_ARG + "' not provided!"); Path dir = Path.of(storageDirArg); - if (Files.isDirectory(dir)) { + if (!Files.isDirectory(dir)) { try { Files.createDirectories(dir); } catch (IOException e) { 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 98e363fae26..d0916c83752 100644 --- a/solr/core/src/test/org/apache/solr/util/FileUtilsTest.java +++ b/solr/core/src/test/org/apache/solr/util/FileUtilsTest.java @@ -25,11 +25,11 @@ public class FileUtilsTest extends SolrTestCase { @Test public void testResolve() { - String cwd = new File(".").getAbsolutePath(); - assertEquals(new File("conf/data"), FileUtils.resolvePath(Path.of("conf"), "data")); + String cwd = Path.of(".").toAbsolutePath().toString(); + assertEquals(Path.of("conf/data"), FileUtils.resolvePath(Path.of("conf"), "data")); assertEquals( - new File(cwd + "/conf/data"), FileUtils.resolvePath(Path.of(cwd + "/conf"), "data")); - assertEquals(new File(cwd + "/data"), FileUtils.resolvePath(Path.of("conf"), cwd + "/data")); + Path.of(cwd + "/conf/data"), FileUtils.resolvePath(Path.of(cwd + "/conf"), "data")); + assertEquals(Path.of(cwd + "/data"), FileUtils.resolvePath(Path.of("conf"), cwd + "/data")); } @Test 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/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 void setUp() throws Exception { 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 static void setupCluster() throws Exception { .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/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 static void setupCluster() throws Exception { .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 static void setupCluster() throws Exception { .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 static void setupCluster() throws Exception { .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 static void setupCluster() throws Exception { .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 static void setupClusterWithSSL() throws Exception { .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 void setUp() throws Exception { 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 static void setupCluster() throws Exception { 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/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 @@ private static SchemaRequest.AddFieldType createFieldTypeRequest(String fieldTyp 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 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/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/client/solrj/request/json/DirectJsonQueryRequestFacetingEmbeddedTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/DirectJsonQueryRequestFacetingEmbeddedTest.java index b009cb15333..8103dda8e19 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/DirectJsonQueryRequestFacetingEmbeddedTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/DirectJsonQueryRequestFacetingEmbeddedTest.java @@ -62,7 +62,7 @@ public static void beforeClass() throws Exception { ContentStreamUpdateRequest up = new ContentStreamUpdateRequest("/update"); up.setParam("collection", COLLECTION_NAME); - up.addFile(getFile("solrj/techproducts.xml").toPath(), "application/xml"); + up.addFile(getFile("solrj/techproducts.xml"), "application/xml"); up.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true); UpdateResponse updateResponse = up.process(client); assertEquals(0, updateResponse.getStatus()); diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/DirectJsonQueryRequestFacetingIntegrationTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/DirectJsonQueryRequestFacetingIntegrationTest.java index 361b541b9fc..7663e44852d 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/DirectJsonQueryRequestFacetingIntegrationTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/DirectJsonQueryRequestFacetingIntegrationTest.java @@ -56,7 +56,7 @@ public static void setupCluster() throws Exception { ContentStreamUpdateRequest up = new ContentStreamUpdateRequest("/update"); up.setParam("collection", COLLECTION_NAME); - up.addFile(getFile("solrj/techproducts.xml").toPath(), "application/xml"); + up.addFile(getFile("solrj/techproducts.xml"), "application/xml"); up.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true); UpdateResponse updateResponse = up.process(cluster.getSolrClient()); assertEquals(0, updateResponse.getStatus()); diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/JsonQueryRequestIntegrationTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/JsonQueryRequestIntegrationTest.java index beea0ae76d7..203f69189ce 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/JsonQueryRequestIntegrationTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/request/json/JsonQueryRequestIntegrationTest.java @@ -58,7 +58,7 @@ public static void setupCluster() throws Exception { ContentStreamUpdateRequest up = new ContentStreamUpdateRequest("/update"); up.setParam("collection", COLLECTION_NAME); - up.addFile(getFile("solrj/books.csv").toPath(), "application/csv"); + up.addFile(getFile("solrj/books.csv"), "application/csv"); up.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true); UpdateResponse updateResponse = up.process(cluster.getSolrClient()); assertEquals(0, updateResponse.getStatus()); From e7f9be145f5fbe6994ace6aab452604baef2a041 Mon Sep 17 00:00:00 2001 From: Matthew Biscocho Date: Fri, 13 Dec 2024 09:59:24 -0500 Subject: [PATCH 06/10] Fix S3InstallShardTest --- .../src/test/org/apache/solr/s3/S3InstallShardTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 590fafdb8a7..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 static void setupClass() throws Exception { AbstractS3ClientTest.setS3ConfFile(); configureCluster(1) // nodes - .addConfig("conf1", getFile("conf/solrconfig.xml").toAbsolutePath()) + .addConfig("conf1", getFile("conf/solrconfig.xml").getParent()) .withSolrXml( SOLR_XML .replace("BUCKET", BUCKET_NAME) From 5035793b4c6db32484ed353486f85953a12ce02b Mon Sep 17 00:00:00 2001 From: Matthew Biscocho Date: Fri, 13 Dec 2024 14:34:32 -0500 Subject: [PATCH 07/10] MiniClusterState change to Path completely --- .../org/apache/solr/bench/MiniClusterState.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) 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 607cda932be..39c1745d387 100755 --- a/solr/benchmark/src/java/org/apache/solr/bench/MiniClusterState.java +++ b/solr/benchmark/src/java/org/apache/solr/bench/MiniClusterState.java @@ -556,7 +556,7 @@ public static Path getFile(String name) { MiniClusterState.class.getClassLoader().getResource(name.replace(File.separatorChar, '/')); if (url != null) { try { - return new File(url.toURI()).toPath(); + return Path.of(url.toURI()); } catch (Exception e) { throw new RuntimeException( "Resource was found on classpath, but cannot be resolved to a " @@ -564,13 +564,13 @@ public static Path getFile(String name) { + name); } } - File file = new File(name); - if (file.exists()) { - return file.toPath(); + Path file = Path.of(name); + if (Files.exists(file)) { + return file; } else { - file = new File("../../../", name); - if (file.exists()) { - return file.toPath(); + file = Path.of("../../../", name); + if (Files.exists(file)) { + return file; } } throw new RuntimeException( From 1c1a3154f17f045f94cbc8d80261f2e23091fe22 Mon Sep 17 00:00:00 2001 From: Matthew Biscocho Date: Mon, 16 Dec 2024 11:50:12 -0500 Subject: [PATCH 08/10] Address PR comments --- .../solr/core/StandardDirectoryFactory.java | 2 +- .../org/apache/solr/handler/IndexFetcher.java | 55 +------------------ .../solr/rest/ManagedResourceStorage.java | 2 +- .../org/apache/solr/update/UpdateLog.java | 14 +++-- .../java/org/apache/solr/util/FileUtils.java | 22 -------- .../org/apache/solr/cli/PostToolTest.java | 2 + .../solr/handler/ReplicationTestHelper.java | 3 +- .../handler/TestReplicationHandlerBackup.java | 3 +- .../apache/solr/handler/TestRestoreCore.java | 3 +- .../schema/ExternalFileFieldSortTest.java | 4 +- .../org/apache/solr/util/FileUtilsTest.java | 9 --- .../TestFoldingMultitermExtrasQuery.java | 13 +++-- .../schema/TestICUCollationFieldOptions.java | 12 ++-- ...ctNamedEntitiesUpdateProcessorFactory.java | 12 ++-- .../clustering/ClusteringComponentTest.java | 10 ++-- .../request/TestConfigSetAdminRequest.java | 8 +-- 16 files changed, 51 insertions(+), 123 deletions(-) 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 611240273eb..5d02de67aa9 100644 --- a/solr/core/src/java/org/apache/solr/core/StandardDirectoryFactory.java +++ b/solr/core/src/java/org/apache/solr/core/StandardDirectoryFactory.java @@ -77,7 +77,7 @@ protected LockFactory createLockFactory(String rawLockType) throws IOException { @Override public String normalize(String path) throws IOException { - return super.normalize(Path.of(path).toAbsolutePath().toString()); + return super.normalize(Path.of(path).toAbsolutePath().normalize().toString()); } @Override 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 ea1178b4df4..0e8f360fe25 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.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.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; @@ -1514,52 +1511,6 @@ private void copyTmpConfFiles2Conf(Path tmpconfDir) { } } - /** - * 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(Path tmpTlogDir) { - Path tlogDir = - FileSystems.getDefault().getPath(solrCore.getUpdateHandler().getUpdateLog().getTlogDir()); - Path backupTlogDir = - FileSystems.getDefault() - .getPath( - tlogDir.getParent().toAbsolutePath().toString(), - tmpTlogDir.getFileName().toString()); - - 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.getFileName().toString()); - 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); } @@ -1602,7 +1553,7 @@ private Collection> getModifiedConfFiles( 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); return true; @@ -2038,7 +1989,7 @@ private static class LocalFsFile implements FileInterface { Path file; LocalFsFile(Path dir, String saveAs) throws IOException { - this.file = Path.of(copy2Dir.toString(), saveAs); + this.file = dir.resolve(saveAs); Path parentDir = this.file.getParent(); if (Files.notExists(parentDir)) { @@ -2057,7 +2008,7 @@ private static class LocalFsFile implements FileInterface { @Override public void sync() throws IOException { - FileUtils.sync(file); + org.apache.lucene.util.IOUtils.fsync(file, false); } @Override 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 46b5a2a23d4..038b9c5f421 100644 --- a/solr/core/src/java/org/apache/solr/rest/ManagedResourceStorage.java +++ b/solr/core/src/java/org/apache/solr/rest/ManagedResourceStorage.java @@ -188,7 +188,7 @@ public void configure(SolrResourceLoader loader, NamedList initArgs) @Override public boolean exists(String storedResourceId) throws IOException { - return (Files.exists(Path.of(storageDir, storedResourceId))); + return Files.exists(Path.of(storageDir, storedResourceId)); } @Override 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 8516ec54989..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,7 +24,6 @@ import com.codahale.metrics.Gauge; import com.codahale.metrics.Meter; import java.io.Closeable; -import java.io.FileNotFoundException; import java.io.IOException; import java.io.UncheckedIOException; import java.lang.invoke.MethodHandles; @@ -733,12 +732,15 @@ private boolean updateFromOldTlogs(UpdateCommand cmd) { public String[] getLogList(Path directory) { final String prefix = TLOG_NAME + '.'; - String[] names = directory.toFile().list((dir, name) -> name.startsWith(prefix)); - if (names == null) { - throw new RuntimeException(new FileNotFoundException(directory.toFile().getAbsolutePath())); + try (Stream 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 ca3e12487de..a76dab57af7 100644 --- a/solr/core/src/java/org/apache/solr/util/FileUtils.java +++ b/solr/core/src/java/org/apache/solr/util/FileUtils.java @@ -16,12 +16,9 @@ */ package org.apache.solr.util; -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; @@ -29,25 +26,6 @@ /** */ public class FileUtils { - /** - * Resolves a path relative a base directory. - * - *

This method does what "new File(base,path)" Should 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 Path resolvePath(Path base, String path) { - Path r = Path.of(path); - return r.isAbsolute() ? r : Path.of(base.toString(), path); - } - - public static void copyFile(Path src, Path destination) throws IOException { - try (FileChannel in = new FileInputStream(src.toFile()).getChannel(); - FileChannel out = new FileOutputStream(destination.toFile()).getChannel()) { - in.transferTo(0, in.size(), out); - } - } - /** * Copied from Lucene's FSDirectory.fsync(String) * 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 da4fce970aa..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,6 +294,7 @@ public void testDoFilesMode() throws IOException { postTool.recursive = 0; postTool.dryRun = true; postTool.solrUpdateUrl = URI.create("http://localhost:8983/solr/fake/update"); + // 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); @@ -316,6 +317,7 @@ public void testRecursionAppliesToFilesMode() throws IOException { postTool.recursive = 1; // This is the default postTool.dryRun = true; postTool.solrUpdateUrl = URI.create("http://localhost:8983/solr/fake/update"); + // 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/handler/ReplicationTestHelper.java b/solr/core/src/test/org/apache/solr/handler/ReplicationTestHelper.java index 72276aaffd0..2efe775a58d 100644 --- a/solr/core/src/test/org/apache/solr/handler/ReplicationTestHelper.java +++ b/solr/core/src/test/org/apache/solr/handler/ReplicationTestHelper.java @@ -43,7 +43,6 @@ 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; @@ -55,7 +54,7 @@ public final class ReplicationTestHelper { "solr" + File.separator + "collection1" + File.separator + "conf" + File.separator; public static JettySolrRunner createAndStartJetty(SolrInstance instance) throws Exception { - FileUtils.copyFile( + Files.copy( Path.of(SolrTestCaseJ4.TEST_HOME(), "solr.xml"), Path.of(instance.getHomeDir(), "solr.xml")); Properties nodeProperties = new Properties(); 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 3f8c03a9595..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.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,7 +71,7 @@ public class TestReplicationHandlerBackup extends SolrJettyTestBase { private static JettySolrRunner createAndStartJetty(ReplicationTestHelper.SolrInstance instance) throws Exception { - FileUtils.copyFile( + Files.copy( Path.of(SolrTestCaseJ4.TEST_HOME(), "solr.xml"), Path.of(instance.getHomeDir(), "solr.xml")); Properties nodeProperties = new Properties(); 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 8c2d4390c5a..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.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,7 +56,7 @@ public class TestRestoreCore extends SolrJettyTestBase { private static JettySolrRunner createAndStartJetty(ReplicationTestHelper.SolrInstance instance) throws Exception { - FileUtils.copyFile( + Files.copy( Path.of(SolrTestCaseJ4.TEST_HOME(), "solr.xml"), Path.of(instance.getHomeDir(), "solr.xml")); Properties nodeProperties = new Properties(); 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 2cd09af64cc..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 @@ public class ExternalFileFieldSortTest extends SolrTestCaseJ4 { static void updateExternalFile() throws IOException { - final String testHome = SolrTestCaseJ4.getFile("solr/collection1").getParent().toString(); + 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/util/FileUtilsTest.java b/solr/core/src/test/org/apache/solr/util/FileUtilsTest.java index d0916c83752..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 @@ public class FileUtilsTest extends SolrTestCase { - @Test - public void testResolve() { - String cwd = Path.of(".").toAbsolutePath().toString(); - assertEquals(Path.of("conf/data"), FileUtils.resolvePath(Path.of("conf"), "data")); - assertEquals( - Path.of(cwd + "/conf/data"), FileUtils.resolvePath(Path.of(cwd + "/conf"), "data")); - assertEquals(Path.of(cwd + "/data"), FileUtils.resolvePath(Path.of("conf"), cwd + "/data")); - } - @Test public void testDetectsPathEscape() { final var parent = Path.of("."); 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 2f97e51145a..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 String getCoreName() { @BeforeClass public static void beforeTests() throws Exception { - File testHome = createTempDir().toFile(); - FileUtils.copyDirectory(getFile("analysis-extras/solr").toFile(), 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/TestICUCollationFieldOptions.java b/solr/modules/analysis-extras/src/test/org/apache/solr/schema/TestICUCollationFieldOptions.java index 119e821aea1..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 @@ public class TestICUCollationFieldOptions extends SolrTestCaseJ4 { @BeforeClass public static void beforeClass() throws Exception { - File testHome = createTempDir().toFile(); - FileUtils.copyDirectory(getFile("analysis-extras/solr").toFile(), 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 77bce084411..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").toFile(), 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/ClusteringComponentTest.java b/solr/modules/clustering/src/test/org/apache/solr/handler/clustering/ClusteringComponentTest.java index f076f6f4498..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.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").toFile(), 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/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 eb88caee5ae..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,14 +34,14 @@ public void testNoAction() { @Test public void testUpload() throws Exception { - final File tmpFile = createTempFile().toFile(); + final Path tmpFile = createTempFile(); ConfigSetAdminRequest.Upload upload = new ConfigSetAdminRequest.Upload(); verifyException(upload, "ConfigSet"); upload.setConfigSetName("name"); verifyException(upload, "There must be a ContentStream"); - upload.setUploadFile(tmpFile.toPath(), "application/zip"); + upload.setUploadFile(tmpFile, "application/zip"); assertEquals(1, upload.getContentStreams().size()); assertEquals( @@ -52,7 +52,7 @@ public void testUpload() throws Exception { assertNull(upload.getParams().get(ConfigSetParams.CLEANUP)); upload - .setUploadFile(tmpFile.toPath(), "application/xml") + .setUploadFile(tmpFile, "application/xml") .setFilePath("solrconfig.xml") .setOverwrite(true); From 4e43fedd3a68cb5e5ad871966b881c20493d23cc Mon Sep 17 00:00:00 2001 From: Matthew Biscocho Date: Mon, 16 Dec 2024 16:07:10 -0500 Subject: [PATCH 09/10] Remove sync in FileUtils --- .../org/apache/solr/handler/IndexFetcher.java | 2 +- .../java/org/apache/solr/util/FileUtils.java | 35 ------------------- 2 files changed, 1 insertion(+), 36 deletions(-) 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 0e8f360fe25..e6025b9b127 100644 --- a/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java +++ b/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java @@ -1989,7 +1989,7 @@ private static class LocalFsFile implements FileInterface { Path file; LocalFsFile(Path dir, String saveAs) throws IOException { - this.file = dir.resolve(saveAs); + this.file = dir.resolve(saveAs); Path parentDir = this.file.getParent(); if (Files.notExists(parentDir)) { 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 a76dab57af7..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,9 +16,7 @@ */ package org.apache.solr.util; -import java.io.FileNotFoundException; import java.io.IOException; -import java.io.RandomAccessFile; import java.nio.file.Files; import java.nio.file.Path; import org.apache.commons.io.FileExistsException; @@ -26,39 +24,6 @@ /** */ public class FileUtils { - /** - * 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(Path fullFile) throws IOException { - if (fullFile == null || Files.notExists(fullFile)) - 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.toFile(), "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 Files.exists(Path.of(filePathString)); } From 02201b4bd3ad4d15cd0fee6aca1cd2c3bd527893 Mon Sep 17 00:00:00 2001 From: Eric Pugh Date: Thu, 19 Dec 2024 11:18:51 -0500 Subject: [PATCH 10/10] Track change --- solr/CHANGES.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 752c2670887..6e02eda65f1 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 ---------------------