Skip to content

Commit 5ba7883

Browse files
committed
Move paths.get to path.of
1 parent 96a66ef commit 5ba7883

File tree

11 files changed

+45
-46
lines changed

11 files changed

+45
-46
lines changed

src/main/java/org/apache/ibatis/migration/commands/BaseCommand.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import java.net.URL;
2828
import java.net.URLClassLoader;
2929
import java.nio.file.Files;
30-
import java.nio.file.Paths;
30+
import java.nio.file.Path;
3131
import java.text.DecimalFormat;
3232
import java.text.ParseException;
3333
import java.text.SimpleDateFormat;
@@ -161,7 +161,7 @@ protected void copyResourceTo(String resource, File toFile, Properties variables
161161
protected void copyExternalResourceTo(String resource, File toFile, Properties variables) {
162162
printStream.println("Creating: " + toFile.getName());
163163
try {
164-
File sourceFile = Paths.get(resource).toFile();
164+
File sourceFile = Path.of(resource).toFile();
165165
copyTemplate(sourceFile, toFile, variables);
166166
} catch (Exception e) {
167167
throw new MigrationException("Error copying " + resource + " to " + toFile.getAbsolutePath() + ". Cause: " + e,
@@ -259,7 +259,7 @@ private ClassLoader getDriverClassLoader() {
259259
private File getCustomDriverPath() {
260260
String customDriverPath = environment().getDriverPath();
261261
if (customDriverPath != null && customDriverPath.length() > 0) {
262-
return Paths.get(customDriverPath).toFile();
262+
return Path.of(customDriverPath).toFile();
263263
}
264264
return options.getPaths().getDriverPath();
265265
}

src/main/java/org/apache/ibatis/migration/io/DefaultVFS.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import java.net.URL;
2727
import java.net.URLEncoder;
2828
import java.nio.file.InvalidPathException;
29-
import java.nio.file.Paths;
29+
import java.nio.file.Path;
3030
import java.util.ArrayList;
3131
import java.util.Arrays;
3232
import java.util.List;
@@ -125,7 +125,7 @@ public List<String> list(URL url, String path) throws IOException {
125125
// No idea where the exception came from so rethrow it
126126
throw e;
127127
}
128-
File file = Paths.get(url.getFile()).toFile();
128+
File file = Path.of(url.getFile()).toFile();
129129
if (log.isLoggable(Level.FINER)) {
130130
log.log(Level.FINER, "Listing directory " + file.getAbsolutePath());
131131
}
@@ -267,12 +267,12 @@ protected URL findJarForResource(URL url) throws MalformedURLException {
267267
log.log(Level.FINER, "Not a JAR: " + jarUrl);
268268
}
269269
jarUrl.replace(0, jarUrl.length(), testUrl.getFile());
270-
File file = Paths.get(jarUrl.toString()).toFile();
270+
File file = Path.of(jarUrl.toString()).toFile();
271271

272272
// File name might be URL-encoded
273273
if (!file.exists()) {
274274
try {
275-
file = Paths.get(URLEncoder.encode(jarUrl.toString(), "UTF-8")).toFile();
275+
file = Path.of(URLEncoder.encode(jarUrl.toString(), "UTF-8")).toFile();
276276
} catch (UnsupportedEncodingException e) {
277277
throw new RuntimeException("Unsupported encoding? UTF-8? That's impossible.");
278278
}

src/main/java/org/apache/ibatis/migration/options/OptionsParser.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import static org.apache.ibatis.migration.utils.Util.isOption;
1919

20-
import java.nio.file.Paths;
20+
import java.nio.file.Path;
2121

2222
public enum OptionsParser {
2323
;
@@ -55,19 +55,19 @@ private static boolean parseOptions(String arg, SelectedOptions options) {
5555

5656
switch (option) {
5757
case PATH:
58-
options.getPaths().setBasePath(Paths.get(argParts[1]).toFile());
58+
options.getPaths().setBasePath(Path.of(argParts[1]).toFile());
5959
break;
6060
case ENVPATH:
61-
options.getPaths().setEnvPath(Paths.get(argParts[1]).toFile());
61+
options.getPaths().setEnvPath(Path.of(argParts[1]).toFile());
6262
break;
6363
case SCRIPTPATH:
64-
options.getPaths().setScriptPath(Paths.get(argParts[1]).toFile());
64+
options.getPaths().setScriptPath(Path.of(argParts[1]).toFile());
6565
break;
6666
case DRIVERPATH:
67-
options.getPaths().setDriverPath(Paths.get(argParts[1]).toFile());
67+
options.getPaths().setDriverPath(Path.of(argParts[1]).toFile());
6868
break;
6969
case HOOKPATH:
70-
options.getPaths().setHookPath(Paths.get(argParts[1]).toFile());
70+
options.getPaths().setHookPath(Path.of(argParts[1]).toFile());
7171
break;
7272
case ENV:
7373
options.setEnvironment(argParts[1]);

src/main/java/org/apache/ibatis/migration/options/SelectedPaths.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
import static org.apache.ibatis.migration.utils.Util.file;
1919

2020
import java.io.File;
21-
import java.nio.file.Paths;
21+
import java.nio.file.Path;
2222

2323
public class SelectedPaths {
24-
private File basePath = Paths.get("./").toFile();
24+
private File basePath = Path.of("./").toFile();
2525
private File envPath;
2626
private File scriptPath;
2727
private File driverPath;

src/main/java/org/apache/ibatis/migration/utils/Util.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import java.io.File;
1919
import java.io.InputStream;
2020
import java.nio.file.Files;
21-
import java.nio.file.Paths;
21+
import java.nio.file.Path;
2222
import java.util.Properties;
2323

2424
public enum Util {
@@ -62,7 +62,7 @@ public static String getPropertyOption(String key) {
6262
}
6363
Properties properties = new Properties();
6464
String path = migrationsHome + File.separator + MIGRATIONS_PROPERTIES;
65-
try (InputStream stream = Files.newInputStream(Paths.get(path))) {
65+
try (InputStream stream = Files.newInputStream(Path.of(path))) {
6666
properties.load(stream);
6767
return properties.getProperty(key);
6868
} catch (Exception e) {
@@ -75,7 +75,7 @@ public static boolean isOption(String arg) {
7575
}
7676

7777
public static File file(File path, String fileName) {
78-
return Paths.get(path.getAbsolutePath() + File.separator + fileName).toFile();
78+
return Path.of(path.getAbsolutePath() + File.separator + fileName).toFile();
7979
}
8080

8181
public static String horizontalLine(String caption, int length) {

src/test/java/org/apache/ibatis/migration/MigratorTest.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import java.io.PrintWriter;
2727
import java.nio.file.Files;
2828
import java.nio.file.Path;
29-
import java.nio.file.Paths;
3029
import java.nio.file.StandardCopyOption;
3130
import java.sql.Connection;
3231
import java.sql.ResultSet;
@@ -187,7 +186,7 @@ void testVersionCommand() throws Exception {
187186
@Order(9)
188187
void testSkippedScript() throws Exception {
189188
testStatusContainsNoPendingMigrations();
190-
File skipped = Paths.get(dir.getCanonicalPath(), "scripts", "20080827200215_skipped_migration.sql").toFile();
189+
File skipped = Path.of(dir.getCanonicalPath(), "scripts", "20080827200215_skipped_migration.sql").toFile();
191190
assertTrue(skipped.createNewFile());
192191
try {
193192
String output = SystemStubs.tapSystemOut(() -> {
@@ -205,8 +204,8 @@ void testSkippedScript() throws Exception {
205204
@Test
206205
@Order(10)
207206
void testMissingScript() throws Exception {
208-
Path original = Paths.get(dir + File.separator + "scripts", "20080827200216_create_procs.sql");
209-
Path renamed = Paths.get(dir + File.separator + "scripts", "20080827200216_create_procs._sql");
207+
Path original = Path.of(dir + File.separator + "scripts", "20080827200216_create_procs.sql");
208+
Path renamed = Path.of(dir + File.separator + "scripts", "20080827200216_create_procs._sql");
210209
assertEquals(renamed, Files.move(original, renamed, StandardCopyOption.REPLACE_EXISTING));
211210
try {
212211
String output = SystemStubs.tapSystemOut(() -> {
@@ -324,7 +323,7 @@ void shouldInitTempDirectory() throws Exception {
324323
Migrator.main(TestUtil.args("--path=" + basePath.getAbsolutePath(), "init"));
325324
assertNotNull(basePath.list());
326325
assertEquals(4, basePath.list().length);
327-
File scriptPath = Paths.get(basePath.getCanonicalPath(), "scripts").toFile();
326+
File scriptPath = Path.of(basePath.getCanonicalPath(), "scripts").toFile();
328327
assertEquals(3, scriptPath.list().length);
329328
Migrator.main(TestUtil.args("--path=" + basePath.getAbsolutePath(), "new", "test new migration"));
330329
assertEquals(4, scriptPath.list().length);
@@ -336,11 +335,11 @@ void shouldRespectIdPattern() throws Exception {
336335
String idPattern = "000";
337336
File basePath = TestUtil.getTempDir();
338337
Migrator.main(TestUtil.args("--path=" + basePath.getAbsolutePath(), "--idpattern=" + idPattern, "init"));
339-
File changelog = Paths.get(basePath.getCanonicalPath(), "scripts", "001_create_changelog.sql").toFile();
338+
File changelog = Path.of(basePath.getCanonicalPath(), "scripts", "001_create_changelog.sql").toFile();
340339
assertTrue(changelog.exists());
341340
Migrator.main(
342341
TestUtil.args("--path=" + basePath.getAbsolutePath(), "--idpattern=" + idPattern, "new", "new migration"));
343-
File newMigration = Paths.get(basePath.getCanonicalPath(), "scripts", "003_new_migration.sql").toFile();
342+
File newMigration = Path.of(basePath.getCanonicalPath(), "scripts", "003_new_migration.sql").toFile();
344343
assertTrue(newMigration.exists());
345344
assertTrue(TestUtil.deleteDirectory(basePath), "delete temp dir");
346345
}
@@ -352,7 +351,7 @@ void useCustomTemplate() throws Exception {
352351
Migrator.main(TestUtil.args("--path=" + basePath.getAbsolutePath(), "init"));
353352
assertNotNull(basePath.list());
354353
assertEquals(4, basePath.list().length);
355-
File scriptPath = Paths.get(basePath.getCanonicalPath(), "scripts").toFile();
354+
File scriptPath = Path.of(basePath.getCanonicalPath(), "scripts").toFile();
356355
assertEquals(3, scriptPath.list().length);
357356

358357
File templatePath = File.createTempFile("customTemplate", "sql");
@@ -364,7 +363,7 @@ void useCustomTemplate() throws Exception {
364363
String[] scripts = scriptPath.list();
365364
Arrays.sort(scripts);
366365
assertEquals(4, scripts.length);
367-
try (Scanner scanner = new Scanner(Paths.get(scriptPath.getCanonicalPath(), scripts[scripts.length - 2]))) {
366+
try (Scanner scanner = new Scanner(Path.of(scriptPath.getCanonicalPath(), scripts[scripts.length - 2]))) {
368367
if (scanner.hasNextLine()) {
369368
assertEquals("// " + desc, scanner.nextLine());
370369
}
@@ -379,7 +378,7 @@ void useCustomTemplateWithNoValue() throws Exception {
379378
Migrator.main(TestUtil.args("--path=" + basePath.getAbsolutePath(), "init"));
380379
assertNotNull(basePath.list());
381380
assertEquals(4, basePath.list().length);
382-
File scriptPath = Paths.get(basePath.getCanonicalPath(), "scripts").toFile();
381+
File scriptPath = Path.of(basePath.getCanonicalPath(), "scripts").toFile();
383382
assertEquals(3, scriptPath.list().length);
384383

385384
File templatePath = File.createTempFile("customTemplate", "sql");
@@ -397,7 +396,7 @@ void useCustomTemplateWithBadPath() throws Exception {
397396
Migrator.main(TestUtil.args("--path=" + basePath.getAbsolutePath(), "init"));
398397
assertNotNull(basePath.list());
399398
assertEquals(4, basePath.list().length);
400-
File scriptPath = Paths.get(basePath.getCanonicalPath(), "scripts").toFile();
399+
File scriptPath = Path.of(basePath.getCanonicalPath(), "scripts").toFile();
401400
assertEquals(3, scriptPath.list().length);
402401

403402
String output = SystemStubs.tapSystemOut(() -> {
@@ -499,8 +498,8 @@ void testInitWithNonExistentBasePath() throws Exception {
499498
String output = SystemStubs
500499
.tapSystemOut(() -> Migrator.main(TestUtil.args("init", "--path=" + baseDir.getAbsolutePath())));
501500
assertFalse(output.contains("Migrations path must be a directory"), output);
502-
assertTrue(Files.exists(Paths.get(baseDir.getCanonicalPath(), "README")), "README created");
503-
assertTrue(Files.isDirectory(Paths.get(baseDir.getCanonicalPath(), "environments")),
501+
assertTrue(Files.exists(Path.of(baseDir.getCanonicalPath(), "README")), "README created");
502+
assertTrue(Files.isDirectory(Path.of(baseDir.getCanonicalPath(), "environments")),
504503
"environments directory created");
505504
assertTrue(TestUtil.deleteDirectory(baseDir), "delete temp dir");
506505
}

src/test/java/org/apache/ibatis/migration/commands/BaseCommandTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import java.io.PrintWriter;
2626
import java.nio.file.FileSystems;
2727
import java.nio.file.NoSuchFileException;
28-
import java.nio.file.Paths;
28+
import java.nio.file.Path;
2929
import java.util.Properties;
3030
import java.util.Scanner;
3131

@@ -53,7 +53,7 @@ void testNonexistentFileLinuxMac() throws Exception {
5353
File dest = File.createTempFile("Out", ".sql");
5454
dest.deleteOnExit();
5555
NoSuchFileException e = assertThrows(NoSuchFileException.class, () -> {
56-
BaseCommand.copyTemplate(Paths.get(srcPath).toFile(), dest, null);
56+
BaseCommand.copyTemplate(Path.of(srcPath).toFile(), dest, null);
5757
});
5858
assertEquals(e.getMessage(), srcPath);
5959
}
@@ -66,7 +66,7 @@ void testNonexistentFileWindows() throws Exception {
6666
File dest = File.createTempFile("Out", ".sql");
6767
dest.deleteOnExit();
6868
NoSuchFileException e = assertThrows(NoSuchFileException.class, () -> {
69-
BaseCommand.copyTemplate(Paths.get(srcPath).toFile(), dest, null);
69+
BaseCommand.copyTemplate(Path.of(srcPath).toFile(), dest, null);
7070
});
7171
assertEquals(e.getMessage(), srcPath + " (The system cannot find the file specified)");
7272
}

src/test/java/org/apache/ibatis/migration/hook/NewHookTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import java.nio.channels.FileChannel;
2525
import java.nio.charset.Charset;
2626
import java.nio.file.Files;
27-
import java.nio.file.Paths;
27+
import java.nio.file.Path;
2828
import java.nio.file.StandardOpenOption;
2929

3030
import org.apache.ibatis.migration.Migrator;
@@ -40,7 +40,7 @@ class NewHookTest {
4040
@Test
4141
void shouldRunNewHooks() throws Throwable {
4242
File basePath = initBaseDir();
43-
File scriptPath = Paths.get(basePath.getCanonicalPath(), "scripts").toFile();
43+
File scriptPath = Path.of(basePath.getCanonicalPath(), "scripts").toFile();
4444
String output = SystemStubs.tapSystemOut(() -> {
4545
Migrator.main(
4646
TestUtil.args("--path=" + basePath.getAbsolutePath(), "--idpattern=00", "new", "create table1 JIRA-123"));
@@ -50,14 +50,14 @@ void shouldRunNewHooks() throws Throwable {
5050
assertTrue(output.contains("SUCCESS"));
5151
assertTrue(output.contains("Description is valid."));
5252
assertTrue(output.contains("Renamed 03_create_table1_JIRA-123.sql to 03_create_table1_JIRA123.sql"));
53-
assertTrue(Files.exists(Paths.get(scriptPath.getCanonicalPath(), "03_create_table1_JIRA123.sql")));
53+
assertTrue(Files.exists(Path.of(scriptPath.getCanonicalPath(), "03_create_table1_JIRA123.sql")));
5454
assertTrue(TestUtil.deleteDirectory(basePath), "delete test dir");
5555
}
5656

5757
@Test
5858
void shouldNotCreateFileWhenBeforeHookThrowsException() throws Throwable {
5959
File basePath = initBaseDir();
60-
File scriptPath = Paths.get(basePath.getCanonicalPath(), "scripts").toFile();
60+
File scriptPath = Path.of(basePath.getCanonicalPath(), "scripts").toFile();
6161
String output = SystemStubs.tapSystemOut(() -> {
6262
int exitCode = SystemStubs.catchSystemExit(() -> {
6363
Migrator.main(TestUtil.args("--path=" + basePath.getAbsolutePath(), "new", "create table1"));
@@ -73,7 +73,7 @@ protected File initBaseDir() throws IOException {
7373
File basePath = TestUtil.getTempDir();
7474
Migrator.main(TestUtil.args("--path=" + basePath.getAbsolutePath(), "--idpattern=00", "init"));
7575
// Copy hook script
76-
File hooksDir = Paths.get(basePath.getCanonicalPath(), "hooks").toFile();
76+
File hooksDir = Path.of(basePath.getCanonicalPath(), "hooks").toFile();
7777
hooksDir.mkdir();
7878
try (
7979
FileChannel srcChannel = FileChannel
@@ -83,7 +83,7 @@ protected File initBaseDir() throws IOException {
8383
srcChannel.transferTo(0, srcChannel.size(), destChannel);
8484
}
8585
// Add hook settings
86-
File envFile = Paths.get(basePath.getCanonicalPath(), "environments", "development.properties").toFile();
86+
File envFile = Path.of(basePath.getCanonicalPath(), "environments", "development.properties").toFile();
8787
try (PrintWriter writer = new PrintWriter(
8888
Files.newBufferedWriter(envFile.toPath(), Charset.forName("utf-8"), StandardOpenOption.APPEND))) {
8989
writer.println("hook_before_new=js:NewHook.js:_function=validateDesc");

src/test/java/org/apache/ibatis/migration/options/OptionsParserTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import static org.junit.jupiter.api.Assertions.assertTrue;
3030

3131
import java.io.File;
32-
import java.nio.file.Paths;
32+
import java.nio.file.Path;
3333

3434
import org.junit.jupiter.api.Test;
3535

@@ -58,7 +58,7 @@ void testEnvAndTemplate() {
5858
@Test
5959
void testFileOptions() {
6060
final String testFileName = "test";
61-
final File testFile = Paths.get(testFileName).toFile();
61+
final File testFile = Path.of(testFileName).toFile();
6262
final SelectedOptions expectedOptions = new SelectedOptions();
6363

6464
final SelectedPaths paths = expectedOptions.getPaths();

src/test/java/org/apache/ibatis/migration/runtime_migration/RuntimeMigrationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import java.io.PrintStream;
2424
import java.math.BigDecimal;
2525
import java.net.URL;
26-
import java.nio.file.Paths;
26+
import java.nio.file.Path;
2727
import java.sql.Connection;
2828
import java.sql.ResultSet;
2929
import java.sql.SQLException;
@@ -250,7 +250,7 @@ protected void assertTableDoesNotExist(ConnectionProvider connectionProvider, St
250250

251251
protected FileMigrationLoader createMigrationsLoader(String resource) {
252252
URL url = getClass().getClassLoader().getResource(resource);
253-
File scriptsDir = Paths.get(url.getPath()).toFile();
253+
File scriptsDir = Path.of(url.getPath()).toFile();
254254
Properties properties = new Properties();
255255
properties.setProperty("changelog", "CHANGELOG");
256256
return new FileMigrationLoader(scriptsDir, "utf-8", properties);

0 commit comments

Comments
 (0)