mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-03-24 01:51:49 +01:00
Replaced json iteration with more efficient entrySet. Also corrected an invalid logging statement.
This commit is contained in:
@@ -32,6 +32,7 @@ import javax.json.*;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileFilter;
|
import java.io.FileFilter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to analyze Node Package Manager (npm) package.json files, and collect information that can be used to determine
|
* Used to analyze Node Package Manager (npm) package.json files, and collect information that can be used to determine
|
||||||
@@ -146,20 +147,21 @@ public class NodePackageAnalyzer extends AbstractFileTypeAnalyzer {
|
|||||||
|
|
||||||
private void addToEvidence(JsonObject json, EvidenceCollection collection, String key) {
|
private void addToEvidence(JsonObject json, EvidenceCollection collection, String key) {
|
||||||
if (json.containsKey(key)) {
|
if (json.containsKey(key)) {
|
||||||
Object value = json.get(key);
|
JsonValue value = json.get(key);
|
||||||
if (value instanceof JsonString) {
|
if (value instanceof JsonString) {
|
||||||
collection.addEvidence(PACKAGE_JSON, key, ((JsonString) value).getString(), Confidence.HIGHEST);
|
collection.addEvidence(PACKAGE_JSON, key, ((JsonString) value).getString(), Confidence.HIGHEST);
|
||||||
} else if (value instanceof JsonObject) {
|
} else if (value instanceof JsonObject) {
|
||||||
final JsonObject jsonObject = (JsonObject) value;
|
final JsonObject jsonObject = (JsonObject) value;
|
||||||
for (String property : jsonObject.keySet()) {
|
for (final Map.Entry<String, JsonValue> entry : jsonObject.entrySet()) {
|
||||||
final Object subValue = jsonObject.get(property);
|
final String property = entry.getKey();
|
||||||
|
final JsonValue subValue = entry.getValue();
|
||||||
if (subValue instanceof JsonString) {
|
if (subValue instanceof JsonString) {
|
||||||
collection.addEvidence(PACKAGE_JSON,
|
collection.addEvidence(PACKAGE_JSON,
|
||||||
String.format("%s.%s", key, property),
|
String.format("%s.%s", key, property),
|
||||||
((JsonString) subValue).getString(),
|
((JsonString) subValue).getString(),
|
||||||
Confidence.HIGHEST);
|
Confidence.HIGHEST);
|
||||||
} else {
|
} else {
|
||||||
LOGGER.warn("JSON sub-value not string as expected: %s");
|
LOGGER.warn("JSON sub-value not string as expected: %s", subValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user