Skip to content

Commit 127eadc

Browse files
committed
eliminate code warnings, make use of java 17 syntax
1 parent a36d0b6 commit 127eadc

14 files changed

Lines changed: 112 additions & 89 deletions

File tree

conga-aem-plugin/src/main/java/io/wcm/devops/conga/plugins/aem/handlebars/helper/AbstractCloudManagerConditionalHelper.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.io.IOException;
2323
import java.util.List;
2424
import java.util.Map;
25-
import java.util.stream.Collectors;
2625

2726
import org.apache.commons.lang3.StringUtils;
2827

@@ -95,7 +94,7 @@ protected abstract void renderBodyContent(Buffer buffer, CharSequence bodyConten
9594
private List<CloudManagerConditional> getCloudManagerConditional(Map<String, Object> cloudManagerConditional) {
9695
return ENVIRONMENTS.stream()
9796
.map(env -> new CloudManagerConditional(env, cloudManagerConditional.getOrDefault(env, Map.of())))
98-
.collect(Collectors.toList());
97+
.toList();
9998
}
10099

101100
/**

conga-aem-plugin/src/main/java/io/wcm/devops/conga/plugins/aem/handlebars/helper/AbstractFilter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ abstract class AbstractFilter {
3737
protected final String getValue(Map<String, Object> map, String key) {
3838
// get and remove value from map
3939
Object value = map.remove(key);
40-
if (value instanceof String) {
41-
return (String)value;
40+
if (value instanceof String stringValue) {
41+
return stringValue;
4242
}
4343
else {
4444
return null;

conga-aem-plugin/src/main/java/io/wcm/devops/conga/plugins/aem/handlebars/helper/AbstractFilterHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public final Object apply(Object context, Options options, HelperContext pluginC
5151
private String toYaml(Map<String, Object> filterMap) {
5252
StringBuilder sb = new StringBuilder();
5353
filterMap.entrySet().forEach(entry -> {
54-
if (sb.length() == 0) {
54+
if (sb.isEmpty()) {
5555
sb.append("- ");
5656
}
5757
else {

conga-aem-plugin/src/main/java/io/wcm/devops/conga/plugins/aem/handlebars/helper/AemCryptoEncryptHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ public Object apply(Object context, Options options, HelperContext pluginContext
7777
cryptoAesKeyUrl = Objects.toString(aemPluginConfig.get(PARAMETER_CRYPTO_AES_KEY_URL), null);
7878
Object cryptoSkipObject = aemPluginConfig.get(PARAMETER_CRYPTO_SKIP);
7979
if (cryptoSkipObject != null) {
80-
if (cryptoSkipObject instanceof Boolean) {
81-
cryptoSkip = (Boolean)cryptoSkipObject;
80+
if (cryptoSkipObject instanceof Boolean booleanValue) {
81+
cryptoSkip = booleanValue;
8282
}
8383
else {
8484
cryptoSkip = BooleanUtils.toBoolean(cryptoSkipObject.toString());

conga-aem-plugin/src/main/java/io/wcm/devops/conga/plugins/aem/util/ContentPackageUtil.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import java.util.Objects;
4848
import java.util.regex.Matcher;
4949
import java.util.regex.Pattern;
50-
import java.util.stream.Collectors;
5150
import java.util.stream.Stream;
5251

5352
import org.apache.commons.lang3.BooleanUtils;
@@ -233,8 +232,8 @@ private static AcHandling getAcHandling(Map<String, Object> options) {
233232
*/
234233
public static String getMandatoryProp(Map<String, Object> options, String key) {
235234
Object value = MapExpander.getDeep(options, key);
236-
if (value instanceof String) {
237-
return (String)value;
235+
if (value instanceof String stringValue) {
236+
return stringValue;
238237
}
239238
else if (value != null) {
240239
return value.toString();
@@ -250,8 +249,8 @@ else if (value != null) {
250249
*/
251250
public static String getOptionalProp(Map<String, Object> options, String key) {
252251
Object value = MapExpander.getDeep(options, key);
253-
if (value instanceof String) {
254-
return (String)value;
252+
if (value instanceof String stringValue) {
253+
return stringValue;
255254
}
256255
else if (value != null) {
257256
return value.toString();
@@ -267,8 +266,8 @@ else if (value != null) {
267266
*/
268267
public static boolean getOptionalPropBoolean(Map<String, Object> options, String key) {
269268
Object value = getOptionalProp(options, key);
270-
if (value instanceof Boolean) {
271-
return (Boolean)value;
269+
if (value instanceof Boolean booleanValue) {
270+
return booleanValue;
272271
}
273272
else if (value != null) {
274273
return BooleanUtils.toBoolean(value.toString());
@@ -369,7 +368,7 @@ private static List<ContentPackageBinaryFile> getMatchingFiles(File targetDir, S
369368
}
370369
})
371370
.filter(Objects::nonNull)
372-
.collect(Collectors.toList());
371+
.toList();
373372
}
374373
}
375374

conga-aem-plugin/src/main/java/io/wcm/devops/conga/plugins/aem/validator/ContentPackageValidator.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ public Void apply(FileContext file, ValidatorContext context) throws ValidationE
9090
// validate package if a package type is defined
9191
// supported only within Maven
9292
String packageType = Objects.toString(ContentPackageProperties.get(file.getFile()).get(NAME_PACKAGE_TYPE), null);
93-
if (packageType != null && context.getContainerContext() instanceof MavenContext) {
94-
validateContentPackage(file.getFile(), context, (MavenContext)context.getContainerContext());
93+
if (packageType != null && context.getContainerContext() instanceof MavenContext mavenContext) {
94+
validateContentPackage(file.getFile(), context, mavenContext);
9595
}
9696
}
9797
catch (IOException | IllegalAccessException | MojoExecutionException | MojoFailureException
@@ -176,24 +176,24 @@ private Map<String, ValidatorSettings> toValidatorsSettings(Map<String, Object>
176176
@SuppressWarnings("unchecked")
177177
private Map<String, Object> toMap(Object value) {
178178
if (value instanceof Map) {
179-
return (Map)value;
179+
return (Map<String, Object>)value;
180180
}
181181
return Collections.emptyMap();
182182
}
183183

184184
private boolean toBoolean(Object value) {
185-
if (value instanceof Boolean) {
186-
return (Boolean)value;
185+
if (value instanceof Boolean booleanValue) {
186+
return booleanValue;
187187
}
188-
if (value instanceof String) {
189-
return BooleanUtils.toBoolean((String)value);
188+
if (value instanceof String stringValue) {
189+
return BooleanUtils.toBoolean(stringValue);
190190
}
191191
return false;
192192
}
193193

194194
private String toString(Object value) {
195-
if (value instanceof String) {
196-
return (String)value;
195+
if (value instanceof String stringValue) {
196+
return stringValue;
197197
}
198198
else if (value != null) {
199199
return value.toString();

conga-aem-plugin/src/test/java/io/wcm/devops/conga/plugins/aem/handlebars/helper/AemHttpdFilterHelperTest.java

Lines changed: 44 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -41,65 +41,69 @@ void setUp() {
4141

4242
@Test
4343
void testLocation() throws Exception {
44-
assertHelper("<Location \"/abc\">\n" +
45-
" <IfVersion < 2.4>\n" +
46-
" Allow from all\n" +
47-
" </IfVersion>\n" +
48-
" <IfVersion >= 2.4>\n" +
49-
" Require all granted\n" +
50-
" </IfVersion>\n" +
51-
"</Location>",
44+
assertHelper("""
45+
<Location "/abc">
46+
<IfVersion < 2.4>
47+
Allow from all
48+
</IfVersion>
49+
<IfVersion >= 2.4>
50+
Require all granted
51+
</IfVersion>
52+
</Location>""",
5253
helper, Map.of("type", "allow", "location", "/abc"), new MockOptions());
5354
}
5455

5556
@Test
5657
void testLocationMatch() throws Exception {
57-
assertHelper("<LocationMatch \"/abc(/.*)?\">\n" +
58-
" <IfVersion < 2.4>\n" +
59-
" Order Deny,Allow\n" +
60-
" Deny from all\n" +
61-
" </IfVersion>\n" +
62-
" <IfVersion >= 2.4>\n" +
63-
" Require all denied\n" +
64-
" </IfVersion>\n" +
65-
"</LocationMatch>",
58+
assertHelper("""
59+
<LocationMatch "/abc(/.*)?">
60+
<IfVersion < 2.4>
61+
Order Deny,Allow
62+
Deny from all
63+
</IfVersion>
64+
<IfVersion >= 2.4>
65+
Require all denied
66+
</IfVersion>
67+
</LocationMatch>""",
6668
helper, Map.of("type", "deny", "locationMatch", "/abc(/.*)?"), new MockOptions());
6769
}
6870

6971
@Test
7072
void testLocationDenyAllowAdmin_NoHash() throws Exception {
71-
assertHelper("<Location \"/abc\">\n" +
72-
" <IfVersion < 2.4>\n" +
73-
" Order Deny,Allow\n" +
74-
" Deny from all\n" +
75-
" </IfVersion>\n" +
76-
" <IfVersion >= 2.4>\n" +
77-
" Require all denied\n" +
78-
" </IfVersion>\n" +
79-
"</Location>",
73+
assertHelper("""
74+
<Location "/abc">
75+
<IfVersion < 2.4>
76+
Order Deny,Allow
77+
Deny from all
78+
</IfVersion>
79+
<IfVersion >= 2.4>
80+
Require all denied
81+
</IfVersion>
82+
</Location>""",
8083
helper, Map.of("type", "deny_allow_admin", "location", "/abc"), new MockOptions());
8184
}
8285

8386
@Test
8487
void testLocationDenyAllowAdmin() throws Exception {
85-
assertHelper("<Location \"/abc\">\n" +
86-
" <IfVersion < 2.4>\n" +
87-
" Order Deny,Allow\n" +
88-
" Deny from all\n" +
89-
" Allow from 1.2.3.4\n" +
90-
" Allow from myhost\n" +
91-
" </IfVersion>\n" +
92-
" <IfVersion >= 2.4>\n" +
93-
" Require all denied\n" +
94-
" Require ip 1.2.3.4\n" +
95-
" Require host myhost\n" +
96-
" </IfVersion>\n" +
97-
"</Location>",
88+
assertHelper("""
89+
<Location "/abc">
90+
<IfVersion < 2.4>
91+
Order Deny,Allow
92+
Deny from all
93+
Allow from 1.2.3.4
94+
Allow from myhost
95+
</IfVersion>
96+
<IfVersion >= 2.4>
97+
Require all denied
98+
Require ip 1.2.3.4
99+
Require host myhost
100+
</IfVersion>
101+
</Location>""",
98102
helper, Map.of("type", "deny_allow_admin", "location", "/abc"), new MockOptions()
99103
.withHash(AemHttpdFilterHelper.HASH_ALLOW_FROM_KEY, "allowFrom")
100104
.withHash(AemHttpdFilterHelper.HASH_ALLOW_FROM_HOST_KEY, "allowFromHost")
101105
.withProperty("allowFrom", "1.2.3.4")
102106
.withProperty("allowFromHost", "myhost"));
103107
}
104108

105-
}
109+
}

conga-aem-plugin/src/test/java/io/wcm/devops/conga/plugins/aem/handlebars/helper/HttpdCloudManagerConditionalHelperTest.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,12 @@ void testApplyWithCloudManagerConditional() throws IOException {
7070
Map<String, Object> model_dev = Map.of("httpd", Map.of("serverName", "host1"));
7171
Map<String, Object> model_stage = Map.of("httpd", Map.of("serverName", "host2"));
7272
Map<String, Object> model_prod = Map.of("httpd", Map.of("serverName", "host0"));
73-
assertHelper("<IfDefine ENVIRONMENT_DEV>" + FN_RETURN + "(" + model_dev + ")</IfDefine>\n"
74-
+ "<IfDefine ENVIRONMENT_STAGE>" + FN_RETURN + "(" + model_stage + ")</IfDefine>\n"
75-
+ "<IfDefine ENVIRONMENT_PROD>" + FN_RETURN + "(" + model_prod + ")</IfDefine>\n",
73+
assertHelper("""
74+
<IfDefine ENVIRONMENT_DEV>%s(%s)</IfDefine>
75+
<IfDefine ENVIRONMENT_STAGE>%s(%s)</IfDefine>
76+
<IfDefine ENVIRONMENT_PROD>%s(%s)</IfDefine>
77+
""".formatted(FN_RETURN, model_dev, FN_RETURN, model_stage, FN_RETURN, model_prod),
7678
helper, null, options);
7779
}
7880

79-
}
81+
}

tooling/conga-aem-maven-plugin/src/main/java/io/wcm/devops/conga/plugins/aem/maven/AbstractCloudManagerMojo.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import java.util.Collections;
2727
import java.util.List;
2828
import java.util.Set;
29-
import java.util.stream.Collectors;
3029

3130
import org.apache.maven.plugin.AbstractMojo;
3231
import org.apache.maven.plugin.MojoExecutionException;
@@ -86,7 +85,7 @@ protected List<File> getEnvironmentDir() throws MojoExecutionException {
8685
directories = Arrays.stream(files)
8786
.filter(File::isDirectory)
8887
.filter(dir -> (selectedEnvironments.isEmpty() || selectedEnvironments.contains(dir.getName())))
89-
.collect(Collectors.toList());
88+
.toList();
9089
}
9190
}
9291
if (directories == null || directories.isEmpty()) {
@@ -117,7 +116,7 @@ protected List<File> getNodeDirs(File environmentDir) {
117116
return Arrays.stream(files)
118117
.filter(File::isDirectory)
119118
.filter(dir -> selectedNodes.isEmpty() || selectedNodes.contains(dir.getName()))
120-
.collect(Collectors.toList());
119+
.toList();
121120
}
122121
else {
123122
return Collections.emptyList();

tooling/conga-aem-maven-plugin/src/main/java/io/wcm/devops/conga/plugins/aem/maven/BuildOutputTimestamp.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,23 @@ public class BuildOutputTimestamp {
3434
private final Optional<Instant> instant;
3535

3636
/**
37+
* Configured output timestamp
3738
* @param outputTimestamp Configured output timestamp
3839
*/
3940
public BuildOutputTimestamp(@Nullable String outputTimestamp) {
4041
this.instant = MavenArchiver.parseBuildOutputTimestamp(outputTimestamp);
4142
}
4243

4344
/**
45+
* Check if a valid timestamp is configured,
4446
* @return true if a valid timestamp is configured
4547
*/
4648
public boolean isValid() {
4749
return instant.isPresent();
4850
}
4951

5052
/**
53+
* File time
5154
* @return FileTime or null if not a valid date
5255
*/
5356
@Nullable

0 commit comments

Comments
 (0)