Merge pull request #409 from awhitford/MinorCodeTweaks

Thanks!
This commit is contained in:
Jeremy Long
2015-11-22 07:14:12 -05:00
8 changed files with 18 additions and 28 deletions

View File

@@ -26,7 +26,6 @@ import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.HashSet; import java.util.HashSet;
@@ -416,11 +415,9 @@ public class ArchiveAnalyzer extends AbstractFileTypeAnalyzer {
FileOutputStream fos = null; FileOutputStream fos = null;
try { try {
final File parent = file.getParentFile(); final File parent = file.getParentFile();
if (!parent.isDirectory()) { if (!parent.isDirectory() && !parent.mkdirs()) {
if (!parent.mkdirs()) { final String msg = String.format("Unable to build directory '%s'.", parent.getAbsolutePath());
final String msg = String.format("Unable to build directory '%s'.", parent.getAbsolutePath()); throw new AnalysisException(msg);
throw new AnalysisException(msg);
}
} }
fos = new FileOutputStream(file); fos = new FileOutputStream(file);
IOUtils.copy(input, fos); IOUtils.copy(input, fos);

View File

@@ -104,7 +104,7 @@ public class NexusAnalyzer extends AbstractFileTypeAnalyzer {
*/ */
boolean retval = false; boolean retval = false;
try { try {
if ((!DEFAULT_URL.equals(Settings.getString(Settings.KEYS.ANALYZER_NEXUS_URL))) if (!DEFAULT_URL.equals(Settings.getString(Settings.KEYS.ANALYZER_NEXUS_URL))
&& Settings.getBoolean(Settings.KEYS.ANALYZER_NEXUS_ENABLED)) { && Settings.getBoolean(Settings.KEYS.ANALYZER_NEXUS_ENABLED)) {
LOGGER.info("Enabling Nexus analyzer"); LOGGER.info("Enabling Nexus analyzer");
retval = true; retval = true;

View File

@@ -73,7 +73,7 @@ public class NvdCveAnalyzer implements Analyzer {
* @return true or false. * @return true or false.
*/ */
public boolean isOpen() { public boolean isOpen() {
return (cveDB != null); return cveDB != null;
} }
/** /**

View File

@@ -27,7 +27,6 @@ import java.sql.DriverManager;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.util.logging.Level;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.owasp.dependencycheck.utils.DBUtils; import org.owasp.dependencycheck.utils.DBUtils;
import org.owasp.dependencycheck.utils.DependencyVersion; import org.owasp.dependencycheck.utils.DependencyVersion;
@@ -302,7 +301,7 @@ public final class ConnectionFactory {
Statement statement = null; Statement statement = null;
try { try {
statement = conn.createStatement(); statement = conn.createStatement();
boolean success = statement.execute(dbStructureUpdate); final boolean success = statement.execute(dbStructureUpdate);
if (!success && statement.getUpdateCount() <= 0) { if (!success && statement.getUpdateCount() <= 0) {
throw new DatabaseException(String.format("Unable to upgrade the database schema to %s", schema)); throw new DatabaseException(String.format("Unable to upgrade the database schema to %s", schema));
} }

View File

@@ -182,13 +182,11 @@ public final class ExtractionUtil {
while ((entry = input.getNextEntry()) != null) { while ((entry = input.getNextEntry()) != null) {
if (entry.isDirectory()) { if (entry.isDirectory()) {
final File dir = new File(destination, entry.getName()); final File dir = new File(destination, entry.getName());
if (!dir.exists()) { if (!dir.exists() && !dir.mkdirs()) {
if (!dir.mkdirs()) { final String msg = String.format(
final String msg = String.format( "Unable to create directory '%s'.",
"Unable to create directory '%s'.", dir.getAbsolutePath());
dir.getAbsolutePath()); throw new AnalysisException(msg);
throw new AnalysisException(msg);
}
} }
} else { } else {
extractFile(input, destination, filter, entry); extractFile(input, destination, filter, entry);
@@ -264,13 +262,11 @@ public final class ExtractionUtil {
private static void createParentFile(final File file) private static void createParentFile(final File file)
throws ExtractionException { throws ExtractionException {
final File parent = file.getParentFile(); final File parent = file.getParentFile();
if (!parent.isDirectory()) { if (!parent.isDirectory() && !parent.mkdirs()) {
if (!parent.mkdirs()) { final String msg = String.format(
final String msg = String.format( "Unable to build directory '%s'.",
"Unable to build directory '%s'.", parent.getAbsolutePath());
parent.getAbsolutePath()); throw new ExtractionException(msg);
throw new ExtractionException(msg);
}
} }
} }
} }

View File

@@ -174,7 +174,7 @@ public class AggregateMojo extends BaseDependencyCheckMojo {
} }
} }
} }
Set<MavenProject> addedDescendants = new HashSet<MavenProject>(); final Set<MavenProject> addedDescendants = new HashSet<MavenProject>();
for (MavenProject dec : descendants) { for (MavenProject dec : descendants) {
for (String mod : dec.getModules()) { for (String mod : dec.getModules()) {
try { try {

View File

@@ -26,7 +26,6 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;

View File

@@ -52,7 +52,6 @@ public final class URLConnectionFactory {
@SuppressFBWarnings(value = "RCN_REDUNDANT_NULLCHECK_OF_NULL_VALUE", justification = "Just being extra safe") @SuppressFBWarnings(value = "RCN_REDUNDANT_NULLCHECK_OF_NULL_VALUE", justification = "Just being extra safe")
public static HttpURLConnection createHttpURLConnection(URL url) throws URLConnectionFailureException { public static HttpURLConnection createHttpURLConnection(URL url) throws URLConnectionFailureException {
HttpURLConnection conn = null; HttpURLConnection conn = null;
Proxy proxy;
final String proxyUrl = Settings.getString(Settings.KEYS.PROXY_SERVER); final String proxyUrl = Settings.getString(Settings.KEYS.PROXY_SERVER);
try { try {
if (proxyUrl != null) { if (proxyUrl != null) {
@@ -74,7 +73,7 @@ public final class URLConnectionFactory {
Authenticator.setDefault(auth); Authenticator.setDefault(auth);
} }
proxy = new Proxy(Proxy.Type.HTTP, address); final Proxy proxy = new Proxy(Proxy.Type.HTTP, address);
conn = (HttpURLConnection) url.openConnection(proxy); conn = (HttpURLConnection) url.openConnection(proxy);
} else { } else {
conn = (HttpURLConnection) url.openConnection(); conn = (HttpURLConnection) url.openConnection();