From 65d3ce5859dc8de3652f5a92f55957814d873440 Mon Sep 17 00:00:00 2001 From: Stefan Seifert Date: Mon, 22 Jan 2024 11:12:40 +0100 Subject: [PATCH] Eliminate SonarQube warnings --- .../devops/conga/generator/FileGenerator.java | 10 ++++----- .../CharsetAwareTemplateSource.java | 1 + .../handlebars/HandlebarsManager.java | 9 ++------ .../fileheader/AbstractFileHeader.java | 2 +- .../helper/AbstractEachIfHelper.java | 10 ++++----- .../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 | 1 + .../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 ++-- 23 files changed, 75 insertions(+), 80 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 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 0434b48d..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 @@ -102,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/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 94c804e0..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 @@ -359,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/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));