Skip to content

Commit b891851

Browse files
SOLR-18057: Prefer Path.resolve over Path.of for derived paths (#4174)
Co-authored-by: Kamlendra <kamlendrachauhan21@gmail.com>
1 parent 570b198 commit b891851

9 files changed

Lines changed: 40 additions & 38 deletions

File tree

solr/core/src/test/org/apache/solr/TestCustomCoreProperties.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ public static void beforeClass() throws Exception {
4949

5050
Files.createDirectories(confDir);
5151

52-
String srcDir = TEST_HOME() + "/collection1/conf";
53-
Files.copy(Path.of(srcDir, "schema-tiny.xml"), confDir.resolve("schema.xml"));
54-
Files.copy(Path.of(srcDir, "solrconfig-coreproperties.xml"), confDir.resolve("solrconfig.xml"));
52+
Path srcDir = TEST_HOME().resolve("collection1").resolve("conf");
53+
Files.copy(srcDir.resolve("schema-tiny.xml"), confDir.resolve("schema.xml"));
54+
Files.copy(srcDir.resolve("solrconfig-coreproperties.xml"), confDir.resolve("solrconfig.xml"));
5555
Files.copy(
56-
Path.of(srcDir, "solrconfig.snippet.randomindexconfig.xml"),
56+
srcDir.resolve("solrconfig.snippet.randomindexconfig.xml"),
5757
confDir.resolve("solrconfig.snippet.randomindexconfig.xml"));
5858

5959
Properties p = new Properties();

solr/core/src/test/org/apache/solr/core/TestCoreDiscovery.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,12 @@ private void addCoreWithProps(String name, Properties stockProps) throws Excepti
104104
}
105105

106106
private void addConfFiles(Path confDir) throws Exception {
107-
String top = SolrTestCaseJ4.TEST_HOME() + "/collection1/conf";
107+
Path top = SolrTestCaseJ4.TEST_HOME().resolve("collection1").resolve("conf");
108108
Files.createDirectories(confDir);
109-
Files.copy(Path.of(top, "schema-tiny.xml"), confDir.resolve("schema-tiny.xml"));
110-
Files.copy(Path.of(top, "solrconfig-minimal.xml"), confDir.resolve("solrconfig-minimal.xml"));
109+
Files.copy(top.resolve("schema-tiny.xml"), confDir.resolve("schema-tiny.xml"));
110+
Files.copy(top.resolve("solrconfig-minimal.xml"), confDir.resolve("solrconfig-minimal.xml"));
111111
Files.copy(
112-
Path.of(top, "solrconfig.snippet.randomindexconfig.xml"),
112+
top.resolve("solrconfig.snippet.randomindexconfig.xml"),
113113
confDir.resolve("solrconfig.snippet.randomindexconfig.xml"));
114114
}
115115

solr/core/src/test/org/apache/solr/core/TestLazyCores.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -416,13 +416,13 @@ private CoreContainer initGoodAndBad(
416416
}
417417

418418
// Collect the files that we'll write to the config directories.
419-
String top = SolrTestCaseJ4.TEST_HOME() + "/collection1/conf";
420-
String min_schema = Files.readString(Path.of(top, "schema-tiny.xml"), StandardCharsets.UTF_8);
419+
Path top = SolrTestCaseJ4.TEST_HOME().resolve("collection1").resolve("conf");
420+
String min_schema = Files.readString(top.resolve("schema-tiny.xml"), StandardCharsets.UTF_8);
421421
String min_config =
422-
Files.readString(Path.of(top, "solrconfig-minimal.xml"), StandardCharsets.UTF_8);
422+
Files.readString(top.resolve("solrconfig-minimal.xml"), StandardCharsets.UTF_8);
423423
String rand_snip =
424424
Files.readString(
425-
Path.of(top, "solrconfig.snippet.randomindexconfig.xml"), StandardCharsets.UTF_8);
425+
top.resolve("solrconfig.snippet.randomindexconfig.xml"), StandardCharsets.UTF_8);
426426

