diff --git a/jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/util/Serialization.java b/jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/util/Serialization.java index 9394a8236f..dea97ca82e 100644 --- a/jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/util/Serialization.java +++ b/jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/util/Serialization.java @@ -31,6 +31,7 @@ import java.net.URL; import java.nio.charset.StandardCharsets; import java.nio.file.Files; +import java.nio.file.Path; public class Serialization { @@ -65,19 +66,28 @@ public static T unmarshal(File file) throws IOException { } public static T unmarshal(File file, Class clazz) throws IOException { - try (InputStream fis = Files.newInputStream(file.toPath())) { + return unmarshal(file.toPath(), clazz); + } + + public static T unmarshal(File file, TypeReference type) throws IOException { + return unmarshal(file.toPath(), type); + } + + public static T unmarshal(Path file, Class clazz) throws IOException { + try (InputStream fis = Files.newInputStream(file)) { return unmarshal(fis, clazz); } } - public static T unmarshal(File file, TypeReference type) throws IOException { - try (InputStream fis = Files.newInputStream(file.toPath())) { + public static T unmarshal(Path file, TypeReference type) throws IOException { + try (InputStream fis = Files.newInputStream(file)) { return unmarshal(fis, type); } } - public static T unmarshal(URL url, Class type) throws IOException { + + public static T unmarshal(URL url, Class clazz) throws IOException { try (InputStream is = url.openStream()){ - return unmarshal(is, type); + return unmarshal(is, clazz); } } @@ -95,8 +105,8 @@ public static T unmarshal(InputStream is, TypeReference type) { return KUBERNETES_SERIALIZATION.unmarshal(is, type); } - public static T unmarshal(String string, Class type) { - return KUBERNETES_SERIALIZATION.unmarshal(string, type); + public static T unmarshal(String string, Class clazz) { + return KUBERNETES_SERIALIZATION.unmarshal(string, clazz); } public static T unmarshal(String string, TypeReference type) { diff --git a/jkube-kit/helm/src/test/java/org/eclipse/jkube/kit/resource/helm/HelmServiceTest.java b/jkube-kit/helm/src/test/java/org/eclipse/jkube/kit/resource/helm/HelmServiceTest.java index 7a200c75c4..d7df3633ea 100644 --- a/jkube-kit/helm/src/test/java/org/eclipse/jkube/kit/resource/helm/HelmServiceTest.java +++ b/jkube-kit/helm/src/test/java/org/eclipse/jkube/kit/resource/helm/HelmServiceTest.java @@ -101,7 +101,7 @@ void generateHelmCharts() throws IOException { helmService.generateHelmCharts(helmConfig.build()); // Then final Map chartYaml = Serialization.unmarshal( - helmOutputDirectory.resolve("kubernetes").resolve("Chart.yaml").toFile(), + helmOutputDirectory.resolve("kubernetes").resolve("Chart.yaml"), new TypeReference>() {}); assertThat(chartYaml) .contains( @@ -164,7 +164,7 @@ void generateHelmCharts_withValidChartYamlFragment_usesMergedChart() throws Exce new HelmService(jKubeConfiguration, resourceServiceConfig, new KitLogger.SilentLogger()) .generateHelmCharts(helmConfig.build()); // Then - final Map savedChart = Serialization.unmarshal(helmOutputDirectory.resolve("kubernetes").resolve("Chart.yaml").toFile(), Map.class); + final Map savedChart = Serialization.unmarshal(helmOutputDirectory.resolve("kubernetes").resolve("Chart.yaml"), Map.class); assertThat(savedChart) .hasFieldOrPropertyWithValue("apiVersion", "v1") .hasFieldOrPropertyWithValue("name", "name-from-fragment") @@ -199,7 +199,7 @@ void generateHelmCharts_withValidValuesYamlFragment_usesMergedValues() throws Ex new HelmService(jKubeConfiguration, resourceServiceConfig, new KitLogger.SilentLogger()) .generateHelmCharts(helmConfig.build()); // Then - final Map savedValues = Serialization.unmarshal(helmOutputDirectory.resolve("kubernetes").resolve("values.yaml").toFile(), Map.class); + final Map savedValues = Serialization.unmarshal(helmOutputDirectory.resolve("kubernetes").resolve("values.yaml"), Map.class); assertThat(savedValues) .hasFieldOrPropertyWithValue("replaceableProperty", "the-value") .hasFieldOrPropertyWithValue("replicaCount", 1) @@ -270,7 +270,7 @@ void createChartYamlWithDependencies() throws Exception { helmService.generateHelmCharts(helmConfig.build()); // Then final Map chartYaml = Serialization.unmarshal( - helmOutputDirectory.resolve("kubernetes").resolve("Chart.yaml").toFile(), + helmOutputDirectory.resolve("kubernetes").resolve("Chart.yaml"), new TypeReference>() {}); assertThat(chartYaml) .contains( diff --git a/kubernetes-maven-plugin/plugin/src/test/java/org/eclipse/jkube/maven/plugin/mojo/build/HelmMojoTest.java b/kubernetes-maven-plugin/plugin/src/test/java/org/eclipse/jkube/maven/plugin/mojo/build/HelmMojoTest.java index 7bd498bbba..cfe32f3f3f 100644 --- a/kubernetes-maven-plugin/plugin/src/test/java/org/eclipse/jkube/maven/plugin/mojo/build/HelmMojoTest.java +++ b/kubernetes-maven-plugin/plugin/src/test/java/org/eclipse/jkube/maven/plugin/mojo/build/HelmMojoTest.java @@ -135,7 +135,7 @@ void executeInternal_findTemplatesFromProvidedFile() throws Exception { .hasFieldOrPropertyWithValue("metadata.name", "the-template-for-params"); final Map savedChart = Serialization.unmarshal( projectDir.resolve("target").resolve("jkube").resolve("helm").resolve("empty-project") - .resolve("kubernetes").resolve("values.yaml").toFile(), new TypeReference>() {}); + .resolve("kubernetes").resolve("values.yaml"), new TypeReference>() {}); assertThat(savedChart).containsEntry("key", "value"); }