From b55522e1621f269ac274750565902327fff3ea18 Mon Sep 17 00:00:00 2001 From: Stefan Seifert Date: Wed, 18 Oct 2023 13:36:12 +0200 Subject: [PATCH 01/26] [gitflow-maven-plugin] Update for next development version 1.16.5-SNAPSHOT --- generator/pom.xml | 4 ++-- model/pom.xml | 4 ++-- parent/pom.xml | 2 +- pom.xml | 4 ++-- resource/pom.xml | 2 +- tooling/conga-cli/pom.xml | 4 ++-- tooling/conga-maven-plugin/pom.xml | 4 ++-- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/generator/pom.xml b/generator/pom.xml index eab9a2f7..bfc58eea 100644 --- a/generator/pom.xml +++ b/generator/pom.xml @@ -25,7 +25,7 @@ io.wcm.devops.conga io.wcm.devops.conga.parent - 1.16.4 + 1.16.5-SNAPSHOT ../parent/pom.xml @@ -44,7 +44,7 @@ io.wcm.devops.conga io.wcm.devops.conga.model - 1.16.4 + 1.16.5-SNAPSHOT compile diff --git a/model/pom.xml b/model/pom.xml index de10e7e5..4a6b450a 100644 --- a/model/pom.xml +++ b/model/pom.xml @@ -25,7 +25,7 @@ io.wcm.devops.conga io.wcm.devops.conga.parent - 1.16.4 + 1.16.5-SNAPSHOT ../parent/pom.xml @@ -40,7 +40,7 @@ io.wcm.devops.conga io.wcm.devops.conga.resource - 1.16.4 + 1.16.5-SNAPSHOT compile diff --git a/parent/pom.xml b/parent/pom.xml index a17d9c46..d5024b9a 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -31,7 +31,7 @@ io.wcm.devops.conga io.wcm.devops.conga.parent - 1.16.4 + 1.16.5-SNAPSHOT pom CONGA diff --git a/pom.xml b/pom.xml index 3227443a..3c783a54 100644 --- a/pom.xml +++ b/pom.xml @@ -25,13 +25,13 @@ io.wcm.devops.conga io.wcm.devops.conga.parent - 1.16.4 + 1.16.5-SNAPSHOT parent/pom.xml io.wcm.devops.conga io.wcm.devops.conga.root - 1.16.4 + 1.16.5-SNAPSHOT pom CONGA diff --git a/resource/pom.xml b/resource/pom.xml index fdebb1c8..d9310acb 100644 --- a/resource/pom.xml +++ b/resource/pom.xml @@ -25,7 +25,7 @@ io.wcm.devops.conga io.wcm.devops.conga.parent - 1.16.4 + 1.16.5-SNAPSHOT ../parent/pom.xml diff --git a/tooling/conga-cli/pom.xml b/tooling/conga-cli/pom.xml index b71fa477..dcecf4c3 100644 --- a/tooling/conga-cli/pom.xml +++ b/tooling/conga-cli/pom.xml @@ -25,7 +25,7 @@ io.wcm.devops.conga io.wcm.devops.conga.parent - 1.16.4 + 1.16.5-SNAPSHOT ../../parent/pom.xml @@ -40,7 +40,7 @@ io.wcm.devops.conga io.wcm.devops.conga.generator - 1.16.4 + 1.16.5-SNAPSHOT compile diff --git a/tooling/conga-maven-plugin/pom.xml b/tooling/conga-maven-plugin/pom.xml index d6f9c0e9..bb153df2 100644 --- a/tooling/conga-maven-plugin/pom.xml +++ b/tooling/conga-maven-plugin/pom.xml @@ -25,7 +25,7 @@ io.wcm.devops.conga io.wcm.devops.conga.parent - 1.16.4 + 1.16.5-SNAPSHOT ../../parent/pom.xml @@ -56,7 +56,7 @@ io.wcm.devops.conga io.wcm.devops.conga.generator - 1.16.4 + 1.16.5-SNAPSHOT compile From bd0c2ec2c67001e0598f6d7523fc9988dee8396d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 Oct 2023 06:02:06 +0000 Subject: [PATCH 02/26] Bump maven-plugin-plugin.version from 3.9.0 to 3.10.1 Bumps `maven-plugin-plugin.version` from 3.9.0 to 3.10.1. Updates `org.apache.maven.plugin-tools:maven-plugin-annotations` from 3.9.0 to 3.10.1 - [Release notes](https://github.com/apache/maven-plugin-tools/releases) - [Commits](https://github.com/apache/maven-plugin-tools/compare/maven-plugin-tools-3.9.0...maven-plugin-tools-3.10.1) Updates `org.apache.maven.plugins:maven-plugin-plugin` from 3.9.0 to 3.10.1 - [Release notes](https://github.com/apache/maven-plugin-tools/releases) - [Commits](https://github.com/apache/maven-plugin-tools/compare/maven-plugin-tools-3.9.0...maven-plugin-tools-3.10.1) --- updated-dependencies: - dependency-name: org.apache.maven.plugin-tools:maven-plugin-annotations dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: org.apache.maven.plugins:maven-plugin-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- tooling/conga-maven-plugin/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tooling/conga-maven-plugin/pom.xml b/tooling/conga-maven-plugin/pom.xml index bb153df2..2968ae4e 100644 --- a/tooling/conga-maven-plugin/pom.xml +++ b/tooling/conga-maven-plugin/pom.xml @@ -40,7 +40,7 @@ tooling/conga-maven-plugin - 3.9.0 + 3.10.1 invoker.mavenOpts From 46da732d4a55ef4b1ad632121b4769189aaac844 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 26 Oct 2023 05:59:11 +0000 Subject: [PATCH 03/26] Bump commons-io:commons-io from 2.14.0 to 2.15.0 Bumps commons-io:commons-io from 2.14.0 to 2.15.0. --- updated-dependencies: - dependency-name: commons-io:commons-io dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- parent/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parent/pom.xml b/parent/pom.xml index d5024b9a..ad06a5f6 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -87,7 +87,7 @@ commons-io commons-io - 2.14.0 + 2.15.0 From 173a4993558f5d544462f08528fafcf087665f82 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 27 Oct 2023 05:41:07 +0000 Subject: [PATCH 04/26] Bump commons-cli:commons-cli from 1.5.0 to 1.6.0 Bumps commons-cli:commons-cli from 1.5.0 to 1.6.0. --- updated-dependencies: - dependency-name: commons-cli:commons-cli dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- parent/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parent/pom.xml b/parent/pom.xml index ad06a5f6..2d19e514 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -93,7 +93,7 @@ commons-cli commons-cli - 1.5.0 + 1.6.0 From 7aaa5887449e31407834f640498e336f871b6161 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 30 Oct 2023 05:33:37 +0000 Subject: [PATCH 05/26] Bump org.apache.commons:commons-text from 1.10.0 to 1.11.0 Bumps org.apache.commons:commons-text from 1.10.0 to 1.11.0. --- updated-dependencies: - dependency-name: org.apache.commons:commons-text dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- parent/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parent/pom.xml b/parent/pom.xml index 2d19e514..b1d5e097 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -69,7 +69,7 @@ org.apache.commons commons-text - 1.10.0 + 1.11.0 From 067f23e24185487b61de7e418afdd06db8f67d09 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 7 Nov 2023 05:56:28 +0000 Subject: [PATCH 06/26] Bump maven-plugin-plugin.version from 3.10.1 to 3.10.2 Bumps `maven-plugin-plugin.version` from 3.10.1 to 3.10.2. Updates `org.apache.maven.plugin-tools:maven-plugin-annotations` from 3.10.1 to 3.10.2 - [Release notes](https://github.com/apache/maven-plugin-tools/releases) - [Commits](https://github.com/apache/maven-plugin-tools/compare/maven-plugin-tools-3.10.1...maven-plugin-tools-3.10.2) Updates `org.apache.maven.plugins:maven-plugin-plugin` from 3.10.1 to 3.10.2 - [Release notes](https://github.com/apache/maven-plugin-tools/releases) - [Commits](https://github.com/apache/maven-plugin-tools/compare/maven-plugin-tools-3.10.1...maven-plugin-tools-3.10.2) --- updated-dependencies: - dependency-name: org.apache.maven.plugin-tools:maven-plugin-annotations dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: org.apache.maven.plugins:maven-plugin-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- tooling/conga-maven-plugin/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tooling/conga-maven-plugin/pom.xml b/tooling/conga-maven-plugin/pom.xml index 2968ae4e..01bb158b 100644 --- a/tooling/conga-maven-plugin/pom.xml +++ b/tooling/conga-maven-plugin/pom.xml @@ -40,7 +40,7 @@ tooling/conga-maven-plugin - 3.10.1 + 3.10.2 invoker.mavenOpts From 1fd0260e78e91b8a41587fbc9c0acce720bf8f9c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 17 Nov 2023 05:07:31 +0000 Subject: [PATCH 07/26] Bump org.springframework:spring-core from 5.3.30 to 5.3.31 Bumps [org.springframework:spring-core](https://github.com/spring-projects/spring-framework) from 5.3.30 to 5.3.31. - [Release notes](https://github.com/spring-projects/spring-framework/releases) - [Commits](https://github.com/spring-projects/spring-framework/compare/v5.3.30...v5.3.31) --- updated-dependencies: - dependency-name: org.springframework:spring-core dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- parent/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parent/pom.xml b/parent/pom.xml index b1d5e097..071f56f6 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -116,7 +116,7 @@ org.springframework spring-core - 5.3.30 + 5.3.31 From c7c1edba069a57b24022110b950f5005d3160675 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 22 Nov 2023 05:25:36 +0000 Subject: [PATCH 08/26] Bump org.apache.commons:commons-lang3 from 3.13.0 to 3.14.0 Bumps org.apache.commons:commons-lang3 from 3.13.0 to 3.14.0. --- updated-dependencies: - dependency-name: org.apache.commons:commons-lang3 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- parent/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parent/pom.xml b/parent/pom.xml index 071f56f6..3798716e 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -63,7 +63,7 @@ org.apache.commons commons-lang3 - 3.13.0 + 3.14.0 From 5b977929a0e67f568f446b34e2520b91ddd63e80 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 30 Nov 2023 05:22:18 +0000 Subject: [PATCH 09/26] Bump commons-io:commons-io from 2.15.0 to 2.15.1 Bumps commons-io:commons-io from 2.15.0 to 2.15.1. --- updated-dependencies: - dependency-name: commons-io:commons-io dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- parent/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parent/pom.xml b/parent/pom.xml index 3798716e..78a2edcb 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -87,7 +87,7 @@ commons-io commons-io - 2.15.0 + 2.15.1 From dffaf468f5b5a85e4da9235b4327648fbd3c31a5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 19 Dec 2023 05:48:43 +0000 Subject: [PATCH 10/26] Bump com.google.guava:guava from 32.1.3-jre to 33.0.0-jre Bumps [com.google.guava:guava](https://github.com/google/guava) from 32.1.3-jre to 33.0.0-jre. - [Release notes](https://github.com/google/guava/releases) - [Commits](https://github.com/google/guava/commits) --- updated-dependencies: - dependency-name: com.google.guava:guava dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- parent/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parent/pom.xml b/parent/pom.xml index 78a2edcb..b27d0b78 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -75,7 +75,7 @@ com.google.guava guava - 32.1.3-jre + 33.0.0-jre From 03856f39b8a67e3e0eb3e08c4632b194b5511a75 Mon Sep 17 00:00:00 2001 From: Stefan Seifert Date: Tue, 9 Jan 2024 14:57:39 +0100 Subject: [PATCH 11/26] Special handling for detecting ".cfg.json" file extensions. (#57) --- changes.xml | 6 +++ .../devops/conga/generator/util/FileUtil.java | 11 ++++- .../conga/generator/util/FileUtilTest.java | 41 +++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 generator/src/test/java/io/wcm/devops/conga/generator/util/FileUtilTest.java diff --git a/changes.xml b/changes.xml index 9e55499b..8701e033 100644 --- a/changes.xml +++ b/changes.xml @@ -23,6 +23,12 @@ xsi:schemaLocation="http://maven.apache.org/changes/1.0.0 https://maven.apache.org/plugins/maven-changes-plugin/xsd/changes-1.0.0.xsd"> + + + Special handling for detecting ".cfg.json" file extensions. + + + Increase SnakeYAML codepoint limit to 64MB (from default 3MB). diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/util/FileUtil.java b/generator/src/main/java/io/wcm/devops/conga/generator/util/FileUtil.java index 6c447d30..0e7d9dd5 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/util/FileUtil.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/util/FileUtil.java @@ -110,7 +110,16 @@ public static boolean matchesExtension(String fileExtension, String extension) { * @return true if file extension matches */ public static boolean matchesExtension(File file, String extension) { - return matchesExtension(FilenameUtils.getExtension(file.getName()), extension); + String fileName = file.getName(); + String fileExtension; + // special handling for OSGi configuration resource file extension + if (fileName.endsWith(".cfg.json")) { + fileExtension = "cfg.json"; + } + else { + fileExtension = FilenameUtils.getExtension(fileName); + } + return matchesExtension(fileExtension, extension); } /** diff --git a/generator/src/test/java/io/wcm/devops/conga/generator/util/FileUtilTest.java b/generator/src/test/java/io/wcm/devops/conga/generator/util/FileUtilTest.java new file mode 100644 index 00000000..7b0b67c1 --- /dev/null +++ b/generator/src/test/java/io/wcm/devops/conga/generator/util/FileUtilTest.java @@ -0,0 +1,41 @@ +/* + * #%L + * wcm.io + * %% + * Copyright (C) 2024 wcm.io + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ +package io.wcm.devops.conga.generator.util; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.io.File; + +import org.junit.jupiter.api.Test; + +class FileUtilTest { + + @Test + void testMatchesExtension() { + assertTrue(FileUtil.matchesExtension(new File("test.txt"), "txt")); + assertTrue(FileUtil.matchesExtension(new File("test.part2.txt"), "txt")); + assertFalse(FileUtil.matchesExtension(new File("test.pdf"), "txt")); + + // special handling for OSGi configuration resource file extension + assertTrue(FileUtil.matchesExtension(new File("test.cfg.json"), "cfg.json")); + } + +} From d95c39c7a470d30cee480808456fbdd01eab7a56 Mon Sep 17 00:00:00 2001 From: Stefan Seifert Date: Tue, 9 Jan 2024 15:14:05 +0100 Subject: [PATCH 12/26] update test cases --- .../java/io/wcm/devops/conga/generator/util/FileUtilTest.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/generator/src/test/java/io/wcm/devops/conga/generator/util/FileUtilTest.java b/generator/src/test/java/io/wcm/devops/conga/generator/util/FileUtilTest.java index 7b0b67c1..9996ca13 100644 --- a/generator/src/test/java/io/wcm/devops/conga/generator/util/FileUtilTest.java +++ b/generator/src/test/java/io/wcm/devops/conga/generator/util/FileUtilTest.java @@ -33,9 +33,12 @@ void testMatchesExtension() { assertTrue(FileUtil.matchesExtension(new File("test.txt"), "txt")); assertTrue(FileUtil.matchesExtension(new File("test.part2.txt"), "txt")); assertFalse(FileUtil.matchesExtension(new File("test.pdf"), "txt")); + assertTrue(FileUtil.matchesExtension(new File("test.json"), "json")); // special handling for OSGi configuration resource file extension assertTrue(FileUtil.matchesExtension(new File("test.cfg.json"), "cfg.json")); + assertFalse(FileUtil.matchesExtension(new File("test.cfg.json"), "json")); + assertFalse(FileUtil.matchesExtension(new File("test.json"), "cfg.json")); } } From d28d37dd1f55bbefe799ec1add65dc991f0d9b0f Mon Sep 17 00:00:00 2001 From: Stefan Seifert Date: Wed, 10 Jan 2024 13:16:05 +0100 Subject: [PATCH 13/26] eliminate usage of guava collections in unit tests --- .../FileGeneratorFileHeaderTest.java | 22 ++-- .../FileGeneratorPostProcessorTest.java | 93 ++++++++-------- .../generator/FileGeneratorValidatorTest.java | 26 +++-- .../GeneratorTestNodeModelExportTest.java | 24 ++--- .../wcm/devops/conga/generator/TestUtils.java | 13 ++- .../fileheader/ConfFileHeaderTest.java | 4 +- .../fileheader/JsonFileHeaderTest.java | 4 +- .../UnixShellScriptFileHeaderTest.java | 4 +- .../WindowsShellScriptFileHeaderTest.java | 4 +- .../plugins/fileheader/XmlFileHeaderTest.java | 4 +- .../handlebars/helper/ContainsHelperTest.java | 14 +-- .../helper/EachIfEqualsHelperTest.java | 16 +-- .../handlebars/helper/EachIfHelperTest.java | 16 +-- .../handlebars/helper/IfEqualsHelperTest.java | 8 +- .../helper/IfNotEqualsHelperTest.java | 8 +- .../handlebars/helper/MockOptions.java | 4 +- .../plugins/multiply/NoneMultiplyTest.java | 4 +- .../plugins/multiply/TenantMultiplyTest.java | 29 +++-- .../AbstractPostProcessorTest.java | 4 +- .../postprocessor/DummyPostProcessor.java | 4 +- .../DummyMapValueProviderPlugin.java | 10 +- ...SystemPropertyValueProviderPluginTest.java | 6 +- .../util/ConfigInheritanceResolverTest.java | 38 +++---- .../generator/util/JexlResolverTest.java | 8 +- .../util/ModelExportConfigProcessorTest.java | 49 ++++----- .../conga/generator/util/RoleUtilTest.java | 100 +++++++++--------- .../conga/generator/util/ValueUtilTest.java | 22 ++-- .../util/VariableMapResolverTest.java | 90 ++++++++-------- .../util/VariableObjectTreeResolverTest.java | 36 +++---- .../VariableStringResolverExpressionTest.java | 26 +++-- .../util/VariableStringResolverTest.java | 40 ++++--- .../model/reader/EnvironmentReaderTest.java | 32 +++--- .../conga/model/reader/RoleReaderTest.java | 32 +++--- .../conga/model/util/MapExpanderTest.java | 70 ++++++------ .../conga/model/util/MapMergerTest.java | 5 +- .../conga/model/util/MapSplitterTest.java | 77 +++++++------- .../conga/model/util/MergingListTest.java | 16 +-- .../resource/ResourceLoaderClasspathTest.java | 12 +-- .../ResourceLoaderFilesystemTest.java | 12 +-- .../plugin/util/PluginConfigUtilTest.java | 18 ++-- .../MavenPropertyValueProviderPluginTest.java | 6 +- 41 files changed, 478 insertions(+), 532 deletions(-) diff --git a/generator/src/test/java/io/wcm/devops/conga/generator/FileGeneratorFileHeaderTest.java b/generator/src/test/java/io/wcm/devops/conga/generator/FileGeneratorFileHeaderTest.java index d714a8ff..d6a06ad9 100644 --- a/generator/src/test/java/io/wcm/devops/conga/generator/FileGeneratorFileHeaderTest.java +++ b/generator/src/test/java/io/wcm/devops/conga/generator/FileGeneratorFileHeaderTest.java @@ -49,8 +49,6 @@ import org.mockito.stubbing.Answer; import com.github.jknack.handlebars.Template; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; import io.wcm.devops.conga.generator.spi.FileHeaderPlugin; import io.wcm.devops.conga.generator.spi.ImplicitApplyOptions; @@ -91,7 +89,7 @@ void setUp(TestInfo testInfo) { when(pluginManager.getAll(FileHeaderPlugin.class)).thenAnswer(new Answer>() { @Override public List answer(InvocationOnMock invocation) throws Throwable { - return ImmutableList.copyOf(fileHeaderPlugins.values()); + return List.copyOf(fileHeaderPlugins.values()); } }); when(pluginManager.get(anyString(), eq(FileHeaderPlugin.class))).thenAnswer(new Answer() { @@ -111,9 +109,9 @@ public FileHeaderPlugin answer(InvocationOnMock invocation) throws Throwable { VariableMapResolver variableMapResolver = new VariableMapResolver( new ValueProviderGlobalContext().pluginContextOptions(pluginContextOptions)); underTest = new FileGenerator(options, "env1", - "role1", ImmutableList.of("variant1"), "template1", - destDir, file, null, null, roleFile, ImmutableMap.of(), template, - variableMapResolver, urlFileManager, pluginContextOptions, ImmutableList.of( + "role1", List.of("variant1"), "template1", + destDir, file, null, null, roleFile, Map.of(), template, + variableMapResolver, urlFileManager, pluginContextOptions, List.of( "version1/1.0.0", "version2/2.0.0-SNAPSHOT", "version3/1.2.0-SNAPSHOT", @@ -125,7 +123,7 @@ public FileHeaderPlugin answer(InvocationOnMock invocation) throws Throwable { void testWithoutFileHeader() throws Exception { FileHeaderPlugin one = mockFileHeader("one", "txt", ImplicitApplyOptions.NEVER); - List result = ImmutableList.copyOf(underTest.generate()); + List result = List.copyOf(underTest.generate()); assertEquals(1, result.size()); assertItem(result.get(0), "test.txt"); @@ -138,7 +136,7 @@ void testExplicitFileHeader() throws Exception { FileHeaderPlugin one = mockFileHeader("one", "txt", ImplicitApplyOptions.NEVER); roleFile.setFileHeader("one"); - List result = ImmutableList.copyOf(underTest.generate()); + List result = List.copyOf(underTest.generate()); assertEquals(1, result.size()); assertItem(result.get(0), "test.txt"); @@ -150,7 +148,7 @@ void testExplicitFileHeader() throws Exception { void testImplicitFileHeader() throws Exception { FileHeaderPlugin one = mockFileHeader("one", "txt", ImplicitApplyOptions.WHEN_UNCONFIGURED); - List result = ImmutableList.copyOf(underTest.generate()); + List result = List.copyOf(underTest.generate()); assertEquals(1, result.size()); assertItem(result.get(0), "test.txt"); @@ -162,7 +160,7 @@ void testImplicitFileHeader() throws Exception { void testAlwaysFileHeader() throws Exception { FileHeaderPlugin one = mockFileHeader("one", "txt", ImplicitApplyOptions.ALWAYS); - List result = ImmutableList.copyOf(underTest.generate()); + List result = List.copyOf(underTest.generate()); assertEquals(1, result.size()); assertItem(result.get(0), "test.txt"); @@ -175,7 +173,7 @@ void testImplicitAndAlwaysFileHeader() throws Exception { FileHeaderPlugin one = mockFileHeader("one", "txt", ImplicitApplyOptions.WHEN_UNCONFIGURED); FileHeaderPlugin two = mockFileHeader("two", "txt", ImplicitApplyOptions.ALWAYS); - List result = ImmutableList.copyOf(underTest.generate()); + List result = List.copyOf(underTest.generate()); assertEquals(1, result.size()); assertItem(result.get(0), "test.txt"); @@ -189,7 +187,7 @@ void testVersions() throws Exception { FileHeaderPlugin one = mockFileHeader("one", "txt", ImplicitApplyOptions.NEVER); roleFile.setFileHeader("one"); - List result = ImmutableList.copyOf(underTest.generate()); + List result = List.copyOf(underTest.generate()); assertEquals(1, result.size()); assertItem(result.get(0), "test.txt"); diff --git a/generator/src/test/java/io/wcm/devops/conga/generator/FileGeneratorPostProcessorTest.java b/generator/src/test/java/io/wcm/devops/conga/generator/FileGeneratorPostProcessorTest.java index 42a3e502..f2b1c640 100644 --- a/generator/src/test/java/io/wcm/devops/conga/generator/FileGeneratorPostProcessorTest.java +++ b/generator/src/test/java/io/wcm/devops/conga/generator/FileGeneratorPostProcessorTest.java @@ -52,9 +52,6 @@ import org.slf4j.Logger; import com.github.jknack.handlebars.Template; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import io.wcm.devops.conga.generator.spi.FileHeaderPlugin; @@ -105,7 +102,7 @@ void setUp(TestInfo testInfo) { when(pluginManager.getAll(PostProcessorPlugin.class)).thenAnswer(new Answer>() { @Override public List answer(InvocationOnMock invocation) throws Throwable { - return ImmutableList.copyOf(postProcessorPlugins.values()); + return List.copyOf(postProcessorPlugins.values()); } }); when(pluginManager.get(anyString(), eq(PostProcessorPlugin.class))).thenAnswer(new Answer() { @@ -125,19 +122,19 @@ public PostProcessorPlugin answer(InvocationOnMock invocation) throws Throwable variableMapResolver = new VariableMapResolver( new ValueProviderGlobalContext().pluginContextOptions(pluginContextOptions)); underTest = new FileGenerator(options, "env1", - "role1", ImmutableList.of("variant1"), "template1", - destDir, file, null, null, roleFile, ImmutableMap.of(), template, - variableMapResolver, urlFileManager, pluginContextOptions, ImmutableList.of()); + "role1", List.of("variant1"), "template1", + destDir, file, null, null, roleFile, Map.of(), template, + variableMapResolver, urlFileManager, pluginContextOptions, List.of()); } @Test void testWithoutPostProcessor() throws Exception { PostProcessorPlugin one = mockPostProcessor("one", "txt", ImplicitApplyOptions.NEVER); - List result = ImmutableList.copyOf(underTest.generate()); + List result = List.copyOf(underTest.generate()); assertEquals(1, result.size()); - assertItem(result.get(0), "test.txt", ImmutableMap.of(), ImmutableSet.of()); + assertItem(result.get(0), "test.txt", Map.of(), Set.of()); verify(one, never()).apply(any(FileContext.class), any(PostProcessorContext.class)); } @@ -145,12 +142,12 @@ void testWithoutPostProcessor() throws Exception { @Test void testOnePostProcessor() throws Exception { PostProcessorPlugin one = mockPostProcessor("one", "txt", ImplicitApplyOptions.NEVER); - roleFile.setPostProcessors(ImmutableList.of("one")); + roleFile.setPostProcessors(List.of("one")); - List result = ImmutableList.copyOf(underTest.generate()); + List result = List.copyOf(underTest.generate()); assertEquals(1, result.size()); - assertItem(result.get(0), "test.txt", ImmutableMap.of(), ImmutableSet.of("one")); + assertItem(result.get(0), "test.txt", Map.of(), Set.of("one")); verify(one, times(1)).apply(any(FileContext.class), any(PostProcessorContext.class)); } @@ -165,17 +162,17 @@ void testOnePostProcessorWithRewrite() throws Exception { public List answer(InvocationOnMock invocation) throws Throwable { // delete input file and create new file test.abc instead FileContext input = invocation.getArgument(0); - assertItem(input, "test.txt", ImmutableMap.of()); + assertItem(input, "test.txt", Map.of()); input.getFile().delete(); - return ImmutableList.of(newFile("test.abc")); + return List.of(newFile("test.abc")); } }); - roleFile.setPostProcessors(ImmutableList.of("one")); + roleFile.setPostProcessors(List.of("one")); - List result = ImmutableList.copyOf(underTest.generate()); + List result = List.copyOf(underTest.generate()); assertEquals(1, result.size()); - assertItem(result.get(0), "test.abc", ImmutableMap.of(), ImmutableSet.of("one")); + assertItem(result.get(0), "test.abc", Map.of(), Set.of("one")); verify(one, times(1)).apply(any(FileContext.class), any(PostProcessorContext.class)); } @@ -189,20 +186,20 @@ void testOnePostProcessorWithRewrite_WithFileHeaderAndValidator() throws Excepti public List answer(InvocationOnMock invocation) throws Throwable { // delete input file and create new file test.abc instead FileContext input = invocation.getArgument(0); - assertItem(input, "test.txt", ImmutableMap.of()); + assertItem(input, "test.txt", Map.of()); input.getFile().delete(); - return ImmutableList.of(newFile("test.abc")); + return List.of(newFile("test.abc")); } }); - roleFile.setPostProcessors(ImmutableList.of("one")); + roleFile.setPostProcessors(List.of("one")); - roleFile.setPostProcessorOptions(ImmutableMap.of( + roleFile.setPostProcessorOptions(Map.of( FileGenerator.POSTPROCESSOR_KEY_FILE_HEADER, "my-fileheader", - FileGenerator.POSTPROCESSOR_KEY_VALIDATORS, ImmutableList.of("my-validator"))); + FileGenerator.POSTPROCESSOR_KEY_VALIDATORS, List.of("my-validator"))); underTest = new FileGenerator(options, "env1", - "role1", ImmutableList.of("variant1"), "template1", - destDir, file, null, null, roleFile, ImmutableMap.of(), template, - variableMapResolver, urlFileManager, pluginContextOptions, ImmutableList.of()); + "role1", List.of("variant1"), "template1", + destDir, file, null, null, roleFile, Map.of(), template, + variableMapResolver, urlFileManager, pluginContextOptions, List.of()); FileHeaderPlugin fileHeaderPlugin = mock(FileHeaderPlugin.class); when(pluginManager.get(eq("my-fileheader"), eq(FileHeaderPlugin.class))).thenAnswer(new Answer() { @@ -220,10 +217,10 @@ public ValidatorPlugin answer(InvocationOnMock invocation) throws Throwable { } }); - List result = ImmutableList.copyOf(underTest.generate()); + List result = List.copyOf(underTest.generate()); assertEquals(1, result.size()); - assertItem(result.get(0), "test.abc", ImmutableMap.of(), ImmutableSet.of("one")); + assertItem(result.get(0), "test.abc", Map.of(), Set.of("one")); verify(one, times(1)).apply(any(FileContext.class), any(PostProcessorContext.class)); verify(fileHeaderPlugin, times(1)).apply(any(FileContext.class), any(FileHeaderContext.class)); @@ -234,12 +231,12 @@ public ValidatorPlugin answer(InvocationOnMock invocation) throws Throwable { void testTwoPostProcessors() throws Exception { PostProcessorPlugin one = mockPostProcessor("one", "txt", ImplicitApplyOptions.NEVER); PostProcessorPlugin two = mockPostProcessor("two", "txt", ImplicitApplyOptions.NEVER); - roleFile.setPostProcessors(ImmutableList.of("one", "two")); + roleFile.setPostProcessors(List.of("one", "two")); - List result = ImmutableList.copyOf(underTest.generate()); + List result = List.copyOf(underTest.generate()); assertEquals(1, result.size()); - assertItem(result.get(0), "test.txt", ImmutableMap.of(), ImmutableSet.of("one", "two")); + assertItem(result.get(0), "test.txt", Map.of(), Set.of("one", "two")); verify(one, times(1)).apply(any(FileContext.class), any(PostProcessorContext.class)); verify(two, times(1)).apply(any(FileContext.class), any(PostProcessorContext.class)); @@ -254,9 +251,9 @@ void testTwoPostProcessorsWithRewrite() throws Exception { public List answer(InvocationOnMock invocation) throws Throwable { // delete input file and create new file test.abc instead FileContext input = invocation.getArgument(0); - assertItem(input, "test.txt", ImmutableMap.of()); + assertItem(input, "test.txt", Map.of()); input.getFile().delete(); - return ImmutableList.of(newFile("test.abc")); + return List.of(newFile("test.abc")); } }); @@ -266,28 +263,28 @@ public List answer(InvocationOnMock invocation) throws Throwable { public List answer(InvocationOnMock invocation) throws Throwable { // create new file test.def FileContext input = invocation.getArgument(0); - assertItem(input, "test.abc", ImmutableMap.of()); - return ImmutableList.of(newFile("test.def")); + assertItem(input, "test.abc", Map.of()); + return List.of(newFile("test.def")); } }); - roleFile.setPostProcessors(ImmutableList.of("one", "two")); + roleFile.setPostProcessors(List.of("one", "two")); - List result = ImmutableList.copyOf(underTest.generate()); + List result = List.copyOf(underTest.generate()); assertEquals(2, result.size()); - assertItem(result.get(0), "test.abc", ImmutableMap.of(), ImmutableSet.of("one", "two")); - assertItem(result.get(1), "test.def", ImmutableMap.of(), ImmutableSet.of("two")); + assertItem(result.get(0), "test.abc", Map.of(), Set.of("one", "two")); + assertItem(result.get(1), "test.def", Map.of(), Set.of("two")); } @Test void testImplicitPostProcessor() throws Exception { PostProcessorPlugin one = mockPostProcessor("one", "txt", ImplicitApplyOptions.WHEN_UNCONFIGURED); - List result = ImmutableList.copyOf(underTest.generate()); + List result = List.copyOf(underTest.generate()); assertEquals(1, result.size()); - assertItem(result.get(0), "test.txt", ImmutableMap.of(), ImmutableSet.of("one")); + assertItem(result.get(0), "test.txt", Map.of(), Set.of("one")); verify(one, times(1)).apply(any(FileContext.class), any(PostProcessorContext.class)); } @@ -296,10 +293,10 @@ void testImplicitPostProcessor() throws Exception { void testAlwaysPostProcessor() throws Exception { PostProcessorPlugin one = mockPostProcessor("one", "txt", ImplicitApplyOptions.ALWAYS); - List result = ImmutableList.copyOf(underTest.generate()); + List result = List.copyOf(underTest.generate()); assertEquals(1, result.size()); - assertItem(result.get(0), "test.txt", ImmutableMap.of(), ImmutableSet.of("one")); + assertItem(result.get(0), "test.txt", Map.of(), Set.of("one")); verify(one, times(1)).apply(any(FileContext.class), any(PostProcessorContext.class)); } @@ -312,20 +309,20 @@ void testPostProcessorWithRewriteAndImplicit() throws Exception { public List answer(InvocationOnMock invocation) throws Throwable { // delete input file and create new file test.abc instead FileContext input = invocation.getArgument(0); - assertItem(input, "test.txt", ImmutableMap.of()); - return ImmutableList.of(newFile("test.abc")); + assertItem(input, "test.txt", Map.of()); + return List.of(newFile("test.abc")); } }); PostProcessorPlugin two = mockPostProcessor("two", "txt", ImplicitApplyOptions.ALWAYS); PostProcessorPlugin three = mockPostProcessor("three", "abc", ImplicitApplyOptions.ALWAYS); - roleFile.setPostProcessors(ImmutableList.of("one")); + roleFile.setPostProcessors(List.of("one")); - List result = ImmutableList.copyOf(underTest.generate()); + List result = List.copyOf(underTest.generate()); assertEquals(2, result.size()); - assertItem(result.get(0), "test.txt", ImmutableMap.of(), ImmutableSet.of("one", "two")); - assertItem(result.get(1), "test.abc", ImmutableMap.of(), ImmutableSet.of("one", "three")); + assertItem(result.get(0), "test.txt", Map.of(), Set.of("one", "two")); + assertItem(result.get(1), "test.abc", Map.of(), Set.of("one", "three")); verify(one, times(1)).apply(any(FileContext.class), any(PostProcessorContext.class)); verify(two, times(1)).apply(any(FileContext.class), any(PostProcessorContext.class)); diff --git a/generator/src/test/java/io/wcm/devops/conga/generator/FileGeneratorValidatorTest.java b/generator/src/test/java/io/wcm/devops/conga/generator/FileGeneratorValidatorTest.java index 09217b24..e2f1323e 100644 --- a/generator/src/test/java/io/wcm/devops/conga/generator/FileGeneratorValidatorTest.java +++ b/generator/src/test/java/io/wcm/devops/conga/generator/FileGeneratorValidatorTest.java @@ -48,8 +48,6 @@ import org.slf4j.Logger; import com.github.jknack.handlebars.Template; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; import io.wcm.devops.conga.generator.spi.ImplicitApplyOptions; import io.wcm.devops.conga.generator.spi.ValidatorPlugin; @@ -92,7 +90,7 @@ void setUp(TestInfo testInfo) { when(pluginManager.getAll(ValidatorPlugin.class)).thenAnswer(new Answer>() { @Override public List answer(InvocationOnMock invocation) throws Throwable { - return ImmutableList.copyOf(validatorPlugins.values()); + return List.copyOf(validatorPlugins.values()); } }); when(pluginManager.get(anyString(), eq(ValidatorPlugin.class))).thenAnswer(new Answer() { @@ -112,16 +110,16 @@ public ValidatorPlugin answer(InvocationOnMock invocation) throws Throwable { VariableMapResolver variableMapResolver = new VariableMapResolver( new ValueProviderGlobalContext().pluginContextOptions(pluginContextOptions)); underTest = new FileGenerator(options, "env1", - "role1", ImmutableList.of("variant1"), "template1", - destDir, file, null, null, roleFile, ImmutableMap.of(), template, - variableMapResolver, urlFileManager, pluginContextOptions, ImmutableList.of()); + "role1", List.of("variant1"), "template1", + destDir, file, null, null, roleFile, Map.of(), template, + variableMapResolver, urlFileManager, pluginContextOptions, List.of()); } @Test void testWithoutValidator() throws Exception { ValidatorPlugin one = mockValidator("one", "txt", ImplicitApplyOptions.NEVER); - List result = ImmutableList.copyOf(underTest.generate()); + List result = List.copyOf(underTest.generate()); assertEquals(1, result.size()); assertItem(result.get(0), "test.txt"); @@ -132,9 +130,9 @@ void testWithoutValidator() throws Exception { @Test void testOneValidator() throws Exception { ValidatorPlugin one = mockValidator("one", "txt", ImplicitApplyOptions.NEVER); - roleFile.setValidators(ImmutableList.of("one")); + roleFile.setValidators(List.of("one")); - List result = ImmutableList.copyOf(underTest.generate()); + List result = List.copyOf(underTest.generate()); assertEquals(1, result.size()); assertItem(result.get(0), "test.txt"); @@ -146,9 +144,9 @@ void testOneValidator() throws Exception { void testTwoValidators() throws Exception { ValidatorPlugin one = mockValidator("one", "txt", ImplicitApplyOptions.NEVER); ValidatorPlugin two = mockValidator("two", "txt", ImplicitApplyOptions.NEVER); - roleFile.setValidators(ImmutableList.of("one", "two")); + roleFile.setValidators(List.of("one", "two")); - List result = ImmutableList.copyOf(underTest.generate()); + List result = List.copyOf(underTest.generate()); assertEquals(1, result.size()); assertItem(result.get(0), "test.txt"); @@ -161,7 +159,7 @@ void testTwoValidators() throws Exception { void testImplicitValidator() throws Exception { ValidatorPlugin one = mockValidator("one", "txt", ImplicitApplyOptions.WHEN_UNCONFIGURED); - List result = ImmutableList.copyOf(underTest.generate()); + List result = List.copyOf(underTest.generate()); assertEquals(1, result.size()); assertItem(result.get(0), "test.txt"); @@ -173,7 +171,7 @@ void testImplicitValidator() throws Exception { void testAlwaysValidator() throws Exception { ValidatorPlugin one = mockValidator("one", "txt", ImplicitApplyOptions.ALWAYS); - List result = ImmutableList.copyOf(underTest.generate()); + List result = List.copyOf(underTest.generate()); assertEquals(1, result.size()); assertItem(result.get(0), "test.txt"); @@ -186,7 +184,7 @@ void testImplicitAndAlwaysValidator() throws Exception { ValidatorPlugin one = mockValidator("one", "txt", ImplicitApplyOptions.WHEN_UNCONFIGURED); ValidatorPlugin two = mockValidator("two", "txt", ImplicitApplyOptions.ALWAYS); - List result = ImmutableList.copyOf(underTest.generate()); + List result = List.copyOf(underTest.generate()); assertEquals(1, result.size()); assertItem(result.get(0), "test.txt"); diff --git a/generator/src/test/java/io/wcm/devops/conga/generator/GeneratorTestNodeModelExportTest.java b/generator/src/test/java/io/wcm/devops/conga/generator/GeneratorTestNodeModelExportTest.java index 3e9ad03e..dc6a46dd 100644 --- a/generator/src/test/java/io/wcm/devops/conga/generator/GeneratorTestNodeModelExportTest.java +++ b/generator/src/test/java/io/wcm/devops/conga/generator/GeneratorTestNodeModelExportTest.java @@ -37,6 +37,7 @@ import java.io.Reader; import java.nio.charset.StandardCharsets; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Map; @@ -49,9 +50,6 @@ import org.junit.jupiter.api.TestInfo; import org.yaml.snakeyaml.Yaml; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; - import io.wcm.devops.conga.model.util.MapExpander; @SuppressWarnings("unchecked") @@ -86,14 +84,14 @@ void testAllEnvironments() throws IOException { "files/sample-copy.txt"); assertFileModelOptions(role1, "files/sample-filesystem.txt", - ImmutableMap.of("modelOption1", "value1")); + Map.of("modelOption1", "value1")); assertEquals("globalFromRole1", getConfig(role1, "globalString")); - assertEquals(ImmutableList.of("tenantRole1", "tenantRole2"), getTenantRoles(role1, "tenant1")); + assertEquals(List.of("tenantRole1", "tenantRole2"), getTenantRoles(role1, "tenant1")); assertEquals("\"value1\" äöü߀", getTenantConfig(role1, "tenant1", "defaultString")); - assertEquals(ImmutableList.of("tenantRole1"), getTenantRoles(role1, "tenant2")); + assertEquals(List.of("tenantRole1"), getTenantRoles(role1, "tenant2")); assertEquals("defaultFromTenant2", getTenantConfig(role1, "tenant2", "defaultString")); - assertEquals(ImmutableList.of(), getTenantRoles(role1, "tenant3_TenantSuffix")); + assertEquals(List.of(), getTenantRoles(role1, "tenant3_TenantSuffix")); assertEquals("\"value1\" äöü߀", getTenantConfig(role1, "tenant3_TenantSuffix", "defaultString")); assertEquals("tenant1 testVersion1ForFileHeader node1 role1", getTenantConfig(role1, "tenant1", "varWithContext")); assertEquals("tenant2 testVersion1ForFileHeader node1 role1", getTenantConfig(role1, "tenant2", "varWithContext")); @@ -103,11 +101,11 @@ void testAllEnvironments() throws IOException { "json/test.json"); assertEquals("globalValue äöü߀", getConfig(role2, "globalString")); assertEquals("globalValue äöü߀", getConfig(role2, "globalString")); - assertEquals(ImmutableList.of("tenantRole1", "tenantRole2"), getTenantRoles(role2, "tenant1")); + assertEquals(List.of("tenantRole1", "tenantRole2"), getTenantRoles(role2, "tenant1")); assertEquals("value2", getTenantConfig(role2, "tenant1", "defaultString")); - assertEquals(ImmutableList.of("tenantRole1"), getTenantRoles(role2, "tenant2")); + assertEquals(List.of("tenantRole1"), getTenantRoles(role2, "tenant2")); assertEquals("defaultFromTenant2", getTenantConfig(role2, "tenant2", "defaultString")); - assertEquals(ImmutableList.of(), getTenantRoles(role2, "tenant3_TenantSuffix")); + assertEquals(List.of(), getTenantRoles(role2, "tenant3_TenantSuffix")); assertEquals("value2", getTenantConfig(role2, "tenant3_TenantSuffix", "defaultString")); assertEquals("tenant1 testVersion1ForFileHeader node1 role2", getTenantConfig(role2, "tenant1", "varWithContext")); assertEquals("tenant2 testVersion1ForFileHeader node1 role2", getTenantConfig(role2, "tenant2", "varWithContext")); @@ -164,7 +162,7 @@ private void assertFiles(Map role, String... fileNamesExpected) if (files != null) { files.forEach(item -> fileNamesFound.add((String)item.get("path"))); } - assertEquals(ImmutableList.copyOf(fileNamesExpected), fileNamesFound); + assertEquals(Arrays.asList(fileNamesExpected), fileNamesFound); } private void assertFileModelOptions(Map role, String fileName, Map expectedOptions) { @@ -212,9 +210,9 @@ private Object getTenantConfig(Map role, String tenant, String k private List getTenantRoles(Map role, String tenant) { Map tenantObject = getTenant(role, tenant); if (tenantObject == null) { - return ImmutableList.of(); + return List.of(); } - return (List)ObjectUtils.defaultIfNull(tenantObject.get("roles"), ImmutableList.of()); + return (List)ObjectUtils.defaultIfNull(tenantObject.get("roles"), List.of()); } } diff --git a/generator/src/test/java/io/wcm/devops/conga/generator/TestUtils.java b/generator/src/test/java/io/wcm/devops/conga/generator/TestUtils.java index 14ce3cc9..82b7f15d 100644 --- a/generator/src/test/java/io/wcm/devops/conga/generator/TestUtils.java +++ b/generator/src/test/java/io/wcm/devops/conga/generator/TestUtils.java @@ -28,13 +28,12 @@ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Files; +import java.util.List; +import java.util.Map; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; - import io.wcm.devops.conga.generator.export.ModelExport; import io.wcm.devops.conga.generator.plugins.valueprovider.DummyPluginConfigValueProviderPlugin; import io.wcm.devops.conga.generator.util.FileUtil; @@ -57,14 +56,14 @@ public static Generator setupGenerator(File destDir) { .destDir(destDir) .version(TEST_VERSION) .pluginManager(new PluginManagerImpl()) - .genericPluginConfig(ImmutableMap.of( - DummyPluginConfigValueProviderPlugin.NAME, ImmutableMap.of( + .genericPluginConfig(Map.of( + DummyPluginConfigValueProviderPlugin.NAME, Map.of( "param1", "value1", "param2", 55, - "param3", ImmutableMap.of("param31", "value31", "param32", "value32")))); + "param3", Map.of("param31", "value31", "param32", "value32")))); ModelExport modelExport = new ModelExport(); - modelExport.setNode(ImmutableList.of("yaml")); + modelExport.setNode(List.of("yaml")); options.modelExport(modelExport); return new Generator(options); diff --git a/generator/src/test/java/io/wcm/devops/conga/generator/plugins/fileheader/ConfFileHeaderTest.java b/generator/src/test/java/io/wcm/devops/conga/generator/plugins/fileheader/ConfFileHeaderTest.java index 34fc9698..414cf132 100644 --- a/generator/src/test/java/io/wcm/devops/conga/generator/plugins/fileheader/ConfFileHeaderTest.java +++ b/generator/src/test/java/io/wcm/devops/conga/generator/plugins/fileheader/ConfFileHeaderTest.java @@ -31,8 +31,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import com.google.common.collect.ImmutableList; - import io.wcm.devops.conga.generator.spi.FileHeaderPlugin; import io.wcm.devops.conga.generator.spi.context.FileContext; import io.wcm.devops.conga.generator.spi.context.FileHeaderContext; @@ -52,7 +50,7 @@ void testApply() throws Exception { File file = new File("target/generation-test/fileHeader.conf"); FileUtils.write(file, "myscript", StandardCharsets.ISO_8859_1); - List lines = ImmutableList.of("Der Jodelkaiser", "aus dem Oetztal", "ist wieder daheim."); + List lines = List.of("Der Jodelkaiser", "aus dem Oetztal", "ist wieder daheim."); FileHeaderContext context = new FileHeaderContext().commentLines(lines); FileContext fileContext = new FileContext().file(file); diff --git a/generator/src/test/java/io/wcm/devops/conga/generator/plugins/fileheader/JsonFileHeaderTest.java b/generator/src/test/java/io/wcm/devops/conga/generator/plugins/fileheader/JsonFileHeaderTest.java index dbf6d019..cc996e11 100644 --- a/generator/src/test/java/io/wcm/devops/conga/generator/plugins/fileheader/JsonFileHeaderTest.java +++ b/generator/src/test/java/io/wcm/devops/conga/generator/plugins/fileheader/JsonFileHeaderTest.java @@ -31,8 +31,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import com.google.common.collect.ImmutableList; - import io.wcm.devops.conga.generator.spi.FileHeaderPlugin; import io.wcm.devops.conga.generator.spi.context.FileContext; import io.wcm.devops.conga.generator.spi.context.FileHeaderContext; @@ -52,7 +50,7 @@ void testApply() throws Exception { File file = new File("target/generation-test/fileHeader.json"); FileUtils.copyFile(new File(getClass().getResource("/validators/json/validJson.json").toURI()), file); - List lines = ImmutableList.of("Der Jodelkaiser", "aus dem Oetztal", "ist wieder daheim."); + List lines = List.of("Der Jodelkaiser", "aus dem Oetztal", "ist wieder daheim."); FileHeaderContext context = new FileHeaderContext().commentLines(lines); FileContext fileContext = new FileContext().file(file); diff --git a/generator/src/test/java/io/wcm/devops/conga/generator/plugins/fileheader/UnixShellScriptFileHeaderTest.java b/generator/src/test/java/io/wcm/devops/conga/generator/plugins/fileheader/UnixShellScriptFileHeaderTest.java index 779b5010..ed5630f2 100644 --- a/generator/src/test/java/io/wcm/devops/conga/generator/plugins/fileheader/UnixShellScriptFileHeaderTest.java +++ b/generator/src/test/java/io/wcm/devops/conga/generator/plugins/fileheader/UnixShellScriptFileHeaderTest.java @@ -31,8 +31,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import com.google.common.collect.ImmutableList; - import io.wcm.devops.conga.generator.spi.FileHeaderPlugin; import io.wcm.devops.conga.generator.spi.context.FileContext; import io.wcm.devops.conga.generator.spi.context.FileHeaderContext; @@ -53,7 +51,7 @@ void testApply() throws Exception { FileUtils.write(file, "#!/bin/bash\n" + "myscript", StandardCharsets.ISO_8859_1); - List lines = ImmutableList.of("Der Jodelkaiser", "aus dem Oetztal", "ist wieder daheim."); + List lines = List.of("Der Jodelkaiser", "aus dem Oetztal", "ist wieder daheim."); FileHeaderContext context = new FileHeaderContext().commentLines(lines); FileContext fileContext = new FileContext().file(file); diff --git a/generator/src/test/java/io/wcm/devops/conga/generator/plugins/fileheader/WindowsShellScriptFileHeaderTest.java b/generator/src/test/java/io/wcm/devops/conga/generator/plugins/fileheader/WindowsShellScriptFileHeaderTest.java index 692b1aca..c682423c 100644 --- a/generator/src/test/java/io/wcm/devops/conga/generator/plugins/fileheader/WindowsShellScriptFileHeaderTest.java +++ b/generator/src/test/java/io/wcm/devops/conga/generator/plugins/fileheader/WindowsShellScriptFileHeaderTest.java @@ -31,8 +31,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import com.google.common.collect.ImmutableList; - import io.wcm.devops.conga.generator.spi.FileHeaderPlugin; import io.wcm.devops.conga.generator.spi.context.FileContext; import io.wcm.devops.conga.generator.spi.context.FileHeaderContext; @@ -52,7 +50,7 @@ void testApply() throws Exception { File file = new File("target/generation-test/fileHeader.cmd"); FileUtils.write(file, "myscript", StandardCharsets.ISO_8859_1); - List lines = ImmutableList.of("Der Jodelkaiser", "aus dem Oetztal", "ist wieder daheim."); + List lines = List.of("Der Jodelkaiser", "aus dem Oetztal", "ist wieder daheim."); FileHeaderContext context = new FileHeaderContext().commentLines(lines); FileContext fileContext = new FileContext().file(file); diff --git a/generator/src/test/java/io/wcm/devops/conga/generator/plugins/fileheader/XmlFileHeaderTest.java b/generator/src/test/java/io/wcm/devops/conga/generator/plugins/fileheader/XmlFileHeaderTest.java index 3bdfa28b..35607a9a 100644 --- a/generator/src/test/java/io/wcm/devops/conga/generator/plugins/fileheader/XmlFileHeaderTest.java +++ b/generator/src/test/java/io/wcm/devops/conga/generator/plugins/fileheader/XmlFileHeaderTest.java @@ -31,8 +31,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import com.google.common.collect.ImmutableList; - import io.wcm.devops.conga.generator.spi.FileHeaderPlugin; import io.wcm.devops.conga.generator.spi.context.FileContext; import io.wcm.devops.conga.generator.spi.context.FileHeaderContext; @@ -52,7 +50,7 @@ void testApply() throws Exception { File file = new File("target/generation-test/fileHeader.xml"); FileUtils.copyFile(new File(getClass().getResource("/validators/xml/validXml.xml").toURI()), file); - List lines = ImmutableList.of("Der Jodelkaiser", "aus dem Oetztal", "ist wieder daheim."); + List lines = List.of("Der Jodelkaiser", "aus dem Oetztal", "ist wieder daheim."); FileHeaderContext context = new FileHeaderContext().commentLines(lines); FileContext fileContext = new FileContext().file(file); diff --git a/generator/src/test/java/io/wcm/devops/conga/generator/plugins/handlebars/helper/ContainsHelperTest.java b/generator/src/test/java/io/wcm/devops/conga/generator/plugins/handlebars/helper/ContainsHelperTest.java index 92fd11a8..e664f592 100644 --- a/generator/src/test/java/io/wcm/devops/conga/generator/plugins/handlebars/helper/ContainsHelperTest.java +++ b/generator/src/test/java/io/wcm/devops/conga/generator/plugins/handlebars/helper/ContainsHelperTest.java @@ -22,12 +22,12 @@ import static io.wcm.devops.conga.generator.plugins.handlebars.helper.MockOptions.FN_RETURN; import static io.wcm.devops.conga.generator.plugins.handlebars.helper.TestUtils.assertHelper; +import java.util.List; +import java.util.Set; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; - import io.wcm.devops.conga.generator.spi.handlebars.HelperPlugin; import io.wcm.devops.conga.generator.util.PluginManagerImpl; @@ -43,22 +43,22 @@ void setUp() { @Test void testContains() throws Exception { - assertHelper(FN_RETURN, helper, ImmutableList.of("a", "b", "c"), new MockOptions("a")); - assertHelper(FN_RETURN, helper, ImmutableSet.of("a", "b", "c"), new MockOptions("b")); + assertHelper(FN_RETURN, helper, List.of("a", "b", "c"), new MockOptions("a")); + assertHelper(FN_RETURN, helper, Set.of("a", "b", "c"), new MockOptions("b")); assertHelper(FN_RETURN, helper, new String[] { "a", "b", "c" }, new MockOptions("a")); assertHelper(FN_RETURN, helper, new String[] { "a", "b", "c" }, new MockOptions("b")); } @Test void testNotContains() throws Exception { - assertHelper("", helper, ImmutableList.of("a", "b", "c"), new MockOptions("z")); + assertHelper("", helper, List.of("a", "b", "c"), new MockOptions("z")); assertHelper("", helper, new String[] { "a", "b", "c" }, new MockOptions("z")); } @Test void testNull() throws Exception { assertHelper("", helper, null, new MockOptions("def")); - assertHelper("", helper, ImmutableList.of("a", "b", "c"), new MockOptions()); + assertHelper("", helper, List.of("a", "b", "c"), new MockOptions()); assertHelper("", helper, null, new MockOptions()); } diff --git a/generator/src/test/java/io/wcm/devops/conga/generator/plugins/handlebars/helper/EachIfEqualsHelperTest.java b/generator/src/test/java/io/wcm/devops/conga/generator/plugins/handlebars/helper/EachIfEqualsHelperTest.java index 61ea416c..fb2a19e4 100644 --- a/generator/src/test/java/io/wcm/devops/conga/generator/plugins/handlebars/helper/EachIfEqualsHelperTest.java +++ b/generator/src/test/java/io/wcm/devops/conga/generator/plugins/handlebars/helper/EachIfEqualsHelperTest.java @@ -21,12 +21,12 @@ import static io.wcm.devops.conga.generator.plugins.handlebars.helper.TestUtils.assertHelper; +import java.util.List; +import java.util.Map; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; - import io.wcm.devops.conga.generator.spi.handlebars.HelperPlugin; import io.wcm.devops.conga.generator.util.PluginManagerImpl; @@ -54,11 +54,11 @@ void testSingleValue() throws Exception { @Test void testList() throws Exception { - assertHelper("", helper, ImmutableList.of("v1", "v2"), new MockOptions()); - assertHelper("", helper, ImmutableList.of("v1", "v2"), new MockOptions("a")); - assertHelper("", helper, ImmutableList.of(ImmutableMap.of("a", "1"), ImmutableMap.of("a", "2")), new MockOptions("a")); - assertHelper("fn({a=1})", helper, ImmutableList.of(ImmutableMap.of("a", "1"), ImmutableMap.of("a", "2")), new MockOptions("a", "1")); - assertHelper("fn({a=1})fn({a=1})", helper, ImmutableList.of(ImmutableMap.of("a", "1"), ImmutableMap.of("a", "1")), new MockOptions("a", "1")); + assertHelper("", helper, List.of("v1", "v2"), new MockOptions()); + assertHelper("", helper, List.of("v1", "v2"), new MockOptions("a")); + assertHelper("", helper, List.of(Map.of("a", "1"), Map.of("a", "2")), new MockOptions("a")); + assertHelper("fn({a=1})", helper, List.of(Map.of("a", "1"), Map.of("a", "2")), new MockOptions("a", "1")); + assertHelper("fn({a=1})fn({a=1})", helper, List.of(Map.of("a", "1"), Map.of("a", "1")), new MockOptions("a", "1")); } } diff --git a/generator/src/test/java/io/wcm/devops/conga/generator/plugins/handlebars/helper/EachIfHelperTest.java b/generator/src/test/java/io/wcm/devops/conga/generator/plugins/handlebars/helper/EachIfHelperTest.java index 51ada850..c1ec9a0b 100644 --- a/generator/src/test/java/io/wcm/devops/conga/generator/plugins/handlebars/helper/EachIfHelperTest.java +++ b/generator/src/test/java/io/wcm/devops/conga/generator/plugins/handlebars/helper/EachIfHelperTest.java @@ -21,12 +21,12 @@ import static io.wcm.devops.conga.generator.plugins.handlebars.helper.TestUtils.assertHelper; +import java.util.List; +import java.util.Map; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; - import io.wcm.devops.conga.generator.spi.handlebars.HelperPlugin; import io.wcm.devops.conga.generator.util.PluginManagerImpl; @@ -54,16 +54,16 @@ void testSingleValue() throws Exception { @Test void testList() throws Exception { - assertHelper("", helper, ImmutableList.of("v1", "v2"), new MockOptions()); - assertHelper("", helper, ImmutableList.of("v1", "v2"), new MockOptions("a")); - assertHelper("fn({a=1})", helper, ImmutableList.of(ImmutableMap.of("a", "1"), ImmutableMap.of("b", "2")), new MockOptions("a")); - assertHelper("fn({a=1})fn({a=2})", helper, ImmutableList.of(ImmutableMap.of("a", "1"), ImmutableMap.of("a", "2")), new MockOptions("a")); + assertHelper("", helper, List.of("v1", "v2"), new MockOptions()); + assertHelper("", helper, List.of("v1", "v2"), new MockOptions("a")); + assertHelper("fn({a=1})", helper, List.of(Map.of("a", "1"), Map.of("b", "2")), new MockOptions("a")); + assertHelper("fn({a=1})fn({a=2})", helper, List.of(Map.of("a", "1"), Map.of("a", "2")), new MockOptions("a")); } @Test void testListDeepMap() throws Exception { assertHelper("fn({a={b=1}})", helper, - ImmutableList.of(ImmutableMap.of("a", "1"), ImmutableMap.of("a", ImmutableMap.of("b", "1"))), new MockOptions("a.b")); + List.of(Map.of("a", "1"), Map.of("a", Map.of("b", "1"))), new MockOptions("a.b")); } } diff --git a/generator/src/test/java/io/wcm/devops/conga/generator/plugins/handlebars/helper/IfEqualsHelperTest.java b/generator/src/test/java/io/wcm/devops/conga/generator/plugins/handlebars/helper/IfEqualsHelperTest.java index 2285c50f..1d3e6d03 100644 --- a/generator/src/test/java/io/wcm/devops/conga/generator/plugins/handlebars/helper/IfEqualsHelperTest.java +++ b/generator/src/test/java/io/wcm/devops/conga/generator/plugins/handlebars/helper/IfEqualsHelperTest.java @@ -22,11 +22,11 @@ import static io.wcm.devops.conga.generator.plugins.handlebars.helper.MockOptions.FN_RETURN; import static io.wcm.devops.conga.generator.plugins.handlebars.helper.TestUtils.assertHelper; +import java.util.List; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import com.google.common.collect.ImmutableList; - import io.wcm.devops.conga.generator.spi.handlebars.HelperPlugin; import io.wcm.devops.conga.generator.util.PluginManagerImpl; @@ -43,13 +43,13 @@ void setUp() { @Test void testEquals() throws Exception { assertHelper(FN_RETURN, helper, "abc", new MockOptions("abc")); - assertHelper(FN_RETURN, helper, ImmutableList.of("a", "b", "c"), new MockOptions(ImmutableList.of("a", "b", "c"))); + assertHelper(FN_RETURN, helper, List.of("a", "b", "c"), new MockOptions(List.of("a", "b", "c"))); } @Test void testNotEquals() throws Exception { assertHelper("", helper, "abc", new MockOptions("def")); - assertHelper("", helper, ImmutableList.of("a", "b", "c"), new MockOptions(ImmutableList.of("d", "e", "f"))); + assertHelper("", helper, List.of("a", "b", "c"), new MockOptions(List.of("d", "e", "f"))); } @Test diff --git a/generator/src/test/java/io/wcm/devops/conga/generator/plugins/handlebars/helper/IfNotEqualsHelperTest.java b/generator/src/test/java/io/wcm/devops/conga/generator/plugins/handlebars/helper/IfNotEqualsHelperTest.java index 3f89e271..c1e3e8f3 100644 --- a/generator/src/test/java/io/wcm/devops/conga/generator/plugins/handlebars/helper/IfNotEqualsHelperTest.java +++ b/generator/src/test/java/io/wcm/devops/conga/generator/plugins/handlebars/helper/IfNotEqualsHelperTest.java @@ -22,11 +22,11 @@ import static io.wcm.devops.conga.generator.plugins.handlebars.helper.MockOptions.FN_RETURN; import static io.wcm.devops.conga.generator.plugins.handlebars.helper.TestUtils.assertHelper; +import java.util.List; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import com.google.common.collect.ImmutableList; - import io.wcm.devops.conga.generator.spi.handlebars.HelperPlugin; import io.wcm.devops.conga.generator.util.PluginManagerImpl; @@ -43,13 +43,13 @@ void setUp() { @Test void testEquals() throws Exception { assertHelper("", helper, "abc", new MockOptions("abc")); - assertHelper("", helper, ImmutableList.of("a", "b", "c"), new MockOptions(ImmutableList.of("a", "b", "c"))); + assertHelper("", helper, List.of("a", "b", "c"), new MockOptions(List.of("a", "b", "c"))); } @Test void testNotEquals() throws Exception { assertHelper(FN_RETURN, helper, "abc", new MockOptions("def")); - assertHelper(FN_RETURN, helper, ImmutableList.of("a", "b", "c"), new MockOptions(ImmutableList.of("d", "e", "f"))); + assertHelper(FN_RETURN, helper, List.of("a", "b", "c"), new MockOptions(List.of("d", "e", "f"))); } @Test diff --git a/generator/src/test/java/io/wcm/devops/conga/generator/plugins/handlebars/helper/MockOptions.java b/generator/src/test/java/io/wcm/devops/conga/generator/plugins/handlebars/helper/MockOptions.java index 4b820394..c6a4f7c9 100644 --- a/generator/src/test/java/io/wcm/devops/conga/generator/plugins/handlebars/helper/MockOptions.java +++ b/generator/src/test/java/io/wcm/devops/conga/generator/plugins/handlebars/helper/MockOptions.java @@ -26,6 +26,7 @@ import java.io.IOException; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.mockito.invocation.InvocationOnMock; @@ -36,7 +37,6 @@ import com.github.jknack.handlebars.Options; import com.github.jknack.handlebars.TagType; import com.github.jknack.handlebars.Template; -import com.google.common.collect.ImmutableList; /** * Subclass of {@link Options} that mocks all dependencies, but allows to set params. @@ -75,7 +75,7 @@ final class MockOptions extends Options { getInverseTemplate(), params, new HashMap<>(), - ImmutableList.of()); + List.of()); } private static Template getFnTemplate() { diff --git a/generator/src/test/java/io/wcm/devops/conga/generator/plugins/multiply/NoneMultiplyTest.java b/generator/src/test/java/io/wcm/devops/conga/generator/plugins/multiply/NoneMultiplyTest.java index ba81e9b8..659c7f3b 100644 --- a/generator/src/test/java/io/wcm/devops/conga/generator/plugins/multiply/NoneMultiplyTest.java +++ b/generator/src/test/java/io/wcm/devops/conga/generator/plugins/multiply/NoneMultiplyTest.java @@ -27,8 +27,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import com.google.common.collect.ImmutableMap; - import io.wcm.devops.conga.generator.spi.MultiplyPlugin; import io.wcm.devops.conga.generator.spi.context.MultiplyContext; import io.wcm.devops.conga.generator.util.PluginManagerImpl; @@ -52,7 +50,7 @@ void setUp() { role = new Role(); roleFile = new RoleFile(); - config = ImmutableMap.of("var1", "v1"); + config = Map.of("var1", "v1"); environment = new Environment(); } diff --git a/generator/src/test/java/io/wcm/devops/conga/generator/plugins/multiply/TenantMultiplyTest.java b/generator/src/test/java/io/wcm/devops/conga/generator/plugins/multiply/TenantMultiplyTest.java index fb58f549..5f2e548b 100644 --- a/generator/src/test/java/io/wcm/devops/conga/generator/plugins/multiply/TenantMultiplyTest.java +++ b/generator/src/test/java/io/wcm/devops/conga/generator/plugins/multiply/TenantMultiplyTest.java @@ -28,9 +28,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; - import io.wcm.devops.conga.generator.ContextProperties; import io.wcm.devops.conga.generator.GeneratorException; import io.wcm.devops.conga.generator.spi.MultiplyPlugin; @@ -65,7 +62,7 @@ void setUp() { role = new Role(); roleFile = new RoleFile(); - config = ImmutableMap.of("var1", "v1", "var2", "v2"); + config = Map.of("var1", "v1", "var2", "v2"); environment = new Environment(); @@ -106,7 +103,7 @@ void testTenantWithoutName() { void testTenantsWithConfig() { Tenant tenant1 = new Tenant(); tenant1.setTenant("tenant1"); - tenant1.setConfig(ImmutableMap.of("var1", "v11", "var3", "v33")); + tenant1.setConfig(Map.of("var1", "v11", "var3", "v33")); environment.getTenants().add(tenant1); Tenant tenant2 = new Tenant(); @@ -117,14 +114,14 @@ void testTenantsWithConfig() { assertEquals(2, configs.size()); Map config1 = configs.get(0); - assertEquals(ImmutableMap.of("var1", "v11", "var2", "v2", "var3", "v33", + assertEquals(Map.of("var1", "v11", "var2", "v2", "var3", "v33", ContextProperties.TENANT, "tenant1", - ContextProperties.TENANT_ROLES, ImmutableList.of()), config1); + ContextProperties.TENANT_ROLES, List.of()), config1); Map config2 = configs.get(1); - assertEquals(ImmutableMap.of("var1", "v1", "var2", "v2", + assertEquals(Map.of("var1", "v1", "var2", "v2", ContextProperties.TENANT, "tenant2", - ContextProperties.TENANT_ROLES, ImmutableList.of()), config2); + ContextProperties.TENANT_ROLES, List.of()), config2); } @Test @@ -135,28 +132,28 @@ void testTenantsFilteredByRoles() { Tenant tenant2 = new Tenant(); tenant2.setTenant("tenant2"); - tenant2.setRoles(ImmutableList.of("role1", "role2")); + tenant2.setRoles(List.of("role1", "role2")); environment.getTenants().add(tenant2); Tenant tenant3 = new Tenant(); tenant3.setTenant("tenant3"); - tenant3.setRoles(ImmutableList.of("role1")); + tenant3.setRoles(List.of("role1")); environment.getTenants().add(tenant3); - roleFile.setMultiplyOptions(ImmutableMap.of(TenantMultiply.ROLES_PROPERTY, ImmutableList.of("role1", "role3"))); + roleFile.setMultiplyOptions(Map.of(TenantMultiply.ROLES_PROPERTY, List.of("role1", "role3"))); List> configs = underTest.multiply(context); assertEquals(2, configs.size()); Map config1 = configs.get(0); - assertEquals(ImmutableMap.of("var1", "v1", "var2", "v2", + assertEquals(Map.of("var1", "v1", "var2", "v2", ContextProperties.TENANT, "tenant2", - ContextProperties.TENANT_ROLES, ImmutableList.of("role1", "role2")), config1); + ContextProperties.TENANT_ROLES, List.of("role1", "role2")), config1); Map config2 = configs.get(1); - assertEquals(ImmutableMap.of("var1", "v1", "var2", "v2", + assertEquals(Map.of("var1", "v1", "var2", "v2", ContextProperties.TENANT, "tenant3", - ContextProperties.TENANT_ROLES, ImmutableList.of("role1")), config2); + ContextProperties.TENANT_ROLES, List.of("role1")), config2); } } diff --git a/generator/src/test/java/io/wcm/devops/conga/generator/plugins/postprocessor/AbstractPostProcessorTest.java b/generator/src/test/java/io/wcm/devops/conga/generator/plugins/postprocessor/AbstractPostProcessorTest.java index 02a9e13f..eaaa105e 100644 --- a/generator/src/test/java/io/wcm/devops/conga/generator/plugins/postprocessor/AbstractPostProcessorTest.java +++ b/generator/src/test/java/io/wcm/devops/conga/generator/plugins/postprocessor/AbstractPostProcessorTest.java @@ -27,8 +27,6 @@ import org.apache.commons.io.FileUtils; import org.junit.jupiter.api.Test; -import com.google.common.collect.ImmutableList; - import io.wcm.devops.conga.generator.plugins.fileheader.ConfFileHeader; import io.wcm.devops.conga.generator.plugins.fileheader.JsonFileHeader; import io.wcm.devops.conga.generator.spi.PostProcessorPlugin; @@ -45,7 +43,7 @@ void testApply() throws Exception { File file = new File("target/generation-test/postProcessor.json"); FileUtils.copyFile(new File(getClass().getResource("/validators/json/validJson.json").toURI()), file); - List lines = ImmutableList.of("Der Jodelkaiser", "aus dem Oetztal", "ist wieder daheim."); + List lines = List.of("Der Jodelkaiser", "aus dem Oetztal", "ist wieder daheim."); FileHeaderContext fileHeader = new FileHeaderContext().commentLines(lines); FileContext fileContext = new FileContext().file(file); new JsonFileHeader().apply(fileContext, fileHeader); diff --git a/generator/src/test/java/io/wcm/devops/conga/generator/plugins/postprocessor/DummyPostProcessor.java b/generator/src/test/java/io/wcm/devops/conga/generator/plugins/postprocessor/DummyPostProcessor.java index ed6e741e..87e171e6 100644 --- a/generator/src/test/java/io/wcm/devops/conga/generator/plugins/postprocessor/DummyPostProcessor.java +++ b/generator/src/test/java/io/wcm/devops/conga/generator/plugins/postprocessor/DummyPostProcessor.java @@ -26,8 +26,6 @@ import org.apache.commons.io.FileUtils; -import com.google.common.collect.ImmutableList; - import io.wcm.devops.conga.generator.spi.context.FileContext; import io.wcm.devops.conga.generator.spi.context.FileHeaderContext; import io.wcm.devops.conga.generator.spi.context.PostProcessorContext; @@ -61,7 +59,7 @@ public List apply(FileContext file, PostProcessorContext context) { applyFileHeader(newFileContext, fileHeader, context); } - return ImmutableList.of(newFileContext); + return List.of(newFileContext); } } diff --git a/generator/src/test/java/io/wcm/devops/conga/generator/plugins/valueprovider/DummyMapValueProviderPlugin.java b/generator/src/test/java/io/wcm/devops/conga/generator/plugins/valueprovider/DummyMapValueProviderPlugin.java index 266f1ffe..8814197a 100644 --- a/generator/src/test/java/io/wcm/devops/conga/generator/plugins/valueprovider/DummyMapValueProviderPlugin.java +++ b/generator/src/test/java/io/wcm/devops/conga/generator/plugins/valueprovider/DummyMapValueProviderPlugin.java @@ -19,10 +19,10 @@ */ package io.wcm.devops.conga.generator.plugins.valueprovider; -import org.apache.commons.lang3.StringUtils; +import java.util.List; +import java.util.Map; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; +import org.apache.commons.lang3.StringUtils; import io.wcm.devops.conga.generator.spi.ValueProviderPlugin; import io.wcm.devops.conga.generator.spi.context.ValueProviderContext; @@ -45,10 +45,10 @@ public String getName() { @Override public Object resolve(String variableName, ValueProviderContext context) { if (StringUtils.equals(variableName, "map")) { - return ImmutableMap.of( + return Map.of( "param1", "value1", "param2", 5, - "listParam", ImmutableList.of("v1", "v2", "v3")); + "listParam", List.of("v1", "v2", "v3")); } else { return null; diff --git a/generator/src/test/java/io/wcm/devops/conga/generator/plugins/valueprovider/SystemPropertyValueProviderPluginTest.java b/generator/src/test/java/io/wcm/devops/conga/generator/plugins/valueprovider/SystemPropertyValueProviderPluginTest.java index e33f417a..c3b9e4a2 100644 --- a/generator/src/test/java/io/wcm/devops/conga/generator/plugins/valueprovider/SystemPropertyValueProviderPluginTest.java +++ b/generator/src/test/java/io/wcm/devops/conga/generator/plugins/valueprovider/SystemPropertyValueProviderPluginTest.java @@ -22,11 +22,11 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; +import java.util.List; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import com.google.common.collect.ImmutableList; - import io.wcm.devops.conga.generator.spi.ValueProviderPlugin; import io.wcm.devops.conga.generator.spi.context.PluginContextOptions; import io.wcm.devops.conga.generator.spi.context.ValueProviderContext; @@ -58,7 +58,7 @@ void testResolve() { System.setProperty(propertyName2, "value1,value2,value3"); assertEquals("value1", underTest.resolve(propertyName1, context)); - assertEquals(ImmutableList.of("value1", "value2", "value3"), underTest.resolve(propertyName2, context)); + assertEquals(List.of("value1", "value2", "value3"), underTest.resolve(propertyName2, context)); assertNull(underTest.resolve(propertyName3, context)); System.clearProperty(propertyName1); diff --git a/generator/src/test/java/io/wcm/devops/conga/generator/util/ConfigInheritanceResolverTest.java b/generator/src/test/java/io/wcm/devops/conga/generator/util/ConfigInheritanceResolverTest.java index baf479d5..277ece3c 100644 --- a/generator/src/test/java/io/wcm/devops/conga/generator/util/ConfigInheritanceResolverTest.java +++ b/generator/src/test/java/io/wcm/devops/conga/generator/util/ConfigInheritanceResolverTest.java @@ -21,10 +21,10 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.jupiter.api.Test; +import java.util.List; +import java.util.Map; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; +import org.junit.jupiter.api.Test; import io.wcm.devops.conga.generator.util.testmodel.ConfScope1; import io.wcm.devops.conga.generator.util.testmodel.ConfScope2; @@ -61,46 +61,46 @@ void testResolve() { scope21.setScope31(scope31); scope21.setScope32(scope32); ConfScope2 scope22 = new ConfScope2(); - scope1.setScope2(ImmutableList.of(scope21, scope22)); + scope1.setScope2(List.of(scope21, scope22)); root.setScope1(scope1); SimpleConf simple1 = new SimpleConf(); - scope1.setMap(ImmutableMap.of("simple", simple1)); + scope1.setMap(Map.of("simple", simple1)); SampleNode sample = new SampleNode(); SimpleConf simple2 = new SimpleConf(); sample.setSimple(simple2); scope1.setSample(sample); - scope1.setConfig(ImmutableMap.of("conf", "s1")); + scope1.setConfig(Map.of("conf", "s1")); - scope21.setConfig(ImmutableMap.of("conf2", "s21")); + scope21.setConfig(Map.of("conf2", "s21")); - scope22.setConfig(ImmutableMap.of("conf", "s22")); + scope22.setConfig(Map.of("conf", "s22")); - scope31.setConfig(ImmutableMap.of("conf2", "s31")); + scope31.setConfig(Map.of("conf2", "s31")); - scope32.setConfig(ImmutableMap.of("conf3", "s32")); + scope32.setConfig(Map.of("conf3", "s32")); - simple1.setConfig(ImmutableMap.of("conf", "simple1")); + simple1.setConfig(Map.of("conf", "simple1")); - simple2.setConfig(ImmutableMap.of("conf2", "simple2")); + simple2.setConfig(Map.of("conf2", "simple2")); ConfigInheritanceResolver.resolve(root); - assertEquals(ImmutableMap.of("conf", "s1"), scope1.getConfig()); + assertEquals(Map.of("conf", "s1"), scope1.getConfig()); - assertEquals(ImmutableMap.of("conf", "s1", "conf2", "s21"), scope21.getConfig()); + assertEquals(Map.of("conf", "s1", "conf2", "s21"), scope21.getConfig()); - assertEquals(ImmutableMap.of("conf", "s22"), scope22.getConfig()); + assertEquals(Map.of("conf", "s22"), scope22.getConfig()); - assertEquals(ImmutableMap.of("conf", "s1", "conf2", "s31"), scope31.getConfig()); + assertEquals(Map.of("conf", "s1", "conf2", "s31"), scope31.getConfig()); - assertEquals(ImmutableMap.of("conf", "s1", "conf2", "s21", "conf3", "s32"), scope32.getConfig()); + assertEquals(Map.of("conf", "s1", "conf2", "s21", "conf3", "s32"), scope32.getConfig()); - assertEquals(ImmutableMap.of("conf", "simple1"), simple1.getConfig()); + assertEquals(Map.of("conf", "simple1"), simple1.getConfig()); - assertEquals(ImmutableMap.of("conf", "s1", "conf2", "simple2"), simple2.getConfig()); + assertEquals(Map.of("conf", "s1", "conf2", "simple2"), simple2.getConfig()); } } diff --git a/generator/src/test/java/io/wcm/devops/conga/generator/util/JexlResolverTest.java b/generator/src/test/java/io/wcm/devops/conga/generator/util/JexlResolverTest.java index 638b2670..e0c5aaa1 100644 --- a/generator/src/test/java/io/wcm/devops/conga/generator/util/JexlResolverTest.java +++ b/generator/src/test/java/io/wcm/devops/conga/generator/util/JexlResolverTest.java @@ -49,8 +49,8 @@ void setUp() { VariableMapResolver variableMapResolver = new VariableMapResolver(context); underTest = new JexlResolver(variableMapResolver); - object2 = ImmutableMap.of("var4", "value4"); - object1 = ImmutableMap.of("var3", "value3", "object2", object2, + object2 = Map.of("var4", "value4"); + object1 = Map.of("var3", "value3", "object2", object2, "nested1var1", "${nested1.nested1var1}", "nested2var1", "${nested1.nested2.nested2var1}"); variables = ImmutableMap.builder() @@ -61,10 +61,10 @@ void setUp() { .put("refVar2", "${var2}") .put("refCombined", "${object1.var3}|${var1}") .put("jexlExpr", "${object1.var3 + ';' + var1}") - .put("nested1", ImmutableMap.of( + .put("nested1", Map.of( "nested1var1", "nested1-value1", "nested1JexlExpr", "${object1.var3 + ';' + var1}", - "nested2", ImmutableMap.of( + "nested2", Map.of( "nested2var1", "nested2-value1", "nested2JexlExpr", "${object1.var3 + ';' + var1}"))) .put("array1", new String[] { "v1", "v2", "v3" }) diff --git a/generator/src/test/java/io/wcm/devops/conga/generator/util/ModelExportConfigProcessorTest.java b/generator/src/test/java/io/wcm/devops/conga/generator/util/ModelExportConfigProcessorTest.java index c27542b8..964578bc 100644 --- a/generator/src/test/java/io/wcm/devops/conga/generator/util/ModelExportConfigProcessorTest.java +++ b/generator/src/test/java/io/wcm/devops/conga/generator/util/ModelExportConfigProcessorTest.java @@ -24,6 +24,7 @@ import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.when; +import java.util.List; import java.util.Map; import java.util.Set; @@ -35,10 +36,6 @@ import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.stubbing.Answer; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; - import io.wcm.devops.conga.generator.spi.ValueEncryptionPlugin; import io.wcm.devops.conga.generator.spi.context.PluginContextOptions; import io.wcm.devops.conga.generator.spi.context.ValueEncryptionContext; @@ -46,7 +43,7 @@ @ExtendWith(MockitoExtension.class) class ModelExportConfigProcessorTest { - private static final Set SENSITIVE_PARAMS = ImmutableSet.of( + private static final Set SENSITIVE_PARAMS = Set.of( "param1", "group1.param3", "group1.group2.param4", @@ -67,7 +64,7 @@ class ModelExportConfigProcessorTest { @BeforeEach void setUp() { // simulate valueEncryptPlugin that prepends {enc} to the value - when(pluginManager.getAll(ValueEncryptionPlugin.class)).thenReturn(ImmutableList.of(valueEncryptPlugin)); + when(pluginManager.getAll(ValueEncryptionPlugin.class)).thenReturn(List.of(valueEncryptPlugin)); when(valueEncryptPlugin.isEnabled()).thenReturn(true); when(valueEncryptPlugin.encrypt(anyString(), any(), any(ValueEncryptionContext.class))).then(new Answer() { @Override @@ -84,21 +81,21 @@ public Object answer(InvocationOnMock invocation) throws Throwable { @Test void testNestedParams() { - Map config = ImmutableMap.of( + Map config = Map.of( "param1", "value1", "param2", "value2", - "group1", ImmutableMap.of( + "group1", Map.of( "param3", 123, - "group2", ImmutableMap.of( + "group2", Map.of( "param4", true, "param5", 5L))); - Map expected = ImmutableMap.of( + Map expected = Map.of( "param1", "{enc}value1", "param2", "value2", - "group1", ImmutableMap.of( + "group1", Map.of( "param3", "{enc}123", - "group2", ImmutableMap.of( + "group2", Map.of( "param4", "{enc}true", "param5", 5L))); @@ -107,29 +104,29 @@ void testNestedParams() { @Test void testList() { - Map config = ImmutableMap.of( - "list1", ImmutableList.of("value1", "value2"), - "list2", ImmutableList.of( - ImmutableMap.of( + Map config = Map.of( + "list1", List.of("value1", "value2"), + "list2", List.of( + Map.of( "param1", "value1a", "param2", 123, - "list3", ImmutableList.of( - ImmutableMap.of( + "list3", List.of( + Map.of( "param3", "value3"))), - ImmutableMap.of( + Map.of( "param1", "value1b", "param2", 345))); - Map expected = ImmutableMap.of( - "list1", ImmutableList.of("{enc}value1", "{enc}value2"), - "list2", ImmutableList.of( - ImmutableMap.of( + Map expected = Map.of( + "list1", List.of("{enc}value1", "{enc}value2"), + "list2", List.of( + Map.of( "param1", "{enc}value1a", "param2", 123, - "list3", ImmutableList.of( - ImmutableMap.of( + "list3", List.of( + Map.of( "param3", "{enc}value3"))), - ImmutableMap.of( + Map.of( "param1", "{enc}value1b", "param2", 345))); diff --git a/generator/src/test/java/io/wcm/devops/conga/generator/util/RoleUtilTest.java b/generator/src/test/java/io/wcm/devops/conga/generator/util/RoleUtilTest.java index 09856ddb..b9adb15e 100644 --- a/generator/src/test/java/io/wcm/devops/conga/generator/util/RoleUtilTest.java +++ b/generator/src/test/java/io/wcm/devops/conga/generator/util/RoleUtilTest.java @@ -25,6 +25,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; +import java.util.Arrays; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -34,9 +35,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; - import io.wcm.devops.conga.generator.GeneratorException; import io.wcm.devops.conga.model.role.Role; import io.wcm.devops.conga.model.role.RoleFile; @@ -68,74 +66,74 @@ void setUp() throws Exception { Role role1 = new Role(); role1.setTemplateDir("role1Dir"); - role1.setConfig(ImmutableMap.of( + role1.setConfig(Map.of( "param1", "value1.1", "param2", 123, "param3", true)); - role1.setFiles(ImmutableList.of( + role1.setFiles(List.of( buildFile("role1", "file1.1"), buildFile("role1", "file1.2"), buildUrlFile("role1", "http://file1.3"))); - role1.setSensitiveConfigParameters(ImmutableList.of("param1")); + role1.setSensitiveConfigParameters(List.of("param1")); roleMap.put("role1", role1); Role role2 = new Role(); - role2.setVariants(ImmutableList.of( + role2.setVariants(List.of( buildVariant("variant1"), - buildVariant("variant2", ImmutableMap.of( + buildVariant("variant2", Map.of( "varparam1", "varvalue2.1", "varparam2", 888)))); role2.setTemplateDir("role2Dir"); - role2.setConfig(ImmutableMap.of( + role2.setConfig(Map.of( "param1", "value2.1", "param4", "value2.4")); - role2.setFiles(ImmutableList.of( + role2.setFiles(List.of( buildFile("role2", "file2.1", "variant1"), buildFile("role2", "file2.2", "variant2"), buildUrlFile("role2", "http://file2.3", "variant1"))); - role2.setInherits(ImmutableList.of( + role2.setInherits(List.of( buildInherit("role1"))); - role2.setSensitiveConfigParameters(ImmutableList.of("param2")); + role2.setSensitiveConfigParameters(List.of("param2")); roleMap.put("role2", role2); Role role3 = new Role(); - role3.setVariants(ImmutableList.of( + role3.setVariants(List.of( buildVariant("variant1"), - buildVariant("variant2", ImmutableMap.of( + buildVariant("variant2", Map.of( "varparam1", "varvalue3.1")), - buildVariant("variant3", ImmutableMap.of( + buildVariant("variant3", Map.of( "varparam1", "varvalue3.2")))); role3.setTemplateDir("role3Dir"); - role3.setConfig(ImmutableMap.of( + role3.setConfig(Map.of( "param1", "value3.1", "param5", "value3.5")); - role3.setFiles(ImmutableList.of( + role3.setFiles(List.of( buildFile("role3", "file3.1", "variant1"), buildFile("role3", "file3.2", "variant2"), buildUrlFile("role3", "http://file3.3", "variant2"), buildFile("role3", "file1.1"), buildUrlFile("role3", "http://file1.3"))); - role3.setInherits(ImmutableList.of( + role3.setInherits(List.of( buildInherit("role2"))); roleMap.put("role3", role3); Role role4 = new Role(); role4.setTemplateDir("role4Dir"); - role4.setConfig(ImmutableMap.of( + role4.setConfig(Map.of( "param1", "value4.1")); - role4.setFiles(ImmutableList.of( + role4.setFiles(List.of( buildFile("role4", "file4.1"))); - role4.setInherits(ImmutableList.of( + role4.setInherits(List.of( buildInherit("role2"))); roleMap.put("role4", role4); Role role5 = new Role(); role5.setTemplateDir("role5Dir"); - role5.setConfig(ImmutableMap.of( + role5.setConfig(Map.of( "param1", "value5.1")); - role5.setFiles(ImmutableList.of( + role5.setFiles(List.of( buildFile("role5", "file5.1"))); - role5.setInherits(ImmutableList.of( + role5.setInherits(List.of( buildInherit("role5"))); roleMap.put("role5", role5); } @@ -163,7 +161,7 @@ void testRole1() { assertFile(role, "role1", "file1.2"); assertUrlFile(role, "role1", "http://file1.3"); - assertEquals(ImmutableList.of("param1"), role.getSensitiveConfigParameters()); + assertEquals(List.of("param1"), role.getSensitiveConfigParameters()); } @Test @@ -192,11 +190,11 @@ void testRole2() { assertUrlFile(role2, "role2", "http://file2.3", "variant1"); assertVariant(role2, "variant1"); - assertVariant(role2, "variant2", ImmutableMap.of( + assertVariant(role2, "variant2", Map.of( "varparam1", "varvalue2.1", "varparam2", 888)); - assertEquals(ImmutableList.of("param1", "param2"), role2.getSensitiveConfigParameters()); + assertEquals(List.of("param1", "param2"), role2.getSensitiveConfigParameters()); } @Test @@ -232,18 +230,18 @@ void testRole3() { assertUrlFile(role3, "role3", "http://file1.3"); assertVariant(role2, "variant1"); - assertVariant(role2, "variant2", ImmutableMap.of( + assertVariant(role2, "variant2", Map.of( "varparam1", "varvalue3.1", "varparam2", 888)); assertVariant(role3, "variant1"); - assertVariant(role3, "variant2", ImmutableMap.of( + assertVariant(role3, "variant2", Map.of( "varparam1", "varvalue3.1", "varparam2", 888)); - assertVariant(role3, "variant3", ImmutableMap.of( + assertVariant(role3, "variant3", Map.of( "varparam1", "varvalue3.2")); - assertEquals(ImmutableList.of("param1", "param2"), role3.getSensitiveConfigParameters()); + assertEquals(List.of("param1", "param2"), role3.getSensitiveConfigParameters()); } @Test @@ -279,7 +277,7 @@ private RoleFile buildFile(String role, String name, String... variants) { file.setFile(name); file.setTemplate(role + "-" + name + ".hbs"); if (variants.length > 0) { - file.setVariants(ImmutableList.copyOf(variants)); + file.setVariants(Arrays.asList(variants)); } return file; } @@ -289,7 +287,7 @@ private RoleFile buildUrlFile(String role, String url, String... variants) { RoleFile file = new RoleFile(); file.setUrl(url); if (variants.length > 0) { - file.setVariants(ImmutableList.copyOf(variants)); + file.setVariants(Arrays.asList(variants)); } return file; } @@ -305,7 +303,7 @@ private void assertFile(Role role, String roleName, String file, String... varia for (RoleFile fileItem : role.getFiles()) { if (StringUtils.equals(file, fileItem.getFile()) && StringUtils.equals(template, fileItem.getTemplate()) - && ImmutableList.copyOf(variants).equals(fileItem.getVariants())) { + && Arrays.asList(variants).equals(fileItem.getVariants())) { // item found return; } @@ -329,7 +327,7 @@ private void assertNotFile(Role role, String roleName, String file, String... va private void assertUrlFile(Role role, String roleName, String url, String... variants) { for (RoleFile fileItem : role.getFiles()) { if (StringUtils.equals(url, fileItem.getUrl()) - && ImmutableList.copyOf(variants).equals(fileItem.getVariants())) { + && Arrays.asList(variants).equals(fileItem.getVariants())) { // item found return; } @@ -349,7 +347,7 @@ private void assertNotUrlFile(Role role, String roleName, String url, String... } private void assertVariant(Role role, String variant) { - assertVariant(role, variant, ImmutableMap.of()); + assertVariant(role, variant, Map.of()); } private void assertVariant(Role role, String variant, Map config) { @@ -365,21 +363,21 @@ private void assertVariant(Role role, String variant, Map config @Test void testMatchesRoleFile() { - assertTrue(RoleUtil.matchesRoleFile(roleFileVariants(ImmutableList.of()), ImmutableList.of())); - assertTrue(RoleUtil.matchesRoleFile(roleFileVariants(ImmutableList.of()), ImmutableList.of("v1"))); - assertTrue(RoleUtil.matchesRoleFile(roleFileVariants(ImmutableList.of()), ImmutableList.of("v1", "v2"))); - - assertTrue(RoleUtil.matchesRoleFile(roleFileVariants(ImmutableList.of("v1")), ImmutableList.of("v1", "v2"))); - assertTrue(RoleUtil.matchesRoleFile(roleFileVariants(ImmutableList.of("v1*")), ImmutableList.of("v1", "v2"))); - assertTrue(RoleUtil.matchesRoleFile(roleFileVariants(ImmutableList.of("v2")), ImmutableList.of("v1", "v2"))); - assertTrue(RoleUtil.matchesRoleFile(roleFileVariants(ImmutableList.of("v1", "v2")), ImmutableList.of("v1", "v2"))); - assertTrue(RoleUtil.matchesRoleFile(roleFileVariants(ImmutableList.of("v1", "v2")), ImmutableList.of("v2", "v3"))); - assertTrue(RoleUtil.matchesRoleFile(roleFileVariants(ImmutableList.of("v1", "v2*")), ImmutableList.of("v2", "v3"))); - assertTrue(RoleUtil.matchesRoleFile(roleFileVariants(ImmutableList.of("v1*", "v2*")), ImmutableList.of("v1", "v2", "v3"))); - - assertFalse(RoleUtil.matchesRoleFile(roleFileVariants(ImmutableList.of("v1")), ImmutableList.of())); - assertFalse(RoleUtil.matchesRoleFile(roleFileVariants(ImmutableList.of("v1")), ImmutableList.of("v2"))); - assertFalse(RoleUtil.matchesRoleFile(roleFileVariants(ImmutableList.of("v1*", "v2*")), ImmutableList.of("v2", "v3"))); + assertTrue(RoleUtil.matchesRoleFile(roleFileVariants(List.of()), List.of())); + assertTrue(RoleUtil.matchesRoleFile(roleFileVariants(List.of()), List.of("v1"))); + assertTrue(RoleUtil.matchesRoleFile(roleFileVariants(List.of()), List.of("v1", "v2"))); + + assertTrue(RoleUtil.matchesRoleFile(roleFileVariants(List.of("v1")), List.of("v1", "v2"))); + assertTrue(RoleUtil.matchesRoleFile(roleFileVariants(List.of("v1*")), List.of("v1", "v2"))); + assertTrue(RoleUtil.matchesRoleFile(roleFileVariants(List.of("v2")), List.of("v1", "v2"))); + assertTrue(RoleUtil.matchesRoleFile(roleFileVariants(List.of("v1", "v2")), List.of("v1", "v2"))); + assertTrue(RoleUtil.matchesRoleFile(roleFileVariants(List.of("v1", "v2")), List.of("v2", "v3"))); + assertTrue(RoleUtil.matchesRoleFile(roleFileVariants(List.of("v1", "v2*")), List.of("v2", "v3"))); + assertTrue(RoleUtil.matchesRoleFile(roleFileVariants(List.of("v1*", "v2*")), List.of("v1", "v2", "v3"))); + + assertFalse(RoleUtil.matchesRoleFile(roleFileVariants(List.of("v1")), List.of())); + assertFalse(RoleUtil.matchesRoleFile(roleFileVariants(List.of("v1")), List.of("v2"))); + assertFalse(RoleUtil.matchesRoleFile(roleFileVariants(List.of("v1*", "v2*")), List.of("v2", "v3"))); } private RoleFile roleFileVariants(List variants) { diff --git a/generator/src/test/java/io/wcm/devops/conga/generator/util/ValueUtilTest.java b/generator/src/test/java/io/wcm/devops/conga/generator/util/ValueUtilTest.java index c749beaa..7775f4fb 100644 --- a/generator/src/test/java/io/wcm/devops/conga/generator/util/ValueUtilTest.java +++ b/generator/src/test/java/io/wcm/devops/conga/generator/util/ValueUtilTest.java @@ -24,10 +24,10 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; -import org.junit.jupiter.api.Test; +import java.util.List; +import java.util.Map; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; +import org.junit.jupiter.api.Test; class ValueUtilTest { @@ -45,8 +45,8 @@ void stringToValue_string() { @Test void stringToValue_stringList() { - assertEquals(ImmutableList.of("abc", "def", "ghi"), stringToValue("abc,def,ghi")); - assertEquals(ImmutableList.of("abc", " def", " ghi"), stringToValue("abc, def, ghi")); + assertEquals(List.of("abc", "def", "ghi"), stringToValue("abc,def,ghi")); + assertEquals(List.of("abc", " def", " ghi"), stringToValue("abc, def, ghi")); } @Test @@ -58,7 +58,7 @@ void stringToValue_integer() { @Test void stringToValue_integerList() { - assertEquals(ImmutableList.of(0, 123456, -5000), stringToValue("0,123456,-5000")); + assertEquals(List.of(0, 123456, -5000), stringToValue("0,123456,-5000")); } @Test @@ -68,7 +68,7 @@ void stringToValue_long() { @Test void stringToValue_longList() { - assertEquals(ImmutableList.of(0, 123456, 1234567890123456L), stringToValue("0,123456,1234567890123456")); + assertEquals(List.of(0, 123456, 1234567890123456L), stringToValue("0,123456,1234567890123456")); } @Test @@ -90,12 +90,12 @@ void stringToValue_boolean() { @Test void stringToValue_booleanList() { - assertEquals(ImmutableList.of(true, false), stringToValue("true,false")); + assertEquals(List.of(true, false), stringToValue("true,false")); } @Test void stringToValue_mixed() { - assertEquals(ImmutableList.of("abc", 123, true), stringToValue("abc,123,true")); + assertEquals(List.of("abc", 123, true), stringToValue("abc,123,true")); } @Test @@ -114,12 +114,12 @@ void valueToString_primitives() { @Test void valueToString_list() { - assertEquals("abc,123,1.23,true", valueToString(ImmutableList.of("abc", 123, 1.23, true))); + assertEquals("abc,123,1.23,true", valueToString(List.of("abc", 123, 1.23, true))); } @Test void valueToString_map() { - assertEquals("prop1=abc,prop2=123", valueToString(ImmutableMap.of("prop1", "abc", "prop2", 123))); + assertEquals("prop1=abc,prop2=123", valueToString(Map.of("prop1", "abc", "prop2", 123))); } } diff --git a/generator/src/test/java/io/wcm/devops/conga/generator/util/VariableMapResolverTest.java b/generator/src/test/java/io/wcm/devops/conga/generator/util/VariableMapResolverTest.java index b58dc87d..06f1f885 100644 --- a/generator/src/test/java/io/wcm/devops/conga/generator/util/VariableMapResolverTest.java +++ b/generator/src/test/java/io/wcm/devops/conga/generator/util/VariableMapResolverTest.java @@ -24,14 +24,12 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +import java.util.List; import java.util.Map; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; - import io.wcm.devops.conga.generator.spi.context.PluginContextOptions; import io.wcm.devops.conga.generator.spi.context.ValueProviderGlobalContext; @@ -50,25 +48,25 @@ void setUp() { @Test void testSimple() { - Map map = ImmutableMap.of("var1", "v1", "var2", 2, + Map map = Map.of("var1", "v1", "var2", 2, "key1", "The ${var1} and ${var2}"); - assertEquals(ImmutableMap.of("var1", "v1", "var2", 2, + assertEquals(Map.of("var1", "v1", "var2", 2, "key1", "The v1 and 2"), underTest.resolve(map)); } @Test void testNested() { - Map map = ImmutableMap.of("var1", "v1", "var2", "${var1}v2", "var3", "${var1}${var2}v3", + Map map = Map.of("var1", "v1", "var2", "${var1}v2", "var3", "${var1}${var2}v3", "key1", "The ${var1} and ${var2} and ${var3}"); - assertEquals(ImmutableMap.of("var1", "v1", "var2", "v1v2", "var3", "v1v1v2v3", + assertEquals(Map.of("var1", "v1", "var2", "v1v2", "var3", "v1v1v2v3", "key1", "The v1 and v1v2 and v1v1v2v3"), underTest.resolve(map)); } @Test void testNestedCyclicReference() { - Map map = ImmutableMap.of("var1", "${var2}", "var2", "${var1}"); + Map map = Map.of("var1", "${var2}", "var2", "${var1}"); assertThrows(IllegalArgumentException.class, () -> { underTest.resolve(map); @@ -77,7 +75,7 @@ void testNestedCyclicReference() { @Test void testUnknownVariables() { - Map map = ImmutableMap.of("key1", "The ${var1} and ${var2}"); + Map map = Map.of("key1", "The ${var1} and ${var2}"); assertThrows(IllegalArgumentException.class, () -> { underTest.resolve(map); @@ -86,89 +84,89 @@ void testUnknownVariables() { @Test void testNestedMap() { - Map map = ImmutableMap.of("var1", "v1", - "var2", ImmutableMap.of("var21", "v21", "var22", ImmutableMap.of("var221", "${var1}${var2.var21}")), + Map map = Map.of("var1", "v1", + "var2", Map.of("var21", "v21", "var22", Map.of("var221", "${var1}${var2.var21}")), "key1", "The ${var1} and ${var2.var22.var221}"); - assertEquals(ImmutableMap.of("var1", "v1", - "var2", ImmutableMap.of("var21", "v21", "var22", ImmutableMap.of("var221", "v1v21")), + assertEquals(Map.of("var1", "v1", + "var2", Map.of("var21", "v21", "var22", Map.of("var221", "v1v21")), "key1", "The v1 and v1v21"), underTest.resolve(map)); } @Test void testNestedList() { - Map map = ImmutableMap.of("var1", "v1", - "var2", ImmutableList.of("v21", ImmutableMap.of("var221", "${var1}")), + Map map = Map.of("var1", "v1", + "var2", List.of("v21", Map.of("var221", "${var1}")), "key1", "The ${var1} and ${var2}"); - assertEquals(ImmutableMap.of("var1", "v1", - "var2", ImmutableList.of("v21", ImmutableMap.of("var221", "v1")), + assertEquals(Map.of("var1", "v1", + "var2", List.of("v21", Map.of("var221", "v1")), "key1", "The v1 and v21,var221=v1"), underTest.resolve(map)); } @Test void testNestedWithEscapedVariable() { - Map map = ImmutableMap.of("var1", "\\${novar}", "var2", "${var1}v2", "var3", "${var1}${var2}v3", + Map map = Map.of("var1", "\\${novar}", "var2", "${var1}v2", "var3", "${var1}${var2}v3", "key1", "The ${var1} and ${var2} and ${var3}"); - assertEquals(ImmutableMap.of("var1", "${novar}", "var2", "${novar}v2", "var3", "${novar}${novar}v2v3", + assertEquals(Map.of("var1", "${novar}", "var2", "${novar}v2", "var3", "${novar}${novar}v2v3", "key1", "The ${novar} and ${novar}v2 and ${novar}${novar}v2v3"), underTest.resolve(map)); } @Test void testIterateDirect() { - Map map = ImmutableMap.of( + Map map = Map.of( "var1", "value1", - "object1", ImmutableMap.of( - LIST_VARIABLE_ITERATE, ImmutableList.of("item1", "item2", "item3"), + "object1", Map.of( + LIST_VARIABLE_ITERATE, List.of("item1", "item2", "item3"), "item", "${" + ITEM_VARIABLE + "}", "refvar1", "${var1}")); - assertEquals(ImmutableMap.of( + assertEquals(Map.of( "var1", "value1", - "object1", ImmutableList.of( - ImmutableMap.of("item", "item1", "refvar1", "value1"), - ImmutableMap.of("item", "item2", "refvar1", "value1"), - ImmutableMap.of("item", "item3", "refvar1", "value1"))), + "object1", List.of( + Map.of("item", "item1", "refvar1", "value1"), + Map.of("item", "item2", "refvar1", "value1"), + Map.of("item", "item3", "refvar1", "value1"))), underTest.resolve(map)); } @Test void testIterateVariable() { - Map map = ImmutableMap.of( + Map map = Map.of( "var1", "value1", - "listholder", ImmutableList.of( - ImmutableMap.of("name", "item1", "var2", "value21"), - ImmutableMap.of("name", "item2", "var2", "value22"), - ImmutableMap.of("name", "item3", "var2", "value23")), - "object1", ImmutableMap.of( + "listholder", List.of( + Map.of("name", "item1", "var2", "value21"), + Map.of("name", "item2", "var2", "value22"), + Map.of("name", "item3", "var2", "value23")), + "object1", Map.of( LIST_VARIABLE_ITERATE, "${listholder}", "item", "${" + ITEM_VARIABLE + ".name}", "refvar1", "${var1}", "refvar2", "${" + ITEM_VARIABLE + ".var2}")); - assertEquals(ImmutableMap.of( + assertEquals(Map.of( "var1", "value1", - "listholder", ImmutableList.of( - ImmutableMap.of("name", "item1", "var2", "value21"), - ImmutableMap.of("name", "item2", "var2", "value22"), - ImmutableMap.of("name", "item3", "var2", "value23")), - "object1", ImmutableList.of( - ImmutableMap.of("item", "item1", "refvar1", "value1", "refvar2", "value21"), - ImmutableMap.of("item", "item2", "refvar1", "value1", "refvar2", "value22"), - ImmutableMap.of("item", "item3", "refvar1", "value1", "refvar2", "value23"))), + "listholder", List.of( + Map.of("name", "item1", "var2", "value21"), + Map.of("name", "item2", "var2", "value22"), + Map.of("name", "item3", "var2", "value23")), + "object1", List.of( + Map.of("item", "item1", "refvar1", "value1", "refvar2", "value21"), + Map.of("item", "item2", "refvar1", "value1", "refvar2", "value22"), + Map.of("item", "item3", "refvar1", "value1", "refvar2", "value23"))), underTest.resolve(map)); } @Test void testIterateSingleValue() { - Map map = ImmutableMap.of( + Map map = Map.of( "var1", "value1", - "object1", ImmutableMap.of(LIST_VARIABLE_ITERATE, "${var1}", + "object1", Map.of(LIST_VARIABLE_ITERATE, "${var1}", "item", "${" + ITEM_VARIABLE + "}")); - assertEquals(ImmutableMap.of( + assertEquals(Map.of( "var1", "value1", - "object1", ImmutableList.of(ImmutableMap.of("item", "value1"))), + "object1", List.of(Map.of("item", "value1"))), underTest.resolve(map)); } diff --git a/generator/src/test/java/io/wcm/devops/conga/generator/util/VariableObjectTreeResolverTest.java b/generator/src/test/java/io/wcm/devops/conga/generator/util/VariableObjectTreeResolverTest.java index 7fd771b7..6c3c8627 100644 --- a/generator/src/test/java/io/wcm/devops/conga/generator/util/VariableObjectTreeResolverTest.java +++ b/generator/src/test/java/io/wcm/devops/conga/generator/util/VariableObjectTreeResolverTest.java @@ -22,14 +22,12 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; - import io.wcm.devops.conga.generator.ContextPropertiesBuilder; import io.wcm.devops.conga.generator.spi.context.PluginContextOptions; import io.wcm.devops.conga.generator.spi.context.ValueProviderGlobalContext; @@ -79,46 +77,46 @@ void testResolve() { scope21.setScope31(scope31); scope21.setScope32(scope32); ConfScope2 scope22 = new ConfScope2(); - scope1.setScope2(ImmutableList.of(scope21, scope22)); + scope1.setScope2(List.of(scope21, scope22)); root.setScope1(scope1); SimpleConf simple1 = new SimpleConf(); - scope1.setMap(ImmutableMap.of("simple", simple1)); + scope1.setMap(Map.of("simple", simple1)); SampleNode sample = new SampleNode(); SimpleConf simple2 = new SimpleConf(); sample.setSimple(simple2); scope1.setSample(sample); - scope1.setConfig(ImmutableMap.of("var1", "v1", "conf", "${var1}")); + scope1.setConfig(Map.of("var1", "v1", "conf", "${var1}")); - scope21.setConfig(ImmutableMap.of("var21", "v21", "conf21", "${var21}")); + scope21.setConfig(Map.of("var21", "v21", "conf21", "${var21}")); - scope22.setConfig(ImmutableMap.of("var22", "v22", "conf22", "${var22}")); + scope22.setConfig(Map.of("var22", "v22", "conf22", "${var22}")); - scope31.setConfig(ImmutableMap.of("var31", "v31", "conf31", "${var31}")); + scope31.setConfig(Map.of("var31", "v31", "conf31", "${var31}")); - scope32.setConfig(ImmutableMap.of("var32", "v32", "conf32", "${var32}")); + scope32.setConfig(Map.of("var32", "v32", "conf32", "${var32}")); - simple1.setConfig(ImmutableMap.of("varS1", "vS1", "confS1", "${varS1}")); + simple1.setConfig(Map.of("varS1", "vS1", "confS1", "${varS1}")); - simple2.setConfig(ImmutableMap.of("varS2", "vS2", "confS2", "${varS2}")); + simple2.setConfig(Map.of("varS2", "vS2", "confS2", "${varS2}")); underTest.resolve(root); - assertMap(ImmutableMap.of("var1", "v1", "conf", "v1"), scope1.getConfig()); + assertMap(Map.of("var1", "v1", "conf", "v1"), scope1.getConfig()); - assertMap(ImmutableMap.of("var21", "v21", "conf21", "v21"), scope21.getConfig()); + assertMap(Map.of("var21", "v21", "conf21", "v21"), scope21.getConfig()); - assertMap(ImmutableMap.of("var22", "v22", "conf22", "v22"), scope22.getConfig()); + assertMap(Map.of("var22", "v22", "conf22", "v22"), scope22.getConfig()); - assertMap(ImmutableMap.of("var31", "v31", "conf31", "v31"), scope31.getConfig()); + assertMap(Map.of("var31", "v31", "conf31", "v31"), scope31.getConfig()); - assertMap(ImmutableMap.of("var32", "v32", "conf32", "v32"), scope32.getConfig()); + assertMap(Map.of("var32", "v32", "conf32", "v32"), scope32.getConfig()); - assertMap(ImmutableMap.of("varS1", "vS1", "confS1", "vS1"), simple1.getConfig()); + assertMap(Map.of("varS1", "vS1", "confS1", "vS1"), simple1.getConfig()); - assertMap(ImmutableMap.of("varS2", "vS2", "confS2", "vS2"), simple2.getConfig()); + assertMap(Map.of("varS2", "vS2", "confS2", "vS2"), simple2.getConfig()); } private void assertMap(Map expected, Map actual) { diff --git a/generator/src/test/java/io/wcm/devops/conga/generator/util/VariableStringResolverExpressionTest.java b/generator/src/test/java/io/wcm/devops/conga/generator/util/VariableStringResolverExpressionTest.java index 9dc25b90..18fd97b2 100644 --- a/generator/src/test/java/io/wcm/devops/conga/generator/util/VariableStringResolverExpressionTest.java +++ b/generator/src/test/java/io/wcm/devops/conga/generator/util/VariableStringResolverExpressionTest.java @@ -22,14 +22,12 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +import java.util.List; import java.util.Map; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; - import io.wcm.devops.conga.generator.spi.context.PluginContextOptions; import io.wcm.devops.conga.generator.spi.context.ValueProviderGlobalContext; @@ -54,28 +52,28 @@ void setUp() { @Test void testSimple() { - Map variables = ImmutableMap.of("var1", "v1", "var2", "v2"); + Map variables = Map.of("var1", "v1", "var2", "v2"); assertEquals("The v1 and v2", underTest.resolve("The ${ var1 + ' and ' + var2 }", variables)); } @Test void testSingleVariableWithObject() { - Map variables = ImmutableMap.of("var1", ImmutableList.of("v1", "v2")); + Map variables = Map.of("var1", List.of("v1", "v2")); - assertEquals(ImmutableList.of("v1", "v2"), underTest.resolve("${ var1 }", variables)); + assertEquals(List.of("v1", "v2"), underTest.resolve("${ var1 }", variables)); } @Test void testNestedVariables() { - Map variables = ImmutableMap.of("var1", "v1", "var2", "${var1 + var1}", "var3", "${var2 + var1}"); + Map variables = Map.of("var1", "v1", "var2", "${var1 + var1}", "var3", "${var2 + var1}"); assertEquals("v1,v1v1,v1v1v1", underTest.resolve("${var1},${var2},${var3}", variables)); } @Test void testNestedVariables_IllegalRecursion() { - Map variables = ImmutableMap.of("var1", "${ var2 }", "var2", "${ var1 }"); + Map variables = Map.of("var1", "${ var2 }", "var2", "${ var1 }"); assertThrows(IllegalArgumentException.class, () -> { underTest.resolve("${var1}", variables); @@ -84,7 +82,7 @@ void testNestedVariables_IllegalRecursion() { @Test void testUnknownVariable() { - Map variables = ImmutableMap.of(); + Map variables = Map.of(); assertThrows(IllegalArgumentException.class, () -> { underTest.resolve("${var1}", variables); @@ -93,7 +91,7 @@ void testUnknownVariable() { @Test void testEscapedVariables() { - Map variables = ImmutableMap.of("var1", "v1", "var2", "\\${ var1 }${ var1 }", "var3", "${ var2 }${ var1 }"); + Map variables = Map.of("var1", "v1", "var2", "\\${ var1 }${ var1 }", "var3", "${ var2 }${ var1 }"); assertEquals("${ var1 },${ var1 }v1,${ var1 }v1v1", underTest.resolve("\\${ var1 },${ var2 },${ var3 }", variables)); assertEquals("\\${ var1 },\\${ var1 }v1,\\${ var1 }v1v1", underTest.resolve("\\${ var1 },${ var2 },${ var3 }", variables, false)); @@ -102,28 +100,28 @@ void testEscapedVariables() { @Test void testDeepMapVariable() { - Map variables = ImmutableMap.of("var1", ImmutableMap.of("k1", "v1", "k2", ImmutableMap.of("k21", "v21", "k22", "v22"))); + Map variables = Map.of("var1", Map.of("k1", "v1", "k2", Map.of("k21", "v21", "k22", "v22"))); assertEquals("The v1 and v21", underTest.resolve("The ${var1.k1 + ' and ' + var1.k2.k21}", variables)); } @Test void testListVariable() { - Map variables = ImmutableMap.of("var1", ImmutableList.of("v1", "v2", ImmutableList.of("v31", "v32"))); + Map variables = Map.of("var1", List.of("v1", "v2", List.of("v31", "v32"))); assertEquals("The v1,v2,v31,v32", underTest.resolve("The ${ var1 }", variables)); } @Test void testListVariable_StringJoin() { - Map variables = ImmutableMap.of("var1", ImmutableList.of("v1", "v2", "v3")); + Map variables = Map.of("var1", List.of("v1", "v2", "v3")); assertEquals("The v1 v2 v3", underTest.resolve("The ${new('java.lang.String').join(' ',var1)}", variables)); } @Test void testMapVariable() { - Map variables = ImmutableMap.of("var1", ImmutableMap.of("k1", "v1", "k2", ImmutableMap.of("k21", "v21", "k22", "v22"))); + Map variables = Map.of("var1", Map.of("k1", "v1", "k2", Map.of("k21", "v21", "k22", "v22"))); assertEquals("The k1=v1,k2=k21=v21,k22=v22", underTest.resolve("The ${ var1 }", variables)); } diff --git a/generator/src/test/java/io/wcm/devops/conga/generator/util/VariableStringResolverTest.java b/generator/src/test/java/io/wcm/devops/conga/generator/util/VariableStringResolverTest.java index 605ccd61..c2e57342 100644 --- a/generator/src/test/java/io/wcm/devops/conga/generator/util/VariableStringResolverTest.java +++ b/generator/src/test/java/io/wcm/devops/conga/generator/util/VariableStringResolverTest.java @@ -24,14 +24,12 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.util.List; import java.util.Map; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; - import io.wcm.devops.conga.generator.spi.context.PluginContextOptions; import io.wcm.devops.conga.generator.spi.context.ValueProviderGlobalContext; @@ -55,41 +53,41 @@ void setUp() { @Test void testSimple() { - Map variables = ImmutableMap.of("var1", "v1", "var2", "v2"); + Map variables = Map.of("var1", "v1", "var2", "v2"); assertEquals("The v1 and v2", underTest.resolve("The ${var1} and ${var2}", variables)); } @Test void testSingleVariableWithObject() { - Map variables = ImmutableMap.of("var1", ImmutableList.of("v1", "v2")); + Map variables = Map.of("var1", List.of("v1", "v2")); - assertEquals(ImmutableList.of("v1", "v2"), underTest.resolve("${var1}", variables)); + assertEquals(List.of("v1", "v2"), underTest.resolve("${var1}", variables)); } @Test void testDefaultValue() { - Map variables = ImmutableMap.of("var1", "v1"); + Map variables = Map.of("var1", "v1"); assertEquals("The v1 and theDefValue2", underTest.resolve("The ${var1:theDefValue1} and ${var2:theDefValue2}", variables)); } @Test void testDefaultEmptyValue() { - Map variables = ImmutableMap.of("var1", "v1"); + Map variables = Map.of("var1", "v1"); assertEquals("The empty value: ''", underTest.resolve("The empty value: '${var2:}'", variables)); } @Test void testNestedVariables() { - Map variables = ImmutableMap.of("var1", "v1", "var2", "${var1}${var1}", "var3", "${var2}${var1}"); + Map variables = Map.of("var1", "v1", "var2", "${var1}${var1}", "var3", "${var2}${var1}"); assertEquals("v1,v1v1,v1v1v1", underTest.resolve("${var1},${var2},${var3}", variables)); } @Test void testNestedVariables_IllegalRecursion() { - Map variables = ImmutableMap.of("var1", "${var2}", "var2", "${var1}"); + Map variables = Map.of("var1", "${var2}", "var2", "${var1}"); assertThrows(IllegalArgumentException.class, () -> { underTest.resolve("${var1}", variables); @@ -98,7 +96,7 @@ void testNestedVariables_IllegalRecursion() { @Test void testUnknownVariable() { - Map variables = ImmutableMap.of(); + Map variables = Map.of(); assertThrows(IllegalArgumentException.class, () -> { underTest.resolve("${var1}", variables); @@ -107,7 +105,7 @@ void testUnknownVariable() { @Test void testEscapedVariables() { - Map variables = ImmutableMap.of("var1", "v1", "var2", "\\${var1}${var1}", "var3", "${var2}${var1}"); + Map variables = Map.of("var1", "v1", "var2", "\\${var1}${var1}", "var3", "${var2}${var1}"); assertEquals("${var1},${var1}v1,${var1}v1v1", underTest.resolve("\\${var1},${var2},${var3}", variables)); assertEquals("\\${var1},\\${var1}v1,\\${var1}v1v1", underTest.resolve("\\${var1},${var2},${var3}", variables, false)); @@ -116,7 +114,7 @@ void testEscapedVariables() { @Test void testEscapedVariables_Provider_DefValue() { - Map variables = ImmutableMap.of("var1", "v1", "var2", "\\${var1}${var1}", "var3", "${var2}${var1}"); + Map variables = Map.of("var1", "v1", "var2", "\\${var1}${var1}", "var3", "${var2}${var1}"); assertEquals("\\${provider::var1},\\${var2:defValue},\\${provider::var3:defValue}", underTest.resolve("\\${provider::var1},\\${var2:defValue},\\${provider::var3:defValue}", variables, false)); @@ -126,21 +124,21 @@ void testEscapedVariables_Provider_DefValue() { @Test void testDeepMapVariable() { - Map variables = ImmutableMap.of("var1", ImmutableMap.of("k1", "v1", "k2", ImmutableMap.of("k21", "v21", "k22", "v22"))); + Map variables = Map.of("var1", Map.of("k1", "v1", "k2", Map.of("k21", "v21", "k22", "v22"))); assertEquals("The v1 and v21", underTest.resolve("The ${var1.k1} and ${var1.k2.k21}", variables)); } @Test void testListVariable() { - Map variables = ImmutableMap.of("var1", ImmutableList.of("v1", "v2", ImmutableList.of("v31", "v32"))); + Map variables = Map.of("var1", List.of("v1", "v2", List.of("v31", "v32"))); assertEquals("The v1,v2,v31,v32", underTest.resolve("The ${var1}", variables)); } @Test void testMapVariable() { - Map variables = ImmutableMap.of("var1", ImmutableMap.of("k1", "v1", "k2", ImmutableMap.of("k21", "v21", "k22", "v22"))); + Map variables = Map.of("var1", Map.of("k1", "v1", "k2", Map.of("k21", "v21", "k22", "v22"))); assertEquals("The k1=v1,k2=k21=v21,k22=v22", underTest.resolve("The ${var1}", variables)); } @@ -151,7 +149,7 @@ void testValueProvider() { String propertyName2 = getClass().getName() + "-test.prop2"; System.setProperty(propertyName1, "value1"); - Map variables = ImmutableMap.of("var1", "v1"); + Map variables = Map.of("var1", "v1"); assertEquals("The v1 and value1", underTest.resolve("The ${var1} and ${system::" + propertyName1 + "}", variables)); assertEquals("The v1 and theDefValue", underTest.resolve("The ${var1} and ${system::" + propertyName2 + ":theDefValue}", variables)); @@ -164,13 +162,13 @@ void testValueProvider() { void testCustomValueProvider() { // define value provider name 'customProvider' of type 'system' globalContext.getPluginContextOptions() - .valueProviderConfig(ImmutableMap.of("customProvider", ImmutableMap.of(ValueProviderGlobalContext.PARAM_PLUGIN_NAME, "system"))); + .valueProviderConfig(Map.of("customProvider", Map.of(ValueProviderGlobalContext.PARAM_PLUGIN_NAME, "system"))); String propertyName1 = getClass().getName() + "-test.propCustom1"; String propertyName2 = getClass().getName() + "-test.propCustom2"; System.setProperty(propertyName1, "value1"); - Map variables = ImmutableMap.of("var1", "v1"); + Map variables = Map.of("var1", "v1"); assertEquals("The v1 and value1", underTest.resolve("The ${var1} and ${customProvider::" + propertyName1 + "}", variables)); assertEquals("The v1 and theDefValue", underTest.resolve("The ${var1} and ${customProvider::" + propertyName2 + ":theDefValue}", variables)); @@ -185,7 +183,7 @@ void testCustomValueProvider() { @Test void testDummyMapValueProvider() { - Map variables = ImmutableMap.of("var1", "v1"); + Map variables = Map.of("var1", "v1"); assertEquals("The v1 and value1 and 5", underTest.resolve("The ${var1} and ${dummy-map::map.param1} and ${dummy-map::map.param2}", variables)); assertEquals("The v1 and theDefValue", underTest.resolve("The ${var1} and ${dummy-map::map.paramNotDefined:theDefValue}", variables)); @@ -193,7 +191,7 @@ void testDummyMapValueProvider() { @Test void testDummyMapValueProvider_ListReturnValue() { - assertEquals(ImmutableList.of("v1", "v2", "v3"), underTest.resolve("${dummy-map::map.listParam}", ImmutableMap.of())); + assertEquals(List.of("v1", "v2", "v3"), underTest.resolve("${dummy-map::map.listParam}", Map.of())); } @Test diff --git a/model/src/test/java/io/wcm/devops/conga/model/reader/EnvironmentReaderTest.java b/model/src/test/java/io/wcm/devops/conga/model/reader/EnvironmentReaderTest.java index 0e1428ee..004b2b3b 100644 --- a/model/src/test/java/io/wcm/devops/conga/model/reader/EnvironmentReaderTest.java +++ b/model/src/test/java/io/wcm/devops/conga/model/reader/EnvironmentReaderTest.java @@ -26,15 +26,13 @@ import java.io.IOException; import java.io.InputStream; +import java.util.List; import java.util.Map; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.yaml.snakeyaml.constructor.ConstructorException; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; - import io.wcm.devops.conga.model.environment.Environment; import io.wcm.devops.conga.model.environment.Node; import io.wcm.devops.conga.model.environment.NodeRole; @@ -60,10 +58,10 @@ public void testEnvironment() { assertEquals(1, environment.getRoleConfig().size()); assertEquals(2, environment.getTenants().size()); - assertEquals(ImmutableMap.of( + assertEquals(Map.of( "topologyConnectorPath", "/connector", - "jvm", ImmutableMap.of("heapspace", ImmutableMap.of("max", "4096m")), - "topologyConnectors", ImmutableList.of("http://host1${topologyConnectorPath}", "http://host2${topologyConnectorPath}") + "jvm", Map.of("heapspace", Map.of("max", "4096m")), + "topologyConnectors", List.of("http://host1${topologyConnectorPath}", "http://host2${topologyConnectorPath}") ), environment.getConfig()); } @@ -73,8 +71,8 @@ public void testNode() { assertEquals("importer", node.getNode()); - assertEquals(ImmutableMap.of("topologyConnectorPath", "/specialConnector", - "jvm", ImmutableMap.of("heapspace", ImmutableMap.of("max", "2048m"))), node.getConfig()); + assertEquals(Map.of("topologyConnectorPath", "/specialConnector", + "jvm", Map.of("heapspace", Map.of("max", "2048m"))), node.getConfig()); assertEquals(2, node.getRoles().size()); } @@ -82,7 +80,7 @@ public void testNode() { @Test public void testMultiNode() { Node node = environment.getNodes().get(1); - assertEquals(ImmutableList.of("services-1", "services-2"), node.getNodes()); + assertEquals(List.of("services-1", "services-2"), node.getNodes()); assertEquals(1, node.getRoles().size()); } @@ -91,13 +89,13 @@ public void testNodeRole() { NodeRole role1 = environment.getNodes().get(0).getRoles().get(0); assertEquals("tomcat-services", role1.getRole()); assertEquals("importer", role1.getVariant()); - assertEquals(ImmutableList.of("importer"), role1.getAggregatedVariants()); - assertEquals(ImmutableMap.of("topologyConnectors", ImmutableList.of("http://host3${topologyConnectorPath}")), role1.getConfig()); + assertEquals(List.of("importer"), role1.getAggregatedVariants()); + assertEquals(Map.of("topologyConnectors", List.of("http://host3${topologyConnectorPath}")), role1.getConfig()); NodeRole role2 = environment.getNodes().get(0).getRoles().get(1); assertEquals("tomcat-backendconnector", role2.getRole()); - assertEquals(ImmutableList.of("var1", "var2"), role2.getVariants()); - assertEquals(ImmutableList.of("var1", "var2"), role2.getAggregatedVariants()); + assertEquals(List.of("var1", "var2"), role2.getVariants()); + assertEquals(List.of("var1", "var2"), role2.getAggregatedVariants()); } @Test @@ -106,7 +104,7 @@ public void testRoleConfig() { assertEquals("tomcat-backendconnector", roleConfig.getRole()); - assertEquals(ImmutableMap.of("jvm", ImmutableMap.of("heapspace", ImmutableMap.of("max", "1024m"))), roleConfig.getConfig()); + assertEquals(Map.of("jvm", Map.of("heapspace", Map.of("max", "1024m"))), roleConfig.getConfig()); } @Test @@ -115,8 +113,8 @@ public void testTenant() { assertEquals("tenant1", tenant.getTenant()); - assertEquals(ImmutableList.of("website", "application"), tenant.getRoles()); - assertEquals(ImmutableMap.of("domain", "mysite.de", "website", ImmutableMap.of("hostname", "www.${domain}")), tenant.getConfig()); + assertEquals(List.of("website", "application"), tenant.getRoles()); + assertEquals(Map.of("domain", "mysite.de", "website", Map.of("hostname", "www.${domain}")), tenant.getConfig()); } @Test @@ -131,7 +129,7 @@ public void testEnvironmentWithNullTenant() { @Test public void testDependencies() { - assertEquals(ImmutableList.of("url1", "mvn:url2"), environment.getDependencies()); + assertEquals(List.of("url1", "mvn:url2"), environment.getDependencies()); } @Test diff --git a/model/src/test/java/io/wcm/devops/conga/model/reader/RoleReaderTest.java b/model/src/test/java/io/wcm/devops/conga/model/reader/RoleReaderTest.java index 34f94640..e40493d9 100644 --- a/model/src/test/java/io/wcm/devops/conga/model/reader/RoleReaderTest.java +++ b/model/src/test/java/io/wcm/devops/conga/model/reader/RoleReaderTest.java @@ -28,13 +28,11 @@ import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.util.List; +import java.util.Map; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; - import io.wcm.devops.conga.model.role.Role; import io.wcm.devops.conga.model.role.RoleFile; import io.wcm.devops.conga.model.role.RoleFile.RoleFileVariantMetadata; @@ -69,12 +67,12 @@ void testRole() { List files = role.getFiles(); assertEquals(7, files.size()); - assertEquals(ImmutableMap.of( + assertEquals(Map.of( "var1", "value1", - "group1", ImmutableMap.of("var2", "value2"), - "tomcat", ImmutableMap.of("port", 8080, "path", "/path/to/tomcat"), - "jvm", ImmutableMap.of("heapspace", ImmutableMap.of("min", "512m", "max", "2048m"), "permgenspace", ImmutableMap.of("max", "256m")), - "topologyConnectors", ImmutableList.of("http://localhost:8080/libs/sling/topology/connector") + "group1", Map.of("var2", "value2"), + "tomcat", Map.of("port", 8080, "path", "/path/to/tomcat"), + "jvm", Map.of("heapspace", Map.of("min", "512m", "max", "2048m"), "permgenspace", Map.of("max", "256m")), + "topologyConnectors", List.of("http://localhost:8080/libs/sling/topology/connector") ), role.getConfig()); } @@ -90,7 +88,7 @@ void testVariant() { RoleVariant variant = role.getVariants().get(0); assertEquals("services", variant.getVariant()); - assertEquals(ImmutableMap.of("var1", "value1_service"), variant.getConfig()); + assertEquals(Map.of("var1", "value1_service"), variant.getConfig()); } @Test @@ -100,12 +98,12 @@ void testFile() { assertEquals("systemconfig-importer.txt", file.getFile()); assertEquals("data/deploy", file.getDir()); assertEquals("systemconfig-importer.txt.hbs", file.getTemplate()); - assertEquals(ImmutableList.of("importer", "variant2*", "variant3"), file.getVariants()); + assertEquals(List.of("importer", "variant2*", "variant3"), file.getVariants()); assertEquals("${abc}", file.getCondition()); - assertEquals(ImmutableList.of("sling-provisioning-model"), file.getValidators()); - assertEquals(ImmutableMap.of("option1", "value1"), file.getValidatorOptions()); - assertEquals(ImmutableList.of("osgi-config-generator"), file.getPostProcessors()); - assertEquals(ImmutableMap.of("option2", "value2"), file.getPostProcessorOptions()); + assertEquals(List.of("sling-provisioning-model"), file.getValidators()); + assertEquals(Map.of("option1", "value1"), file.getValidatorOptions()); + assertEquals(List.of("osgi-config-generator"), file.getPostProcessors()); + assertEquals(Map.of("option2", "value2"), file.getPostProcessorOptions()); assertEquals("sling-provisioning", file.getFileHeader()); assertEquals("none", file.getMultiply()); assertEquals(StandardCharsets.UTF_8.name(), file.getCharset()); @@ -114,7 +112,7 @@ void testFile() { RoleFile vhostFile = role.getFiles().get(4); assertEquals("tenant", vhostFile.getMultiply()); - assertEquals(ImmutableMap.of("roles", ImmutableList.of("website")), vhostFile.getMultiplyOptions()); + assertEquals(Map.of("roles", List.of("website")), vhostFile.getMultiplyOptions()); assertEquals(LineEndings.unix, vhostFile.getLineEndings()); List variantsMetadata = file.getVariantsMetadata(); @@ -132,7 +130,7 @@ void testDownload() { assertEquals("download", file.getDir()); assertEquals("classpath://xyz.txt", file.getUrl()); - assertEquals(ImmutableMap.of("modelOption1", "value1"), file.getModelOptions()); + assertEquals(Map.of("modelOption1", "value1"), file.getModelOptions()); assertTrue(file.isDeleteSource()); } @@ -147,7 +145,7 @@ void testSymlink() { @Test void testSensitiveConfigurationParameters() { - assertEquals(ImmutableList.of("var1", "group1.var2"), role.getSensitiveConfigParameters()); + assertEquals(List.of("var1", "group1.var2"), role.getSensitiveConfigParameters()); } } diff --git a/model/src/test/java/io/wcm/devops/conga/model/util/MapExpanderTest.java b/model/src/test/java/io/wcm/devops/conga/model/util/MapExpanderTest.java index c66e94da..e243cc6d 100644 --- a/model/src/test/java/io/wcm/devops/conga/model/util/MapExpanderTest.java +++ b/model/src/test/java/io/wcm/devops/conga/model/util/MapExpanderTest.java @@ -24,10 +24,10 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; -import org.junit.jupiter.api.Test; +import java.util.List; +import java.util.Map; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; +import org.junit.jupiter.api.Test; class MapExpanderTest { @@ -38,73 +38,73 @@ void testNull() { @Test void testEmpty() { - assertEquals(ImmutableMap.of(), expand(ImmutableMap.of())); + assertEquals(Map.of(), expand(Map.of())); } @Test void testSimple() { - assertEquals(ImmutableMap.of("key1", "value1"), - expand(ImmutableMap.of("key1", "value1"))); + assertEquals(Map.of("key1", "value1"), + expand(Map.of("key1", "value1"))); - assertEquals(ImmutableMap.of("key1", "value1", "key2", 5), - expand(ImmutableMap.of("key1", "value1", "key2", 5))); + assertEquals(Map.of("key1", "value1", "key2", 5), + expand(Map.of("key1", "value1", "key2", 5))); } @Test void testSimpleNested() { - assertEquals(ImmutableMap.of("key1", "value1", "key2", ImmutableMap.of("key21", "value21")), - expand(ImmutableMap.of("key1", "value1", "key2", ImmutableMap.of("key21", "value21")))); + assertEquals(Map.of("key1", "value1", "key2", Map.of("key21", "value21")), + expand(Map.of("key1", "value1", "key2", Map.of("key21", "value21")))); } @Test void testOneLevel_1() { - assertEquals(ImmutableMap.of("key1", "value1", "key2", ImmutableMap.of("key21", "value21")), - expand(ImmutableMap.of("key1", "value1", "key2.key21", "value21"))); + assertEquals(Map.of("key1", "value1", "key2", Map.of("key21", "value21")), + expand(Map.of("key1", "value1", "key2.key21", "value21"))); } @Test void testOneLevel_2() { - assertEquals(ImmutableMap.of("key1", "value1", "key2", ImmutableMap.of("key21", "value21", "key22", 55)), - expand(ImmutableMap.of("key1", "value1", "key2.key21", "value21", "key2.key22", 55))); + assertEquals(Map.of("key1", "value1", "key2", Map.of("key21", "value21", "key22", 55)), + expand(Map.of("key1", "value1", "key2.key21", "value21", "key2.key22", 55))); } @Test void testThreeLevels() { - assertEquals(ImmutableMap.of("key1", "value1", "a", ImmutableMap.of("b", ImmutableMap.of( - "c", ImmutableMap.of("1", "v1", "2", 99), - "d", ImmutableMap.of("1", true)))), - expand(ImmutableMap.of("key1", "value1", "a.b.c.1", "v1", "a.b.c.2", 99, "a.b.d.1", true))); + assertEquals(Map.of("key1", "value1", "a", Map.of("b", Map.of( + "c", Map.of("1", "v1", "2", 99), + "d", Map.of("1", true)))), + expand(Map.of("key1", "value1", "a.b.c.1", "v1", "a.b.c.2", 99, "a.b.d.1", true))); } @Test void testMapDeeperLevel() { - assertEquals(ImmutableMap.of("key1", ImmutableMap.of("a", ImmutableMap.of("b", ImmutableMap.of("c", "v1")))), - expand(ImmutableMap.of("key1", ImmutableMap.of("a.b.c", "v1")))); + assertEquals(Map.of("key1", Map.of("a", Map.of("b", Map.of("c", "v1")))), + expand(Map.of("key1", Map.of("a.b.c", "v1")))); } @Test void testWithList() { - assertEquals(ImmutableMap.of("key1", ImmutableList.of( - ImmutableMap.of("a", ImmutableMap.of("b", "v1", "c", ImmutableMap.of("d", "v2"))), - ImmutableMap.of("a", ImmutableMap.of("b", "v3")) + assertEquals(Map.of("key1", List.of( + Map.of("a", Map.of("b", "v1", "c", Map.of("d", "v2"))), + Map.of("a", Map.of("b", "v3")) )), - expand(ImmutableMap.of("key1", ImmutableList.of( - ImmutableMap.of("a.b", "v1", "a.c.d", "v2"), - ImmutableMap.of("a.b", "v3") + expand(Map.of("key1", List.of( + Map.of("a.b", "v1", "a.c.d", "v2"), + Map.of("a.b", "v3") )))); } @Test void testGetDeep() { - assertNull(getDeep(ImmutableMap.of(), null)); - assertNull(getDeep(ImmutableMap.of(), "p1")); - assertNull(getDeep(ImmutableMap.of(), "p1.p2")); - assertNull(getDeep(ImmutableMap.of(), "p1.p2.p3")); - - assertEquals("v1", getDeep(ImmutableMap.of("p1", "v1", "p2", "v2"), "p1")); - assertNull(getDeep(ImmutableMap.of("p1", "v1", "p2", "v2"), "p1.p2")); - assertEquals("v1", getDeep(ImmutableMap.of("p1", ImmutableMap.of("p2", "v1"), "p2", "v2"), "p1.p2")); - assertEquals("v1", getDeep(ImmutableMap.of("p1", ImmutableMap.of("p2", ImmutableMap.of("p3", "v1")), "p2", "v2"), "p1.p2.p3")); + assertNull(getDeep(Map.of(), "")); + assertNull(getDeep(Map.of(), "p1")); + assertNull(getDeep(Map.of(), "p1.p2")); + assertNull(getDeep(Map.of(), "p1.p2.p3")); + + assertEquals("v1", getDeep(Map.of("p1", "v1", "p2", "v2"), "p1")); + assertNull(getDeep(Map.of("p1", "v1", "p2", "v2"), "p1.p2")); + assertEquals("v1", getDeep(Map.of("p1", Map.of("p2", "v1"), "p2", "v2"), "p1.p2")); + assertEquals("v1", getDeep(Map.of("p1", Map.of("p2", Map.of("p3", "v1")), "p2", "v2"), "p1.p2.p3")); } } diff --git a/model/src/test/java/io/wcm/devops/conga/model/util/MapMergerTest.java b/model/src/test/java/io/wcm/devops/conga/model/util/MapMergerTest.java index dca6804f..52a6c202 100644 --- a/model/src/test/java/io/wcm/devops/conga/model/util/MapMergerTest.java +++ b/model/src/test/java/io/wcm/devops/conga/model/util/MapMergerTest.java @@ -23,6 +23,7 @@ import static io.wcm.devops.conga.model.util.MapMerger.merge; import static org.junit.jupiter.api.Assertions.assertEquals; +import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -30,8 +31,6 @@ import org.junit.jupiter.api.Test; -import com.google.common.collect.ImmutableList; - class MapMergerTest { @Test @@ -267,7 +266,7 @@ void testMergeList_EliminateDuplicates_Map() { } private static List list(Object... items) { - return ImmutableList.copyOf(items); + return Arrays.asList(items); } private static Map map(Object... items) { diff --git a/model/src/test/java/io/wcm/devops/conga/model/util/MapSplitterTest.java b/model/src/test/java/io/wcm/devops/conga/model/util/MapSplitterTest.java index a3ea135b..64b92251 100644 --- a/model/src/test/java/io/wcm/devops/conga/model/util/MapSplitterTest.java +++ b/model/src/test/java/io/wcm/devops/conga/model/util/MapSplitterTest.java @@ -31,34 +31,31 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; - import io.wcm.devops.conga.model.util.MapSplitter.SplitResult; class MapSplitterTest { - private static final Map TEST_MAP = ImmutableMap.of( + private static final Map TEST_MAP = Map.of( "var1", "value1", "var2", "value2", - "obj1", ImmutableMap.of( + "obj1", Map.of( "var11", "value11", "var12", "value12", - "obj13", ImmutableMap.of( + "obj13", Map.of( "var131", "value131", "var132", "value132"), - "list14", ImmutableList.of( + "list14", List.of( "value14a", "value14b", "value14c")), - "list2", ImmutableList.of( - ImmutableMap.of( + "list2", List.of( + Map.of( "var21a", "value11a", "var22a", "value22a", - "obj23a", ImmutableMap.of( + "obj23a", Map.of( "var23a1", "value23a1", "var23a2", "value23a2")), - ImmutableMap.of( + Map.of( "var21b", "value11b", "var22b", "value22b"))); @@ -81,30 +78,30 @@ void testAllOut() { @Test void testKeyStartsWithVar1() { result = splitMap(TEST_MAP, entry -> StringUtils.startsWith(entry.getKey(), "var1")); - assertEquals(ImmutableMap.of( + assertEquals(Map.of( "var1", "value1", - "obj1", ImmutableMap.of( + "obj1", Map.of( "var11", "value11", "var12", "value12", - "obj13", ImmutableMap.of( + "obj13", Map.of( "var131", "value131", "var132", "value132"))), result.getMatching()); - assertEquals(ImmutableMap.of( + assertEquals(Map.of( "var2", "value2", - "obj1", ImmutableMap.of( - "list14", ImmutableList.of( + "obj1", Map.of( + "list14", List.of( "value14a", "value14b", "value14c")), - "list2", ImmutableList.of( - ImmutableMap.of( + "list2", List.of( + Map.of( "var21a", "value11a", "var22a", "value22a", - "obj23a", ImmutableMap.of( + "obj23a", Map.of( "var23a1", "value23a1", "var23a2", "value23a2")), - ImmutableMap.of( + Map.of( "var21b", "value11b", "var22b", "value22b"))), result.getUnmatching()); @@ -114,29 +111,29 @@ void testKeyStartsWithVar1() { void testValueStartsWithValue2() { result = splitMap(TEST_MAP, entry -> matchesSimpleListValue(entry.getValue(), value -> (value instanceof String) && StringUtils.startsWith(value.toString(), "value2"))); - assertEquals(ImmutableMap.of( + assertEquals(Map.of( "var2", "value2"), result.getMatching()); - assertEquals(ImmutableMap.of( + assertEquals(Map.of( "var1", "value1", - "obj1", ImmutableMap.of( + "obj1", Map.of( "var11", "value11", "var12", "value12", - "obj13", ImmutableMap.of( + "obj13", Map.of( "var131", "value131", "var132", "value132"), - "list14", ImmutableList.of( + "list14", List.of( "value14a", "value14b", "value14c")), - "list2", ImmutableList.of( - ImmutableMap.of( + "list2", List.of( + Map.of( "var21a", "value11a", "var22a", "value22a", - "obj23a", ImmutableMap.of( + "obj23a", Map.of( "var23a1", "value23a1", "var23a2", "value23a2")), - ImmutableMap.of( + Map.of( "var21b", "value11b", "var22b", "value22b"))), result.getUnmatching()); @@ -146,30 +143,30 @@ void testValueStartsWithValue2() { void testStartsWithValue14() { result = splitMap(TEST_MAP, entry -> matchesSimpleListValue(entry.getValue(), value -> (value instanceof String) && StringUtils.startsWith(value.toString(), "value14"))); - assertEquals(ImmutableMap.of( - "obj1", ImmutableMap.of( - "list14", ImmutableList.of( + assertEquals(Map.of( + "obj1", Map.of( + "list14", List.of( "value14a", "value14b", "value14c"))), result.getMatching()); - assertEquals(ImmutableMap.of( + assertEquals(Map.of( "var1", "value1", "var2", "value2", - "obj1", ImmutableMap.of( + "obj1", Map.of( "var11", "value11", "var12", "value12", - "obj13", ImmutableMap.of( + "obj13", Map.of( "var131", "value131", "var132", "value132")), - "list2", ImmutableList.of( - ImmutableMap.of( + "list2", List.of( + Map.of( "var21a", "value11a", "var22a", "value22a", - "obj23a", ImmutableMap.of( + "obj23a", Map.of( "var23a1", "value23a1", "var23a2", "value23a2")), - ImmutableMap.of( + Map.of( "var21b", "value11b", "var22b", "value22b"))), result.getUnmatching()); diff --git a/model/src/test/java/io/wcm/devops/conga/model/util/MergingListTest.java b/model/src/test/java/io/wcm/devops/conga/model/util/MergingListTest.java index f6189e02..8c1e4596 100644 --- a/model/src/test/java/io/wcm/devops/conga/model/util/MergingListTest.java +++ b/model/src/test/java/io/wcm/devops/conga/model/util/MergingListTest.java @@ -22,11 +22,11 @@ import static io.wcm.devops.conga.model.util.MapMerger.LIST_MERGE_ENTRY; import static org.junit.jupiter.api.Assertions.assertEquals; +import java.util.List; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import com.google.common.collect.ImmutableList; - class MergingListTest { private MergingList underTest; @@ -46,7 +46,7 @@ void testNoMerging_Duplicates() { underTest.add("item5"); underTest.add("item5"); - assertEquals(ImmutableList.of("item1", "item2", "item4", "item5"), underTest); + assertEquals(List.of("item1", "item2", "item4", "item5"), underTest); } @Test @@ -58,7 +58,7 @@ void testMergeStart() { underTest.add("item4"); underTest.add("item5"); - assertEquals(ImmutableList.of("item4", "item5", "item1", "item2"), underTest); + assertEquals(List.of("item4", "item5", "item1", "item2"), underTest); } @Test @@ -70,7 +70,7 @@ void testMergeMiddle() { underTest.add("item4"); underTest.add("item5"); - assertEquals(ImmutableList.of("item1", "item4", "item5", "item2"), underTest); + assertEquals(List.of("item1", "item4", "item5", "item2"), underTest); } @Test @@ -84,7 +84,7 @@ void testMergeMiddle_Duplicates() { underTest.add("item1"); underTest.add("item5"); - assertEquals(ImmutableList.of("item1", "item4", "item5", "item2"), underTest); + assertEquals(List.of("item1", "item4", "item5", "item2"), underTest); } @Test @@ -96,7 +96,7 @@ void testMergeEnd() { underTest.add("item4"); underTest.add("item5"); - assertEquals(ImmutableList.of("item1", "item2", "item4", "item5"), underTest); + assertEquals(List.of("item1", "item2", "item4", "item5"), underTest); } @Test @@ -109,7 +109,7 @@ void testMergeMultipleTokens() { underTest.add("item4"); underTest.add("item5"); - assertEquals(ImmutableList.of("item1", "item4", "item5", "item2"), underTest); + assertEquals(List.of("item1", "item4", "item5", "item2"), underTest); } } diff --git a/resource/src/test/java/io/wcm/devops/conga/resource/ResourceLoaderClasspathTest.java b/resource/src/test/java/io/wcm/devops/conga/resource/ResourceLoaderClasspathTest.java index dd55d5c5..39da464d 100644 --- a/resource/src/test/java/io/wcm/devops/conga/resource/ResourceLoaderClasspathTest.java +++ b/resource/src/test/java/io/wcm/devops/conga/resource/ResourceLoaderClasspathTest.java @@ -32,8 +32,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import com.google.common.collect.ImmutableList; - class ResourceLoaderClasspathTest { private static final String ROOT = "/test-files"; @@ -71,16 +69,16 @@ void testResourceCollection() throws Exception { assertEquals(ROOT + "/folder1", col.getPath()); assertEquals(CLASSPATH_PREFIX + ROOT + "/folder1", col.getCanonicalPath()); - List resources = ImmutableList.copyOf(col.getResources()); + List resources = List.copyOf(col.getResources()); assertEquals(2, resources.size()); assertEquals("file1.txt", resources.get(0).getName()); assertEquals("file2.txt", resources.get(1).getName()); - List resourceCollections = ImmutableList.copyOf(col.getResourceCollections()); + List resourceCollections = List.copyOf(col.getResourceCollections()); assertEquals(1, resourceCollections.size()); assertEquals("folder2", resourceCollections.get(0).getName()); - List folder2Resources = ImmutableList.copyOf(resourceCollections.get(0).getResources()); + List folder2Resources = List.copyOf(resourceCollections.get(0).getResources()); assertEquals(1, folder2Resources.size()); assertEquals("file3.txt", folder2Resources.get(0).getName()); } @@ -112,8 +110,8 @@ void testNonExistingResource() throws Exception { void testNonExistingResourceCollection() throws Exception { ResourceCollection col = underTest.getResourceCollection(CLASSPATH_PREFIX + ROOT + "/invalidFolder"); assertFalse(col.exists()); - assertEquals(ImmutableList.of(), ImmutableList.copyOf(col.getResources())); - assertEquals(ImmutableList.of(), ImmutableList.copyOf(col.getResourceCollections())); + assertEquals(List.of(), List.copyOf(col.getResources())); + assertEquals(List.of(), List.copyOf(col.getResourceCollections())); } @Test diff --git a/resource/src/test/java/io/wcm/devops/conga/resource/ResourceLoaderFilesystemTest.java b/resource/src/test/java/io/wcm/devops/conga/resource/ResourceLoaderFilesystemTest.java index 33776ba3..05f7b6ce 100644 --- a/resource/src/test/java/io/wcm/devops/conga/resource/ResourceLoaderFilesystemTest.java +++ b/resource/src/test/java/io/wcm/devops/conga/resource/ResourceLoaderFilesystemTest.java @@ -33,8 +33,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import com.google.common.collect.ImmutableList; - class ResourceLoaderFilesystemTest { private static final String ROOT = "src/test/resources/test-files"; @@ -74,16 +72,16 @@ void testResourceCollection() throws Exception { assertTrue(StringUtils.endsWith(unifySlashes(col.getCanonicalPath()), "/" + ROOT + "/folder1"), "Canonical path " + unifySlashes(col.getCanonicalPath()) + " does not end with /" + ROOT + "/folder1"); - List resources = ImmutableList.copyOf(col.getResources()); + List resources = List.copyOf(col.getResources()); assertEquals(2, resources.size()); assertEquals("file1.txt", resources.get(0).getName()); assertEquals("file2.txt", resources.get(1).getName()); - List resourceCollections = ImmutableList.copyOf(col.getResourceCollections()); + List resourceCollections = List.copyOf(col.getResourceCollections()); assertEquals(1, resourceCollections.size()); assertEquals("folder2", resourceCollections.get(0).getName()); - List folder2Resources = ImmutableList.copyOf(resourceCollections.get(0).getResources()); + List folder2Resources = List.copyOf(resourceCollections.get(0).getResources()); assertEquals(1, folder2Resources.size()); assertEquals("file3.txt", folder2Resources.get(0).getName()); } @@ -113,8 +111,8 @@ void testNonExistingResourceAutoDetect() throws Exception { void testNonExistingResourceCollection() throws Exception { ResourceCollection col = underTest.getResourceCollection(FILE_PREFIX + ROOT + "/invalidFolder"); assertFalse(col.exists()); - assertEquals(ImmutableList.of(), ImmutableList.copyOf(col.getResources())); - assertEquals(ImmutableList.of(), ImmutableList.copyOf(col.getResourceCollections())); + assertEquals(List.of(), List.copyOf(col.getResources())); + assertEquals(List.of(), List.copyOf(col.getResourceCollections())); } @Test diff --git a/tooling/conga-maven-plugin/src/test/java/io/wcm/devops/conga/tooling/maven/plugin/util/PluginConfigUtilTest.java b/tooling/conga-maven-plugin/src/test/java/io/wcm/devops/conga/tooling/maven/plugin/util/PluginConfigUtilTest.java index d439c6e9..9567f746 100644 --- a/tooling/conga-maven-plugin/src/test/java/io/wcm/devops/conga/tooling/maven/plugin/util/PluginConfigUtilTest.java +++ b/tooling/conga-maven-plugin/src/test/java/io/wcm/devops/conga/tooling/maven/plugin/util/PluginConfigUtilTest.java @@ -21,25 +21,25 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.jupiter.api.Test; +import java.util.Map; -import com.google.common.collect.ImmutableMap; +import org.junit.jupiter.api.Test; public class PluginConfigUtilTest { @Test public void testGetConfigMap() { - assertEquals(ImmutableMap.of(), + assertEquals(Map.of(), PluginConfigUtil.getConfigMap(null)); - assertEquals(ImmutableMap.of( - "plugin1", ImmutableMap.of(), - "plugin2", ImmutableMap.of()), + assertEquals(Map.of( + "plugin1", Map.of(), + "plugin2", Map.of()), PluginConfigUtil.getConfigMap("plugin1,plugin2")); - assertEquals(ImmutableMap.of( - "plugin1", ImmutableMap.of("param1", "abc", "param2", 5), - "plugin2", ImmutableMap.of("param3", true)), + assertEquals(Map.of( + "plugin1", Map.of("param1", "abc", "param2", 5), + "plugin2", Map.of("param3", true)), PluginConfigUtil.getConfigMap("plugin1;param1=abc;param2=5,plugin2;param3=true")); } diff --git a/tooling/conga-maven-plugin/src/test/java/io/wcm/devops/conga/tooling/maven/plugin/valueprovider/MavenPropertyValueProviderPluginTest.java b/tooling/conga-maven-plugin/src/test/java/io/wcm/devops/conga/tooling/maven/plugin/valueprovider/MavenPropertyValueProviderPluginTest.java index a1eb0dc0..91ba87b0 100644 --- a/tooling/conga-maven-plugin/src/test/java/io/wcm/devops/conga/tooling/maven/plugin/valueprovider/MavenPropertyValueProviderPluginTest.java +++ b/tooling/conga-maven-plugin/src/test/java/io/wcm/devops/conga/tooling/maven/plugin/valueprovider/MavenPropertyValueProviderPluginTest.java @@ -24,12 +24,12 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; +import java.util.List; + import org.apache.maven.project.MavenProject; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import com.google.common.collect.ImmutableList; - import io.wcm.devops.conga.generator.spi.ValueProviderPlugin; import io.wcm.devops.conga.generator.spi.context.PluginContextOptions; import io.wcm.devops.conga.generator.spi.context.ValueProviderContext; @@ -73,7 +73,7 @@ void testResolve() { mavenProject.getProperties().setProperty(propertyDependency, "1.10"); assertEquals("value1", underTest.resolve(propertyName1, context)); - assertEquals(ImmutableList.of("value1", "value2", "value3"), underTest.resolve(propertyName2, context)); + assertEquals(List.of("value1", "value2", "value3"), underTest.resolve(propertyName2, context)); assertNull(underTest.resolve(propertyName3, context)); assertNotNull(underTest.resolve(propertyJavaVersion, context)); From bbd120fd0acf36555f137b39ca6c5328fb1ee70b Mon Sep 17 00:00:00 2001 From: Stefan Seifert Date: Wed, 10 Jan 2024 13:22:51 +0100 Subject: [PATCH 14/26] reduce usage of Guava --- .../io/wcm/devops/conga/generator/EnvironmentGenerator.java | 2 +- .../java/io/wcm/devops/conga/generator/FileGenerator.java | 2 +- .../io/wcm/devops/conga/generator/ResourceLoaderUtil.java | 2 +- .../generator/plugins/fileheader/AbstractFileHeader.java | 2 +- .../plugins/handlebars/escaping/JsonEscapingStrategy.java | 6 +++--- .../conga/generator/spi/context/ValueProviderContext.java | 4 +--- .../conga/generator/util/ConfigInheritanceResolver.java | 4 +--- .../devops/conga/generator/util/EnvironmentExpander.java | 4 +--- .../wcm/devops/conga/model/reader/AbstractModelReader.java | 4 +--- .../conga/tooling/maven/plugin/AbstractCongaMojo.java | 3 +-- .../wcm/devops/conga/tooling/maven/plugin/ValidateMojo.java | 4 ++-- .../conga/tooling/maven/plugin/util/ClassLoaderUtil.java | 5 ++--- .../tooling/maven/plugin/util/MavenArtifactHelper.java | 4 +--- 13 files changed, 17 insertions(+), 29 deletions(-) diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/EnvironmentGenerator.java b/generator/src/main/java/io/wcm/devops/conga/generator/EnvironmentGenerator.java index 4f60920e..f4685568 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/EnvironmentGenerator.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/EnvironmentGenerator.java @@ -158,7 +158,7 @@ class EnvironmentGenerator { ContextPropertiesBuilder.buildEnvironmentContextVariables(environmentName, this.environment, options.getVersion(), variableObjectTreeResolver, variableStringResolver)); - this.dependencyVersions = options.getDependencyVersionBuilder() != null ? options.getDependencyVersionBuilder().apply(environment) : ImmutableList.of(); + this.dependencyVersions = options.getDependencyVersionBuilder() != null ? options.getDependencyVersionBuilder().apply(environment) : List.of(); // prepare YAML representer yamlRepresenter = new YamlRepresenter(); diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/FileGenerator.java b/generator/src/main/java/io/wcm/devops/conga/generator/FileGenerator.java index e21aac75..e77cfe85 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/FileGenerator.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/FileGenerator.java @@ -510,7 +510,7 @@ private List getPostProcessorValidators() { return (List)validators; } else { - return ImmutableList.of(); + return List.of(); } } diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/ResourceLoaderUtil.java b/generator/src/main/java/io/wcm/devops/conga/generator/ResourceLoaderUtil.java index f27034da..635a12e7 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/ResourceLoaderUtil.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/ResourceLoaderUtil.java @@ -79,7 +79,7 @@ public static List getEnvironmentClasspathUrls(List dependencyUrls, List classpathUrls = new ArrayList<>(); for (String dependencyUrl : dependencyUrls) { // resolver variables without config map - thus supporting only value providers with external values - String resolvedDependencyUrl = variableStringResolver.resolveString(dependencyUrl, ImmutableMap.of()); + String resolvedDependencyUrl = variableStringResolver.resolveString(dependencyUrl, Map.of()); try { classpathUrls.addAll(urlFileManager.getFileUrlsWithDependencies(resolvedDependencyUrl)); } diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/plugins/fileheader/AbstractFileHeader.java b/generator/src/main/java/io/wcm/devops/conga/generator/plugins/fileheader/AbstractFileHeader.java index e152674c..95a01b08 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/plugins/fileheader/AbstractFileHeader.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/plugins/fileheader/AbstractFileHeader.java @@ -50,7 +50,7 @@ public final Void apply(FileContext file, FileHeaderContext context) { List sanitizedCommentLines; if (context.getCommentLines() == null) { - sanitizedCommentLines = ImmutableList.of(); + sanitizedCommentLines = List.of(); } else { sanitizedCommentLines = context.getCommentLines().stream() diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/plugins/handlebars/escaping/JsonEscapingStrategy.java b/generator/src/main/java/io/wcm/devops/conga/generator/plugins/handlebars/escaping/JsonEscapingStrategy.java index 2cf91647..985abfdc 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/plugins/handlebars/escaping/JsonEscapingStrategy.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/plugins/handlebars/escaping/JsonEscapingStrategy.java @@ -19,13 +19,13 @@ */ package io.wcm.devops.conga.generator.plugins.handlebars.escaping; +import java.util.Map; + import org.apache.commons.text.translate.AggregateTranslator; import org.apache.commons.text.translate.CharSequenceTranslator; import org.apache.commons.text.translate.EntityArrays; import org.apache.commons.text.translate.LookupTranslator; -import com.google.common.collect.ImmutableMap; - import io.wcm.devops.conga.generator.spi.handlebars.EscapingStrategyPlugin; import io.wcm.devops.conga.generator.spi.handlebars.context.EscapingStrategyContext; import io.wcm.devops.conga.generator.util.FileUtil; @@ -50,7 +50,7 @@ public class JsonEscapingStrategy implements EscapingStrategyPlugin { private static final CharSequenceTranslator ESCAPE_JSON = new AggregateTranslator( new LookupTranslator( - ImmutableMap.of( + Map.of( "\"", "\\\"", "\\", "\\\\" )), diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/spi/context/ValueProviderContext.java b/generator/src/main/java/io/wcm/devops/conga/generator/spi/context/ValueProviderContext.java index f292d9b1..8e0c8378 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/spi/context/ValueProviderContext.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/spi/context/ValueProviderContext.java @@ -21,8 +21,6 @@ import java.util.Map; -import com.google.common.collect.ImmutableMap; - /** * Context for a single {@link io.wcm.devops.conga.generator.spi.ValueProviderPlugin} instance. */ @@ -64,7 +62,7 @@ public String getValueProviderName() { public Object getValueProviderConfig(String key) { Map config = valueProviderGlobalContext.getValueProviderConfig(valueProviderName); if (config == null) { - config = ImmutableMap.of(); + config = Map.of(); } return config.get(key); } diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/util/ConfigInheritanceResolver.java b/generator/src/main/java/io/wcm/devops/conga/generator/util/ConfigInheritanceResolver.java index 325f58b6..d467dce1 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/util/ConfigInheritanceResolver.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/util/ConfigInheritanceResolver.java @@ -26,8 +26,6 @@ import org.apache.commons.lang3.StringUtils; -import com.google.common.collect.ImmutableSet; - import io.wcm.devops.conga.model.environment.Environment; import io.wcm.devops.conga.model.environment.Node; import io.wcm.devops.conga.model.environment.NodeRole; @@ -67,7 +65,7 @@ public static void resolve(Object model) { } if (model instanceof Role) { // do not inherit config of role variants field (WDCONGA-24) - ignorePropertyNames = ImmutableSet.of("variants"); + ignorePropertyNames = Set.of("variants"); } new ConfigInheritanceResolver(ignorePropertyNames).process(model, PROCESSOR, new HashMap<>()); } diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/util/EnvironmentExpander.java b/generator/src/main/java/io/wcm/devops/conga/generator/util/EnvironmentExpander.java index ad70dbec..06179683 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/util/EnvironmentExpander.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/util/EnvironmentExpander.java @@ -26,8 +26,6 @@ import org.apache.commons.lang3.StringUtils; -import com.google.common.collect.ImmutableList; - import io.wcm.devops.conga.generator.GeneratorException; import io.wcm.devops.conga.model.environment.Environment; import io.wcm.devops.conga.model.environment.Node; @@ -77,7 +75,7 @@ else if (hasNodes) { for (String nodeName : node.getNodes()) { Node clonedNode = ObjectCloner.deepClone(node); clonedNode.setNode(nodeName); - clonedNode.setNodes(ImmutableList.of()); + clonedNode.setNodes(List.of()); nodes.add(clonedNode); } } diff --git a/model/src/main/java/io/wcm/devops/conga/model/reader/AbstractModelReader.java b/model/src/main/java/io/wcm/devops/conga/model/reader/AbstractModelReader.java index 4ee1be33..a1785a9b 100644 --- a/model/src/main/java/io/wcm/devops/conga/model/reader/AbstractModelReader.java +++ b/model/src/main/java/io/wcm/devops/conga/model/reader/AbstractModelReader.java @@ -28,8 +28,6 @@ import org.yaml.snakeyaml.Yaml; -import com.google.common.collect.ImmutableSet; - import io.wcm.devops.conga.resource.Resource; /** @@ -38,7 +36,7 @@ public abstract class AbstractModelReader implements ModelReader { private static final String YAML_EXTENSION = "yaml"; - private static final Set SUPPORTED_EXTENSIONS = ImmutableSet.of(YAML_EXTENSION); + private static final Set SUPPORTED_EXTENSIONS = Set.of(YAML_EXTENSION); private final Yaml yaml; diff --git a/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/AbstractCongaMojo.java b/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/AbstractCongaMojo.java index faf38c3a..92e66a45 100644 --- a/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/AbstractCongaMojo.java +++ b/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/AbstractCongaMojo.java @@ -54,7 +54,6 @@ import org.codehaus.plexus.archiver.jar.ManifestException; import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import io.wcm.devops.conga.generator.export.ModelExport; @@ -172,7 +171,7 @@ abstract class AbstractCongaMojo extends AbstractMojo { @Component protected MavenProjectHelper projectHelper; - private static final Map DEFAULT_ARTIFACT_TYPE_MAPPINGS = ImmutableMap.of( + private static final Map DEFAULT_ARTIFACT_TYPE_MAPPINGS = Map.of( "bundle", "jar", "content-package", "zip"); diff --git a/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/ValidateMojo.java b/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/ValidateMojo.java index eeb6080e..d89262f5 100644 --- a/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/ValidateMojo.java +++ b/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/ValidateMojo.java @@ -204,12 +204,12 @@ private List validateFiles(ResourceCollection sourceDir, ResourceCollecti private List validateFiles(ResourceCollection sourceDir, ResourceCollection rootSourceDir, DefinitionValidator validator, Function resourceFilter) throws MojoFailureException { if (!sourceDir.exists()) { - return ImmutableList.of(); + return List.of(); } SortedSet files = sourceDir.getResources(); SortedSet dirs = sourceDir.getResourceCollections(); if (files.isEmpty() && dirs.isEmpty()) { - return ImmutableList.of(); + return List.of(); } List result = new ArrayList<>(); diff --git a/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/util/ClassLoaderUtil.java b/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/util/ClassLoaderUtil.java index 2498e331..a025b708 100644 --- a/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/util/ClassLoaderUtil.java +++ b/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/util/ClassLoaderUtil.java @@ -25,14 +25,13 @@ import java.net.URLClassLoader; import java.util.ArrayList; import java.util.List; +import java.util.Map; import org.apache.maven.artifact.DependencyResolutionRequiredException; import org.apache.maven.model.Resource; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.project.MavenProject; -import com.google.common.collect.ImmutableMap; - import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import io.wcm.devops.conga.generator.spi.context.PluginContextOptions; import io.wcm.devops.conga.generator.spi.context.ValueProviderGlobalContext; @@ -94,7 +93,7 @@ public static String resolveDependencyUrl(String dependencyUrl, PluginContextOpt VariableStringResolver variableStringResolver = new VariableStringResolver(valueProviderGlobalContext, variableMapResolver); // resolver variables without config map - thus supporting only value providers with external values - return variableStringResolver.resolveString(dependencyUrl, ImmutableMap.of()); + return variableStringResolver.resolveString(dependencyUrl, Map.of()); } } diff --git a/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/util/MavenArtifactHelper.java b/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/util/MavenArtifactHelper.java index 3924a1ef..650bb03a 100644 --- a/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/util/MavenArtifactHelper.java +++ b/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/util/MavenArtifactHelper.java @@ -45,8 +45,6 @@ import org.eclipse.aether.resolution.ArtifactResolutionException; import org.eclipse.aether.resolution.ArtifactResult; -import com.google.common.collect.ImmutableList; - import io.wcm.devops.conga.generator.spi.context.PluginContextOptions; import io.wcm.devops.conga.model.environment.Environment; import io.wcm.devops.conga.tooling.maven.plugin.urlfile.MavenUrlFilePlugin; @@ -75,7 +73,7 @@ public MavenArtifactHelper(Environment environment, PluginContextOptions pluginC this.repoSession = mavenContext.getRepoSession(); this.remoteRepos = mavenContext.getRemoteRepos(); this.artifactTypeMappings = mavenContext.getArtifactTypeMappings(); - this.environmentDependencyUrls = environment != null ? environment.getDependencies() : ImmutableList.of(); + this.environmentDependencyUrls = environment != null ? environment.getDependencies() : List.of(); this.pluginContextOptions = pluginContextOptions; } From c10b8e343c512517262ba708a14490185782eda3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 11 Jan 2024 05:57:00 +0000 Subject: [PATCH 15/26] Bump maven-plugin-plugin.version from 3.10.2 to 3.11.0 Bumps `maven-plugin-plugin.version` from 3.10.2 to 3.11.0. Updates `org.apache.maven.plugin-tools:maven-plugin-annotations` from 3.10.2 to 3.11.0 - [Release notes](https://github.com/apache/maven-plugin-tools/releases) - [Commits](https://github.com/apache/maven-plugin-tools/compare/maven-plugin-tools-3.10.2...maven-plugin-tools-3.11.0) Updates `org.apache.maven.plugins:maven-plugin-plugin` from 3.10.2 to 3.11.0 - [Release notes](https://github.com/apache/maven-plugin-tools/releases) - [Commits](https://github.com/apache/maven-plugin-tools/compare/maven-plugin-tools-3.10.2...maven-plugin-tools-3.11.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugin-tools:maven-plugin-annotations dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: org.apache.maven.plugins:maven-plugin-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- tooling/conga-maven-plugin/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tooling/conga-maven-plugin/pom.xml b/tooling/conga-maven-plugin/pom.xml index 01bb158b..1777ed3b 100644 --- a/tooling/conga-maven-plugin/pom.xml +++ b/tooling/conga-maven-plugin/pom.xml @@ -40,7 +40,7 @@ tooling/conga-maven-plugin - 3.10.2 + 3.11.0 invoker.mavenOpts From fbda3489dff62a064cf7fedba9c0e70c452642a6 Mon Sep 17 00:00:00 2001 From: Stefan Seifert Date: Thu, 18 Jan 2024 11:03:56 +0100 Subject: [PATCH 16/26] eliminate code warning --- .../devops/conga/resource/ClasspathResourceCollectionImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resource/src/main/java/io/wcm/devops/conga/resource/ClasspathResourceCollectionImpl.java b/resource/src/main/java/io/wcm/devops/conga/resource/ClasspathResourceCollectionImpl.java index 01953e0e..0c954301 100644 --- a/resource/src/main/java/io/wcm/devops/conga/resource/ClasspathResourceCollectionImpl.java +++ b/resource/src/main/java/io/wcm/devops/conga/resource/ClasspathResourceCollectionImpl.java @@ -32,7 +32,7 @@ import com.google.common.collect.ImmutableSortedSet; -class ClasspathResourceCollectionImpl extends AbstractClasspathResourceImpl implements ResourceCollection { +final class ClasspathResourceCollectionImpl extends AbstractClasspathResourceImpl implements ResourceCollection { private final List fileUrls = new ArrayList<>(); private final List folderPaths = new ArrayList<>(); From a61f1cea47898200436b17c74b2d7aa340cc5aa5 Mon Sep 17 00:00:00 2001 From: Stefan Seifert Date: Thu, 18 Jan 2024 18:48:38 +0100 Subject: [PATCH 17/26] update parent dependency, eliminate code warnings --- .../io/wcm/devops/conga/generator/EnvironmentGenerator.java | 2 +- .../devops/conga/generator/util/ModelExportConfigProcessor.java | 2 +- parent/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/EnvironmentGenerator.java b/generator/src/main/java/io/wcm/devops/conga/generator/EnvironmentGenerator.java index f4685568..3e5784b4 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/EnvironmentGenerator.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/EnvironmentGenerator.java @@ -82,7 +82,7 @@ /** * Generates file for one environment. */ -class EnvironmentGenerator { +final class EnvironmentGenerator { private final GeneratorOptions options; private final String environmentName; diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/util/ModelExportConfigProcessor.java b/generator/src/main/java/io/wcm/devops/conga/generator/util/ModelExportConfigProcessor.java index 22a8b00e..f3198e80 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/util/ModelExportConfigProcessor.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/util/ModelExportConfigProcessor.java @@ -36,7 +36,7 @@ * Processes map of CONGA configuration parameters before serializing them in a model export file. * Removes CONGA-defined context variables, and encrypts sensitive parameter values if required. */ -public class ModelExportConfigProcessor { +public final class ModelExportConfigProcessor { private final ValueEncryptionPlugin valueEncryptionPlugin; private final ValueEncryptionContext valueEncryptionContext; diff --git a/parent/pom.xml b/parent/pom.xml index b27d0b78..d0b7fb69 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -25,7 +25,7 @@ io.wcm.devops io.wcm.devops.parent_toplevel - 1.4.2 + 1.4.3-SNAPSHOT From 5d5a6f075516a657691eaa027fdf73f513ed5af5 Mon Sep 17 00:00:00 2001 From: Stefan Seifert Date: Mon, 22 Jan 2024 10:23:45 +0100 Subject: [PATCH 18/26] Eliminate Guava (#59) Eliminate Guava use Caffeine as replacement for LoaderCache --- changes.xml | 5 ++- generator/pom.xml | 10 ++++-- .../generator/ContextPropertiesBuilder.java | 31 +++++++++---------- .../conga/generator/EnvironmentGenerator.java | 11 +++---- .../devops/conga/generator/FileGenerator.java | 7 ++--- .../wcm/devops/conga/generator/Generator.java | 4 +-- .../conga/generator/ResourceLoaderUtil.java | 5 ++- .../handlebars/HandlebarsManager.java | 17 +++------- .../plugins/export/YamlNodeModelExport.java | 9 +++--- .../fileheader/AbstractFileHeader.java | 5 ++- .../plugins/fileheader/XmlFileHeader.java | 5 ++- .../helper/AbstractEachIfHelper.java | 4 +-- .../handlebars/helper/EachIfEqualsHelper.java | 4 +-- .../plugins/multiply/NoneMultiply.java | 4 +-- .../conga/generator/spi/UrlFilePlugin.java | 4 +-- .../generator/util/PluginManagerImpl.java | 30 ++++++------------ .../devops/conga/generator/util/RoleUtil.java | 8 ++--- .../generator/util/VariableMapResolver.java | 4 +-- .../generator/util/JexlResolverTest.java | 27 ++++++++-------- model/pom.xml | 10 ++---- parent/pom.xml | 14 ++++----- pom.xml | 4 +-- resource/pom.xml | 8 +---- .../AbstractClasspathResourceImpl.java | 2 +- .../AbstractFileResourceInfoImpl.java | 2 +- .../ClasspathResourceCollectionImpl.java | 11 +++---- .../resource/FileResourceCollectionImpl.java | 22 ++++++------- .../devops/conga/resource/ResourceInfo.java | 2 +- .../devops/conga/resource/ResourceLoader.java | 6 ++-- tooling/conga-cli/pom.xml | 4 +-- tooling/conga-maven-plugin/pom.xml | 4 +-- .../maven/plugin/AbstractCongaMojo.java | 5 ++- .../tooling/maven/plugin/PackageMojo.java | 4 +-- .../tooling/maven/plugin/ValidateMojo.java | 4 +-- 34 files changed, 123 insertions(+), 173 deletions(-) diff --git a/changes.xml b/changes.xml index 8701e033..c908812c 100644 --- a/changes.xml +++ b/changes.xml @@ -23,10 +23,13 @@ xsi:schemaLocation="http://maven.apache.org/changes/1.0.0 https://maven.apache.org/plugins/maven-changes-plugin/xsd/changes-1.0.0.xsd"> - + Special handling for detecting ".cfg.json" file extensions. + + Remove Guava dependency. + diff --git a/generator/pom.xml b/generator/pom.xml index bfc58eea..39211504 100644 --- a/generator/pom.xml +++ b/generator/pom.xml @@ -25,7 +25,7 @@ io.wcm.devops.conga io.wcm.devops.conga.parent - 1.16.5-SNAPSHOT + 1.17.0-SNAPSHOT ../parent/pom.xml @@ -44,7 +44,7 @@ io.wcm.devops.conga io.wcm.devops.conga.model - 1.16.5-SNAPSHOT + 1.17.0-SNAPSHOT compile @@ -54,6 +54,12 @@ compile + + com.github.ben-manes.caffeine + caffeine + compile + + com.github.jknack handlebars diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/ContextPropertiesBuilder.java b/generator/src/main/java/io/wcm/devops/conga/generator/ContextPropertiesBuilder.java index a0a55c25..df0bf929 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/ContextPropertiesBuilder.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/ContextPropertiesBuilder.java @@ -32,6 +32,7 @@ import static io.wcm.devops.conga.generator.ContextProperties.TENANTS_BY_ROLE; import static io.wcm.devops.conga.generator.ContextProperties.TENANT_ROLES; import static io.wcm.devops.conga.generator.ContextProperties.VERSION; +import static java.util.Map.entry; import java.util.ArrayList; import java.util.Collections; @@ -39,8 +40,6 @@ import java.util.List; import java.util.Map; -import com.google.common.collect.ImmutableMap; - import io.wcm.devops.conga.generator.util.ObjectCloner; import io.wcm.devops.conga.generator.util.VariableObjectTreeResolver; import io.wcm.devops.conga.generator.util.VariableStringResolver; @@ -55,20 +54,20 @@ */ public final class ContextPropertiesBuilder { - static final Map EMPTY_CONTEXT_VARIABLES = ImmutableMap.builder() - .put(VERSION, "") - .put(ENVIRONMENT, "") - .put(NODES, Collections.emptyList()) - .put(NODES_BY_ROLE, Collections.emptyMap()) - .put(NODES_BY_ROLE_VARIANT, Collections.emptyMap()) - .put(TENANTS, Collections.emptyMap()) - .put(TENANTS_BY_ROLE, Collections.emptyMap()) - .put(ROLE, "") - .put(ROLE_VARIANT, "") - .put(NODE, "") - .put(TENANT, "") - .put(TENANT_ROLES, Collections.emptyList()) - .build(); + static final Map EMPTY_CONTEXT_VARIABLES = Map.ofEntries( + entry(VERSION, ""), + entry(ENVIRONMENT, ""), + entry(NODES, Collections.emptyList()), + entry(NODES_BY_ROLE, Collections.emptyMap()), + entry(NODES_BY_ROLE_VARIANT, Collections.emptyMap()), + entry(TENANTS, Collections.emptyMap()), + entry(TENANTS_BY_ROLE, Collections.emptyMap()), + entry(ROLE, ""), + entry(ROLE_VARIANT, ""), + entry(NODE, ""), + entry(TENANT, ""), + entry(TENANT_ROLES, Collections.emptyList()) + ); private ContextPropertiesBuilder() { // static methods only diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/EnvironmentGenerator.java b/generator/src/main/java/io/wcm/devops/conga/generator/EnvironmentGenerator.java index 3e5784b4..46eb4c0b 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/EnvironmentGenerator.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/EnvironmentGenerator.java @@ -40,9 +40,6 @@ import com.github.jknack.handlebars.Handlebars; import com.github.jknack.handlebars.Template; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import io.wcm.devops.conga.generator.export.NodeModelExport; @@ -132,10 +129,10 @@ final class EnvironmentGenerator { ResourceLoader resourceLoader = new ResourceLoader(resourceClassLoader); // prepare template and role directories - List templateDirs = ImmutableList.of( + List templateDirs = List.of( resourceLoader.getResourceCollection(ResourceLoader.FILE_PREFIX + options.getTemplateDir()), resourceLoader.getResourceCollection(ResourceLoader.CLASSPATH_PREFIX + GeneratorOptions.CLASSPATH_TEMPLATES_DIR)); - List roleDirs = ImmutableList.of( + List roleDirs = List.of( resourceLoader.getResourceCollection(ResourceLoader.FILE_PREFIX + options.getRoleDir()), resourceLoader.getResourceCollection(ResourceLoader.CLASSPATH_PREFIX + GeneratorOptions.CLASSPATH_ROLES_DIR)); @@ -154,7 +151,7 @@ final class EnvironmentGenerator { this.handlebarsManager = new HandlebarsManager(templateDirs, this.pluginContextOptions); this.defaultMultiplyPlugin = options.getPluginManager().get(NoneMultiply.NAME, MultiplyPlugin.class); - this.environmentContextProperties = ImmutableMap.copyOf( + this.environmentContextProperties = Collections.unmodifiableMap( ContextPropertiesBuilder.buildEnvironmentContextVariables(environmentName, this.environment, options.getVersion(), variableObjectTreeResolver, variableStringResolver)); @@ -178,7 +175,7 @@ public void generate(String[] nodeNames) { log.info(""); log.info("===== Environment '{}' =====", environmentName); - Set nodeNamesIndex = ArrayUtils.isEmpty(nodeNames) ? Collections.emptySet() : ImmutableSet.copyOf(nodeNames); + Set nodeNamesIndex = ArrayUtils.isEmpty(nodeNames) ? Collections.emptySet() : Set.of(nodeNames); for (Node node : environment.getNodes()) { if (isSelectedNode(node, nodeNamesIndex)) { generateNode(node); diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/FileGenerator.java b/generator/src/main/java/io/wcm/devops/conga/generator/FileGenerator.java index e77cfe85..89473afd 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/FileGenerator.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/FileGenerator.java @@ -42,7 +42,6 @@ import org.slf4j.Logger; import com.github.jknack.handlebars.Template; -import com.google.common.collect.ImmutableList; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import io.wcm.devops.conga.generator.plugins.fileheader.NoneFileHeader; @@ -423,7 +422,7 @@ private Collection applyPostProcessor(FileContext fileItem private void applyPostProcessor(Map consolidatedFiles, PostProcessorPlugin plugin) { // process all files from given map - ImmutableList.copyOf(consolidatedFiles.values()).stream() + List.copyOf(consolidatedFiles.values()).stream() // do not apply post processor twice .filter(fileItem -> !fileItem.getPostProcessors().contains(plugin.getName())) .filter(fileItem -> plugin.accepts(fileItem.getFileContext(), postProcessorContext)) @@ -441,7 +440,7 @@ private void applyPostProcessor(Map consolidatedFi }); // remove items that do no longer exist - ImmutableList.copyOf(consolidatedFiles.values()).forEach(fileItem -> { + List.copyOf(consolidatedFiles.values()).forEach(fileItem -> { if (!fileItem.getFileContext().getFile().exists()) { consolidatedFiles.remove(fileItem.getFileContext().getCanonicalPath()); } @@ -469,7 +468,7 @@ private void applyPostProcessor(Map consolidatedFi }); // remove items that do no longer exist - ImmutableList.copyOf(consolidatedFiles.values()).forEach(fileItem -> { + List.copyOf(consolidatedFiles.values()).forEach(fileItem -> { if (!fileItem.getFileContext().getFile().exists()) { consolidatedFiles.remove(fileItem.getFileContext().getCanonicalPath()); } diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/Generator.java b/generator/src/main/java/io/wcm/devops/conga/generator/Generator.java index 138dfa94..59d5d420 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/Generator.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/Generator.java @@ -27,8 +27,6 @@ import org.apache.commons.io.FileUtils; -import com.google.common.collect.ImmutableList; - import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import io.wcm.devops.conga.generator.util.FileUtil; import io.wcm.devops.conga.model.environment.Environment; @@ -54,7 +52,7 @@ public Generator(GeneratorOptions options) { ClassLoader resourceClassLoader = ResourceLoaderUtil.buildClassLoader(options.getContainerClasspathUrls()); ResourceLoader resourceLoader = new ResourceLoader(resourceClassLoader); - List environmentDirs = ImmutableList.of( + List environmentDirs = List.of( resourceLoader.getResourceCollection(ResourceLoader.FILE_PREFIX + options.getEnvironmentDir()), resourceLoader.getResourceCollection(ResourceLoader.CLASSPATH_PREFIX + GeneratorOptions.CLASSPATH_ENVIRONMENTS_DIR)); this.environments = ResourceLoaderUtil.readModels(environmentDirs, new EnvironmentReader()); diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/ResourceLoaderUtil.java b/generator/src/main/java/io/wcm/devops/conga/generator/ResourceLoaderUtil.java index 635a12e7..abe01365 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/ResourceLoaderUtil.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/ResourceLoaderUtil.java @@ -23,14 +23,13 @@ import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.commons.io.FilenameUtils; -import com.google.common.collect.ImmutableMap; - import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import io.wcm.devops.conga.generator.spi.context.PluginContextOptions; import io.wcm.devops.conga.generator.spi.context.UrlFilePluginContext; @@ -114,7 +113,7 @@ public static Map readModels(List dirs, Model } } } - return ImmutableMap.copyOf(models); + return Collections.unmodifiableMap(models); } } diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/handlebars/HandlebarsManager.java b/generator/src/main/java/io/wcm/devops/conga/generator/handlebars/HandlebarsManager.java index 96b5855d..cecdc308 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/handlebars/HandlebarsManager.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/handlebars/HandlebarsManager.java @@ -21,8 +21,10 @@ import java.io.IOException; import java.util.List; -import java.util.concurrent.ExecutionException; +import com.github.benmanes.caffeine.cache.CacheLoader; +import com.github.benmanes.caffeine.cache.Caffeine; +import com.github.benmanes.caffeine.cache.LoadingCache; import com.github.jknack.handlebars.EscapingStrategy; import com.github.jknack.handlebars.Handlebars; import com.github.jknack.handlebars.Helper; @@ -31,11 +33,7 @@ import com.github.jknack.handlebars.helper.ConditionalHelpers; import com.github.jknack.handlebars.helper.StringHelpers; import com.github.jknack.handlebars.io.TemplateLoader; -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.CacheLoader; -import com.google.common.cache.LoadingCache; -import io.wcm.devops.conga.generator.GeneratorException; import io.wcm.devops.conga.generator.spi.context.PluginContextOptions; import io.wcm.devops.conga.generator.spi.handlebars.EscapingStrategyPlugin; import io.wcm.devops.conga.generator.spi.handlebars.HelperPlugin; @@ -55,7 +53,7 @@ public class HandlebarsManager { private final HelperContext helperContext; private final LoadingCache handlebarsCache = - CacheBuilder.newBuilder().build(new CacheLoader() { + Caffeine.newBuilder().build(new CacheLoader() { @SuppressWarnings("unchecked") @Override public Handlebars load(HandlebarsKey options) throws Exception { @@ -108,12 +106,7 @@ public HandlebarsManager(List templateDirs, PluginContextOpt */ public Handlebars get(String escapingStrategy, String charset) { HandlebarsKey key = new HandlebarsKey(escapingStrategy, charset); - try { - return handlebarsCache.get(key); - } - catch (ExecutionException ex) { - throw new GeneratorException("Unable to get handlebars instance for " + key.toString(), ex); - } + return handlebarsCache.get(key); } } diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/plugins/export/YamlNodeModelExport.java b/generator/src/main/java/io/wcm/devops/conga/generator/plugins/export/YamlNodeModelExport.java index 28432392..edd3ab21 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/plugins/export/YamlNodeModelExport.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/plugins/export/YamlNodeModelExport.java @@ -24,17 +24,16 @@ import java.io.OutputStreamWriter; import java.nio.charset.StandardCharsets; import java.util.ArrayList; +import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.TreeMap; import java.util.stream.Collectors; import org.apache.commons.lang3.StringUtils; import org.yaml.snakeyaml.Yaml; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSortedMap; - import io.wcm.devops.conga.generator.GeneratorException; import io.wcm.devops.conga.generator.spi.export.NodeModelExportPlugin; import io.wcm.devops.conga.generator.spi.export.context.ExportNodeRoleData; @@ -74,7 +73,7 @@ public void export(NodeModelExportContext context) { Map versionInfo = context.getContainerVersionInfo(); if (versionInfo != null) { - modelMap.put("versionInfo", ImmutableSortedMap.copyOf(versionInfo)); + modelMap.put("versionInfo", Collections.unmodifiableSortedMap(new TreeMap<>(versionInfo))); } // save YAML file @@ -101,7 +100,7 @@ private void addRole(List> modelList, ExportNodeRoleData rol Map itemMap = new LinkedHashMap<>(); itemMap.put("path", cleanupFileName(item.getFileContext().getCanonicalPath(), nodeDirPath)); if (!item.getPostProcessors().isEmpty()) { - itemMap.put("postProcessors", ImmutableList.copyOf(item.getPostProcessors())); + itemMap.put("postProcessors", List.copyOf(item.getPostProcessors())); } Map modelOptions = item.getFileContext().getModelOptions(); if (modelOptions != null) { diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/plugins/fileheader/AbstractFileHeader.java b/generator/src/main/java/io/wcm/devops/conga/generator/plugins/fileheader/AbstractFileHeader.java index 95a01b08..81bcaf8c 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/plugins/fileheader/AbstractFileHeader.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/plugins/fileheader/AbstractFileHeader.java @@ -21,6 +21,7 @@ import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; @@ -28,8 +29,6 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; -import com.google.common.collect.ImmutableList; - import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import io.wcm.devops.conga.generator.GeneratorException; import io.wcm.devops.conga.generator.spi.FileHeaderPlugin; @@ -120,7 +119,7 @@ protected final FileHeaderContext extractFileHeaderBetweenBlockStartEnd(FileCont int posBlockEnd = content.indexOf(getCommentBlockEnd()); if (posBlockStart == insertPosition && posBlockEnd > 0) { String fileHeader = content.substring(posBlockStart + getCommentBlockStart().length(), posBlockEnd); - List lines = ImmutableList.copyOf(StringUtils.split(fileHeader, getLineBreak())); + List lines = Arrays.asList(StringUtils.split(fileHeader, getLineBreak())); return new FileHeaderContext().commentLines(lines); } } diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/plugins/fileheader/XmlFileHeader.java b/generator/src/main/java/io/wcm/devops/conga/generator/plugins/fileheader/XmlFileHeader.java index 3d0c9731..aa8a5ec2 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/plugins/fileheader/XmlFileHeader.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/plugins/fileheader/XmlFileHeader.java @@ -21,6 +21,7 @@ import java.io.IOException; import java.nio.file.Files; +import java.util.Arrays; import java.util.List; import javax.xml.XMLConstants; @@ -40,8 +41,6 @@ import org.w3c.dom.Node; import org.xml.sax.SAXException; -import com.google.common.collect.ImmutableList; - import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import io.wcm.devops.conga.generator.GeneratorException; import io.wcm.devops.conga.generator.spi.FileHeaderPlugin; @@ -121,7 +120,7 @@ public FileHeaderContext extract(FileContext file) { Node firstNode = doc.getChildNodes().item(0); if (firstNode instanceof Comment) { String comment = StringUtils.trim(((Comment)firstNode).getTextContent()); - List lines = ImmutableList.copyOf(StringUtils.split(comment, "\n")); + List lines = Arrays.asList(StringUtils.split(comment, "\n")); return new FileHeaderContext().commentLines(lines); } } diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/plugins/handlebars/helper/AbstractEachIfHelper.java b/generator/src/main/java/io/wcm/devops/conga/generator/plugins/handlebars/helper/AbstractEachIfHelper.java index e8fc8531..d7d23528 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/plugins/handlebars/helper/AbstractEachIfHelper.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/plugins/handlebars/helper/AbstractEachIfHelper.java @@ -21,6 +21,7 @@ import java.io.IOException; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Objects; @@ -34,7 +35,6 @@ import com.github.jknack.handlebars.Helper; import com.github.jknack.handlebars.Options; import com.github.jknack.handlebars.helper.EachHelper; -import com.google.common.collect.ImmutableList; import io.wcm.devops.conga.generator.spi.handlebars.HelperPlugin; import io.wcm.devops.conga.generator.spi.handlebars.context.HelperContext; @@ -67,7 +67,7 @@ public final Object apply(Object context, Options options, HelperContext pluginC } } else { - return apply(ImmutableList.of(context), options, pluginContext); + return apply(List.of(context), options, pluginContext); } } return delegate.apply(context, options); diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/plugins/handlebars/helper/EachIfEqualsHelper.java b/generator/src/main/java/io/wcm/devops/conga/generator/plugins/handlebars/helper/EachIfEqualsHelper.java index 276b06f1..920b5ea2 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/plugins/handlebars/helper/EachIfEqualsHelper.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/plugins/handlebars/helper/EachIfEqualsHelper.java @@ -19,7 +19,7 @@ */ package io.wcm.devops.conga.generator.plugins.handlebars.helper; -import com.google.common.base.Objects; +import java.util.Objects; /** * Handlebars helper that extends the each helper by iterating only on list items that have a specified property set to @@ -41,7 +41,7 @@ public EachIfEqualsHelper() { if (expectedValue == null) { return false; } - return Objects.equal(value, expectedValue); + return Objects.equals(value, expectedValue); }); } diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/plugins/multiply/NoneMultiply.java b/generator/src/main/java/io/wcm/devops/conga/generator/plugins/multiply/NoneMultiply.java index ab89e002..485bfc71 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/plugins/multiply/NoneMultiply.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/plugins/multiply/NoneMultiply.java @@ -22,8 +22,6 @@ import java.util.List; import java.util.Map; -import com.google.common.collect.ImmutableList; - import io.wcm.devops.conga.generator.spi.MultiplyPlugin; import io.wcm.devops.conga.generator.spi.context.MultiplyContext; @@ -44,7 +42,7 @@ public String getName() { @Override public List> multiply(MultiplyContext context) { - return ImmutableList.of(context.getConfig()); + return List.of(context.getConfig()); } } diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/spi/UrlFilePlugin.java b/generator/src/main/java/io/wcm/devops/conga/generator/spi/UrlFilePlugin.java index 5f8f0ed3..d2f480d4 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/spi/UrlFilePlugin.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/spi/UrlFilePlugin.java @@ -25,8 +25,6 @@ import java.net.URL; import java.util.List; -import com.google.common.collect.ImmutableList; - import io.wcm.devops.conga.generator.spi.context.UrlFilePluginContext; /** @@ -80,7 +78,7 @@ default URL getFileUrl(String url, UrlFilePluginContext context) throws IOExcept * @throws IOException If the access to the file failed */ default List getFileUrlsWithDependencies(String url, UrlFilePluginContext context) throws IOException { - return ImmutableList.of(getFileUrl(url, context)); + return List.of(getFileUrl(url, context)); } /** diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/util/PluginManagerImpl.java b/generator/src/main/java/io/wcm/devops/conga/generator/util/PluginManagerImpl.java index ef987fac..8bbcefcc 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/util/PluginManagerImpl.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/util/PluginManagerImpl.java @@ -23,12 +23,10 @@ import java.util.ServiceLoader; import java.util.SortedMap; import java.util.TreeMap; -import java.util.concurrent.ExecutionException; -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.CacheLoader; -import com.google.common.cache.LoadingCache; -import com.google.common.collect.ImmutableList; +import com.github.benmanes.caffeine.cache.CacheLoader; +import com.github.benmanes.caffeine.cache.Caffeine; +import com.github.benmanes.caffeine.cache.LoadingCache; import io.wcm.devops.conga.generator.GeneratorException; import io.wcm.devops.conga.generator.spi.Plugin; @@ -39,7 +37,7 @@ public final class PluginManagerImpl implements PluginManager { private final LoadingCache, SortedMap> pluginCache = - CacheBuilder.newBuilder().build(new CacheLoader, SortedMap>() { + Caffeine.newBuilder().build(new CacheLoader, SortedMap>() { @Override public SortedMap load(Class pluginClass) throws Exception { ServiceLoader loadedPlugins = ServiceLoader.load(pluginClass); @@ -66,16 +64,11 @@ public SortedMap load(Class pluginClass) throws Exceptio @Override @SuppressWarnings("unchecked") public T get(String name, Class pluginClass) throws GeneratorException { - try { - Plugin plugin = pluginCache.get((Class)pluginClass).get(name); - if (plugin == null) { - throw new GeneratorException(pluginClass.getSimpleName() + " not found: '" + name + "'"); - } - return (T)plugin; - } - catch (ExecutionException ex) { - throw new GeneratorException("Untable to build plugin cache for " + pluginClass.getName(), ex); + Plugin plugin = pluginCache.get((Class)pluginClass).get(name); + if (plugin == null) { + throw new GeneratorException(pluginClass.getSimpleName() + " not found: '" + name + "'"); } + return (T)plugin; } /** @@ -88,12 +81,7 @@ public T get(String name, Class pluginClass) throws Genera @Override @SuppressWarnings("unchecked") public List getAll(Class pluginClass) throws GeneratorException { - try { - return (List)ImmutableList.copyOf(pluginCache.get((Class)pluginClass).values()); - } - catch (ExecutionException ex) { - throw new GeneratorException("Untable to build plugin cache for " + pluginClass.getName(), ex); - } + return (List)List.copyOf(pluginCache.get((Class)pluginClass).values()); } } diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/util/RoleUtil.java b/generator/src/main/java/io/wcm/devops/conga/generator/util/RoleUtil.java index ea3418c2..e103fd10 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/util/RoleUtil.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/util/RoleUtil.java @@ -28,8 +28,6 @@ import org.apache.commons.lang3.StringUtils; -import com.google.common.collect.ImmutableList; - import io.wcm.devops.conga.generator.GeneratorException; import io.wcm.devops.conga.model.role.Role; import io.wcm.devops.conga.model.role.RoleFile; @@ -159,8 +157,8 @@ private static void mergeRoleConfig(Role role, Role superRole) { Set sensitiveConfigParameters = new HashSet<>(); sensitiveConfigParameters.addAll(role.getSensitiveConfigParameters()); sensitiveConfigParameters.addAll(superRole.getSensitiveConfigParameters()); - role.setSensitiveConfigParameters(ImmutableList.copyOf(sensitiveConfigParameters)); - superRole.setSensitiveConfigParameters(ImmutableList.copyOf(sensitiveConfigParameters)); + role.setSensitiveConfigParameters(List.copyOf(sensitiveConfigParameters)); + superRole.setSensitiveConfigParameters(List.copyOf(sensitiveConfigParameters)); } /** @@ -170,7 +168,7 @@ private static void mergeRoleConfig(Role role, Role superRole) { * @param resolvedRoles Resolved roles */ private static void removeFileDuplicates(Map resolvedRoles) { - List roles = ImmutableList.copyOf(resolvedRoles.values()); + List roles = List.copyOf(resolvedRoles.values()); // super roles are first, sub roles last. // got from last to first, collect all generated file definitions and remove duplicates diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/util/VariableMapResolver.java b/generator/src/main/java/io/wcm/devops/conga/generator/util/VariableMapResolver.java index 67c362af..a73b8fdb 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/util/VariableMapResolver.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/util/VariableMapResolver.java @@ -28,8 +28,6 @@ import java.util.Map; import java.util.regex.Matcher; -import com.google.common.collect.ImmutableList; - import io.wcm.devops.conga.generator.spi.context.ValueProviderGlobalContext; /** @@ -206,7 +204,7 @@ private List replaceIterate(Map map, Map } if (!(listObject instanceof List)) { // allow to iterate over single values as well - listObject = ImmutableList.of(listObject); + listObject = List.of(listObject); } Map variablesClone = new LinkedHashMap<>(ObjectCloner.deepClone(variables)); List result = new ArrayList<>(); diff --git a/generator/src/test/java/io/wcm/devops/conga/generator/util/JexlResolverTest.java b/generator/src/test/java/io/wcm/devops/conga/generator/util/JexlResolverTest.java index e0c5aaa1..04df3496 100644 --- a/generator/src/test/java/io/wcm/devops/conga/generator/util/JexlResolverTest.java +++ b/generator/src/test/java/io/wcm/devops/conga/generator/util/JexlResolverTest.java @@ -19,6 +19,7 @@ */ package io.wcm.devops.conga.generator.util; +import static java.util.Map.entry; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -27,8 +28,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import com.google.common.collect.ImmutableMap; - import io.wcm.devops.conga.generator.GeneratorException; import io.wcm.devops.conga.generator.spi.context.PluginContextOptions; import io.wcm.devops.conga.generator.spi.context.ValueProviderGlobalContext; @@ -53,22 +52,22 @@ void setUp() { object1 = Map.of("var3", "value3", "object2", object2, "nested1var1", "${nested1.nested1var1}", "nested2var1", "${nested1.nested2.nested2var1}"); - variables = ImmutableMap.builder() - .put("var1", "value1") - .put("var2", 123) - .put("object1", object1) - .put("refVar1", "${var1}") - .put("refVar2", "${var2}") - .put("refCombined", "${object1.var3}|${var1}") - .put("jexlExpr", "${object1.var3 + ';' + var1}") - .put("nested1", Map.of( + variables = Map.ofEntries( + entry("var1", "value1"), + entry("var2", 123), + entry("object1", object1), + entry("refVar1", "${var1}"), + entry("refVar2", "${var2}"), + entry("refCombined", "${object1.var3}|${var1}"), + entry("jexlExpr", "${object1.var3 + ';' + var1}"), + entry("nested1", Map.of( "nested1var1", "nested1-value1", "nested1JexlExpr", "${object1.var3 + ';' + var1}", "nested2", Map.of( "nested2var1", "nested2-value1", - "nested2JexlExpr", "${object1.var3 + ';' + var1}"))) - .put("array1", new String[] { "v1", "v2", "v3" }) - .build(); + "nested2JexlExpr", "${object1.var3 + ';' + var1}"))), + entry("array1", new String[] { "v1", "v2", "v3" }) + ); } @Test diff --git a/model/pom.xml b/model/pom.xml index 4a6b450a..2e548cf8 100644 --- a/model/pom.xml +++ b/model/pom.xml @@ -25,7 +25,7 @@ io.wcm.devops.conga io.wcm.devops.conga.parent - 1.16.5-SNAPSHOT + 1.17.0-SNAPSHOT ../parent/pom.xml @@ -40,7 +40,7 @@ io.wcm.devops.conga io.wcm.devops.conga.resource - 1.16.5-SNAPSHOT + 1.17.0-SNAPSHOT compile @@ -68,12 +68,6 @@ compile - - com.google.guava - guava - compile - - diff --git a/parent/pom.xml b/parent/pom.xml index d0b7fb69..52cb481f 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -31,7 +31,7 @@ io.wcm.devops.conga io.wcm.devops.conga.parent - 1.16.5-SNAPSHOT + 1.17.0-SNAPSHOT pom CONGA @@ -72,12 +72,6 @@ 1.11.0 - - com.google.guava - guava - 33.0.0-jre - - commons-beanutils commons-beanutils @@ -96,6 +90,12 @@ 1.6.0 + + com.github.ben-manes.caffeine + caffeine + 3.1.8 + + com.github.jknack handlebars diff --git a/pom.xml b/pom.xml index 3c783a54..cb61fba3 100644 --- a/pom.xml +++ b/pom.xml @@ -25,13 +25,13 @@ io.wcm.devops.conga io.wcm.devops.conga.parent - 1.16.5-SNAPSHOT + 1.17.0-SNAPSHOT parent/pom.xml io.wcm.devops.conga io.wcm.devops.conga.root - 1.16.5-SNAPSHOT + 1.17.0-SNAPSHOT pom CONGA diff --git a/resource/pom.xml b/resource/pom.xml index d9310acb..897edd08 100644 --- a/resource/pom.xml +++ b/resource/pom.xml @@ -25,7 +25,7 @@ io.wcm.devops.conga io.wcm.devops.conga.parent - 1.16.5-SNAPSHOT + 1.17.0-SNAPSHOT ../parent/pom.xml @@ -49,12 +49,6 @@ compile - - com.google.guava - guava - compile - - org.springframework spring-core diff --git a/resource/src/main/java/io/wcm/devops/conga/resource/AbstractClasspathResourceImpl.java b/resource/src/main/java/io/wcm/devops/conga/resource/AbstractClasspathResourceImpl.java index 9a090788..4038fbb8 100644 --- a/resource/src/main/java/io/wcm/devops/conga/resource/AbstractClasspathResourceImpl.java +++ b/resource/src/main/java/io/wcm/devops/conga/resource/AbstractClasspathResourceImpl.java @@ -52,7 +52,7 @@ protected static String convertPath(String path) { } @Override - public int compareTo(Resource o) { + public int compareTo(ResourceInfo o) { return getName().compareTo(o.getName()); } diff --git a/resource/src/main/java/io/wcm/devops/conga/resource/AbstractFileResourceInfoImpl.java b/resource/src/main/java/io/wcm/devops/conga/resource/AbstractFileResourceInfoImpl.java index 06b3ba88..566236c4 100644 --- a/resource/src/main/java/io/wcm/devops/conga/resource/AbstractFileResourceInfoImpl.java +++ b/resource/src/main/java/io/wcm/devops/conga/resource/AbstractFileResourceInfoImpl.java @@ -63,7 +63,7 @@ public final String getCanonicalPath() { } @Override - public int compareTo(Resource o) { + public int compareTo(ResourceInfo o) { return getName().compareTo(o.getName()); } diff --git a/resource/src/main/java/io/wcm/devops/conga/resource/ClasspathResourceCollectionImpl.java b/resource/src/main/java/io/wcm/devops/conga/resource/ClasspathResourceCollectionImpl.java index 0c954301..a46abd6f 100644 --- a/resource/src/main/java/io/wcm/devops/conga/resource/ClasspathResourceCollectionImpl.java +++ b/resource/src/main/java/io/wcm/devops/conga/resource/ClasspathResourceCollectionImpl.java @@ -25,13 +25,12 @@ import java.util.ArrayList; import java.util.List; import java.util.SortedSet; +import java.util.TreeSet; import java.util.stream.Collectors; import org.apache.commons.lang3.StringUtils; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; -import com.google.common.collect.ImmutableSortedSet; - final class ClasspathResourceCollectionImpl extends AbstractClasspathResourceImpl implements ResourceCollection { private final List fileUrls = new ArrayList<>(); @@ -83,16 +82,16 @@ public ResourceCollection getResourceCollection(String childPath) { @Override public SortedSet getResources() { - return ImmutableSortedSet.copyOf(fileUrls.stream() + return fileUrls.stream() .map(url -> new ClasspathResourceImpl(url, resourceLoader)) - .collect(Collectors.toList())); + .collect(Collectors.toCollection(TreeSet::new)); } @Override public SortedSet getResourceCollections() { - return ImmutableSortedSet.copyOf(folderPaths.stream() + return folderPaths.stream() .map(folderPath -> new ClasspathResourceCollectionImpl(folderPath, resourceLoader)) - .collect(Collectors.toList())); + .collect(Collectors.toCollection(TreeSet::new)); } } diff --git a/resource/src/main/java/io/wcm/devops/conga/resource/FileResourceCollectionImpl.java b/resource/src/main/java/io/wcm/devops/conga/resource/FileResourceCollectionImpl.java index d9fc6852..9a5a10ff 100644 --- a/resource/src/main/java/io/wcm/devops/conga/resource/FileResourceCollectionImpl.java +++ b/resource/src/main/java/io/wcm/devops/conga/resource/FileResourceCollectionImpl.java @@ -21,11 +21,11 @@ import java.io.File; import java.util.Arrays; +import java.util.Collections; import java.util.SortedSet; +import java.util.TreeSet; import java.util.stream.Collectors; -import com.google.common.collect.ImmutableSortedSet; - class FileResourceCollectionImpl extends FileResourceImpl implements ResourceCollection { private final ResourceLoader resourceLoader; @@ -60,23 +60,23 @@ public ResourceCollection getResourceCollection(String path) { @Override public SortedSet getResources() { if (!exists()) { - return ImmutableSortedSet.of(); + return Collections.emptySortedSet(); } - return ImmutableSortedSet.copyOf(Arrays.stream(file.listFiles()) - .filter(child -> child.isFile()) - .map(child -> new FileResourceImpl(child)) - .collect(Collectors.toList())); + return Arrays.stream(file.listFiles()) + .filter(File::isFile) + .map(FileResourceImpl::new) + .collect(Collectors.toCollection(TreeSet::new)); } @Override public SortedSet getResourceCollections() { if (!exists()) { - return ImmutableSortedSet.of(); + return Collections.emptySortedSet(); } - return ImmutableSortedSet.copyOf(Arrays.stream(file.listFiles()) - .filter(child -> child.isDirectory()) + return Arrays.stream(file.listFiles()) + .filter(File::isDirectory) .map(child -> new FileResourceCollectionImpl(child, resourceLoader)) - .collect(Collectors.toList())); + .collect(Collectors.toCollection(TreeSet::new)); } } diff --git a/resource/src/main/java/io/wcm/devops/conga/resource/ResourceInfo.java b/resource/src/main/java/io/wcm/devops/conga/resource/ResourceInfo.java index a158f6d0..172df0af 100644 --- a/resource/src/main/java/io/wcm/devops/conga/resource/ResourceInfo.java +++ b/resource/src/main/java/io/wcm/devops/conga/resource/ResourceInfo.java @@ -22,7 +22,7 @@ /** * Abstraction for resource information. */ -public interface ResourceInfo extends Comparable { +public interface ResourceInfo extends Comparable { /** * @return true if resource exists diff --git a/resource/src/main/java/io/wcm/devops/conga/resource/ResourceLoader.java b/resource/src/main/java/io/wcm/devops/conga/resource/ResourceLoader.java index 77970bcb..88f7bbf9 100644 --- a/resource/src/main/java/io/wcm/devops/conga/resource/ResourceLoader.java +++ b/resource/src/main/java/io/wcm/devops/conga/resource/ResourceLoader.java @@ -23,8 +23,6 @@ import org.apache.commons.lang3.StringUtils; -import com.google.common.collect.ImmutableList; - /** * Resource loader to read resource and resource collections from filesystem or classpath. */ @@ -125,12 +123,12 @@ private List getSupportedResourceTypes(String path) { // check for explicit path specification for (ResourceType resourceType : ResourceType.values()) { if (StringUtils.startsWith(path, resourceType.getPrefix())) { - return ImmutableList.of(resourceType); + return List.of(resourceType); } } // otherwise check all resource types in order of definition in enum - return ImmutableList.copyOf(ResourceType.values()); + return List.of(ResourceType.values()); } ClassLoader getClassLoader() { diff --git a/tooling/conga-cli/pom.xml b/tooling/conga-cli/pom.xml index dcecf4c3..72095007 100644 --- a/tooling/conga-cli/pom.xml +++ b/tooling/conga-cli/pom.xml @@ -25,7 +25,7 @@ io.wcm.devops.conga io.wcm.devops.conga.parent - 1.16.5-SNAPSHOT + 1.17.0-SNAPSHOT ../../parent/pom.xml @@ -40,7 +40,7 @@ io.wcm.devops.conga io.wcm.devops.conga.generator - 1.16.5-SNAPSHOT + 1.17.0-SNAPSHOT compile diff --git a/tooling/conga-maven-plugin/pom.xml b/tooling/conga-maven-plugin/pom.xml index 1777ed3b..bc3e75c6 100644 --- a/tooling/conga-maven-plugin/pom.xml +++ b/tooling/conga-maven-plugin/pom.xml @@ -25,7 +25,7 @@ io.wcm.devops.conga io.wcm.devops.conga.parent - 1.16.5-SNAPSHOT + 1.17.0-SNAPSHOT ../../parent/pom.xml @@ -56,7 +56,7 @@ io.wcm.devops.conga io.wcm.devops.conga.generator - 1.16.5-SNAPSHOT + 1.17.0-SNAPSHOT compile diff --git a/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/AbstractCongaMojo.java b/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/AbstractCongaMojo.java index 92e66a45..d8662854 100644 --- a/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/AbstractCongaMojo.java +++ b/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/AbstractCongaMojo.java @@ -30,6 +30,7 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.SortedSet; @@ -53,8 +54,6 @@ import org.codehaus.plexus.archiver.jar.JarArchiver; import org.codehaus.plexus.archiver.jar.ManifestException; -import com.google.common.collect.ImmutableList; - import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import io.wcm.devops.conga.generator.export.ModelExport; import io.wcm.devops.conga.resource.Resource; @@ -200,7 +199,7 @@ protected ModelExport getModelExport() { String[] nodeExportPlugins = StringUtils.split(this.modelExportNode, ","); if (nodeExportPlugins != null) { - modelExport.setNode(ImmutableList.copyOf(nodeExportPlugins)); + modelExport.setNode(Arrays.asList(nodeExportPlugins)); } return modelExport; diff --git a/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/PackageMojo.java b/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/PackageMojo.java index 767ba926..c8b4e26d 100644 --- a/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/PackageMojo.java +++ b/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/PackageMojo.java @@ -43,8 +43,6 @@ import org.codehaus.plexus.archiver.ArchiverException; import org.codehaus.plexus.archiver.zip.ZipArchiver; -import com.google.common.collect.ImmutableSet; - import io.wcm.devops.conga.generator.util.FileUtil; /** @@ -83,7 +81,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { private void buildGeneratedConfigurationAttachments() throws MojoExecutionException, MojoFailureException { Set selectedEnvironments; if (environments != null && environments.length > 0) { - selectedEnvironments = ImmutableSet.copyOf(environments); + selectedEnvironments = Set.copyOf(Arrays.asList(environments)); } else { selectedEnvironments = null; diff --git a/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/ValidateMojo.java b/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/ValidateMojo.java index d89262f5..6b99aaa3 100644 --- a/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/ValidateMojo.java +++ b/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/ValidateMojo.java @@ -49,8 +49,6 @@ import org.sonatype.plexus.build.incremental.BuildContext; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; -import com.google.common.collect.ImmutableList; - import io.wcm.devops.conga.generator.GeneratorException; import io.wcm.devops.conga.generator.GeneratorOptions; import io.wcm.devops.conga.generator.UrlFileManager; @@ -153,7 +151,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { .logger(new MavenSlf4jLogFacade(getLog())); // validate that all templates can be compiled - HandlebarsManager handlebarsManager = new HandlebarsManager(ImmutableList.of(templateDir), pluginContextOptions); + HandlebarsManager handlebarsManager = new HandlebarsManager(List.of(templateDir), pluginContextOptions); validateFiles(templateDir, templateDir, new TemplateValidator(templateDir, handlebarsManager)); // validate that roles reference existing templates From b36286a11d4119666aefc0d0fe0cbb9531203016 Mon Sep 17 00:00:00 2001 From: Stefan Seifert Date: Mon, 22 Jan 2024 11:27:21 +0100 Subject: [PATCH 19/26] Eliminate SonarQube warnings (#60) --- .../conga/generator/EnvironmentGenerator.java | 8 ++++++- .../devops/conga/generator/FileGenerator.java | 10 ++++----- .../CharsetAwareTemplateSource.java | 1 + .../handlebars/HandlebarsManager.java | 9 ++------ .../fileheader/AbstractFileHeader.java | 5 +++-- .../helper/AbstractEachIfHelper.java | 10 ++++----- .../urlfile/FilesystemUrlFilePlugin.java | 3 ++- .../util/ConfigInheritanceResolver.java | 11 ++++------ .../devops/conga/generator/util/FileUtil.java | 2 +- .../conga/model/shared/LineEndings.java | 1 + .../devops/conga/model/util/DefaultUtil.java | 6 ++--- .../devops/conga/model/util/MapExpander.java | 14 +++++++----- .../devops/conga/model/util/MapMerger.java | 4 ++-- .../devops/conga/model/util/MapSplitter.java | 17 +++++++------- .../devops/conga/model/util/MergingList.java | 2 +- .../model/reader/EnvironmentReaderTest.java | 22 +++++++++---------- .../devops/conga/resource/ResourceType.java | 10 ++++----- .../maven/plugin/AbstractCongaMojo.java | 4 +++- .../maven/plugin/GenerateVersionInfoMojo.java | 8 ++++++- .../tooling/maven/plugin/PackageMojo.java | 2 +- .../tooling/maven/plugin/ValidateMojo.java | 14 ++++++------ .../maven/plugin/util/VersionInfoUtil.java | 2 +- .../NoValueProviderInRoleValidator.java | 4 ++-- .../validation/RoleTemplateFileValidator.java | 2 +- .../maven/plugin/MavenSlf4jLogFacadeTest.java | 5 ++--- .../plugin/util/PluginConfigUtilTest.java | 4 ++-- 26 files changed, 95 insertions(+), 85 deletions(-) diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/EnvironmentGenerator.java b/generator/src/main/java/io/wcm/devops/conga/generator/EnvironmentGenerator.java index 46eb4c0b..3a531d43 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/EnvironmentGenerator.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/EnvironmentGenerator.java @@ -22,6 +22,7 @@ import java.io.File; import java.io.IOException; import java.net.URL; +import java.nio.file.Files; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -383,7 +384,12 @@ private Collection generateFile(RoleFile roleFile, String File file = new File(nodeDir, dir != null ? FilenameUtils.concat(dir, generatedFileName) : generatedFileName); if (file.exists()) { - file.delete(); + try { + Files.delete(file.toPath()); + } + catch (IOException ex) { + throw new GeneratorException("Unable to delete: " + FileUtil.getCanonicalPath(file), ex); + } } FileGenerator fileGenerator = new FileGenerator(options, environmentName, diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/FileGenerator.java b/generator/src/main/java/io/wcm/devops/conga/generator/FileGenerator.java index 89473afd..d3225479 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/FileGenerator.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/FileGenerator.java @@ -309,7 +309,7 @@ private boolean createSymlinkToLocalFile() throws IOException { } catch (IOException ex) { // creates symbolic link failed - log warning and fallback to copying content - log.warn("Unable to create symbolic link: " + ex.getMessage()); + log.warn("Unable to create symbolic link: {}", ex.getMessage()); return false; } } @@ -332,7 +332,7 @@ private void createSymlinkToSymlinkTarget() throws IOException { } catch (IOException ex) { // creates symbolic link failed - create text file with link instead (similar to git) - log.warn("Created link textfile instead of symbolic link: " + ex.getMessage()); + log.warn("Created link textfile instead of symbolic link: {}", ex.getMessage()); FileUtils.write(linkPath.toFile(), relativizedPath.toString(), StandardCharsets.UTF_8); } } @@ -447,7 +447,7 @@ private void applyPostProcessor(Map consolidatedFi }); // apply post processor configured as implicit ALWAYS - consolidatedFiles.values().forEach(fileItem -> { + consolidatedFiles.values().forEach(fileItem -> pluginManager.getAll(PostProcessorPlugin.class).stream() .filter(implicitPlugin -> implicitPlugin.accepts(fileItem.getFileContext(), postProcessorContext)) .filter(implicitPlugin -> implicitPlugin.implicitApply(fileItem.getFileContext(), postProcessorContext) == ImplicitApplyOptions.ALWAYS) @@ -464,8 +464,8 @@ private void applyPostProcessor(Map consolidatedFi } generatedFileContext.postProcessor(implicitPlugin.getName()); }); - }); - }); + }) + ); // remove items that do no longer exist List.copyOf(consolidatedFiles.values()).forEach(fileItem -> { diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/handlebars/CharsetAwareTemplateSource.java b/generator/src/main/java/io/wcm/devops/conga/generator/handlebars/CharsetAwareTemplateSource.java index 5c8404c4..550722b8 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/handlebars/CharsetAwareTemplateSource.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/handlebars/CharsetAwareTemplateSource.java @@ -32,6 +32,7 @@ /** * Charset-aware TemplateSource for handlebars. */ +@SuppressWarnings("java:S2160") // equals/hashCode is implemented in base class class CharsetAwareTemplateSource extends AbstractTemplateSource { private final Resource file; diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/handlebars/HandlebarsManager.java b/generator/src/main/java/io/wcm/devops/conga/generator/handlebars/HandlebarsManager.java index cecdc308..fa8a3f03 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/handlebars/HandlebarsManager.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/handlebars/HandlebarsManager.java @@ -25,7 +25,6 @@ import com.github.benmanes.caffeine.cache.CacheLoader; import com.github.benmanes.caffeine.cache.Caffeine; import com.github.benmanes.caffeine.cache.LoadingCache; -import com.github.jknack.handlebars.EscapingStrategy; import com.github.jknack.handlebars.Handlebars; import com.github.jknack.handlebars.Helper; import com.github.jknack.handlebars.Options; @@ -61,12 +60,8 @@ public Handlebars load(HandlebarsKey options) throws Exception { // setup handlebars TemplateLoader templateLoader = new CharsetAwareTemplateLoader(templateDirs, options.getCharset()); EscapingStrategyPlugin escapingStrategy = pluginManager.get(options.getEscapingStrategy(), EscapingStrategyPlugin.class); - Handlebars handlebars = new Handlebars(templateLoader).with(new EscapingStrategy() { - @Override - public CharSequence escape(CharSequence value) { - return escapingStrategy.escape(value, escapingStrategyContext); - } - }); + Handlebars handlebars = new Handlebars(templateLoader) + .with(value -> escapingStrategy.escape(value, escapingStrategyContext)); // register helpers provided by JKnack Handlebars implementation handlebars.registerHelpers(StringHelpers.class); diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/plugins/fileheader/AbstractFileHeader.java b/generator/src/main/java/io/wcm/devops/conga/generator/plugins/fileheader/AbstractFileHeader.java index 81bcaf8c..ba213fd9 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/plugins/fileheader/AbstractFileHeader.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/plugins/fileheader/AbstractFileHeader.java @@ -20,6 +20,7 @@ package io.wcm.devops.conga.generator.plugins.fileheader; import java.io.IOException; +import java.nio.file.Files; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -68,7 +69,7 @@ public final Void apply(FileContext file, FileHeaderContext context) { + StringUtils.defaultString(getBlockSuffix()) + StringUtils.substring(content, insertPosition); - file.getFile().delete(); + Files.delete(file.getFile().toPath()); FileUtils.write(file.getFile(), content, file.getCharset()); } catch (IOException ex) { @@ -101,7 +102,7 @@ protected String getBlockSuffix() { return null; } - protected int getInsertPosition(@SuppressWarnings("unused") String content) { + protected int getInsertPosition(@SuppressWarnings({ "unused", "java:S1172" }) String content) { return 0; } diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/plugins/handlebars/helper/AbstractEachIfHelper.java b/generator/src/main/java/io/wcm/devops/conga/generator/plugins/handlebars/helper/AbstractEachIfHelper.java index d7d23528..d8ec3054 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/plugins/handlebars/helper/AbstractEachIfHelper.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/plugins/handlebars/helper/AbstractEachIfHelper.java @@ -26,7 +26,7 @@ import java.util.Map.Entry; import java.util.Objects; import java.util.Set; -import java.util.function.BiFunction; +import java.util.function.BiPredicate; import java.util.stream.Collectors; import java.util.stream.StreamSupport; @@ -43,12 +43,12 @@ /** * Handlebars helper that extends the each helper by iterating only on list items that match a certain condition. */ -abstract class AbstractEachIfHelper implements HelperPlugin { +abstract class AbstractEachIfHelper implements HelperPlugin { private final Helper delegate = new EachHelper(); - private final BiFunction propertyEvaluator; + private final BiPredicate propertyEvaluator; - AbstractEachIfHelper(BiFunction propertyEvaluator) { + AbstractEachIfHelper(BiPredicate propertyEvaluator) { this.propertyEvaluator = propertyEvaluator; } @@ -90,7 +90,7 @@ private Iterable filterIterable(Iterable items, String propertyN private boolean checkProperty(Object item, String propertyName, Options options) { Map propertyMap = toMap(options.propertySet(item)); Object value = MapExpander.getDeep(propertyMap, propertyName); - return propertyEvaluator.apply(value, options); + return propertyEvaluator.test(value, options); } private Map toMap(Set> entries) { diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/plugins/urlfile/FilesystemUrlFilePlugin.java b/generator/src/main/java/io/wcm/devops/conga/generator/plugins/urlfile/FilesystemUrlFilePlugin.java index 9a3746fc..40b9bac8 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/plugins/urlfile/FilesystemUrlFilePlugin.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/plugins/urlfile/FilesystemUrlFilePlugin.java @@ -26,6 +26,7 @@ import java.io.IOException; import java.io.InputStream; import java.net.URL; +import java.nio.file.Files; import org.apache.commons.lang3.StringUtils; @@ -90,7 +91,7 @@ public void deleteFile(String url, UrlFilePluginContext context) throws IOExcept if (!file.exists()) { throw new FileNotFoundException("File does not exist: " + FileUtil.getCanonicalPath(file)); } - file.delete(); + Files.delete(file.toPath()); } private static File getFileInternal(String url, UrlFilePluginContext context) { diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/util/ConfigInheritanceResolver.java b/generator/src/main/java/io/wcm/devops/conga/generator/util/ConfigInheritanceResolver.java index d467dce1..3ca49fbd 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/util/ConfigInheritanceResolver.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/util/ConfigInheritanceResolver.java @@ -41,13 +41,10 @@ */ public final class ConfigInheritanceResolver extends AbstractConfigurableObjectTreeProcessor> { - private static final ConfigurableProcessor> PROCESSOR = new ConfigurableProcessor>() { - @Override - public Map process(Configurable configurable, Map parentConfig) { - Map mergedConfig = MapMerger.merge(configurable.getConfig(), parentConfig); - configurable.setConfig(mergedConfig); - return mergedConfig; - } + private static final ConfigurableProcessor> PROCESSOR = (configurable, parentConfig) -> { + Map mergedConfig = MapMerger.merge(configurable.getConfig(), parentConfig); + configurable.setConfig(mergedConfig); + return mergedConfig; }; private ConfigInheritanceResolver(Set ignorePropertyNames) { diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/util/FileUtil.java b/generator/src/main/java/io/wcm/devops/conga/generator/util/FileUtil.java index 0e7d9dd5..b4a1c07c 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/util/FileUtil.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/util/FileUtil.java @@ -60,7 +60,7 @@ public static String getCanonicalPath(File file) { * @return Canonical path * @deprecated use {@link FileContext#getCanonicalPath()} instead. */ - @Deprecated + @Deprecated(forRemoval = true) public static String getCanonicalPath(FileContext fileContext) { return fileContext.getCanonicalPath(); } diff --git a/model/src/main/java/io/wcm/devops/conga/model/shared/LineEndings.java b/model/src/main/java/io/wcm/devops/conga/model/shared/LineEndings.java index bea3f3be..265db353 100644 --- a/model/src/main/java/io/wcm/devops/conga/model/shared/LineEndings.java +++ b/model/src/main/java/io/wcm/devops/conga/model/shared/LineEndings.java @@ -22,6 +22,7 @@ /** * Line endings for generated files. */ +@SuppressWarnings("java:S115") // naming convention public enum LineEndings { /** diff --git a/model/src/main/java/io/wcm/devops/conga/model/util/DefaultUtil.java b/model/src/main/java/io/wcm/devops/conga/model/util/DefaultUtil.java index 3b125859..8a80192f 100644 --- a/model/src/main/java/io/wcm/devops/conga/model/util/DefaultUtil.java +++ b/model/src/main/java/io/wcm/devops/conga/model/util/DefaultUtil.java @@ -44,14 +44,14 @@ public static List defaultEmptyList(List list) { if (list != null) { // do not allow null entries in list - if (list.stream().filter(Objects::isNull).findFirst().isPresent()) { + if (list.stream().anyMatch(Objects::isNull)) { throw new IllegalArgumentException("Null element detected in list."); } return list; } else { - return new ArrayList(); + return new ArrayList<>(); } } @@ -67,7 +67,7 @@ public static Map defaultEmptyMap(Map map) { return map; } else { - return new HashMap(); + return new HashMap<>(); } } diff --git a/model/src/main/java/io/wcm/devops/conga/model/util/MapExpander.java b/model/src/main/java/io/wcm/devops/conga/model/util/MapExpander.java index 2e0e5559..65bebdf3 100644 --- a/model/src/main/java/io/wcm/devops/conga/model/util/MapExpander.java +++ b/model/src/main/java/io/wcm/devops/conga/model/util/MapExpander.java @@ -26,6 +26,8 @@ import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * Expands map with shortcut keys like @@ -46,7 +48,7 @@ private MapExpander() { * @return Value or null */ @SuppressWarnings("unchecked") - public static Object getDeep(Map map, String key) { + public static @Nullable Object getDeep(@NotNull Map map, @NotNull String key) { if (map.containsKey(key)) { return ObjectUtils.defaultIfNull(map.get(key), ""); } @@ -67,7 +69,7 @@ public static Object getDeep(Map map, String key) { * @return Expanded amp */ @SuppressWarnings("unchecked") - public static Map expand(Map map) { + public static @Nullable Map expand(@Nullable Map map) { if (map == null) { return null; } @@ -89,9 +91,9 @@ public static Map expand(Map map) { return expanded; } - private static Map.Entry expandEntry(Map.Entry entry) { + private static @NotNull Map.Entry expandEntry(@NotNull Map.Entry entry) { if (!StringUtils.contains(entry.getKey(), ".")) { - return new MapEntry(entry.getKey(), expandDeep(entry.getValue())); + return new MapEntry<>(entry.getKey(), expandDeep(entry.getValue())); } String key = StringUtils.substringBefore(entry.getKey(), "."); @@ -101,11 +103,11 @@ private static Map.Entry expandEntry(Map.Entry e map.put(remaining, expandDeep(entry.getValue())); Map expandedMap = expand(map); - return new MapEntry(key, expandedMap); + return new MapEntry<>(key, expandedMap); } @SuppressWarnings("unchecked") - private static Object expandDeep(Object object) { + private static @Nullable Object expandDeep(@Nullable Object object) { if (object instanceof Map) { return expand((Map)object); } diff --git a/model/src/main/java/io/wcm/devops/conga/model/util/MapMerger.java b/model/src/main/java/io/wcm/devops/conga/model/util/MapMerger.java index edb4fd72..1a31cc16 100644 --- a/model/src/main/java/io/wcm/devops/conga/model/util/MapMerger.java +++ b/model/src/main/java/io/wcm/devops/conga/model/util/MapMerger.java @@ -137,9 +137,9 @@ private static List mergeList(List l1, List l2) { } else { mergedList = new MergingList<>(); - l1.forEach(item -> mergedList.addCheckMergeToken(item)); + l1.forEach(mergedList::addCheckMergeToken); } - l2.forEach(item -> mergedList.add(item)); + l2.forEach(mergedList::add); return mergedList; } diff --git a/model/src/main/java/io/wcm/devops/conga/model/util/MapSplitter.java b/model/src/main/java/io/wcm/devops/conga/model/util/MapSplitter.java index 614465f2..54291747 100644 --- a/model/src/main/java/io/wcm/devops/conga/model/util/MapSplitter.java +++ b/model/src/main/java/io/wcm/devops/conga/model/util/MapSplitter.java @@ -22,7 +22,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.function.Function; +import java.util.function.Predicate; import org.jetbrains.annotations.NotNull; @@ -45,7 +45,7 @@ private MapSplitter() { */ @SuppressWarnings("unchecked") public static @NotNull SplitResult splitMap(Map map, - @NotNull Function, Boolean> matcher) { + @NotNull Predicate> matcher) { Map matching = new HashMap<>(); Map unmatching = new HashMap<>(); @@ -75,9 +75,9 @@ else if (entry.getValue() instanceof List) { private static void processSimpleValue(@NotNull Map.Entry entry, @NotNull Map matching, @NotNull Map unmatching, - @NotNull Function, Boolean> matcher) { + @NotNull Predicate> matcher) { - if (matcher.apply(entry)) { + if (matcher.test(entry)) { matching.put(entry.getKey(), entry.getValue()); } else { @@ -89,7 +89,7 @@ private static void processSimpleValue(@NotNull Map.Entry entry, private static void processMapValue(@NotNull Map.Entry entry, @NotNull Map matching, @NotNull Map unmatching, - @NotNull Function, Boolean> matcher) { + @NotNull Predicate> matcher) { Map map = (Map)entry.getValue(); SplitResult subResult = splitMap(map, matcher); @@ -105,7 +105,7 @@ private static void processMapValue(@NotNull Map.Entry entry, private static void processListValue(@NotNull Map.Entry entry, @NotNull Map matching, @NotNull Map unmatching, - @NotNull Function, Boolean> matcher) { + @NotNull Predicate> matcher) { // we cannot split up the list - so it's put to unmatched if at least one list entry is unmatched // to make processing easy we convert to list to a map and check of any unmatched @@ -125,12 +125,11 @@ private static void processListValue(@NotNull Map.Entry entry, private static boolean listHasSubStructures(@NotNull List list) { return list.stream() - .filter(item -> (item instanceof List) || (item instanceof Map)) - .findFirst().isPresent(); + .anyMatch(item -> (item instanceof List) || (item instanceof Map)); } /** - * Result of {@link #splitMap(Map, Function)} method. + * Result of {@link #splitMap(Map, Predicate)} method. */ public static final class SplitResult { diff --git a/model/src/main/java/io/wcm/devops/conga/model/util/MergingList.java b/model/src/main/java/io/wcm/devops/conga/model/util/MergingList.java index 5d9eb334..51bab7cf 100644 --- a/model/src/main/java/io/wcm/devops/conga/model/util/MergingList.java +++ b/model/src/main/java/io/wcm/devops/conga/model/util/MergingList.java @@ -35,7 +35,7 @@ final class MergingList extends LinkedList { } MergingList(MergingList mergingList) { - mergingList.forEach(item -> super.add(item)); + mergingList.forEach(super::add); this.mergePositionIndex = mergingList.mergePositionIndex; } diff --git a/model/src/test/java/io/wcm/devops/conga/model/reader/EnvironmentReaderTest.java b/model/src/test/java/io/wcm/devops/conga/model/reader/EnvironmentReaderTest.java index 004b2b3b..d255d738 100644 --- a/model/src/test/java/io/wcm/devops/conga/model/reader/EnvironmentReaderTest.java +++ b/model/src/test/java/io/wcm/devops/conga/model/reader/EnvironmentReaderTest.java @@ -39,12 +39,12 @@ import io.wcm.devops.conga.model.environment.RoleConfig; import io.wcm.devops.conga.model.environment.Tenant; -public class EnvironmentReaderTest { +class EnvironmentReaderTest { private Environment environment; @BeforeEach - public void setUp() throws IOException { + void setUp() throws IOException { EnvironmentReader reader = new EnvironmentReader(); try (InputStream is = getClass().getResourceAsStream("/environment.yaml")) { environment = reader.read(is); @@ -53,7 +53,7 @@ public void setUp() throws IOException { } @Test - public void testEnvironment() { + void testEnvironment() { assertEquals(3, environment.getNodes().size()); assertEquals(1, environment.getRoleConfig().size()); assertEquals(2, environment.getTenants().size()); @@ -66,7 +66,7 @@ public void testEnvironment() { } @Test - public void testNode() { + void testNode() { Node node = environment.getNodes().get(0); assertEquals("importer", node.getNode()); @@ -78,14 +78,14 @@ public void testNode() { } @Test - public void testMultiNode() { + void testMultiNode() { Node node = environment.getNodes().get(1); assertEquals(List.of("services-1", "services-2"), node.getNodes()); assertEquals(1, node.getRoles().size()); } @Test - public void testNodeRole() { + void testNodeRole() { NodeRole role1 = environment.getNodes().get(0).getRoles().get(0); assertEquals("tomcat-services", role1.getRole()); assertEquals("importer", role1.getVariant()); @@ -99,7 +99,7 @@ public void testNodeRole() { } @Test - public void testRoleConfig() { + void testRoleConfig() { RoleConfig roleConfig = environment.getRoleConfig().get(0); assertEquals("tomcat-backendconnector", roleConfig.getRole()); @@ -108,7 +108,7 @@ public void testRoleConfig() { } @Test - public void testTenant() { + void testTenant() { Tenant tenant = environment.getTenants().get(0); assertEquals("tenant1", tenant.getTenant()); @@ -118,7 +118,7 @@ public void testTenant() { } @Test - public void testEnvironmentWithNullTenant() { + void testEnvironmentWithNullTenant() { assertThrows(ConstructorException.class, () -> { EnvironmentReader reader = new EnvironmentReader(); try (InputStream is = getClass().getResourceAsStream("/environment_null_tenant.yaml")) { @@ -128,12 +128,12 @@ public void testEnvironmentWithNullTenant() { } @Test - public void testDependencies() { + void testDependencies() { assertEquals(List.of("url1", "mvn:url2"), environment.getDependencies()); } @Test - public void testPluginConfig() { + void testPluginConfig() { Map> pluginConfig = environment.getPluginConfig(); assertNotNull(pluginConfig); diff --git a/resource/src/main/java/io/wcm/devops/conga/resource/ResourceType.java b/resource/src/main/java/io/wcm/devops/conga/resource/ResourceType.java index 38e3e54d..f35b8230 100644 --- a/resource/src/main/java/io/wcm/devops/conga/resource/ResourceType.java +++ b/resource/src/main/java/io/wcm/devops/conga/resource/ResourceType.java @@ -29,13 +29,13 @@ enum ResourceType { FILE(ResourceLoader.FILE_PREFIX, (path, resourceLoader) -> new FileResourceImpl(path), - (path, resourceLoader) -> new FileResourceCollectionImpl(path, resourceLoader), - resource -> resource instanceof AbstractFileResourceInfoImpl), + FileResourceCollectionImpl::new, + AbstractFileResourceInfoImpl.class::isInstance), CLASSPATH(ResourceLoader.CLASSPATH_PREFIX, - (path, resourceLoader) -> new ClasspathResourceImpl(path, resourceLoader), - (path, resourceLoader) -> new ClasspathResourceCollectionImpl(path, resourceLoader), - resource -> resource instanceof AbstractClasspathResourceImpl); + ClasspathResourceImpl::new, + ClasspathResourceCollectionImpl::new, + AbstractClasspathResourceImpl.class::isInstance); private final String prefix; private final BiFunction resourceFactory; diff --git a/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/AbstractCongaMojo.java b/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/AbstractCongaMojo.java index d8662854..d1584d90 100644 --- a/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/AbstractCongaMojo.java +++ b/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/AbstractCongaMojo.java @@ -30,6 +30,7 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.nio.file.Files; import java.util.Arrays; import java.util.List; import java.util.Map; @@ -345,7 +346,7 @@ private void copyDefinitions(ResourceCollection sourceDir, File rootOutputDir, F getLog().info("Include " + getPathForLog(rootOutputDir, targetFile)); if (targetFile.exists()) { - targetFile.delete(); + Files.delete(targetFile.toPath()); } try (InputStream is = file.getInputStream()) { byte[] data = IOUtils.toByteArray(is); @@ -358,6 +359,7 @@ private void copyDefinitions(ResourceCollection sourceDir, File rootOutputDir, F } } + @SuppressWarnings("java:S1075") // not a filesystem path private String getPathForLog(File rootOutputDir, File file) throws IOException { String path = unifySlashes(file.getCanonicalPath()); String rootPath = unifySlashes(rootOutputDir.getCanonicalPath()) + "/"; diff --git a/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/GenerateVersionInfoMojo.java b/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/GenerateVersionInfoMojo.java index f30e47dd..fe5a8c26 100644 --- a/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/GenerateVersionInfoMojo.java +++ b/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/GenerateVersionInfoMojo.java @@ -23,6 +23,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.nio.file.Files; import java.util.Properties; import org.apache.maven.plugin.AbstractMojo; @@ -64,7 +65,12 @@ public void execute() throws MojoExecutionException, MojoFailureException { File propsFile = new File(outputDir, BuildConstants.FILE_VERSION_INFO); if (propsFile.exists()) { - propsFile.delete(); + try { + Files.delete(propsFile.toPath()); + } + catch (IOException ex) { + throw new MojoExecutionException("Unable to delete file: " + FileUtil.getCanonicalPath(propsFile), ex); + } } Properties versionInfo = VersionInfoUtil.getVersionInfoProperties(project); try (OutputStream os = new FileOutputStream(propsFile)) { diff --git a/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/PackageMojo.java b/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/PackageMojo.java index c8b4e26d..bef29bb2 100644 --- a/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/PackageMojo.java +++ b/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/PackageMojo.java @@ -90,7 +90,7 @@ private void buildGeneratedConfigurationAttachments() throws MojoExecutionExcept // collect configuration environment directories File configRootDir = getTargetDir(); List environmentDirs = Arrays.stream(configRootDir.listFiles()) - .filter(file -> file.isDirectory()) + .filter(File::isDirectory) .filter(dir -> selectedEnvironments == null || selectedEnvironments.contains(dir.getName())) .collect(Collectors.toList()); diff --git a/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/ValidateMojo.java b/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/ValidateMojo.java index 6b99aaa3..dc1f7297 100644 --- a/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/ValidateMojo.java +++ b/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/ValidateMojo.java @@ -27,7 +27,7 @@ import java.util.List; import java.util.Properties; import java.util.SortedSet; -import java.util.function.Function; +import java.util.function.Predicate; import java.util.stream.Collectors; import org.apache.commons.io.FilenameUtils; @@ -200,7 +200,7 @@ private List validateFiles(ResourceCollection sourceDir, ResourceCollecti } private List validateFiles(ResourceCollection sourceDir, ResourceCollection rootSourceDir, DefinitionValidator validator, - Function resourceFilter) throws MojoFailureException { + Predicate resourceFilter) throws MojoFailureException { if (!sourceDir.exists()) { return List.of(); } @@ -212,12 +212,12 @@ private List validateFiles(ResourceCollection sourceDir, ResourceCollecti List result = new ArrayList<>(); for (Resource file : files) { - if (resourceFilter.apply(file)) { + if (resourceFilter.test(file)) { result.add(validator.validate(file, getPathForLog(rootSourceDir, file))); } } for (ResourceCollection dir : dirs) { - if (resourceFilter.apply(dir)) { + if (resourceFilter.test(dir)) { result.addAll(validateFiles(dir, rootSourceDir, validator, resourceFilter)); } } @@ -269,7 +269,7 @@ private List getEnvironmentClasspathUrls(List dependencyUrls, Plugi throw new GeneratorException("Unable to resolve: " + resolvedDependencyUrl, ex); } }) - .flatMap(list -> list.stream()) + .flatMap(List::stream) .collect(Collectors.toList()); } @@ -295,7 +295,7 @@ private List getDependencyVersionInfos(ClassLoader classLoader) thro org.springframework.core.io.Resource[] resources = resolver.getResources( "classpath*:" + GeneratorOptions.CLASSPATH_PREFIX + BuildConstants.FILE_VERSION_INFO); return Arrays.stream(resources) - .map(resource -> toProperties(resource)) + .map(this::toProperties) .collect(Collectors.toList()); } catch (IOException ex) { @@ -310,7 +310,7 @@ private Properties toProperties(org.springframework.core.io.Resource resource) { return props; } catch (IOException ex) { - throw new RuntimeException("Unable to read properties file: " + resource.toString(), ex); + throw new IllegalArgumentException("Unable to read properties file: " + resource.toString(), ex); } } diff --git a/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/util/VersionInfoUtil.java b/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/util/VersionInfoUtil.java index b5a65dd2..f47cd93b 100644 --- a/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/util/VersionInfoUtil.java +++ b/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/util/VersionInfoUtil.java @@ -34,7 +34,7 @@ public final class VersionInfoUtil { // match versions like 2.1.2-20180125.094723-16 - private static final Pattern SNAPSHOT_VERSION_PATTERN = Pattern.compile("(\\d+(\\.\\d+)*)-(\\d{8}\\.\\d{6}\\-\\d+)"); + private static final Pattern SNAPSHOT_VERSION_PATTERN = Pattern.compile("^(\\d+(\\.\\d+)*+)-(\\d{8}\\.\\d{6}\\-\\d+)$"); private VersionInfoUtil() { // static methods only diff --git a/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/validation/NoValueProviderInRoleValidator.java b/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/validation/NoValueProviderInRoleValidator.java index 78c81ad9..2850477c 100644 --- a/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/validation/NoValueProviderInRoleValidator.java +++ b/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/validation/NoValueProviderInRoleValidator.java @@ -37,7 +37,7 @@ */ public final class NoValueProviderInRoleValidator implements DefinitionValidator { - private final ModelReader mapReader = new MapReader(); + private final ModelReader> mapReader = new MapReader(); @Override @SuppressWarnings("PMD.PreserveStackTrace") @@ -71,7 +71,7 @@ private void validate(String value) { } } - private static class MapReader extends AbstractModelReader { + private static class MapReader extends AbstractModelReader> { MapReader() { super(getYaml()); } diff --git a/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/validation/RoleTemplateFileValidator.java b/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/validation/RoleTemplateFileValidator.java index ea411433..340184bd 100644 --- a/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/validation/RoleTemplateFileValidator.java +++ b/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/validation/RoleTemplateFileValidator.java @@ -67,7 +67,7 @@ public Void validate(Resource resource, String pathForLog) throws MojoFailureExc boolean hasTemplate = StringUtils.isNotEmpty(roleFile.getTemplate()); boolean hasUrl = StringUtils.isNotEmpty(roleFile.getUrl()); boolean hasSymlinkTarget = StringUtils.isNotEmpty(roleFile.getSymlinkTarget()); - if ((hasTemplate && hasUrl) || (hasTemplate & hasSymlinkTarget) || (hasUrl && hasSymlinkTarget)) { + if ((hasTemplate && hasUrl) || (hasTemplate && hasSymlinkTarget) || (hasUrl && hasSymlinkTarget)) { throw new IllegalArgumentException("Only one of the attributes 'template', 'url', 'symlinkTarget' is allowed for a file definition."); } diff --git a/tooling/conga-maven-plugin/src/test/java/io/wcm/devops/conga/tooling/maven/plugin/MavenSlf4jLogFacadeTest.java b/tooling/conga-maven-plugin/src/test/java/io/wcm/devops/conga/tooling/maven/plugin/MavenSlf4jLogFacadeTest.java index 1670ec29..7458d38d 100644 --- a/tooling/conga-maven-plugin/src/test/java/io/wcm/devops/conga/tooling/maven/plugin/MavenSlf4jLogFacadeTest.java +++ b/tooling/conga-maven-plugin/src/test/java/io/wcm/devops/conga/tooling/maven/plugin/MavenSlf4jLogFacadeTest.java @@ -24,11 +24,10 @@ import org.junit.jupiter.api.Test; - -public class MavenSlf4jLogFacadeTest { +class MavenSlf4jLogFacadeTest { @Test - public void testFormatMessage() { + void testFormatMessage() { assertEquals("Der", formatMessage("Der")); assertEquals("Der {}", formatMessage("Der {}")); assertEquals("Der Jodelkaiser", formatMessage("Der {}", "Jodelkaiser")); diff --git a/tooling/conga-maven-plugin/src/test/java/io/wcm/devops/conga/tooling/maven/plugin/util/PluginConfigUtilTest.java b/tooling/conga-maven-plugin/src/test/java/io/wcm/devops/conga/tooling/maven/plugin/util/PluginConfigUtilTest.java index 9567f746..4cae1ad4 100644 --- a/tooling/conga-maven-plugin/src/test/java/io/wcm/devops/conga/tooling/maven/plugin/util/PluginConfigUtilTest.java +++ b/tooling/conga-maven-plugin/src/test/java/io/wcm/devops/conga/tooling/maven/plugin/util/PluginConfigUtilTest.java @@ -25,10 +25,10 @@ import org.junit.jupiter.api.Test; -public class PluginConfigUtilTest { +class PluginConfigUtilTest { @Test - public void testGetConfigMap() { + void testGetConfigMap() { assertEquals(Map.of(), PluginConfigUtil.getConfigMap(null)); From cb0b964f07becd46aa6353b852485b8545a26783 Mon Sep 17 00:00:00 2001 From: Stefan Seifert Date: Mon, 22 Jan 2024 12:03:59 +0100 Subject: [PATCH 20/26] Eliminate SonarQube warnings (#61) --- .../devops/conga/generator/FileGenerator.java | 24 ++++++++++++++----- ...stractConfigurableObjectTreeProcessor.java | 2 +- .../conga/generator/util/JexlResolver.java | 7 +++--- .../generator/util/VariableMapResolver.java | 5 ++-- .../util/VariableObjectTreeResolver.java | 1 + .../FileGeneratorPostProcessorTest.java | 4 ++-- .../conga/model/environment/Environment.java | 1 + .../devops/conga/model/environment/Node.java | 1 + .../conga/model/environment/Tenant.java | 1 + .../model/reader/AbstractModelReader.java | 2 +- .../wcm/devops/conga/model/role/RoleFile.java | 3 ++- .../model/shared/AbstractConfigurable.java | 1 + .../devops/conga/model/util/MapSplitter.java | 11 ++++----- .../devops/conga/model/util/MergingList.java | 1 + .../maven/plugin/MavenSlf4jLogFacade.java | 1 + .../tooling/maven/plugin/ValidateMojo.java | 1 + .../NoValueProviderInRoleValidator.java | 2 +- .../plugin/validation/TemplateValidator.java | 5 +++- 18 files changed, 48 insertions(+), 25 deletions(-) diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/FileGenerator.java b/generator/src/main/java/io/wcm/devops/conga/generator/FileGenerator.java index d3225479..3be609c9 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/FileGenerator.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/FileGenerator.java @@ -214,7 +214,9 @@ public Collection generate() throws IOException { Collection postProcessedFiles; if (template != null) { - log.info("Generate file {}", getFilenameForLog(fileContext)); + if (log.isInfoEnabled()) { + log.info("Generate file {}", getFilenameForLog(fileContext)); + } // generate with template generateWithTemplate(); @@ -230,7 +232,9 @@ else if (StringUtils.isNotBlank(url)) { // if copying from a local file try to create a symlink instead of coyping it boolean symlinkCreated = false; if (allowSymlinks && !symlinkCreationFailed && urlFileManager.isLocalFile(url) && !roleFile.isDeleteSource()) { - log.info("Symlink file {} from {}", getFilenameForLog(fileContext), url); + if (log.isInfoEnabled()) { + log.info("Symlink file {} from {}", getFilenameForLog(fileContext), url); + } if (createSymlinkToLocalFile()) { symlinkCreated = true; } @@ -241,7 +245,9 @@ else if (StringUtils.isNotBlank(url)) { // generate by downloading/copying from URL if (!symlinkCreated) { - log.info("Copy file {} from {}", getFilenameForLog(fileContext), url); + if (log.isInfoEnabled()) { + log.info("Copy file {} from {}", getFilenameForLog(fileContext), url); + } copyFromUrlFile(); } @@ -386,7 +392,9 @@ private void applyFileHeader(FileContext fileItem, String pluginName) { } private void applyFileHeader(FileContext fileItem, FileHeaderPlugin plugin) { - log.debug(" Add {} file header to file {}", plugin.getName(), getFilenameForLog(fileItem)); + if (log.isDebugEnabled()) { + log.debug(" Add {} file header to file {}", plugin.getName(), getFilenameForLog(fileItem)); + } plugin.apply(fileItem, fileHeaderContext); } @@ -397,7 +405,9 @@ private void applyValidation(FileContext fileItem, List pluginNames) { } private void applyValidation(FileContext fileItem, ValidatorPlugin plugin) { - log.info(" Validate {} for file {}", plugin.getName(), getFilenameForLog(fileItem)); + if (log.isInfoEnabled()) { + log.info(" Validate {} for file {}", plugin.getName(), getFilenameForLog(fileItem)); + } plugin.apply(fileItem, validatorContext); } @@ -477,7 +487,9 @@ private void applyPostProcessor(Map consolidatedFi } private List applyPostProcessor(FileContext fileItem, PostProcessorPlugin plugin) { - log.info(" Post-process {} for file {}", plugin.getName(), getFilenameForLog(fileItem)); + if (log.isInfoEnabled()) { + log.info(" Post-process {} for file {}", plugin.getName(), getFilenameForLog(fileItem)); + } List processedFiles = plugin.apply(fileItem, postProcessorContext); diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/util/AbstractConfigurableObjectTreeProcessor.java b/generator/src/main/java/io/wcm/devops/conga/generator/util/AbstractConfigurableObjectTreeProcessor.java index 50184333..358a93c1 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/util/AbstractConfigurableObjectTreeProcessor.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/util/AbstractConfigurableObjectTreeProcessor.java @@ -92,7 +92,7 @@ private void resolveNestedObjects(Object object, ConfigurableProcessor proces } } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) { - throw new RuntimeException("Unable to get bean properties from '" + object.getClass().getName() + "'.", ex); + throw new IllegalArgumentException("Unable to get bean properties from '" + object.getClass().getName() + "'.", ex); } } diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/util/JexlResolver.java b/generator/src/main/java/io/wcm/devops/conga/generator/util/JexlResolver.java index e915c6a2..e2cad0ba 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/util/JexlResolver.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/util/JexlResolver.java @@ -79,10 +79,9 @@ private Map resolveMapWithoutCycles(Map variable SplitResult splitResult = MapSplitter.splitMap(variables, entry -> { if (entry.getValue() instanceof List) { for (Object item : (List)entry.getValue()) { - if (item instanceof String) { - if (hasJexlExpresssions((String)item)) { - return false; - } + if ((item instanceof String) + && hasJexlExpresssions((String)item)) { + return false; } } } diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/util/VariableMapResolver.java b/generator/src/main/java/io/wcm/devops/conga/generator/util/VariableMapResolver.java index a73b8fdb..0ce1d841 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/util/VariableMapResolver.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/util/VariableMapResolver.java @@ -26,6 +26,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.regex.Matcher; import io.wcm.devops.conga.generator.spi.context.ValueProviderGlobalContext; @@ -176,7 +177,7 @@ private Map replaceMap(Map map, Map entry : mapCopy.entrySet()) { Object replacedValue = replaceAny(entry.getValue(), variables); - if (entry.getValue() != replacedValue) { + if (!Objects.equals(entry.getValue(), replacedValue)) { entry.setValue(replacedValue); replacedAny = true; } @@ -254,7 +255,7 @@ private Map deescapeMap(Map map) { Map mapCopy = new HashMap<>(map); for (Map.Entry entry : mapCopy.entrySet()) { Object deescapedValue = deescapeAny(entry.getValue()); - if (entry.getValue() != deescapedValue) { + if (!Objects.equals(entry.getValue(), deescapedValue)) { entry.setValue(deescapedValue); } } diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/util/VariableObjectTreeResolver.java b/generator/src/main/java/io/wcm/devops/conga/generator/util/VariableObjectTreeResolver.java index cb5175c8..35e4bb7d 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/util/VariableObjectTreeResolver.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/util/VariableObjectTreeResolver.java @@ -35,6 +35,7 @@ public final class VariableObjectTreeResolver extends AbstractConfigurableObject private final VariableMapResolver variableMapResolver; // payload not used for this processor + @SuppressWarnings("java:S1604") // not possible to use lambda here private final ConfigurableProcessor processor = new ConfigurableProcessor() { @Override public Object process(Configurable configurable, Object payload) { diff --git a/generator/src/test/java/io/wcm/devops/conga/generator/FileGeneratorPostProcessorTest.java b/generator/src/test/java/io/wcm/devops/conga/generator/FileGeneratorPostProcessorTest.java index f2b1c640..225de650 100644 --- a/generator/src/test/java/io/wcm/devops/conga/generator/FileGeneratorPostProcessorTest.java +++ b/generator/src/test/java/io/wcm/devops/conga/generator/FileGeneratorPostProcessorTest.java @@ -202,7 +202,7 @@ public List answer(InvocationOnMock invocation) throws Throwable { variableMapResolver, urlFileManager, pluginContextOptions, List.of()); FileHeaderPlugin fileHeaderPlugin = mock(FileHeaderPlugin.class); - when(pluginManager.get(eq("my-fileheader"), eq(FileHeaderPlugin.class))).thenAnswer(new Answer() { + when(pluginManager.get("my-fileheader", FileHeaderPlugin.class)).thenAnswer(new Answer() { @Override public FileHeaderPlugin answer(InvocationOnMock invocation) throws Throwable { return fileHeaderPlugin; @@ -210,7 +210,7 @@ public FileHeaderPlugin answer(InvocationOnMock invocation) throws Throwable { }); ValidatorPlugin validatorPlugin = mock(ValidatorPlugin.class); - when(pluginManager.get(eq("my-validator"), eq(ValidatorPlugin.class))).thenAnswer(new Answer() { + when(pluginManager.get("my-validator", ValidatorPlugin.class)).thenAnswer(new Answer() { @Override public ValidatorPlugin answer(InvocationOnMock invocation) throws Throwable { return validatorPlugin; diff --git a/model/src/main/java/io/wcm/devops/conga/model/environment/Environment.java b/model/src/main/java/io/wcm/devops/conga/model/environment/Environment.java index 7de14d05..08a55e14 100644 --- a/model/src/main/java/io/wcm/devops/conga/model/environment/Environment.java +++ b/model/src/main/java/io/wcm/devops/conga/model/environment/Environment.java @@ -33,6 +33,7 @@ * Defines an environment with a set of nodes and configuration. * The filename of the environment YAML file is the environment name, it's not included in the model. */ +@SuppressWarnings("java:S1948") // assume the maps are serializable public final class Environment extends AbstractConfigurable { private static final long serialVersionUID = -3146650632389125273L; diff --git a/model/src/main/java/io/wcm/devops/conga/model/environment/Node.java b/model/src/main/java/io/wcm/devops/conga/model/environment/Node.java index a5ca5f46..025ef551 100644 --- a/model/src/main/java/io/wcm/devops/conga/model/environment/Node.java +++ b/model/src/main/java/io/wcm/devops/conga/model/environment/Node.java @@ -33,6 +33,7 @@ public final class Node extends AbstractConfigurable { private static final long serialVersionUID = -7827167562783775179L; + @SuppressWarnings("java:S1700") private String node; private List nodes = new ArrayList<>(); private List roles = new ArrayList<>(); diff --git a/model/src/main/java/io/wcm/devops/conga/model/environment/Tenant.java b/model/src/main/java/io/wcm/devops/conga/model/environment/Tenant.java index 1cf089cf..9c08fe90 100644 --- a/model/src/main/java/io/wcm/devops/conga/model/environment/Tenant.java +++ b/model/src/main/java/io/wcm/devops/conga/model/environment/Tenant.java @@ -33,6 +33,7 @@ public final class Tenant extends AbstractConfigurable { private static final long serialVersionUID = 3984905428304600647L; + @SuppressWarnings("java:S1700") private String tenant; private List roles = new ArrayList<>(); diff --git a/model/src/main/java/io/wcm/devops/conga/model/reader/AbstractModelReader.java b/model/src/main/java/io/wcm/devops/conga/model/reader/AbstractModelReader.java index a1785a9b..d6514af2 100644 --- a/model/src/main/java/io/wcm/devops/conga/model/reader/AbstractModelReader.java +++ b/model/src/main/java/io/wcm/devops/conga/model/reader/AbstractModelReader.java @@ -43,7 +43,7 @@ public abstract class AbstractModelReader implements ModelReader { /** * @param yaml YAML */ - public AbstractModelReader(Yaml yaml) { + protected AbstractModelReader(Yaml yaml) { this.yaml = yaml; } diff --git a/model/src/main/java/io/wcm/devops/conga/model/role/RoleFile.java b/model/src/main/java/io/wcm/devops/conga/model/role/RoleFile.java index 6dbe084e..6d717927 100644 --- a/model/src/main/java/io/wcm/devops/conga/model/role/RoleFile.java +++ b/model/src/main/java/io/wcm/devops/conga/model/role/RoleFile.java @@ -38,6 +38,7 @@ /** * Defines a file to be generated or downloaded for a role. */ +@SuppressWarnings("java:S1948") // assume the maps are serializable public final class RoleFile extends AbstractModel { private static final long serialVersionUID = -6027099825211623171L; @@ -155,7 +156,7 @@ public void setVariants(List variants) { */ public List getVariantsMetadata() { return this.variants.stream() - .map(variant -> new RoleFileVariantMetadata(variant)) + .map(RoleFileVariantMetadata::new) .collect(Collectors.toList()); } diff --git a/model/src/main/java/io/wcm/devops/conga/model/shared/AbstractConfigurable.java b/model/src/main/java/io/wcm/devops/conga/model/shared/AbstractConfigurable.java index c184ad4f..e1f11403 100644 --- a/model/src/main/java/io/wcm/devops/conga/model/shared/AbstractConfigurable.java +++ b/model/src/main/java/io/wcm/devops/conga/model/shared/AbstractConfigurable.java @@ -30,6 +30,7 @@ /** * Abstract {@link Configurable} implementation. */ +@SuppressWarnings("java:S1948") // assume the maps are serializable public abstract class AbstractConfigurable extends AbstractModel implements Configurable, Serializable { private static final long serialVersionUID = 5009663684342529022L; diff --git a/model/src/main/java/io/wcm/devops/conga/model/util/MapSplitter.java b/model/src/main/java/io/wcm/devops/conga/model/util/MapSplitter.java index 54291747..0e50e6ba 100644 --- a/model/src/main/java/io/wcm/devops/conga/model/util/MapSplitter.java +++ b/model/src/main/java/io/wcm/devops/conga/model/util/MapSplitter.java @@ -57,12 +57,11 @@ private MapSplitter() { continue; } - else if (entry.getValue() instanceof List) { - if (listHasSubStructures((List)entry.getValue())) { - // process nested "structural" lists - processListValue(entry, matching, unmatching, matcher); - continue; - } + else if ((entry.getValue() instanceof List) + && listHasSubStructures((List)entry.getValue())) { + // process nested "structural" lists + processListValue(entry, matching, unmatching, matcher); + continue; } // value is not a structural (map/list) value - apply matching diff --git a/model/src/main/java/io/wcm/devops/conga/model/util/MergingList.java b/model/src/main/java/io/wcm/devops/conga/model/util/MergingList.java index 51bab7cf..11de246f 100644 --- a/model/src/main/java/io/wcm/devops/conga/model/util/MergingList.java +++ b/model/src/main/java/io/wcm/devops/conga/model/util/MergingList.java @@ -25,6 +25,7 @@ * Special list that marks a list as "mergeable" in downstream and preservers the merge position. * @param List type */ +@SuppressWarnings("java:S2160") // equals/hashCode is implemented in base class final class MergingList extends LinkedList { private static final long serialVersionUID = 1L; diff --git a/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/MavenSlf4jLogFacade.java b/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/MavenSlf4jLogFacade.java index d3310972..22f1159c 100644 --- a/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/MavenSlf4jLogFacade.java +++ b/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/MavenSlf4jLogFacade.java @@ -29,6 +29,7 @@ /** * Facade to rout SLF4J logging calls to maven plugin logger. */ +@SuppressWarnings("java:S2629") class MavenSlf4jLogFacade implements Logger { private static final Pattern ARGUMENT_PATTERN = Pattern.compile("\\{\\}"); diff --git a/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/ValidateMojo.java b/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/ValidateMojo.java index dc1f7297..043ef26b 100644 --- a/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/ValidateMojo.java +++ b/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/ValidateMojo.java @@ -224,6 +224,7 @@ private List validateFiles(ResourceCollection sourceDir, ResourceCollecti return result; } + @SuppressWarnings("java:S1075") // no filesystem path private static String getPathForLog(ResourceCollection rootSourceDir, Resource file) { String path = PathUtil.unifySlashes(file.getCanonicalPath()); String rootPath = PathUtil.unifySlashes(rootSourceDir.getCanonicalPath()) + "/"; diff --git a/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/validation/NoValueProviderInRoleValidator.java b/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/validation/NoValueProviderInRoleValidator.java index 2850477c..06034146 100644 --- a/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/validation/NoValueProviderInRoleValidator.java +++ b/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/validation/NoValueProviderInRoleValidator.java @@ -67,7 +67,7 @@ else if (value instanceof List) { private void validate(String value) { if (VariableStringResolver.hasValueProviderReference(value)) { - throw new RuntimeException("Role definitions must not reference value providers: " + value); + throw new IllegalStateException("Role definitions must not reference value providers: " + value); } } diff --git a/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/validation/TemplateValidator.java b/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/validation/TemplateValidator.java index b3d5902e..66a62628 100644 --- a/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/validation/TemplateValidator.java +++ b/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/validation/TemplateValidator.java @@ -52,7 +52,10 @@ public TemplateValidator(ResourceCollection templateDir, HandlebarsManager handl } @Override - @SuppressWarnings("PMD.PreserveStackTrace") + @SuppressWarnings({ + "PMD.PreserveStackTrace", + "java:S1075" // uses / by intention + }) public Void validate(Resource resource, String pathForLog) throws MojoFailureException { if (StringUtils.equalsIgnoreCase(resource.getFileExtension(), FILE_EXTENSION)) { String templatePath = StringUtils.substringAfter(PathUtil.unifySlashes(resource.getCanonicalPath()), From 265bb479b40227fe7c26bea02ce13bc9cabb2096 Mon Sep 17 00:00:00 2001 From: Stefan Seifert Date: Mon, 22 Jan 2024 12:33:55 +0100 Subject: [PATCH 21/26] Eliminate SonarQube warnings (#62) --- .../conga/generator/ContextPropertiesBuilder.java | 1 + .../devops/conga/generator/EnvironmentGenerator.java | 9 ++++++--- .../io/wcm/devops/conga/generator/FileGenerator.java | 7 +++++-- .../io/wcm/devops/conga/generator/Generator.java | 1 + .../conga/generator/export/NodeModelExport.java | 5 ++--- .../plugins/fileheader/AbstractFileHeader.java | 1 + .../plugins/urlfile/FilesystemUrlFilePlugin.java | 10 +++++++--- .../conga/generator/util/VariableStringResolver.java | 3 +++ .../io/wcm/devops/conga/generator/GeneratorTest.java | 1 + .../io/wcm/devops/conga/model/util/MapMerger.java | 6 +++++- .../io/wcm/devops/conga/model/util/MapSplitter.java | 5 ++++- .../conga/model/reader/EnvironmentReaderTest.java | 12 ++++++------ .../tooling/maven/plugin/AbstractCongaMojo.java | 1 + .../conga/tooling/maven/plugin/PackageMojo.java | 6 +++++- 14 files changed, 48 insertions(+), 20 deletions(-) diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/ContextPropertiesBuilder.java b/generator/src/main/java/io/wcm/devops/conga/generator/ContextPropertiesBuilder.java index df0bf929..61d1fd75 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/ContextPropertiesBuilder.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/ContextPropertiesBuilder.java @@ -82,6 +82,7 @@ private ContextPropertiesBuilder() { * @param variableStringResolver Variable string resolver * @return Context variables map */ + @SuppressWarnings("java:S3776") // ignore complexity public static Map buildEnvironmentContextVariables(String environmentName, Environment environment, String version, VariableObjectTreeResolver variableObjectTreeResolver, VariableStringResolver variableStringResolver) { diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/EnvironmentGenerator.java b/generator/src/main/java/io/wcm/devops/conga/generator/EnvironmentGenerator.java index 3a531d43..6b78a15e 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/EnvironmentGenerator.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/EnvironmentGenerator.java @@ -239,8 +239,7 @@ private void generateNode(Node node) { mergedConfig.putAll(ContextPropertiesBuilder.buildCurrentContextVariables(node, nodeRole)); // collect role and tenant information for export model - ExportNodeRoleData exportNodeRoleData = exportModelGenerator.addRole(roleName, variants, mergedConfig, - role.getSensitiveConfigParameters()); + ExportNodeRoleData exportNodeRoleData = exportModelGenerator.addRole(roleName, variants, mergedConfig); // generate files List allFiles = new ArrayList<>(); @@ -319,6 +318,7 @@ private String getEscapingStrategy(RoleFile roleFile) { .getName(); } + @SuppressWarnings("java:S107") // allow many parameters private void multiplyFiles(Role role, RoleFile roleFile, Map config, File nodeDir, Template template, String roleName, List roleVariantNames, String templateName, List generatedFiles) { MultiplyPlugin multiplyPlugin = defaultMultiplyPlugin; @@ -365,7 +365,10 @@ private void multiplyFiles(Role role, RoleFile roleFile, Map con } } - @SuppressWarnings("PMD.PreserveStackTrace") + @SuppressWarnings({ + "PMD.PreserveStackTrace", + "java:S107" // allow many parameters + }) @SuppressFBWarnings("RV_RETURN_VALUE_IGNORED_BAD_PRACTICE") private Collection generateFile(RoleFile roleFile, String dir, String fileName, String url, String symlinkTarget, diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/FileGenerator.java b/generator/src/main/java/io/wcm/devops/conga/generator/FileGenerator.java index 3be609c9..09f233e3 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/FileGenerator.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/FileGenerator.java @@ -97,14 +97,13 @@ class FileGenerator { static final String POSTPROCESSOR_KEY_FILE_HEADER = "postProcessor.fileHeader"; static final String POSTPROCESSOR_KEY_VALIDATORS = "postProcessor.validators"; - //CHECKSTYLE:OFF + @SuppressWarnings({ "java:S107", "checkstyle:ParameterNumberCheck" }) // allow many parameters FileGenerator(GeneratorOptions options, String environmentName, String roleName, List roleVariantNames, String templateName, File nodeDir, File file, String url, String symlinkTarget, RoleFile roleFile, Map config, Template template, VariableMapResolver variableMapResolver, UrlFileManager urlFileManager, PluginContextOptions pluginContextOptions, Collection dependencyVersions) { - //CHECKSTYLE:ON this.environmentName = environmentName; this.roleName = roleName; this.roleVariantNames = roleVariantNames; @@ -206,6 +205,10 @@ private List formatFileHeaderCommentLines(List lines) { * @return List of files that where generated directly or indirectly (by post processors). */ @SuppressFBWarnings({ "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD", "RV_RETURN_VALUE_IGNORED_BAD_PRACTICE" }) + @SuppressWarnings({ + "java:S3776", // ignore complexity + "java:S2696" // static variable set by intention + }) public Collection generate() throws IOException { File dir = file.getParentFile(); if (!dir.exists()) { diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/Generator.java b/generator/src/main/java/io/wcm/devops/conga/generator/Generator.java index 59d5d420..03217b42 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/Generator.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/Generator.java @@ -72,6 +72,7 @@ public void generate(String[] environmentNames) { * @param nodeNames Node names to generate. If none specified all nodes are generated. */ @SuppressFBWarnings("RV_RETURN_VALUE_IGNORED_BAD_PRACTICE") + @SuppressWarnings("java:S3776") // ignore complexity public void generate(String[] environmentNames, String[] nodeNames) { Map selectedEnvironments = new HashMap<>(); if (environmentNames == null || environmentNames.length == 0) { diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/export/NodeModelExport.java b/generator/src/main/java/io/wcm/devops/conga/generator/export/NodeModelExport.java index ae82efc4..6ec58493 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/export/NodeModelExport.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/export/NodeModelExport.java @@ -71,6 +71,7 @@ public final class NodeModelExport { * environment. * @param yamlRepresenter YAML representer */ + @SuppressWarnings("java:S107") // allow many parameters public NodeModelExport(File nodeDir, Node node, Environment environment, ModelExport modelExport, VariableStringResolver variableStringResolver, VariableMapResolver variableMapResolver, Map containerVersionInfo, PluginContextOptions pluginContextOptions, @@ -105,11 +106,9 @@ private boolean isActive() { * @param role Role name * @param roleVariants Role variant name * @param config Merged configuration (unresolved) - * @param sensitiveConfigParametersList List of configuration parameter names that contain sensitive data * @return Node role data */ - public ExportNodeRoleData addRole(String role, List roleVariants, Map config, - List sensitiveConfigParametersList) { + public ExportNodeRoleData addRole(String role, List roleVariants, Map config) { if (!isActive()) { return new ExportNodeRoleData(); } diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/plugins/fileheader/AbstractFileHeader.java b/generator/src/main/java/io/wcm/devops/conga/generator/plugins/fileheader/AbstractFileHeader.java index ba213fd9..2e918eac 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/plugins/fileheader/AbstractFileHeader.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/plugins/fileheader/AbstractFileHeader.java @@ -136,6 +136,7 @@ protected final FileHeaderContext extractFileHeaderBetweenBlockStartEnd(FileCont * @param file File File * @return File header or null */ + @SuppressWarnings("java:S3776") // ignore complexity protected final FileHeaderContext extractFileHeaderWithLinePrefixes(FileContext file) { try { if (StringUtils.isNotEmpty(getLineBreak()) && StringUtils.isNotEmpty(getCommentLinePrefix())) { diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/plugins/urlfile/FilesystemUrlFilePlugin.java b/generator/src/main/java/io/wcm/devops/conga/generator/plugins/urlfile/FilesystemUrlFilePlugin.java index 40b9bac8..6ae89d3e 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/plugins/urlfile/FilesystemUrlFilePlugin.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/plugins/urlfile/FilesystemUrlFilePlugin.java @@ -70,7 +70,7 @@ public String getFileName(String url, UrlFilePluginContext context) { public InputStream getFile(String url, UrlFilePluginContext context) throws IOException { File file = getFileInternal(url, context); if (!file.exists()) { - throw new FileNotFoundException("File does not exist: " + FileUtil.getCanonicalPath(file)); + throwFileNotFoundException(file); } return new BufferedInputStream(new FileInputStream(file)); } @@ -79,7 +79,7 @@ public InputStream getFile(String url, UrlFilePluginContext context) throws IOEx public URL getFileUrl(String url, UrlFilePluginContext context) throws IOException { File file = getFileInternal(url, context); if (!file.exists()) { - throw new FileNotFoundException("File does not exist: " + FileUtil.getCanonicalPath(file)); + throwFileNotFoundException(file); } return file.toURI().toURL(); } @@ -89,7 +89,7 @@ public URL getFileUrl(String url, UrlFilePluginContext context) throws IOExcepti public void deleteFile(String url, UrlFilePluginContext context) throws IOException { File file = getFileInternal(url, context); if (!file.exists()) { - throw new FileNotFoundException("File does not exist: " + FileUtil.getCanonicalPath(file)); + throwFileNotFoundException(file); } Files.delete(file.toPath()); } @@ -115,4 +115,8 @@ else if (StringUtils.startsWith(url, PREFIX_NODE)) { } } + private static void throwFileNotFoundException(File file) throws FileNotFoundException { + throw new FileNotFoundException("File does not exist: " + FileUtil.getCanonicalPath(file)); + } + } diff --git a/generator/src/main/java/io/wcm/devops/conga/generator/util/VariableStringResolver.java b/generator/src/main/java/io/wcm/devops/conga/generator/util/VariableStringResolver.java index 06a47f6f..db2f7b04 100644 --- a/generator/src/main/java/io/wcm/devops/conga/generator/util/VariableStringResolver.java +++ b/generator/src/main/java/io/wcm/devops/conga/generator/util/VariableStringResolver.java @@ -41,6 +41,7 @@ public final class VariableStringResolver { * ${provider::var1} * ${provider::Var1:defaultValue} */ + @SuppressWarnings("java:S125") // no commented out code private static final String NAME_PATTERN_STRING = "[^\\}\\{\\$\\:()'\"/\\#,;\\+\\*@!\\^\\s]"; private static final String NAME_PATTERN_STRING_NOT_EMPTY = NAME_PATTERN_STRING + "+"; private static final String NAME_PATTERN_STRING_OR_EMPTY = NAME_PATTERN_STRING + "*"; @@ -172,6 +173,7 @@ private Object resolve(String value, Map variables, int iteratio } } + @SuppressWarnings("java:S3776") // ignore complexity private Object resolveSingle(Matcher matcher, Map variables, int iterationCount) { boolean escapedVariable = StringUtils.equals(matcher.group(EXPRESSION_POS_DOLLAR_SIGN), "\\$"); String expression = matcher.group(EXPRESSION_POS_EXPRESSION); @@ -224,6 +226,7 @@ private Object resolveSingle(Matcher matcher, Map variables, int } } + @SuppressWarnings("java:S3776") // ignore complexity private Object resolveMulti(Matcher matcher, Map variables, int iterationCount) { StringBuffer sb = new StringBuffer(); boolean replacedAny = false; diff --git a/generator/src/test/java/io/wcm/devops/conga/generator/GeneratorTest.java b/generator/src/test/java/io/wcm/devops/conga/generator/GeneratorTest.java index 7f5e794e..3992fc13 100644 --- a/generator/src/test/java/io/wcm/devops/conga/generator/GeneratorTest.java +++ b/generator/src/test/java/io/wcm/devops/conga/generator/GeneratorTest.java @@ -50,6 +50,7 @@ void setUp(TestInfo testInfo) throws IOException { } @Test + @SuppressWarnings("java:S5961") // number of asserts void testAllEnvironments() { File node1Dir = assertDirectory(destDir, "env1/node1"); diff --git a/model/src/main/java/io/wcm/devops/conga/model/util/MapMerger.java b/model/src/main/java/io/wcm/devops/conga/model/util/MapMerger.java index 1a31cc16..47aeb805 100644 --- a/model/src/main/java/io/wcm/devops/conga/model/util/MapMerger.java +++ b/model/src/main/java/io/wcm/devops/conga/model/util/MapMerger.java @@ -48,7 +48,11 @@ private MapMerger() { * @param map2 Map 2 * @return Merged map */ - @SuppressWarnings("unchecked") + @SuppressWarnings({ + "unchecked", + "java:S3776", // ignore complexity + "java:S2234" // parameter arguments switched by intention + }) public static Map merge(Map map1, Map map2) { Map merged = new HashMap<>(); if (map1 == null || map2 == null) { diff --git a/model/src/main/java/io/wcm/devops/conga/model/util/MapSplitter.java b/model/src/main/java/io/wcm/devops/conga/model/util/MapSplitter.java index 0e50e6ba..e1da0627 100644 --- a/model/src/main/java/io/wcm/devops/conga/model/util/MapSplitter.java +++ b/model/src/main/java/io/wcm/devops/conga/model/util/MapSplitter.java @@ -43,7 +43,10 @@ private MapSplitter() { * @return Result with the first map (matching) with all matching values, and the second map (unmatching) with all * values that do not match. */ - @SuppressWarnings("unchecked") + @SuppressWarnings({ + "unchecked", + "java:S135" // multiple continue statements + }) public static @NotNull SplitResult splitMap(Map map, @NotNull Predicate> matcher) { Map matching = new HashMap<>(); diff --git a/model/src/test/java/io/wcm/devops/conga/model/reader/EnvironmentReaderTest.java b/model/src/test/java/io/wcm/devops/conga/model/reader/EnvironmentReaderTest.java index d255d738..48aaafde 100644 --- a/model/src/test/java/io/wcm/devops/conga/model/reader/EnvironmentReaderTest.java +++ b/model/src/test/java/io/wcm/devops/conga/model/reader/EnvironmentReaderTest.java @@ -118,13 +118,13 @@ void testTenant() { } @Test - void testEnvironmentWithNullTenant() { - assertThrows(ConstructorException.class, () -> { - EnvironmentReader reader = new EnvironmentReader(); - try (InputStream is = getClass().getResourceAsStream("/environment_null_tenant.yaml")) { + void testEnvironmentWithNullTenant() throws IOException { + EnvironmentReader reader = new EnvironmentReader(); + try (InputStream is = getClass().getResourceAsStream("/environment_null_tenant.yaml")) { + assertThrows(ConstructorException.class, () -> { reader.read(is); - } - }); + }); + } } @Test diff --git a/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/AbstractCongaMojo.java b/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/AbstractCongaMojo.java index d1584d90..2bea94af 100644 --- a/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/AbstractCongaMojo.java +++ b/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/AbstractCongaMojo.java @@ -279,6 +279,7 @@ private File buildJarFile(File contentDirectory) throws MojoExecutionException { return jarFile; } + @SuppressWarnings("java:S1168") // null array is allowed private String[] toArray(List values) { if (values == null || values.isEmpty()) { return null; diff --git a/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/PackageMojo.java b/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/PackageMojo.java index bef29bb2..51c122f2 100644 --- a/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/PackageMojo.java +++ b/tooling/conga-maven-plugin/src/main/java/io/wcm/devops/conga/tooling/maven/plugin/PackageMojo.java @@ -77,7 +77,10 @@ public void execute() throws MojoExecutionException, MojoFailureException { } - @SuppressWarnings("PMD.UseStringBufferForStringAppends") + @SuppressWarnings({ + "PMD.UseStringBufferForStringAppends", + "java:S3776" // ignore complexity + }) private void buildGeneratedConfigurationAttachments() throws MojoExecutionException, MojoFailureException { Set selectedEnvironments; if (environments != null && environments.length > 0) { @@ -167,6 +170,7 @@ private File buildZipFile(File contentDirectory, String classifier) throws MojoE * @param basePath Base path * @param directory Directory to include */ + @SuppressWarnings("java:S3776") // ignore complexity private void addZipDirectory(String basePath, File directory) throws MojoExecutionException { String directoryPath = toZipDirectoryPath(directory); if (StringUtils.startsWith(directoryPath, basePath)) { From 0340a8f436a844b0045fbaaff2d336faa0d7e434 Mon Sep 17 00:00:00 2001 From: Stefan Seifert Date: Mon, 22 Jan 2024 12:38:04 +0100 Subject: [PATCH 22/26] add dependency note --- parent/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/parent/pom.xml b/parent/pom.xml index 52cb481f..ef83493e 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -116,6 +116,7 @@ org.springframework spring-core + 5.3.31 From 59c2c61dd755baaf79b7df20592ff2c350128cc3 Mon Sep 17 00:00:00 2001 From: Stefan Seifert Date: Thu, 25 Jan 2024 12:33:47 +0100 Subject: [PATCH 23/26] Eliminate SonarQube warnings --- .../src/main/java/io/wcm/devops/conga/tooling/cli/CongaCli.java | 1 + 1 file changed, 1 insertion(+) diff --git a/tooling/conga-cli/src/main/java/io/wcm/devops/conga/tooling/cli/CongaCli.java b/tooling/conga-cli/src/main/java/io/wcm/devops/conga/tooling/cli/CongaCli.java index 9a518746..f820a6fb 100644 --- a/tooling/conga-cli/src/main/java/io/wcm/devops/conga/tooling/cli/CongaCli.java +++ b/tooling/conga-cli/src/main/java/io/wcm/devops/conga/tooling/cli/CongaCli.java @@ -35,6 +35,7 @@ /** * CONGA command line interface. */ +@SuppressWarnings("java:S1192") // duplicate string literals public final class CongaCli { /** From dbad068234288cbc1e2cde2a1f576302cb1960d3 Mon Sep 17 00:00:00 2001 From: Stefan Seifert Date: Thu, 25 Jan 2024 17:26:49 +0100 Subject: [PATCH 24/26] update parent dependency --- parent/pom.xml | 2 +- tooling/conga-maven-plugin/src/it/example/environments/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/parent/pom.xml b/parent/pom.xml index ef83493e..36e6575b 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -25,7 +25,7 @@ io.wcm.devops io.wcm.devops.parent_toplevel - 1.4.3-SNAPSHOT + 1.4.4 diff --git a/tooling/conga-maven-plugin/src/it/example/environments/pom.xml b/tooling/conga-maven-plugin/src/it/example/environments/pom.xml index e70a2441..8c815454 100644 --- a/tooling/conga-maven-plugin/src/it/example/environments/pom.xml +++ b/tooling/conga-maven-plugin/src/it/example/environments/pom.xml @@ -51,7 +51,7 @@ io.wcm.devops io.wcm.devops.parent_toplevel - 1.4.2 + 1.4.4 xml site compile From e3a41a9523d47d00d182829f6b9fb198cfb3c3b5 Mon Sep 17 00:00:00 2001 From: Stefan Seifert Date: Fri, 26 Jan 2024 11:13:53 +0100 Subject: [PATCH 25/26] prepare release --- changes.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changes.xml b/changes.xml index c908812c..def3d735 100644 --- a/changes.xml +++ b/changes.xml @@ -23,7 +23,7 @@ xsi:schemaLocation="http://maven.apache.org/changes/1.0.0 https://maven.apache.org/plugins/maven-changes-plugin/xsd/changes-1.0.0.xsd"> - + Special handling for detecting ".cfg.json" file extensions. From 817be422d35393563137df0cd300d29c584b286f Mon Sep 17 00:00:00 2001 From: Stefan Seifert Date: Fri, 26 Jan 2024 11:16:24 +0100 Subject: [PATCH 26/26] [gitflow-maven-plugin] Update versions for release 1.17.0 --- generator/pom.xml | 4 ++-- model/pom.xml | 4 ++-- parent/pom.xml | 2 +- pom.xml | 4 ++-- resource/pom.xml | 2 +- tooling/conga-cli/pom.xml | 4 ++-- tooling/conga-maven-plugin/pom.xml | 4 ++-- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/generator/pom.xml b/generator/pom.xml index 39211504..f11dacce 100644 --- a/generator/pom.xml +++ b/generator/pom.xml @@ -25,7 +25,7 @@ io.wcm.devops.conga io.wcm.devops.conga.parent - 1.17.0-SNAPSHOT + 1.17.0 ../parent/pom.xml @@ -44,7 +44,7 @@ io.wcm.devops.conga io.wcm.devops.conga.model - 1.17.0-SNAPSHOT + 1.17.0 compile diff --git a/model/pom.xml b/model/pom.xml index 2e548cf8..38cece12 100644 --- a/model/pom.xml +++ b/model/pom.xml @@ -25,7 +25,7 @@ io.wcm.devops.conga io.wcm.devops.conga.parent - 1.17.0-SNAPSHOT + 1.17.0 ../parent/pom.xml @@ -40,7 +40,7 @@ io.wcm.devops.conga io.wcm.devops.conga.resource - 1.17.0-SNAPSHOT + 1.17.0 compile diff --git a/parent/pom.xml b/parent/pom.xml index 36e6575b..b9007fb1 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -31,7 +31,7 @@ io.wcm.devops.conga io.wcm.devops.conga.parent - 1.17.0-SNAPSHOT + 1.17.0 pom CONGA diff --git a/pom.xml b/pom.xml index cb61fba3..20834ea3 100644 --- a/pom.xml +++ b/pom.xml @@ -25,13 +25,13 @@ io.wcm.devops.conga io.wcm.devops.conga.parent - 1.17.0-SNAPSHOT + 1.17.0 parent/pom.xml io.wcm.devops.conga io.wcm.devops.conga.root - 1.17.0-SNAPSHOT + 1.17.0 pom CONGA diff --git a/resource/pom.xml b/resource/pom.xml index 897edd08..426ceb78 100644 --- a/resource/pom.xml +++ b/resource/pom.xml @@ -25,7 +25,7 @@ io.wcm.devops.conga io.wcm.devops.conga.parent - 1.17.0-SNAPSHOT + 1.17.0 ../parent/pom.xml diff --git a/tooling/conga-cli/pom.xml b/tooling/conga-cli/pom.xml index 72095007..2b215510 100644 --- a/tooling/conga-cli/pom.xml +++ b/tooling/conga-cli/pom.xml @@ -25,7 +25,7 @@ io.wcm.devops.conga io.wcm.devops.conga.parent - 1.17.0-SNAPSHOT + 1.17.0 ../../parent/pom.xml @@ -40,7 +40,7 @@ io.wcm.devops.conga io.wcm.devops.conga.generator - 1.17.0-SNAPSHOT + 1.17.0 compile diff --git a/tooling/conga-maven-plugin/pom.xml b/tooling/conga-maven-plugin/pom.xml index bc3e75c6..bc094e35 100644 --- a/tooling/conga-maven-plugin/pom.xml +++ b/tooling/conga-maven-plugin/pom.xml @@ -25,7 +25,7 @@ io.wcm.devops.conga io.wcm.devops.conga.parent - 1.17.0-SNAPSHOT + 1.17.0 ../../parent/pom.xml @@ -56,7 +56,7 @@ io.wcm.devops.conga io.wcm.devops.conga.generator - 1.17.0-SNAPSHOT + 1.17.0 compile