427427
// Now purposely mess up the config files, introducing stupid syntax errors.
428428
String bad_config = min_config.replace("<requestHandler", "<reqsthalr");
@@ -449,9 +449,8 @@ private CoreContainer initGoodAndBad(
449449
private void copyGoodConf(String coreName, String srcName, String dstName) throws IOException {
450450
Path coreRoot = solrHomeDirectory.resolve(coreName);
451451
Path subHome = coreRoot.resolve("conf");
452-
String top = SolrTestCaseJ4.TEST_HOME() + "/collection1/conf";
453-
Files.copy(
454-
Path.of(top, srcName), subHome.resolve(dstName), StandardCopyOption.REPLACE_EXISTING);
452+
Path top = SolrTestCaseJ4.TEST_HOME().resolve("collection1").resolve("conf");
453+
Files.copy(top.resolve(srcName), subHome.resolve(dstName), StandardCopyOption.REPLACE_EXISTING);
455454
}
456455

457456
// If ok==true, we shouldn't be seeing any failure cases.

solr/core/src/test/org/apache/solr/handler/ReplicationTestHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,8 @@ public void setUp() throws Exception {
299299
SolrTestCaseJ4.writeCoreProperties(
300300
homeDir.resolve("collection1"), props, "TestReplicationHandler");
301301

302-
dataDir = Path.of(homeDir + "/collection1", "data");
303-
confDir = Path.of(homeDir + "/collection1", "conf");
302+
dataDir = homeDir.resolve("collection1").resolve("data");
303+
confDir = homeDir.resolve("collection1").resolve("conf");
304304

305305
Files.createDirectories(homeDir);
306306
Files.createDirectories(dataDir);

solr/core/src/test/org/apache/solr/handler/admin/CoreAdminCreateDiscoverTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ private static void setupCore(String coreName) throws IOException {
6868
Files.createDirectories(subHome);
6969

7070
// Be sure we pick up sysvars when we create this
71-
String srcDir = SolrTestCaseJ4.TEST_HOME() + "/collection1/conf";
72-
Files.copy(Path.of(srcDir, "schema-tiny.xml"), subHome.resolve("schema_ren.xml"));
73-
Files.copy(Path.of(srcDir, "solrconfig-minimal.xml"), subHome.resolve("solrconfig_ren.xml"));
71+
Path srcDir = SolrTestCaseJ4.TEST_HOME().resolve("collection1").resolve("conf");
72+
Files.copy(srcDir.resolve("schema-tiny.xml"), subHome.resolve("schema_ren.xml"));
73+
Files.copy(srcDir.resolve("solrconfig-minimal.xml"), subHome.resolve("solrconfig_ren.xml"));
7474

7575
Files.copy(
76-
Path.of(srcDir, "solrconfig.snippet.randomindexconfig.xml"),
76+
srcDir.resolve("solrconfig.snippet.randomindexconfig.xml"),
7777
subHome.resolve("solrconfig.snippet.randomindexconfig.xml"));
7878
}
7979

solr/core/src/test/org/apache/solr/handler/admin/CoreAdminHandlerTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ public void testCreateWithSysVars() throws Exception {
7777
Files.createDirectories(subHome);
7878

7979
// Be sure we pick up sysvars when we create this
80-
String srcDir = SolrTestCaseJ4.TEST_HOME() + "/collection1/conf";
81-
Files.copy(Path.of(srcDir, "schema-tiny.xml"), subHome.resolve("schema_ren.xml"));
82-
Files.copy(Path.of(srcDir, "solrconfig-minimal.xml"), subHome.resolve("solrconfig_ren.xml"));
80+
Path srcDir = SolrTestCaseJ4.TEST_HOME().resolve("collection1").resolve("conf");
81+
Files.copy(srcDir.resolve("schema-tiny.xml"), subHome.resolve("schema_ren.xml"));
82+
Files.copy(srcDir.resolve("solrconfig-minimal.xml"), subHome.resolve("solrconfig_ren.xml"));
8383
Files.copy(
84-
Path.of(srcDir, "solrconfig.snippet.randomindexconfig.xml"),
84+
srcDir.resolve("solrconfig.snippet.randomindexconfig.xml"),
8585
subHome.resolve("solrconfig.snippet.randomindexconfig.xml"));
8686

8787
final CoreContainer cores = h.getCoreContainer();
@@ -475,9 +475,9 @@ public void testDeleteInstanceDirAfterCreateFailure() throws Exception {
475475
}
476476

477477
Path subHome = solrHomeDirectory.resolve("corex").resolve("conf");
478-
String top = SolrTestCaseJ4.TEST_HOME() + "/collection1/conf";
478+
Path top = SolrTestCaseJ4.TEST_HOME().resolve("collection1").resolve("conf");
479479
Files.copy(
480-
Path.of(top, "bad-error-solrconfig.xml"),
480+
top.resolve("bad-error-solrconfig.xml"),
481481
subHome.resolve("solrconfig.xml"),
482482
StandardCopyOption.REPLACE_EXISTING);
483483

solr/core/src/test/org/apache/solr/response/TestRawTransformer.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ private static void initStandalone() throws Exception {
8080
final Path collDir = homeDir.resolve("collection1");
8181
final Path confDir = collDir.resolve("conf");
8282
Files.createDirectories(confDir);
83-
String src_dir = TEST_HOME() + "/collection1/conf";
84-
Files.copy(Path.of(src_dir, "schema_latest.xml"), confDir.resolve("schema.xml"));
85-
Files.copy(Path.of(src_dir, "solrconfig-minimal.xml"), confDir.resolve("solrconfig.xml"));
83+
Path srcDir = TEST_HOME().resolve("collection1").resolve("conf");
84+
Files.copy(srcDir.resolve("schema_latest.xml"), confDir.resolve("schema.xml"));
85+
Files.copy(srcDir.resolve("solrconfig-minimal.xml"), confDir.resolve("solrconfig.xml"));
8686
for (String file :
8787
new String[] {
8888
"solrconfig.snippet.randomindexconfig.xml",
@@ -92,7 +92,7 @@ private static void initStandalone() throws Exception {
9292
"currency.xml",
9393
"enumsConfig.xml"
9494
}) {
95-
Files.copy(Path.of(src_dir, file), confDir.resolve(file));
95+
Files.copy(srcDir.resolve(file), confDir.resolve(file));
9696
}
9797
Files.createFile(collDir.resolve("core.properties"));
9898
JSR =

solr/core/src/test/org/apache/solr/schema/TestBinaryField.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ public static void beforeTest() throws Exception {
5252
copyMinConf(collDir, "name=collection1\n", "solrconfig-basic.xml");
5353

5454
// Copy the custom schema for binary field tests
55-
String sourceConfDir = TEST_HOME() + "/collection1/conf";
55+
Path sourceConfDir = TEST_HOME().resolve("collection1").resolve("conf");
5656
Files.copy(
57-
Path.of(sourceConfDir, "schema-binaryfield.xml"),
57+
sourceConfDir.resolve("schema-binaryfield.xml"),
5858
collDir.resolve("conf/schema.xml"),
5959
StandardCopyOption.REPLACE_EXISTING);
6060

solr/core/src/test/org/apache/solr/util/TestSystemIdResolver.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public void testResolving() throws Exception {
4343
final ResourceLoader loader =
4444
new SolrResourceLoader(testHome.resolve("collection1"), this.getClass().getClassLoader());
4545
final SystemIdResolver resolver = new SystemIdResolver(loader);
46-
final String fileUri = Path.of(testHome + "/crazy-path-to-config.xml").toUri().toASCIIString();
46+
final String fileUri = testHome.resolve("crazy-path-to-config.xml").toUri().toASCIIString();
4747

4848
assertEquals("solrres:/test.xml", SystemIdResolver.createSystemIdFromResourceName("test.xml"));
4949
assertEquals(
@@ -84,9 +84,10 @@ public void testResolving() throws Exception {
8484
"TestSystemIdResolver.class");
8585
assertEntityResolving(
8686
resolver,
87-
SystemIdResolver.createSystemIdFromResourceName(testHome + "/collection1/conf/schema.xml"),
8887
SystemIdResolver.createSystemIdFromResourceName(
89-
testHome + "/collection1/conf/solrconfig.xml"),
88+
testHome.resolve("collection1").resolve("conf").resolve("schema.xml").toString()),
89+
SystemIdResolver.createSystemIdFromResourceName(
90+
testHome.resolve("collection1").resolve("conf").resolve("solrconfig.xml").toString()),
9091
"schema.xml");
9192

9293
// if somebody uses an absolute uri (e.g., file://) we should fail resolving:
@@ -132,8 +133,10 @@ public void testUnsafeResolving() throws Exception {
132133

133134
assertEntityResolving(
134135
resolver,
135-
SystemIdResolver.createSystemIdFromResourceName(testHome + "/crazy-path-to-schema.xml"),
136-
SystemIdResolver.createSystemIdFromResourceName(testHome + "/crazy-path-to-config.xml"),
136+
SystemIdResolver.createSystemIdFromResourceName(
137+
testHome.resolve("crazy-path-to-schema.xml").toString()),
138+
SystemIdResolver.createSystemIdFromResourceName(
139+
testHome.resolve("crazy-path-to-config.xml").toString()),
137140
"crazy-path-to-schema.xml");
138141
}
139142
}

0 commit comments

Comments
 (0)