From 7f2c51f337c546fd76ec7c5f2a69f50cdb7d33f2 Mon Sep 17 00:00:00 2001 From: Jeremy Long Date: Sat, 1 Mar 2014 16:08:58 -0500 Subject: [PATCH] cleaned up code duplication Former-commit-id: 561f5f16b22f07199450d090ebb8c56df3703739 --- .../dependencycheck/analyzer/JarAnalyzer.java | 43 +++++-------------- 1 file changed, 11 insertions(+), 32 deletions(-) diff --git a/dependency-check-core/src/main/java/org/owasp/dependencycheck/analyzer/JarAnalyzer.java b/dependency-check-core/src/main/java/org/owasp/dependencycheck/analyzer/JarAnalyzer.java index fd5316a56..1e974f6a7 100644 --- a/dependency-check-core/src/main/java/org/owasp/dependencycheck/analyzer/JarAnalyzer.java +++ b/dependency-check-core/src/main/java/org/owasp/dependencycheck/analyzer/JarAnalyzer.java @@ -604,38 +604,7 @@ public class JarAnalyzer extends AbstractAnalyzer implements Analyzer { addMatchingValues(classes, trimmedDescription, dependency.getProductEvidence()); } } - - //license - if (pom.getLicenses() != null) { - String license = null; - for (License lic : pom.getLicenses().getLicense()) { - String tmp = null; - if (lic.getName() != null) { - tmp = interpolateString(lic.getName(), pomProperties); - } - if (lic.getUrl() != null) { - if (tmp == null) { - tmp = interpolateString(lic.getUrl(), pomProperties); - } else { - tmp += ": " + interpolateString(lic.getUrl(), pomProperties); - } - } - if (tmp == null) { - continue; - } - if (HTML_DETECTION_PATTERN.matcher(tmp).find()) { - tmp = Jsoup.parse(tmp).text(); - } - if (license == null) { - license = tmp; - } else { - license += "\n" + tmp; - } - } - if (license != null) { - dependency.setLicense(license); - } - } + extractLicense(pom, pomProperties, dependency); return foundSomething; } @@ -1250,7 +1219,17 @@ public class JarAnalyzer extends AbstractAnalyzer implements Analyzer { addDescription(dependency, description, "pom", "description"); } } + extractLicense(pom, pomProperties, dependency); + } + /** + * Extracts the license information from the pom and adds it to the dependency. + * + * @param pom the pom object + * @param pomProperties the properties, used for string interpolation + * @param dependency the dependency to add license information too + */ + private void extractLicense(Model pom, Properties pomProperties, Dependency dependency) { //license if (pom.getLicenses() != null) { String license = null;