diff --git a/crd-generator/maven-plugin/src/it/dependency-explicit/verify.groovy b/crd-generator/maven-plugin/src/it/dependency-explicit/verify.groovy index 2c35dff485c..2ce7d2962c9 100644 --- a/crd-generator/maven-plugin/src/it/dependency-explicit/verify.groovy +++ b/crd-generator/maven-plugin/src/it/dependency-explicit/verify.groovy @@ -14,20 +14,22 @@ * limitations under the License. */ import io.fabric8.crd.generator.maven.plugin.Verify +import java.nio.file.Path +Path basedirPath = basedir.toPath(); [ "multiples.sample.fabric8.io-v1" ].each { Verify.verifyContentEquals( - new File(basedir, sprintf("/target/classes/META-INF/fabric8/%s.yml",it)), - new File(basedir, sprintf("/expected/%s.yml",it))) + basedirPath.resolve(Path.of("target", "classes", "META-INF", "fabric8", it + ".yml")), + basedirPath.resolve(Path.of("expected", it + ".yml"))) } [ "mycustomresources.other.sample.fabric8.io-v1" ].each { - Verify.verifyAbsent(new File(basedir, sprintf("/target/classes/META-INF/fabric8/%s.yml", it))) + Verify.verifyAbsent(basedirPath.resolve(Path.of("target", "classes", "META-INF", "fabric8", it + ".yml"))) } true diff --git a/crd-generator/maven-plugin/src/it/dependency-indexed-scan/verify.groovy b/crd-generator/maven-plugin/src/it/dependency-indexed-scan/verify.groovy index aed36676ccc..258c565e21c 100644 --- a/crd-generator/maven-plugin/src/it/dependency-indexed-scan/verify.groovy +++ b/crd-generator/maven-plugin/src/it/dependency-indexed-scan/verify.groovy @@ -14,6 +14,8 @@ * limitations under the License. */ import io.fabric8.crd.generator.maven.plugin.Verify +import java.nio.file.Path +Path basedirPath = basedir.toPath(); [ @@ -21,8 +23,8 @@ import io.fabric8.crd.generator.maven.plugin.Verify "mycustomresources.other.sample.fabric8.io-v1" ].each { Verify.verifyContentEquals( - new File(basedir, sprintf("/target/classes/META-INF/fabric8/%s.yml",it)), - new File(basedir, sprintf("/expected/%s.yml",it))) + basedirPath.resolve(Path.of("target", "classes", "META-INF", "fabric8", it + ".yml")), + basedirPath.resolve(Path.of("expected", it + ".yml"))) } true diff --git a/crd-generator/maven-plugin/src/it/dependency-scan-package-exclusion/verify.groovy b/crd-generator/maven-plugin/src/it/dependency-scan-package-exclusion/verify.groovy index 2c35dff485c..2ce7d2962c9 100644 --- a/crd-generator/maven-plugin/src/it/dependency-scan-package-exclusion/verify.groovy +++ b/crd-generator/maven-plugin/src/it/dependency-scan-package-exclusion/verify.groovy @@ -14,20 +14,22 @@ * limitations under the License. */ import io.fabric8.crd.generator.maven.plugin.Verify +import java.nio.file.Path +Path basedirPath = basedir.toPath(); [ "multiples.sample.fabric8.io-v1" ].each { Verify.verifyContentEquals( - new File(basedir, sprintf("/target/classes/META-INF/fabric8/%s.yml",it)), - new File(basedir, sprintf("/expected/%s.yml",it))) + basedirPath.resolve(Path.of("target", "classes", "META-INF", "fabric8", it + ".yml")), + basedirPath.resolve(Path.of("expected", it + ".yml"))) } [ "mycustomresources.other.sample.fabric8.io-v1" ].each { - Verify.verifyAbsent(new File(basedir, sprintf("/target/classes/META-INF/fabric8/%s.yml", it))) + Verify.verifyAbsent(basedirPath.resolve(Path.of("target", "classes", "META-INF", "fabric8", it + ".yml"))) } true diff --git a/crd-generator/maven-plugin/src/it/dependency-scan-package-inclusion/verify.groovy b/crd-generator/maven-plugin/src/it/dependency-scan-package-inclusion/verify.groovy index e26dc546e5b..15d304f9037 100644 --- a/crd-generator/maven-plugin/src/it/dependency-scan-package-inclusion/verify.groovy +++ b/crd-generator/maven-plugin/src/it/dependency-scan-package-inclusion/verify.groovy @@ -14,20 +14,22 @@ * limitations under the License. */ import io.fabric8.crd.generator.maven.plugin.Verify +import java.nio.file.Path +Path basedirPath = basedir.toPath(); [ "mycustomresources.other.sample.fabric8.io-v1" ].each { Verify.verifyContentEquals( - new File(basedir, sprintf("/target/classes/META-INF/fabric8/%s.yml",it)), - new File(basedir, sprintf("/expected/%s.yml",it))) + basedirPath.resolve(Path.of("target", "classes", "META-INF", "fabric8", it + ".yml")), + basedirPath.resolve(Path.of("expected", it + ".yml"))) } [ "multiples.sample.fabric8.io-v1" ].each { - Verify.verifyAbsent(new File(basedir, sprintf("/target/classes/META-INF/fabric8/%s.yml", it))) + Verify.verifyAbsent(basedirPath.resolve(Path.of("target", "classes", "META-INF", "fabric8", it + ".yml"))) } true diff --git a/crd-generator/maven-plugin/src/it/dependency-scan/verify.groovy b/crd-generator/maven-plugin/src/it/dependency-scan/verify.groovy index aed36676ccc..04e3e3566f9 100644 --- a/crd-generator/maven-plugin/src/it/dependency-scan/verify.groovy +++ b/crd-generator/maven-plugin/src/it/dependency-scan/verify.groovy @@ -14,15 +14,16 @@ * limitations under the License. */ import io.fabric8.crd.generator.maven.plugin.Verify - +import java.nio.file.Path +Path basedirPath = basedir.toPath(); [ "multiples.sample.fabric8.io-v1", "mycustomresources.other.sample.fabric8.io-v1" ].each { Verify.verifyContentEquals( - new File(basedir, sprintf("/target/classes/META-INF/fabric8/%s.yml",it)), - new File(basedir, sprintf("/expected/%s.yml",it))) + basedirPath.resolve(Path.of("target", "classes", "META-INF", "fabric8", it + ".yml")), + basedirPath.resolve(Path.of("expected", it + ".yml"))) } true diff --git a/crd-generator/maven-plugin/src/it/intermediate-class/verify.groovy b/crd-generator/maven-plugin/src/it/intermediate-class/verify.groovy index dca9b91d454..215b40b4ac6 100644 --- a/crd-generator/maven-plugin/src/it/intermediate-class/verify.groovy +++ b/crd-generator/maven-plugin/src/it/intermediate-class/verify.groovy @@ -14,6 +14,8 @@ * limitations under the License. */ import io.fabric8.crd.generator.maven.plugin.Verify +import java.nio.file.Path +Path basedirPath = basedir.toPath(); [ @@ -22,8 +24,8 @@ import io.fabric8.crd.generator.maven.plugin.Verify "myintermediatehasmetadatainterfaces.sample.fabric8.io-v1" ].each { Verify.verifyContentEquals( - new File(basedir, sprintf("/target/classes/META-INF/fabric8/%s.yml",it)), - new File(basedir, sprintf("/expected/%s.yml",it))) + basedirPath.resolve(Path.of("target", "classes", "META-INF", "fabric8", it + ".yml")), + basedirPath.resolve(Path.of("expected", it + ".yml"))) } true diff --git a/crd-generator/maven-plugin/src/it/project-and-dependency-scan/verify.groovy b/crd-generator/maven-plugin/src/it/project-and-dependency-scan/verify.groovy index 8716db05f08..853b8097935 100644 --- a/crd-generator/maven-plugin/src/it/project-and-dependency-scan/verify.groovy +++ b/crd-generator/maven-plugin/src/it/project-and-dependency-scan/verify.groovy @@ -14,7 +14,8 @@ * limitations under the License. */ import io.fabric8.crd.generator.maven.plugin.Verify - +import java.nio.file.Path +Path basedirPath = basedir.toPath(); [ "multiples.sample.fabric8.io-v1", @@ -22,8 +23,8 @@ import io.fabric8.crd.generator.maven.plugin.Verify "projects.sample.fabric8.io-v1" ].each { Verify.verifyContentEquals( - new File(basedir, sprintf("/target/classes/META-INF/fabric8/%s.yml",it)), - new File(basedir, sprintf("/expected/%s.yml",it))) + basedirPath.resolve(Path.of("target", "classes", "META-INF", "fabric8", it + ".yml")), + basedirPath.resolve(Path.of("expected", it + ".yml"))) } true diff --git a/crd-generator/maven-plugin/src/it/project-explicit/verify.groovy b/crd-generator/maven-plugin/src/it/project-explicit/verify.groovy index 06ff2117289..4cd4cba2d63 100644 --- a/crd-generator/maven-plugin/src/it/project-explicit/verify.groovy +++ b/crd-generator/maven-plugin/src/it/project-explicit/verify.groovy @@ -14,14 +14,15 @@ * limitations under the License. */ import io.fabric8.crd.generator.maven.plugin.Verify - +import java.nio.file.Path +Path basedirPath = basedir.toPath(); [ "multiples.sample.fabric8.io-v1" ].each { Verify.verifyContentEquals( - new File(basedir, sprintf("/target/classes/META-INF/fabric8/%s.yml",it)), - new File(basedir, sprintf("/expected/%s.yml",it))) + basedirPath.resolve(Path.of("target", "classes", "META-INF", "fabric8", it + ".yml")), + basedirPath.resolve(Path.of("expected", it + ".yml"))) } true diff --git a/crd-generator/maven-plugin/src/it/project-scan/verify.groovy b/crd-generator/maven-plugin/src/it/project-scan/verify.groovy index 06ff2117289..cde4db7cc65 100644 --- a/crd-generator/maven-plugin/src/it/project-scan/verify.groovy +++ b/crd-generator/maven-plugin/src/it/project-scan/verify.groovy @@ -14,14 +14,16 @@ * limitations under the License. */ import io.fabric8.crd.generator.maven.plugin.Verify +import java.nio.file.Path +Path basedirPath = basedir.toPath(); [ "multiples.sample.fabric8.io-v1" ].each { Verify.verifyContentEquals( - new File(basedir, sprintf("/target/classes/META-INF/fabric8/%s.yml",it)), - new File(basedir, sprintf("/expected/%s.yml",it))) + basedirPath.resolve(Path.of("target", "classes", "META-INF", "fabric8", it + ".yml")), + basedirPath.resolve(Path.of("expected", it + ".yml"))) } true diff --git a/crd-generator/maven-plugin/src/test/java/io/fabric8/crd/generator/maven/plugin/Verify.java b/crd-generator/maven-plugin/src/test/java/io/fabric8/crd/generator/maven/plugin/Verify.java index bc242ceffde..f62c1c5fa97 100644 --- a/crd-generator/maven-plugin/src/test/java/io/fabric8/crd/generator/maven/plugin/Verify.java +++ b/crd-generator/maven-plugin/src/test/java/io/fabric8/crd/generator/maven/plugin/Verify.java @@ -15,35 +15,35 @@ */ package io.fabric8.crd.generator.maven.plugin; -import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; +import java.nio.file.Path; import java.util.Objects; class Verify { - static void verifyExist(File file) { + static void verifyExist(Path file) { Objects.requireNonNull(file); - if (!file.exists()) - throw new AssertionError("File " + file.getAbsoluteFile() + " does not exist"); + if (!Files.exists(file)) + throw new AssertionError("File " + file.normalize() + " does not exist"); } - static void verifyAbsent(File file) { + static void verifyAbsent(Path file) { Objects.requireNonNull(file); - if (file.exists()) - throw new AssertionError("File " + file.getAbsoluteFile() + " exists"); + if (Files.exists(file)) + throw new AssertionError("File " + file.normalize() + " exists"); } - static void verifyContentEquals(File file1, File file2) throws IOException { + static void verifyContentEquals(Path file1, Path file2) throws IOException { verifyExist(file1); verifyExist(file2); if (!Objects.equals(readFile(file1), readFile(file2))) { - throw new AssertionError("File contents not equal: " + file1.getAbsoluteFile() + " " + file2.getAbsoluteFile()); + throw new AssertionError("File contents not equal: " + file1.normalize() + " " + file2.normalize()); } } - private static String readFile(File path) throws IOException { - return new String(Files.readAllBytes(path.toPath()), StandardCharsets.UTF_8); + private static String readFile(Path path) throws IOException { + return new String(Files.readAllBytes(path), StandardCharsets.UTF_8); } }