Skip to content

Commit

Permalink
eliminate code warning
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseifert committed Jan 10, 2024
1 parent d6750d3 commit 2594e16
Showing 21 changed files with 82 additions and 106 deletions.
Original file line number Diff line number Diff line change
@@ -19,11 +19,11 @@
*/
package io.wcm.devops.conga.plugins.aem.handlebars.escaping;

import java.util.Map;

import org.apache.commons.text.translate.CharSequenceTranslator;
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;
@@ -44,7 +44,7 @@ public class AnyEscapingStrategy implements EscapingStrategyPlugin {
* Defines translations for strings in ANY files.
*/
private static final CharSequenceTranslator ESCAPE_ANY =
new LookupTranslator(ImmutableMap.of(
new LookupTranslator(Map.of(
"\"", "\\\"",
"\\", "\\\\"));

Original file line number Diff line number Diff line change
@@ -29,7 +29,6 @@
import com.github.jknack.handlebars.Context;
import com.github.jknack.handlebars.Options;
import com.github.jknack.handlebars.Options.Buffer;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;

import io.wcm.devops.conga.generator.spi.handlebars.HelperPlugin;
@@ -45,7 +44,7 @@ abstract class AbstractCloudManagerConditionalHelper implements HelperPlugin<Obj

static final String HTTPD_KEY = "httpd";
static final String CLOUD_MANAGER_CONDITIONAL_KEY = "cloudManagerConditional";
static final List<String> ENVIRONMENTS = ImmutableList.of("dev", "stage", "prod");
static final List<String> ENVIRONMENTS = List.of("dev", "stage", "prod");

@Override
@SuppressWarnings("unchecked")
@@ -96,7 +95,7 @@ protected abstract void renderBodyContent(Buffer buffer, CharSequence bodyConten

private List<CloudManagerConditional> getCloudManagerConditional(Map<String, Object> cloudManagerConditional) {
return ENVIRONMENTS.stream()
.map(env -> new CloudManagerConditional(env, cloudManagerConditional.getOrDefault(env, ImmutableMap.of())))
.map(env -> new CloudManagerConditional(env, cloudManagerConditional.getOrDefault(env, Map.of())))
.collect(Collectors.toList());
}

@@ -115,7 +114,7 @@ private static class CloudManagerConditional {
this.config = (Map<String, Object>)value;
}
else {
this.config = ImmutableMap.of();
this.config = Map.of();
}
}

Original file line number Diff line number Diff line change
@@ -29,8 +29,6 @@
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;

import com.google.common.collect.ImmutableList;

import io.wcm.devops.conga.generator.GeneratorException;
import io.wcm.devops.conga.generator.plugins.postprocessor.AbstractPostProcessor;
import io.wcm.devops.conga.generator.spi.ImplicitApplyOptions;
@@ -103,7 +101,7 @@ public List<FileContext> apply(FileContext fileContext, PostProcessorContext con
throw new GeneratorException("Unable to extract properties from AEM package " + fileContext.getCanonicalPath(), ex);
}

return ImmutableList.of();
return List.of();
}

}
Original file line number Diff line number Diff line change
@@ -51,8 +51,6 @@
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;

import com.google.common.collect.ImmutableMap;

import io.wcm.devops.conga.generator.GeneratorException;
import io.wcm.devops.conga.generator.UrlFileManager;
import io.wcm.devops.conga.generator.spi.context.FileHeaderContext;
@@ -230,7 +228,7 @@ else if (rootPath != null) {
private static Map<String,Object> getAdditionalyProperties(Map<String, Object> options) {
Map<String, Object> props = getOptionalPropMap(options, PROPERTY_PACKAGE_PROPERTIES);
if (props == null) {
props = ImmutableMap.of();
props = Map.of();
}
return props;
}
Original file line number Diff line number Diff line change
@@ -34,8 +34,6 @@
import org.apache.sling.contentparser.json.JSONParserOptions;
import org.apache.sling.contentparser.json.internal.JSONContentParser;

import com.google.common.collect.ImmutableSet;

import io.wcm.devops.conga.generator.GeneratorException;
import io.wcm.devops.conga.generator.util.FileUtil;
import io.wcm.tooling.commons.contentpackagebuilder.element.ContentElement;
@@ -45,7 +43,7 @@
*/
public final class JsonContentLoader {

private static final Set<String> IGNORED_NAMES = ImmutableSet.of(
private static final Set<String> IGNORED_NAMES = Set.of(
JcrConstants.JCR_BASEVERSION,
JcrConstants.JCR_PREDECESSORS,
JcrConstants.JCR_SUCCESSORS,
Original file line number Diff line number Diff line change
@@ -35,8 +35,6 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;

import com.google.common.collect.ImmutableMap;

import io.wcm.devops.conga.generator.spi.ImplicitApplyOptions;
import io.wcm.devops.conga.generator.spi.ValidationException;
import io.wcm.devops.conga.generator.spi.ValidatorPlugin;
@@ -63,8 +61,8 @@ public class ContentPackageValidator implements ValidatorPlugin {
private static final String OPTION_VALIDATORS_SETTINGS = "contentPackage.validatorsSettings";

// apply default validation for AEM and wcm.io node types
private static final Map<String, Object> DEFAULT_VALIDATORS_SETTINGS = ImmutableMap.of("jackrabbit-nodetypes",
ImmutableMap.of("options", ImmutableMap.of("cnds", "tccl:aem.cnd,tccl:wcmio.cnd")));
private static final Map<String, Object> DEFAULT_VALIDATORS_SETTINGS = Map.of("jackrabbit-nodetypes",
Map.of("options", Map.of("cnds", "tccl:aem.cnd,tccl:wcmio.cnd")));

@Override
public String getName() {
Original file line number Diff line number Diff line change
@@ -30,8 +30,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;
@@ -51,7 +49,7 @@ void testApply() throws Exception {
File file = new File("target/generation-test/fileHeader.any");
FileUtils.write(file, "myany { }", StandardCharsets.UTF_8);

List<String> lines = ImmutableList.of("Der Jodelkaiser", "aus dem Oetztal", "ist wieder daheim.");
List<String> lines = List.of("Der Jodelkaiser", "aus dem Oetztal", "ist wieder daheim.");
FileHeaderContext context = new FileHeaderContext().commentLines(lines);
FileContext fileContext = new FileContext().file(file);

Original file line number Diff line number Diff line change
@@ -30,12 +30,11 @@
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.IOException;
import java.util.Map;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import com.google.common.collect.ImmutableMap;

import io.wcm.devops.conga.generator.UrlFileManager;
import io.wcm.devops.conga.generator.spi.context.PluginContextOptions;
import io.wcm.devops.conga.generator.spi.context.UrlFilePluginContext;
@@ -82,15 +81,15 @@ void testWithoutKey() throws Exception {
@Test
void testWithoutKey_Skip() throws Exception {
pluginContext.getGenericPluginConfig().put(PLUGIN_NAME,
ImmutableMap.of(PARAMETER_CRYPTO_SKIP, true));
Map.of(PARAMETER_CRYPTO_SKIP, true));

assertHelper(INPUT, helper, INPUT, new MockOptions(), pluginContext);
}

@Test
void testEncrypt() throws Exception {
pluginContext.getGenericPluginConfig().put(PLUGIN_NAME,
ImmutableMap.of(PARAMETER_CRYPTO_AES_KEY_URL, "classpath:/crypto/master"));
Map.of(PARAMETER_CRYPTO_AES_KEY_URL, "classpath:/crypto/master"));

String encrypted = (String)executeHelper(helper, INPUT, new MockOptions(), pluginContext);
assertTrue(CryptoString.isCryptoString(encrypted));
@@ -99,7 +98,7 @@ void testEncrypt() throws Exception {
@Test
void testEncrypt_Skip() throws Exception {
pluginContext.getGenericPluginConfig().put(PLUGIN_NAME,
ImmutableMap.of(PARAMETER_CRYPTO_AES_KEY_URL, "classpath:/crypto/master",
Map.of(PARAMETER_CRYPTO_AES_KEY_URL, "classpath:/crypto/master",
PARAMETER_CRYPTO_SKIP, "true"));

assertHelper(INPUT, helper, INPUT, new MockOptions(), pluginContext);
Original file line number Diff line number Diff line change
@@ -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.handlebars.HelperPlugin;
import io.wcm.devops.conga.generator.util.PluginManagerImpl;

@@ -45,7 +43,7 @@ void setUp() {
@Test
void testUrl() throws Exception {
assertHelper("{ /type \"allow\" /url '/abc(/.*)?' }",
helper, ImmutableMap.of("type", "allow", "url", "/abc(/.*)?"), new MockOptions());
helper, Map.of("type", "allow", "url", "/abc(/.*)?"), new MockOptions());
}

@Test
Original file line number Diff line number Diff line change
@@ -21,11 +21,11 @@

import static io.wcm.devops.conga.plugins.aem.handlebars.helper.TestUtils.assertHelper;

import java.util.Map;

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.handlebars.HelperPlugin;
import io.wcm.devops.conga.generator.util.PluginManagerImpl;

@@ -49,7 +49,7 @@ void testLocation() throws Exception {
" Require all granted\n" +
" </IfVersion>\n" +
"</Location>",
helper, ImmutableMap.of("type", "allow", "location", "/abc"), new MockOptions());
helper, Map.of("type", "allow", "location", "/abc"), new MockOptions());
}

@Test
@@ -63,7 +63,7 @@ void testLocationMatch() throws Exception {
" Require all denied\n" +
" </IfVersion>\n" +
"</LocationMatch>",
helper, ImmutableMap.of("type", "deny", "locationMatch", "/abc(/.*)?"), new MockOptions());
helper, Map.of("type", "deny", "locationMatch", "/abc(/.*)?"), new MockOptions());
}

@Test
@@ -77,7 +77,7 @@ void testLocationDenyAllowAdmin_NoHash() throws Exception {
" Require all denied\n" +
" </IfVersion>\n" +
"</Location>",
helper, ImmutableMap.of("type", "deny_allow_admin", "location", "/abc"), new MockOptions());
helper, Map.of("type", "deny_allow_admin", "location", "/abc"), new MockOptions());
}

@Test
@@ -95,7 +95,7 @@ void testLocationDenyAllowAdmin() throws Exception {
" Require host myhost\n" +
" </IfVersion>\n" +
"</Location>",
helper, ImmutableMap.of("type", "deny_allow_admin", "location", "/abc"), new MockOptions()
helper, Map.of("type", "deny_allow_admin", "location", "/abc"), new MockOptions()
.withHash(AemHttpdFilterHelper.HASH_ALLOW_FROM_KEY, "allowFrom")
.withHash(AemHttpdFilterHelper.HASH_ALLOW_FROM_HOST_KEY, "allowFromHost")
.withProperty("allowFrom", "1.2.3.4")
Original file line number Diff line number Diff line change
@@ -28,55 +28,53 @@

import org.junit.jupiter.api.Test;

import com.google.common.collect.ImmutableMap;

class DispatcherFilterTest {

@Test
void testEmpty() {
assertThrows(IllegalArgumentException.class, () -> {
new DispatcherFilter(ImmutableMap.of());
new DispatcherFilter(Map.of());
});
}

@Test
void testOnlyType() {
assertThrows(IllegalArgumentException.class, () -> {
new DispatcherFilter(ImmutableMap.of("type", "allow"));
new DispatcherFilter(Map.of("type", "allow"));
});
}

@Test
void testTypeMissing() {
assertThrows(IllegalArgumentException.class, () -> {
new DispatcherFilter(ImmutableMap.of("glob", "abc"));
new DispatcherFilter(Map.of("glob", "abc"));
});
}

@Test
void testIllegalType() {
assertThrows(IllegalArgumentException.class, () -> {
new DispatcherFilter(ImmutableMap.of("glob", "abc", "type", "this_is_not_a_valid_value"));
new DispatcherFilter(Map.of("glob", "abc", "type", "this_is_not_a_valid_value"));
});
}

@Test
void testIllegalRegexp() {
assertThrows(IllegalArgumentException.class, () -> {
new DispatcherFilter(ImmutableMap.of("glob", "(abc", "type", "allow"));
new DispatcherFilter(Map.of("glob", "(abc", "type", "allow"));
});
}

@Test
void testInvalidParam() {
assertThrows(IllegalArgumentException.class, () -> {
new DispatcherFilter(ImmutableMap.of("glob", "abc", "type", "allow", "invalidParam", "value"));
new DispatcherFilter(Map.of("glob", "abc", "type", "allow", "invalidParam", "value"));
});
}

@Test
void testUrl() {
DispatcherFilter underTest = new DispatcherFilter(ImmutableMap.of("url", "/abc", "type", "allow"));
DispatcherFilter underTest = new DispatcherFilter(Map.of("url", "/abc", "type", "allow"));
assertEquals(DispatcherFilterType.ALLOW, underTest.getType());
assertNull(underTest.getMethod());
assertEquals("/abc", underTest.getUrl());
Original file line number Diff line number Diff line change
@@ -28,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.spi.handlebars.HelperPlugin;
import io.wcm.devops.conga.generator.util.PluginManagerImpl;

@@ -45,33 +43,33 @@ void setUp() {

@Test
void testApply() throws IOException {
Map<String, Object> model = ImmutableMap.of("httpd", ImmutableMap.of("serverName", "host1"));
Map<String, Object> model = Map.of("httpd", Map.of("serverName", "host1"));
MockOptions options = new MockOptions(model);

assertHelper(FN_RETURN + "(" + model + ")", helper, null, options);
}

@Test
void testApplySeparateModel() throws IOException {
Map<String, Object> model = ImmutableMap.of("httpd", ImmutableMap.of("serverName", "host1"));
Map<String, Object> model = Map.of("httpd", Map.of("serverName", "host1"));
MockOptions options = new MockOptions();

assertHelper(FN_RETURN + "(" + model + ")", helper, model, options);
}

@Test
void testApplyWithCloudManagerConditional() throws IOException {
Map<String, Object> model = ImmutableMap.of("httpd",
ImmutableMap.of("serverName", "host0",
"cloudManagerConditional", ImmutableMap.of(
"dev", ImmutableMap.of("serverName", "host1"),
"stage", ImmutableMap.of("serverName", "host2"),
"prod", ImmutableMap.of())));
Map<String, Object> model = Map.of("httpd",
Map.of("serverName", "host0",
"cloudManagerConditional", Map.of(
"dev", Map.of("serverName", "host1"),
"stage", Map.of("serverName", "host2"),
"prod", Map.of())));
MockOptions options = new MockOptions(model);

Map<String, Object> model_dev = ImmutableMap.of("httpd", ImmutableMap.of("serverName", "host1"));
Map<String, Object> model_stage = ImmutableMap.of("httpd", ImmutableMap.of("serverName", "host2"));
Map<String, Object> model_prod = ImmutableMap.of("httpd", ImmutableMap.of("serverName", "host0"));
Map<String, Object> model_dev = Map.of("httpd", Map.of("serverName", "host1"));
Map<String, Object> model_stage = Map.of("httpd", Map.of("serverName", "host2"));
Map<String, Object> model_prod = Map.of("httpd", Map.of("serverName", "host0"));
assertHelper("<IfDefine ENVIRONMENT_DEV>" + FN_RETURN + "(" + model_dev + ")</IfDefine>\n"
+ "<IfDefine ENVIRONMENT_STAGE>" + FN_RETURN + "(" + model_stage + ")</IfDefine>\n"
+ "<IfDefine ENVIRONMENT_PROD>" + FN_RETURN + "(" + model_prod + ")</IfDefine>\n",
Loading

0 comments on commit 2594e16

Please sign in to comment.