Merge pull request #344 from awhitford/DbOpts

Db opts
This commit is contained in:
Jeremy Long
2015-09-11 05:25:16 -04:00
12 changed files with 40 additions and 14 deletions

View File

@@ -147,7 +147,7 @@ public class AssemblyAnalyzer extends AbstractFileTypeAnalyzer {
// First, see if there was an error // First, see if there was an error
final String error = xpath.evaluate("/assembly/error", doc); final String error = xpath.evaluate("/assembly/error", doc);
if (error != null && !"".equals(error)) { if (error != null && !error.isEmpty()) {
throw new AnalysisException(error); throw new AnalysisException(error);
} }
@@ -246,7 +246,7 @@ public class AssemblyAnalyzer extends AbstractFileTypeAnalyzer {
final Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(p.getInputStream()); final Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(p.getInputStream());
final XPath xpath = XPathFactory.newInstance().newXPath(); final XPath xpath = XPathFactory.newInstance().newXPath();
final String error = xpath.evaluate("/assembly/error", doc); final String error = xpath.evaluate("/assembly/error", doc);
if (p.waitFor() != 1 || error == null || "".equals(error)) { if (p.waitFor() != 1 || error == null || error.isEmpty()) {
LOGGER.warn("An error occurred with the .NET AssemblyAnalyzer, please see the log for more details."); LOGGER.warn("An error occurred with the .NET AssemblyAnalyzer, please see the log for more details.");
LOGGER.debug("GrokAssembly.exe is not working properly"); LOGGER.debug("GrokAssembly.exe is not working properly");
grokAssemblyExe = null; grokAssemblyExe = null;

View File

@@ -339,7 +339,7 @@ public class CPEAnalyzer implements Analyzer {
final String cleanText = cleanseText(searchText); final String cleanText = cleanseText(searchText);
if ("".equals(cleanText)) { if (cleanText.isEmpty()) {
return false; return false;
} }

View File

@@ -151,7 +151,7 @@ public final class CpeMemoryIndex {
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private Analyzer createIndexingAnalyzer() { private Analyzer createIndexingAnalyzer() {
final Map fieldAnalyzers = new HashMap(); final Map<String,Analyzer> fieldAnalyzers = new HashMap<String, Analyzer>();
fieldAnalyzers.put(Fields.DOCUMENT_KEY, new KeywordAnalyzer()); fieldAnalyzers.put(Fields.DOCUMENT_KEY, new KeywordAnalyzer());
return new PerFieldAnalyzerWrapper(new FieldAnalyzer(LuceneUtils.CURRENT_VERSION), fieldAnalyzers); return new PerFieldAnalyzerWrapper(new FieldAnalyzer(LuceneUtils.CURRENT_VERSION), fieldAnalyzers);
} }

View File

@@ -132,10 +132,10 @@ public class NexusSearch {
"/org.sonatype.nexus.rest.model.NexusArtifact/pomLink", "/org.sonatype.nexus.rest.model.NexusArtifact/pomLink",
doc); doc);
final MavenArtifact ma = new MavenArtifact(groupId, artifactId, version); final MavenArtifact ma = new MavenArtifact(groupId, artifactId, version);
if (link != null && !"".equals(link)) { if (link != null && !link.isEmpty()) {
ma.setArtifactUrl(link); ma.setArtifactUrl(link);
} }
if (pomLink != null && !"".equals(pomLink)) { if (pomLink != null && !pomLink.isEmpty()) {
ma.setPomUrl(pomLink); ma.setPomUrl(pomLink);
} }
return ma; return ma;

View File

@@ -340,7 +340,6 @@ public class CveDB {
* @throws DatabaseException thrown if there is an exception retrieving data * @throws DatabaseException thrown if there is an exception retrieving data
*/ */
public List<Vulnerability> getVulnerabilities(String cpeStr) throws DatabaseException { public List<Vulnerability> getVulnerabilities(String cpeStr) throws DatabaseException {
ResultSet rs = null;
final VulnerableSoftware cpe = new VulnerableSoftware(); final VulnerableSoftware cpe = new VulnerableSoftware();
try { try {
cpe.parseName(cpeStr); cpe.parseName(cpeStr);
@@ -350,7 +349,8 @@ public class CveDB {
final DependencyVersion detectedVersion = parseDependencyVersion(cpe); final DependencyVersion detectedVersion = parseDependencyVersion(cpe);
final List<Vulnerability> vulnerabilities = new ArrayList<Vulnerability>(); final List<Vulnerability> vulnerabilities = new ArrayList<Vulnerability>();
PreparedStatement ps; PreparedStatement ps = null;
ResultSet rs = null;
try { try {
ps = getConnection().prepareStatement(statementBundle.getString("SELECT_CVE_FROM_SOFTWARE")); ps = getConnection().prepareStatement(statementBundle.getString("SELECT_CVE_FROM_SOFTWARE"));
ps.setString(1, cpe.getVendor()); ps.setString(1, cpe.getVendor());
@@ -384,12 +384,11 @@ public class CveDB {
v.setMatchedCPE(matchedCPE.getKey(), matchedCPE.getValue() ? "Y" : null); v.setMatchedCPE(matchedCPE.getKey(), matchedCPE.getValue() ? "Y" : null);
vulnerabilities.add(v); vulnerabilities.add(v);
} }
DBUtils.closeResultSet(rs);
DBUtils.closeStatement(ps);
} catch (SQLException ex) { } catch (SQLException ex) {
throw new DatabaseException("Exception retrieving vulnerability for " + cpeStr, ex); throw new DatabaseException("Exception retrieving vulnerability for " + cpeStr, ex);
} finally { } finally {
DBUtils.closeResultSet(rs); DBUtils.closeResultSet(rs);
DBUtils.closeStatement(ps);
} }
return vulnerabilities; return vulnerabilities;
} }
@@ -767,9 +766,9 @@ public class CveDB {
* @return a dependency version * @return a dependency version
*/ */
private DependencyVersion parseDependencyVersion(VulnerableSoftware cpe) { private DependencyVersion parseDependencyVersion(VulnerableSoftware cpe) {
DependencyVersion cpeVersion; final DependencyVersion cpeVersion;
if (cpe.getVersion() != null && !cpe.getVersion().isEmpty()) { if (cpe.getVersion() != null && !cpe.getVersion().isEmpty()) {
String versionText; final String versionText;
if (cpe.getUpdate() != null && !cpe.getUpdate().isEmpty()) { if (cpe.getUpdate() != null && !cpe.getUpdate().isEmpty()) {
versionText = String.format("%s.%s", cpe.getVersion(), cpe.getUpdate()); versionText = String.format("%s.%s", cpe.getVersion(), cpe.getUpdate());
} else { } else {

View File

@@ -43,6 +43,10 @@ import org.slf4j.LoggerFactory;
*/ */
public class Dependency implements Serializable, Comparable<Dependency> { public class Dependency implements Serializable, Comparable<Dependency> {
/**
* The serial version UID for serialization.
*/
private static final long serialVersionUID = 1L;
/** /**
* The logger. * The logger.
*/ */

View File

@@ -29,6 +29,10 @@ import java.io.Serializable;
*/ */
public class Evidence implements Serializable, Comparable<Evidence> { public class Evidence implements Serializable, Comparable<Evidence> {
/**
* The serial version UID for serialization.
*/
private static final long serialVersionUID = 1L;
/** /**
* Used as starting point for generating the value in {@link #hashCode()}. * Used as starting point for generating the value in {@link #hashCode()}.
*/ */

View File

@@ -39,6 +39,10 @@ import org.slf4j.LoggerFactory;
*/ */
public class EvidenceCollection implements Serializable, Iterable<Evidence> { public class EvidenceCollection implements Serializable, Iterable<Evidence> {
/**
* The serial version UID for serialization.
*/
private static final long serialVersionUID = 1L;
/** /**
* The logger. * The logger.
*/ */

View File

@@ -25,6 +25,11 @@ import java.io.Serializable;
*/ */
public class Identifier implements Serializable, Comparable<Identifier> { public class Identifier implements Serializable, Comparable<Identifier> {
/**
* The serial version UID for serialization.
*/
private static final long serialVersionUID = 1L;
/** /**
* Default constructor. Should only be used for automatic class * Default constructor. Should only be used for automatic class
* creation as is the case with many XML parsers (for the parsing * creation as is the case with many XML parsers (for the parsing

View File

@@ -26,6 +26,11 @@ import java.io.IOException;
*/ */
public class SuppressionParseException extends IOException { public class SuppressionParseException extends IOException {
/**
* The serial version UID for serialization.
*/
private static final long serialVersionUID = 1L;
/** /**
* Creates a new SuppressionParseException. * Creates a new SuppressionParseException.
*/ */

View File

@@ -37,7 +37,7 @@ import org.apache.commons.lang3.StringUtils;
* *
* @author Jeremy Long * @author Jeremy Long
*/ */
public class DependencyVersion implements Iterable, Comparable<DependencyVersion> { public class DependencyVersion implements Iterable<String>, Comparable<DependencyVersion> {
/** /**
* Constructor for a empty DependencyVersion. * Constructor for a empty DependencyVersion.
@@ -103,7 +103,7 @@ public class DependencyVersion implements Iterable, Comparable<DependencyVersion
* *
* @return an iterator for the version parts * @return an iterator for the version parts
*/ */
public Iterator iterator() { public Iterator<String> iterator() {
return versionParts.iterator(); return versionParts.iterator();
} }

View File

@@ -26,6 +26,11 @@ import java.io.IOException;
*/ */
public class PomParseException extends IOException { public class PomParseException extends IOException {
/**
* The serial version UID for serialization.
*/
private static final long serialVersionUID = 1L;
/** /**
* Creates a new SuppressionParseException. * Creates a new SuppressionParseException.
*/ */