Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ideaVersion = 2022.1
projectVersion=1.1.0-SNAPSHOT-1
projectVersion=1.1.0-SNAPSHOT
jetBrainsToken=invalid
jetBrainsChannel=stable
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;

import static org.jboss.tools.intellij.componentanalysis.CAService.iterateOverListOfStringDelimitedByCommaAndNewLineGetString;


public abstract class CAAnnotator extends ExternalAnnotator<CAAnnotator.Info, Map<Dependency, CAAnnotator.Result>> {

Expand Down Expand Up @@ -85,33 +85,14 @@ public abstract class CAAnnotator extends ExternalAnnotator<CAAnnotator.Info, Ma

LOG.info("Get vulnerability report from cache");
Map<Dependency, Map<VulnerabilitySource, DependencyReport>> reports = CAService.getReports(path);
List<String> pairsOfDepsVulnsFromMap = CAService.getPairsOfDepsVulnsFromMap(reports);
LOG.info("Resolved Dependency->vuln pairs from cache");
LOG.info(iterateOverListOfStringDelimitedByCommaAndNewLineGetString(pairsOfDepsVulnsFromMap));
Map<Dependency, Result> dependencyResultMap = this.matchDependencies(info.getDependencies(), reports);
String debugString;
if(Objects.nonNull(dependencyResultMap)) {
debugString = reformatDependencyResultMapForDebugging(dependencyResultMap);
LOG.info("Pairs with offsets that are going to be applied=>");
LOG.info(debugString);
}

return dependencyResultMap;
}

return null;
}

private String reformatDependencyResultMapForDebugging(Map<Dependency, Result> dependencyResultMap) {
List<String> allPairsWithOffsetsInUi = dependencyResultMap.entrySet().stream().map(entry -> {
String dependency = entry.getKey().toPurl("maven").toString();
String stringOffSets = entry.getValue().elements.get(0).getTextRange().toString();
String dependencyVuln = entry.getValue().getReports().entrySet().stream().map(Map.Entry::getValue).map(dep -> dep.getRef().toString()).findFirst().get();
return String.format("%s==>%s==>%s", dependency, dependencyVuln, stringOffSets);
}).collect(Collectors.toList());
return iterateOverListOfStringDelimitedByCommaAndNewLineGetString(allPairsWithOffsetsInUi);
}

@Override
public void apply(@NotNull PsiFile file, Map<Dependency, Result> annotationResult, @NotNull AnnotationHolder holder) {
LOG.info("Annotate dependencies");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,40 +148,19 @@ public static boolean performAnalysis(String packageManager,
}
});
}
List<String> allPairs = getPairsOfDepsVulnsFromMap(resultMap);
LOG.info("Before - List of all dependencies and their purl from vulnerability dependency report " + iterateOverListOfStringDelimitedByCommaAndNewLineGetString(allPairs));


if (!resultMap.isEmpty()) {
getInstance().vulnerabilityCache.put(filePath, resultMap);
} else {
getInstance().vulnerabilityCache.invalidate(filePath);
}
if(Objects.nonNull(resultMap)) {
allPairs = getPairsOfDepsVulnsFromMap(resultMap);
LOG.info("After - List of all dependencies and their purl from vulnerability dependency report " + iterateOverListOfStringDelimitedByCommaAndNewLineGetString(allPairs));
}
LOG.info("List of dependencies in cache, before update" + System.lineSeparator() + getListOfDependencies(getInstance().dependencyCache.get(filePath, p -> Collections.emptySet())));
getInstance().dependencyCache.put(filePath, dependencies);
LOG.info("List of dependencies in cache, after after" + System.lineSeparator() + getListOfDependencies(dependencies));
return true;


}
return false;
}

public static String iterateOverListOfStringDelimitedByCommaAndNewLineGetString(List<String> allPairs) {
return allPairs.stream().collect(Collectors.joining("," + System.lineSeparator()));
}

public static @NotNull List<String> getPairsOfDepsVulnsFromMap(Map<Dependency, Map<VulnerabilitySource, DependencyReport>> resultMap) {
Map<Dependency, DependencyReport> collect = resultMap.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().entrySet().stream().map(Map.Entry::getValue).findAny().get()));
List<String> allPairs = collect.entrySet().stream().map(p -> p.getKey().toPurl("maven").toString() + "==>" + p.getValue().getRef().toString()).collect(Collectors.toList());
return allPairs;
}

public static String getListOfDependencies(Set<Dependency> dependencies) {
return dependencies.stream().map(dep -> dep.toPurl("maven").toString()).collect(joining(";" + System.lineSeparator()));
}
}