From 0b9c719d6bfe8e60d04acf407539d4f2d3449d56 Mon Sep 17 00:00:00 2001 From: augustearth Date: Fri, 11 Nov 2022 14:03:04 -0800 Subject: [PATCH] Directory String to Path --- .../groovy/carnival/vine/VineConfiguration.groovy | 11 ++++------- .../src/main/groovy/carnival/vine/VineMethod.groovy | 2 +- .../src/test/groovy/carnival/vine/JsonVineSpec.groovy | 6 +++--- .../test/groovy/carnival/vine/VineMethodSpec.groovy | 4 ++-- .../src/test/groovy/carnival/vine/VineSpec.groovy | 8 +++++--- 5 files changed, 15 insertions(+), 16 deletions(-) diff --git a/app/carnival-vine/src/main/groovy/carnival/vine/VineConfiguration.groovy b/app/carnival-vine/src/main/groovy/carnival/vine/VineConfiguration.groovy index f97db53..3e17e29 100644 --- a/app/carnival-vine/src/main/groovy/carnival/vine/VineConfiguration.groovy +++ b/app/carnival-vine/src/main/groovy/carnival/vine/VineConfiguration.groovy @@ -23,10 +23,9 @@ class VineConfiguration { static public VineConfiguration defaultConfiguration() { Path currentRelativePath = Paths.get(""); Path cachePath = currentRelativePath.resolve(CACHE_PATH_DEFAULT) - String cachePathString = cachePath.toAbsolutePath().toString() VineConfiguration config = new VineConfiguration() - config.cache.directory = cachePathString + config.cache.directory = cachePath return config } @@ -39,7 +38,7 @@ class VineConfiguration { @ToString(includeNames=true) static class Cache { CacheMode mode = CacheMode.IGNORE - String directory + Path directory Boolean directoryCreateIfNotPresent = true } Cache cache = new Cache() @@ -67,9 +66,7 @@ class VineConfiguration { * */ public File getCacheDirectory() { - String dirPathString = cache.directory - assert dirPathString != null - Path relativePath = Paths.get(dirPathString.trim()) - return relativePath.toFile() + assert cache.directory != null + return cache.directory.toFile() } } \ No newline at end of file diff --git a/app/carnival-vine/src/main/groovy/carnival/vine/VineMethod.groovy b/app/carnival-vine/src/main/groovy/carnival/vine/VineMethod.groovy index 7087a7d..eaf9f3a 100644 --- a/app/carnival-vine/src/main/groovy/carnival/vine/VineMethod.groovy +++ b/app/carnival-vine/src/main/groovy/carnival/vine/VineMethod.groovy @@ -98,7 +98,7 @@ abstract class VineMethod { } void _cacheDirectoryInitialize() { - Path cachePath = Paths.get(vineConfiguration.cache.directory) + Path cachePath = vineConfiguration.cache.directory if (cachePath == null) throw new RuntimeException("cachePath is null") def assertDirectoryAttributes = { Path dirPath -> diff --git a/app/carnival-vine/src/test/groovy/carnival/vine/JsonVineSpec.groovy b/app/carnival-vine/src/test/groovy/carnival/vine/JsonVineSpec.groovy index 28dfdc3..809270a 100644 --- a/app/carnival-vine/src/test/groovy/carnival/vine/JsonVineSpec.groovy +++ b/app/carnival-vine/src/test/groovy/carnival/vine/JsonVineSpec.groovy @@ -211,11 +211,11 @@ class JsonVineSpec extends Specification { def "custom cache directory"() { when: def vine = new JvsTestVineDefault() - vine.vineConfiguration.cache.directory += "2" - Path cacheDirPath = Paths.get(vine.vineConfiguration.cache.directory) + vine.vineConfiguration.cache.directory = Paths.get(vine.vineConfiguration.cache.directory.toString() + "2") + Path cacheDirPath = vine.vineConfiguration.cache.directory then: - vine.vineConfiguration.cache.directory.endsWith("2") + vine.vineConfiguration.cache.directory.toString().endsWith("2") !Files.exists(cacheDirPath) when: diff --git a/app/carnival-vine/src/test/groovy/carnival/vine/VineMethodSpec.groovy b/app/carnival-vine/src/test/groovy/carnival/vine/VineMethodSpec.groovy index 9bc0efd..c084f5f 100644 --- a/app/carnival-vine/src/test/groovy/carnival/vine/VineMethodSpec.groovy +++ b/app/carnival-vine/src/test/groovy/carnival/vine/VineMethodSpec.groovy @@ -14,7 +14,7 @@ class SomeVineMethod extends VineMethod { static VineConfiguration EXAMPLE_CONFIG = new VineConfiguration( cache: new VineConfiguration.Cache( mode: CacheMode.REQUIRED, - directory: '/path/to/directory', + directory: Paths.get('/path/to/directory'), directoryCreateIfNotPresent: false ) ) @@ -44,7 +44,7 @@ class VineMethodSpec extends Specification { then: vm.vineConfiguration == SomeVineMethod.EXAMPLE_CONFIG vm.vineConfiguration.cache.mode == CacheMode.REQUIRED - vm.vineConfiguration.cache.directory == '/path/to/directory' + vm.vineConfiguration.cache.directory == Paths.get('/path/to/directory') vm.vineConfiguration.cache.directoryCreateIfNotPresent == false } diff --git a/app/carnival-vine/src/test/groovy/carnival/vine/VineSpec.groovy b/app/carnival-vine/src/test/groovy/carnival/vine/VineSpec.groovy index 3c124a3..fb10f79 100644 --- a/app/carnival-vine/src/test/groovy/carnival/vine/VineSpec.groovy +++ b/app/carnival-vine/src/test/groovy/carnival/vine/VineSpec.groovy @@ -15,12 +15,14 @@ class VsVineWithConfig implements Vine { static VineConfiguration EXAMPLE_CONFIG = new VineConfiguration( cache: new VineConfiguration.Cache( mode: CacheMode.REQUIRED, - directory: '/path/to/directory', + directory: Paths.get('/path/to/directory'), directoryCreateIfNotPresent: false ) ) - VineConfiguration vineConfiguration = EXAMPLE_CONFIG + public VsVineWithConfig() { + this.vineConfiguration = EXAMPLE_CONFIG + } @ToString(includeNames=true) static class Person { String name } @@ -45,7 +47,7 @@ class VineSpec extends Specification { then: vine.vineConfiguration == VsVineWithConfig.EXAMPLE_CONFIG vine.vineConfiguration.cache.mode == CacheMode.REQUIRED - vine.vineConfiguration.cache.directory == '/path/to/directory' + vine.vineConfiguration.cache.directory == Paths.get('/path/to/directory') vine.vineConfiguration.cache.directoryCreateIfNotPresent == false }