Fixed merge conflict in App.java

This commit is contained in:
Dale Visser
2015-11-23 13:27:22 -05:00
126 changed files with 2556 additions and 1296 deletions

View File

@@ -57,7 +57,6 @@ public final class Checksum {
* @throws IOException when the file does not exist
* @throws NoSuchAlgorithmException when an algorithm is specified that does not exist
*/
@SuppressWarnings("empty-statement")
public static byte[] getChecksum(String algorithm, File file) throws NoSuchAlgorithmException, IOException {
MessageDigest digest = MessageDigest.getInstance(algorithm);
FileInputStream fis = null;
@@ -79,12 +78,6 @@ public final class Checksum {
digest.update(byteBuffer);
start += amountToRead;
}
// BufferedInputStream bis = new BufferedInputStream(fis);
// DigestInputStream dis = new DigestInputStream(bis, digest);
// //yes, we are reading in a buffer for performance reasons - 1 byte at a time is SLOW
// byte[] buffer = new byte[8192];
// while (dis.read(buffer) != -1);
} finally {
if (fis != null) {
try {

View File

@@ -17,6 +17,7 @@
*/
package org.owasp.dependencycheck.utils;
import org.apache.commons.io.FilenameUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -58,12 +59,8 @@ public final class FileUtils {
* @return the file extension.
*/
public static String getFileExtension(String fileName) {
String ret = null;
final int pos = fileName.lastIndexOf(".");
if (pos >= 0) {
ret = fileName.substring(pos + 1, fileName.length()).toLowerCase();
}
return ret;
final String fileExt = FilenameUtils.getExtension(fileName);
return null == fileExt || fileExt.isEmpty() ? null : fileExt.toLowerCase();
}
/**
@@ -73,9 +70,8 @@ public final class FileUtils {
* @return true if the file was deleted successfully, otherwise false
*/
public static boolean delete(File file) {
boolean success = true;
if (!org.apache.commons.io.FileUtils.deleteQuietly(file)) {
success = false;
final boolean success = org.apache.commons.io.FileUtils.deleteQuietly(file);
if (!success) {
LOGGER.debug("Failed to delete file: {}; attempting to delete on exit.", file.getPath());
file.deleteOnExit();
}

View File

@@ -117,6 +117,10 @@ public final class Settings {
* The properties key for the URL to retrieve the recently modified and added CVE entries (last 8 days).
*/
public static final String CVE_MODIFIED_VALID_FOR_DAYS = "cve.url.modified.validfordays";
/**
* The properties key to control the skipping of the check for CVE updates.
*/
public static final String CVE_CHECK_VALID_FOR_HOURS = "cve.check.validforhours";
/**
* The properties key for the telling us how many cve.url.* URLs exists. This is used in combination with CVE_BASE_URL to
* be able to retrieve the URLs for all of the files that make up the NVD CVE listing.
@@ -236,7 +240,7 @@ public final class Settings {
/**
* The properties key for using the proxy to reach Nexus.
*/
public static final String ANALYZER_NEXUS_PROXY = "analyzer.nexus.proxy";
public static final String ANALYZER_NEXUS_USES_PROXY = "analyzer.nexus.proxy";
/**
* The properties key for whether the Central analyzer is enabled.
*/
@@ -261,19 +265,6 @@ public final class Settings {
* The additional configured zip file extensions, if available.
*/
public static final String ADDITIONAL_ZIP_EXTENSIONS = "extensions.zip";
/**
* The properties key for whether Test Scope dependencies should be skipped.
*/
public static final String SKIP_TEST_SCOPE = "skip.test.scope";
/**
* The properties key for whether Runtime Scope dependencies should be skipped.
*/
public static final String SKIP_RUNTIME_SCOPE = "skip.runtime.scope";
/**
* The properties key for whether Provided Scope dependencies should be skipped.
*/
public static final String SKIP_PROVIDED_SCOPE = "skip.provided.scope";
/**
* The key to obtain the path to the VFEED data file.
*/
@@ -461,6 +452,30 @@ public final class Settings {
LOGGER.debug("Setting: {}='{}'", key, value);
}
/**
* Sets a property value only if the value is not null.
*
* @param key the key for the property
* @param value the value for the property
*/
public static void setStringIfNotNull(String key, String value) {
if (null != value) {
setString(key, value);
}
}
/**
* Sets a property value only if the value is not null and not empty.
*
* @param key the key for the property
* @param value the value for the property
*/
public static void setStringIfNotEmpty(String key, String value) {
if (null != value && !value.isEmpty()) {
setString(key, value);
}
}
/**
* Sets a property value.
*
@@ -468,14 +483,44 @@ public final class Settings {
* @param value the value for the property
*/
public static void setBoolean(String key, boolean value) {
if (value) {
localSettings.get().props.setProperty(key, Boolean.TRUE.toString());
} else {
localSettings.get().props.setProperty(key, Boolean.FALSE.toString());
setString(key, Boolean.toString(value));
}
/**
* Sets a property value only if the value is not null.
*
* @param key the key for the property
* @param value the value for the property
*/
public static void setBooleanIfNotNull(String key, Boolean value) {
if (null != value) {
setBoolean(key, value);
}
}
/**
* Sets a property value.
*
* @param key the key for the property
* @param value the value for the property
*/
public static void setInt(String key, int value) {
localSettings.get().props.setProperty(key, String.valueOf(value));
LOGGER.debug("Setting: {}='{}'", key, value);
}
/**
* Sets a property value only if the value is not null.
*
* @param key the key for the property
* @param value the value for the property
*/
public static void setIntIfNotNull(String key, Integer value) {
if (null != value) {
setInt(key, value);
}
}
/**
* Merges a new properties file into the current properties. This method allows for the loading of a user provided properties
* file.<br/><br/>
@@ -672,13 +717,11 @@ public final class Settings {
* @throws InvalidSettingException is thrown if there is an error retrieving the setting
*/
public static int getInt(String key) throws InvalidSettingException {
int value;
try {
value = Integer.parseInt(Settings.getString(key));
return Integer.parseInt(Settings.getString(key));
} catch (NumberFormatException ex) {
throw new InvalidSettingException("Could not convert property '" + key + "' to an int.", ex);
}
return value;
}
/**
@@ -712,13 +755,11 @@ public final class Settings {
* @throws InvalidSettingException is thrown if there is an error retrieving the setting
*/
public static long getLong(String key) throws InvalidSettingException {
long value;
try {
value = Long.parseLong(Settings.getString(key));
return Long.parseLong(Settings.getString(key));
} catch (NumberFormatException ex) {
throw new InvalidSettingException("Could not convert property '" + key + "' to an int.", ex);
throw new InvalidSettingException("Could not convert property '" + key + "' to a long.", ex);
}
return value;
}
/**
@@ -731,13 +772,7 @@ public final class Settings {
* @throws InvalidSettingException is thrown if there is an error retrieving the setting
*/
public static boolean getBoolean(String key) throws InvalidSettingException {
boolean value;
try {
value = Boolean.parseBoolean(Settings.getString(key));
} catch (NumberFormatException ex) {
throw new InvalidSettingException("Could not convert property '" + key + "' to an int.", ex);
}
return value;
return Boolean.parseBoolean(Settings.getString(key));
}
/**
@@ -751,17 +786,7 @@ public final class Settings {
* @throws InvalidSettingException is thrown if there is an error retrieving the setting
*/
public static boolean getBoolean(String key, boolean defaultValue) throws InvalidSettingException {
boolean value;
try {
final String strValue = Settings.getString(key);
if (strValue == null) {
return defaultValue;
}
value = Boolean.parseBoolean(strValue);
} catch (NumberFormatException ex) {
throw new InvalidSettingException("Could not convert property '" + key + "' to an int.", ex);
}
return value;
return Boolean.parseBoolean(Settings.getString(key, Boolean.toString(defaultValue)));
}
/**

View File

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

View File

@@ -35,8 +35,8 @@ public class FileUtilsTest extends BaseTest {
*/
@Test
public void testGetFileExtension() {
String[] fileName = {"something-0.9.5.jar", "lib2-1.1.js"};
String[] expResult = {"jar", "js"};
String[] fileName = {"something-0.9.5.jar", "lib2-1.1.js", "dir.tmp/noext"};
String[] expResult = {"jar", "js", null};
for (int i = 0; i < fileName.length; i++) {
String result = FileUtils.getFileExtension(fileName[i]);

View File

@@ -77,6 +77,32 @@ public class SettingsTest extends BaseTest {
Assert.assertEquals(expResults, value);
}
/**
* Test of setStringIfNotNull method, of class Settings.
*/
@Test
public void testSetStringIfNotNull() {
String key = "nullableProperty";
String value = "someValue";
Settings.setString(key, value);
Settings.setStringIfNotNull(key, null); // NO-OP
String expResults = Settings.getString(key);
Assert.assertEquals(expResults, value);
}
/**
* Test of setStringIfNotNull method, of class Settings.
*/
@Test
public void testSetStringIfNotEmpty() {
String key = "optionalProperty";
String value = "someValue";
Settings.setString(key, value);
Settings.setStringIfNotEmpty(key, ""); // NO-OP
String expResults = Settings.getString(key);
Assert.assertEquals(expResults, value);
}
/**
* Test of getString method, of class Settings.
*/

View File

@@ -17,7 +17,7 @@ engine.version.url=http://jeremylong.github.io/DependencyCheck/current.txt
# below contains a %s then the data.directory will replace the %s.
data.directory=[JAR]/data
data.file_name=dc.h2.db
data.version=2.9
data.version=3.0
data.connection_string=jdbc:h2:file:%s;FILE_LOCK=SERIALIZED;AUTOCOMMIT=ON;
#data.connection_string=jdbc:h2:file:%s;AUTO_SERVER=TRUE;AUTOCOMMIT=ON;
#data.connection_string=jdbc:mysql://localhost:3306/dependencycheck