Skip to content

Commit

Permalink
Eliminate SonarQube warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseifert committed Jan 22, 2024
1 parent 7b257f6 commit 8c49368
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
/**
* AES crypto support implementation with the same algorithms as used by AEM 6.3 and up.
*/
@SuppressWarnings("java:S5542") // cannot use a more secure cipher mode, we have to be compatible with AEM
public class AesCryptoSupport extends CryptoSupport {

private static final String AES_KEY_ALGORITHM = "AES";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -106,7 +107,7 @@ public List<FileContext> apply(FileContext fileContext, PostProcessorContext con
}

// delete provisioning file after transformation
file.delete();
Files.delete(file.toPath());

// set force to true by default for CONGA-generated packages (but allow override from role definition)
Map<String, Object> modelOptions = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
final class ContentElementHandler implements ContentHandler {

private ContentElement root;
private static final Pattern PATH_PATTERN = Pattern.compile("^((/[^/]+)*)(/([^/]+))$");
private static final Pattern PATH_PATTERN = Pattern.compile("^((/[^/]+)*+)(/([^/]+))$");

@Override
public void resource(String path, Map<String, Object> properties) {
Expand All @@ -44,11 +44,11 @@ public void resource(String path, Map<String, Object> properties) {
}
else {
if (root == null) {
throw new RuntimeException("Root resource not set.");
throw new IllegalArgumentException("Root resource not set.");
}
Matcher matcher = PATH_PATTERN.matcher(path);
if (!matcher.matches()) {
throw new RuntimeException("Unexpected path:" + path);
throw new IllegalArgumentException("Unexpected path:" + path);
}
String relativeParentPath = StringUtils.stripStart(matcher.group(1), "/");
String name = matcher.group(4);
Expand All @@ -60,7 +60,7 @@ public void resource(String path, Map<String, Object> properties) {
parent = root.getChild(relativeParentPath);
}
if (parent == null) {
throw new RuntimeException("Parent '" + relativeParentPath + "' does not exist.");
throw new IllegalArgumentException("Parent '" + relativeParentPath + "' does not exist.");
}
parent.getChildren().put(name, new ContentElementImpl(name, properties));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;

import org.apache.commons.lang3.StringUtils;

Expand Down Expand Up @@ -101,7 +102,7 @@ public void deleteIfRequired(UrlFileManager urlFileManager, File targetDir) thro
}
File file = getFile(targetDir);
if (file != null) {
file.delete();
Files.delete(file.toPath());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -395,24 +396,25 @@ private static List<ContentPackageBinaryFile> getMatchingFiles(File targetDir, S
Pattern pattern = Pattern.compile(fileMatch);

// collect all files below the target dir
return Files.walk(Paths.get(fileTargetDir.toURI()))
.filter(Files::isRegularFile)
// strip off the target dir paths, keep only the relative path/file name
.map(ContentPackageUtil::normalizedAbsolutePath)
.map(file -> StringUtils.removeStart(file, targetPathPrefix))
// check if file matches with the regex, apply matching input groups to path
.map(file -> {
Matcher matcher = pattern.matcher(file);
if (matcher.matches()) {
String adaptedPath = matcher.replaceAll(path);
return new ContentPackageBinaryFile(file, dir, null, adaptedPath, delete);
}
else {
return null;
}
})
.filter(Objects::nonNull)
.collect(Collectors.toList());
try (Stream<Path> paths = Files.walk(Paths.get(fileTargetDir.toURI()))) {
return paths.filter(Files::isRegularFile)
// strip off the target dir paths, keep only the relative path/file name
.map(ContentPackageUtil::normalizedAbsolutePath)
.map(file -> StringUtils.removeStart(file, targetPathPrefix))
// check if file matches with the regex, apply matching input groups to path
.map(file -> {
Matcher matcher = pattern.matcher(file);
if (matcher.matches()) {
String adaptedPath = matcher.replaceAll(path);
return new ContentPackageBinaryFile(file, dir, null, adaptedPath, delete);
}
else {
return null;
}
})
.filter(Objects::nonNull)
.collect(Collectors.toList());
}
}

private static String normalizedAbsolutePath(Path path) {
Expand Down

0 comments on commit 8c49368

Please sign in to comment.