Skip to content

Commit 87675d1

Browse files
Eliminate SonarQube warnings (#88)
1 parent 7b257f6 commit 87675d1

22 files changed

Lines changed: 79 additions & 55 deletions

File tree

conga-aem-plugin/src/main/java/io/wcm/devops/conga/plugins/aem/crypto/impl/AesCryptoSupport.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
/**
3838
* AES crypto support implementation with the same algorithms as used by AEM 6.3 and up.
3939
*/
40+
@SuppressWarnings("java:S5542") // cannot use a more secure cipher mode, we have to be compatible with AEM
4041
public class AesCryptoSupport extends CryptoSupport {
4142

4243
private static final String AES_KEY_ALGORITHM = "AES";
@@ -54,7 +55,7 @@ private static Random initRandom() {
5455
return SecureRandom.getInstance(SECURE_RANDOM_ALGORITHM);
5556
}
5657
catch (NoSuchAlgorithmException ex) {
57-
throw new RuntimeException(ex);
58+
throw new IllegalStateException(ex);
5859
}
5960
}
6061

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public String getName() {
6363
}
6464

6565
@Override
66+
@SuppressWarnings({ "java:S3776", "java:S5411" }) // ignore complexity
6667
public Object apply(Object context, Options options, HelperContext pluginContext) throws IOException {
6768
if (context == null) {
6869
return null;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ protected String generateFilter(Map<String, Object> filterMap, Options options)
7373
allowFrom, allowFromHost);
7474
}
7575

76+
@SuppressWarnings("java:S3776") // ignore complexity
7677
private String generateRule(String ruleType, String ruleExpression, HttpdFilterType filterType,
7778
String allowFrom, String allowFromHost) {
7879
StringBuilder sb = new StringBuilder();

conga-aem-plugin/src/main/java/io/wcm/devops/conga/plugins/aem/postprocessor/ContentPackageOsgiConfigPostProcessor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ private boolean generateOsgiConfigurations(Model model, ContentPackage contentPa
153153
List<Void> result = ProvisioningUtil.visitOsgiConfigurations(model, new ConfigConsumer<Void>() {
154154
@Override
155155
@SuppressFBWarnings("RV_RETURN_VALUE_IGNORED_BAD_PRACTICE")
156+
@SuppressWarnings("java:S3457") // log placeholders
156157
public Void accept(String path, Dictionary<String, Object> properties) throws IOException {
157158
String contentPath = rootPath + (StringUtils.contains(path, "/") ? "." : "/") + path;
158159
context.getLogger().info(" Include " + contentPath);

conga-aem-plugin/src/main/java/io/wcm/devops/conga/plugins/aem/postprocessor/ContentPackagePostProcessor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.io.File;
2525
import java.io.IOException;
2626
import java.io.InputStream;
27+
import java.nio.file.Files;
2728
import java.util.HashMap;
2829
import java.util.List;
2930
import java.util.Map;
@@ -106,7 +107,7 @@ public List<FileContext> apply(FileContext fileContext, PostProcessorContext con
106107
}
107108

108109
// delete provisioning file after transformation
109-
file.delete();
110+
Files.delete(file.toPath());
110111

111112
// set force to true by default for CONGA-generated packages (but allow override from role definition)
112113
Map<String, Object> modelOptions = new HashMap<>();

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ public void resource(String path, Map<String, Object> properties) {
4444
}
4545
else {
4646
if (root == null) {
47-
throw new RuntimeException("Root resource not set.");
47+
throw new IllegalArgumentException("Root resource not set.");
4848
}
4949
Matcher matcher = PATH_PATTERN.matcher(path);
5050
if (!matcher.matches()) {
51-
throw new RuntimeException("Unexpected path:" + path);
51+
throw new IllegalArgumentException("Unexpected path:" + path);
5252
}
5353
String relativeParentPath = StringUtils.stripStart(matcher.group(1), "/");
5454
String name = matcher.group(4);
@@ -60,7 +60,7 @@ public void resource(String path, Map<String, Object> properties) {
6060
parent = root.getChild(relativeParentPath);
6161
}
6262
if (parent == null) {
63-
throw new RuntimeException("Parent '" + relativeParentPath + "' does not exist.");
63+
throw new IllegalArgumentException("Parent '" + relativeParentPath + "' does not exist.");
6464
}
6565
parent.getChildren().put(name, new ContentElementImpl(name, properties));
6666
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.io.FileInputStream;
2525
import java.io.IOException;
2626
import java.io.InputStream;
27+
import java.nio.file.Files;
2728

2829
import org.apache.commons.lang3.StringUtils;
2930

@@ -101,7 +102,7 @@ public void deleteIfRequired(UrlFileManager urlFileManager, File targetDir) thro
101102
}
102103
File file = getFile(targetDir);
103104
if (file != null) {
104-
file.delete();
105+
Files.delete(file.toPath());
105106
}
106107
}
107108
}

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

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

5152
import org.apache.commons.lang3.BooleanUtils;
5253
import org.apache.commons.lang3.StringUtils;
@@ -184,6 +185,7 @@ private static String mergeDescriptionFileHeader(String description, FileHeaderC
184185
* @param options Options
185186
* @return Filters list
186187
*/
188+
@SuppressWarnings("java:S3776") // ignore complexity
187189
private static List<PackageFilter> getFilters(Map<String, Object> options) {
188190
List<PackageFilter> filters = new ArrayList<>();
189191

@@ -384,6 +386,7 @@ public static List<ContentPackageBinaryFile> getFiles(Map<String, Object> option
384386
return files;
385387
}
386388

389+
@SuppressWarnings("java:S1075") // no filesystem path
387390
private static List<ContentPackageBinaryFile> getMatchingFiles(File targetDir, String fileMatch,
388391
String dir, String path, boolean delete) throws IOException {
389392
File fileTargetDir = targetDir;
@@ -395,24 +398,25 @@ private static List<ContentPackageBinaryFile> getMatchingFiles(File targetDir, S
395398
Pattern pattern = Pattern.compile(fileMatch);
396399

397400
// collect all files below the target dir
398-
return Files.walk(Paths.get(fileTargetDir.toURI()))
399-
.filter(Files::isRegularFile)
400-
// strip off the target dir paths, keep only the relative path/file name
401-
.map(ContentPackageUtil::normalizedAbsolutePath)
402-
.map(file -> StringUtils.removeStart(file, targetPathPrefix))
403-
// check if file matches with the regex, apply matching input groups to path
404-
.map(file -> {
405-
Matcher matcher = pattern.matcher(file);
406-
if (matcher.matches()) {
407-
String adaptedPath = matcher.replaceAll(path);
408-
return new ContentPackageBinaryFile(file, dir, null, adaptedPath, delete);
409-
}
410-
else {
411-
return null;
412-
}
413-
})
414-
.filter(Objects::nonNull)
415-
.collect(Collectors.toList());
401+
try (Stream<Path> paths = Files.walk(Paths.get(fileTargetDir.toURI()))) {
402+
return paths.filter(Files::isRegularFile)
403+
// strip off the target dir paths, keep only the relative path/file name
404+
.map(ContentPackageUtil::normalizedAbsolutePath)
405+
.map(file -> StringUtils.removeStart(file, targetPathPrefix))
406+
// check if file matches with the regex, apply matching input groups to path
407+
.map(file -> {
408+
Matcher matcher = pattern.matcher(file);
409+
if (matcher.matches()) {
410+
String adaptedPath = matcher.replaceAll(path);
411+
return new ContentPackageBinaryFile(file, dir, null, adaptedPath, delete);
412+
}
413+
else {
414+
return null;
415+
}
416+
})
417+
.filter(Objects::nonNull)
418+
.collect(Collectors.toList());
419+
}
416420
}
417421

418422
private static String normalizedAbsolutePath(Path path) {

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232

3333
import com.day.any.BaseHandler;
3434
import com.day.any.Parser;
35-
import com.day.any.ResourceExpander;
3635

3736
import io.wcm.devops.conga.generator.spi.ValidationException;
3837
import io.wcm.devops.conga.generator.spi.ValidatorPlugin;
@@ -70,12 +69,7 @@ public Void apply(FileContext file, ValidatorContext context) throws ValidationE
7069

7170
// set resource expander and entity resolver that do not resolve anything
7271
// just make sure they are in place to allow any parser parsing files with include directives
73-
parser.setResourceExpander(new ResourceExpander() {
74-
@Override
75-
public String[] expand(String arg0) {
76-
return new String[0];
77-
}
78-
});
72+
parser.setResourceExpander(arg -> new String[0]);
7973
parser.setEnitiyResolver(new EntityResolver() {
8074
@Override
8175
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ private void setProperty(Object object, String propertyName, Object value)
133133
setProperty(object, object.getClass(), propertyName, value);
134134
}
135135

136-
@SuppressWarnings("PMD.AvoidAccessibilityAlteration")
136+
@SuppressWarnings({ "PMD.AvoidAccessibilityAlteration", "java:S3011" })
137137
private void setProperty(Object object, Class<?> clazz, String propertyName, Object value)
138138
throws IllegalArgumentException, IllegalAccessException {
139139
try {

0 commit comments

Comments
 (0)