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 b36286a commit c1e44b3
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.regex.Matcher;

import io.wcm.devops.conga.generator.spi.context.ValueProviderGlobalContext;
Expand Down Expand Up @@ -176,7 +177,7 @@ private Map<String, Object> replaceMap(Map<String, Object> map, Map<String, Obje
boolean replacedAny = mapCopy.remove(LIST_VARIABLE_ITERATE) != null;
for (Map.Entry<String, Object> entry : mapCopy.entrySet()) {
Object replacedValue = replaceAny(entry.getValue(), variables);
if (entry.getValue() != replacedValue) {
if (!Objects.equals(entry.getValue(), replacedValue)) {
entry.setValue(replacedValue);
replacedAny = true;
}
Expand Down Expand Up @@ -254,7 +255,7 @@ private Map<String, Object> deescapeMap(Map<String, Object> map) {
Map<String, Object> mapCopy = new HashMap<>(map);
for (Map.Entry<String, Object> entry : mapCopy.entrySet()) {
Object deescapedValue = deescapeAny(entry.getValue());
if (entry.getValue() != deescapedValue) {
if (!Objects.equals(entry.getValue(), deescapedValue)) {
entry.setValue(deescapedValue);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,11 @@ private MapSplitter() {
continue;
}

else if (entry.getValue() instanceof List) {
if (listHasSubStructures((List<Object>)entry.getValue())) {
// process nested "structural" lists
processListValue(entry, matching, unmatching, matcher);
continue;
}
else if ((entry.getValue() instanceof List)
&& listHasSubStructures((List<Object>)entry.getValue())) {
// process nested "structural" lists
processListValue(entry, matching, unmatching, matcher);
continue;
}

// value is not a structural (map/list) value - apply matching
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* Special list that marks a list as "mergeable" in downstream and preservers the merge position.
* @param <T> List type
*/
@SuppressWarnings("java:S2160") // equals/hashCode is implemented in base class
final class MergingList<T> extends LinkedList<T> {
private static final long serialVersionUID = 1L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
/**
* Facade to rout SLF4J logging calls to maven plugin logger.
*/
@SuppressWarnings("java:S2629")
class MavenSlf4jLogFacade implements Logger {

private static final Pattern ARGUMENT_PATTERN = Pattern.compile("\\{\\}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ private <T> List<T> validateFiles(ResourceCollection sourceDir, ResourceCollecti
return result;
}

@SuppressWarnings("java:S1075") // no filesystem path
private static String getPathForLog(ResourceCollection rootSourceDir, Resource file) {
String path = PathUtil.unifySlashes(file.getCanonicalPath());
String rootPath = PathUtil.unifySlashes(rootSourceDir.getCanonicalPath()) + "/";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ else if (value instanceof List) {

private void validate(String value) {
if (VariableStringResolver.hasValueProviderReference(value)) {
throw new RuntimeException("Role definitions must not reference value providers: " + value);
throw new IllegalStateException("Role definitions must not reference value providers: " + value);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ public TemplateValidator(ResourceCollection templateDir, HandlebarsManager handl
}

@Override
@SuppressWarnings("PMD.PreserveStackTrace")
@SuppressWarnings({
"PMD.PreserveStackTrace",
"java:S1075" // uses / by intention
})
public Void validate(Resource resource, String pathForLog) throws MojoFailureException {
if (StringUtils.equalsIgnoreCase(resource.getFileExtension(), FILE_EXTENSION)) {
String templatePath = StringUtils.substringAfter(PathUtil.unifySlashes(resource.getCanonicalPath()),
Expand Down

0 comments on commit c1e44b3

Please sign in to comment.