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 c7fc30a0d..f17680cce 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
@@ -61,6 +61,7 @@ import org.owasp.dependencycheck.dependency.Confidence;
import org.owasp.dependencycheck.dependency.Dependency;
import org.owasp.dependencycheck.dependency.EvidenceCollection;
import org.owasp.dependencycheck.jaxb.pom.MavenNamespaceFilter;
+import org.owasp.dependencycheck.jaxb.pom.PomUtils;
import org.owasp.dependencycheck.jaxb.pom.generated.License;
import org.owasp.dependencycheck.jaxb.pom.generated.Model;
import org.owasp.dependencycheck.jaxb.pom.generated.Organization;
@@ -158,24 +159,15 @@ public class JarAnalyzer extends AbstractFileTypeAnalyzer {
* A pattern to detect HTML within text.
*/
private static final Pattern HTML_DETECTION_PATTERN = Pattern.compile("\\<[a-z]+.*/?\\>", Pattern.CASE_INSENSITIVE);
- /**
- * The unmarshaller used to parse the pom.xml from a JAR file.
- */
- private Unmarshaller pomUnmarshaller;
+
+ private PomUtils pomUtils = null;
//
/**
* Constructs a new JarAnalyzer.
*/
public JarAnalyzer() {
- try {
- //final JAXBContext jaxbContext = JAXBContext.newInstance("org.owasp.dependencycheck.jaxb.pom.generated");
- final JAXBContext jaxbContext = JAXBContext.newInstance(Model.class);
- pomUnmarshaller = jaxbContext.createUnmarshaller();
- } catch (JAXBException ex) { //guess we will just have a null pointer exception later...
- LOGGER.log(Level.SEVERE, "Unable to load parser. See the log for more details.");
- LOGGER.log(Level.FINE, null, ex);
- }
+ pomUtils = new PomUtils();
}
//
- * A utility function that will interpolate strings based on values given in the properties file. It will also
- * interpolate the strings contained within the properties file so that properties can reference other
- * properties.
*
* @param dependency a dependency
* @param description the description
* @param source the source of the evidence
* @param key the "name" of the evidence
- * @return if the description is trimmed, the trimmed version is returned; otherwise the original description is
- * returned
+ * @return if the description is trimmed, the trimmed version is returned; otherwise the original description is returned
*/
- private String addDescription(Dependency dependency, String description, String source, String key) {
+ public static String addDescription(Dependency dependency, String description, String source, String key) {
if (dependency.getDescription() == null) {
dependency.setDescription(description);
}
@@ -1064,12 +988,11 @@ public class JarAnalyzer extends AbstractFileTypeAnalyzer {
/**
*
- * Note: if there is no property found the reference will be removed. In other words, if the interpolated - * string will be replaced with an empty string. + * Note: if there is no property found the reference will be removed. In other words, if the interpolated string will + * be replaced with an empty string. *
** Example:
@@ -1089,13 +1012,13 @@ public class JarAnalyzer extends AbstractFileTypeAnalyzer { * @param properties a collection of properties that may be referenced within the text. * @return the interpolated text. */ - protected String interpolateString(String text, Properties properties) { + public static String interpolateString(String text, Properties properties) { Properties props = properties; if (text == null) { return text; } if (props == null) { - props = new Properties(); + return text; } final int pos = text.indexOf("${"); @@ -1133,8 +1056,8 @@ public class JarAnalyzer extends AbstractFileTypeAnalyzer { } /** - * Cycles through an enumeration of JarEntries, contained within the dependency, and returns a list of the class - * names. This does not include core Java package names (i.e. java.* or javax.*). + * Cycles through an enumeration of JarEntries, contained within the dependency, and returns a list of the class names. This + * does not include core Java package names (i.e. java.* or javax.*). * * @param dependency the dependency being analyzed * @return an list of fully qualified class names @@ -1171,8 +1094,8 @@ public class JarAnalyzer extends AbstractFileTypeAnalyzer { } /** - * Cycles through the list of class names and places the package levels 0-3 into the provided maps for vendor and - * product. This is helpful when analyzing vendor/product as many times this is included in the package name. + * Cycles through the list of class names and places the package levels 0-3 into the provided maps for vendor and product. + * This is helpful when analyzing vendor/product as many times this is included in the package name. * * @param classNames a list of class names * @param vendor HashMap of possible vendor names from package names (e.g. owasp) @@ -1203,8 +1126,8 @@ public class JarAnalyzer extends AbstractFileTypeAnalyzer { } /** - * Adds an entry to the specified collection and sets the Integer (e.g. the count) to 1. If the entry already exists - * in the collection then the Integer is incremented by 1. + * Adds an entry to the specified collection and sets the Integer (e.g. the count) to 1. If the entry already exists in the + * collection then the Integer is incremented by 1. * * @param collection a collection of strings and their occurrence count * @param key the key to add to the collection @@ -1218,9 +1141,9 @@ public class JarAnalyzer extends AbstractFileTypeAnalyzer { } /** - * Cycles through the collection of class name information to see if parts of the package names are contained in the - * provided value. If found, it will be added as the HIGHEST confidence evidence because we have more then one - * source corroborating the value. + * Cycles through the collection of class name information to see if parts of the package names are contained in the provided + * value. If found, it will be added as the HIGHEST confidence evidence because we have more then one source corroborating the + * value. * * @param classes a collection of class name information * @param value the value to check to see if it contains a package name @@ -1261,7 +1184,7 @@ public class JarAnalyzer extends AbstractFileTypeAnalyzer { * @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) { + public static void extractLicense(Model pom, Properties pomProperties, Dependency dependency) { //license if (pom.getLicenses() != null) { String license = null; @@ -1302,9 +1225,9 @@ public class JarAnalyzer extends AbstractFileTypeAnalyzer { /** *- * Stores information about a given class name. This class will keep the fully qualified class name and a list - * of the important parts of the package structure. Up to the first four levels of the package structure are - * stored, excluding a leading "org" or "com". Example:
+ * Stores information about a given class name. This class will keep the fully qualified class name and a list of the + * important parts of the package structure. Up to the first four levels of the package structure are stored, excluding a + * leading "org" or "com". Example: *ClassNameInformation obj = new ClassNameInformation("org.owasp.dependencycheck.analyzer.JarAnalyzer");
* System.out.println(obj.getName());
* for (String p : obj.getPackageStructure())