mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-03-29 05:12:14 +02:00
Issue #730: Remove redundant method from Settings
Pull file loading from loadSuppressionData() to make it easier to read Add test assertion to happy case Ant task test
This commit is contained in:
@@ -127,6 +127,8 @@ public class DependencyCheckTaskTest {
|
|||||||
buildFileRule.executeTarget(antTaskName);
|
buildFileRule.executeTarget(antTaskName);
|
||||||
|
|
||||||
// THEN the ant task executed without error
|
// THEN the ant task executed without error
|
||||||
|
final File report = new File("target/dependency-check-report.html");
|
||||||
|
assertTrue("Expected the DependencyCheck report to be generated", report.exists());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -99,13 +99,12 @@ public abstract class AbstractSuppressionAnalyzer extends AbstractAnalyzer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads the suppression rules file.
|
* Loads all the suppression rules files configured in the {@link Settings} singleton.
|
||||||
*
|
*
|
||||||
* @throws SuppressionParseException thrown if the XML cannot be parsed.
|
* @throws SuppressionParseException thrown if the XML cannot be parsed.
|
||||||
*/
|
*/
|
||||||
private void loadSuppressionData() throws SuppressionParseException {
|
private void loadSuppressionData() throws SuppressionParseException {
|
||||||
final SuppressionParser parser = new SuppressionParser();
|
final SuppressionParser parser = new SuppressionParser();
|
||||||
File file = null;
|
|
||||||
try {
|
try {
|
||||||
final InputStream in = this.getClass().getClassLoader().getResourceAsStream("dependencycheck-base-suppression.xml");
|
final InputStream in = this.getClass().getClassLoader().getResourceAsStream("dependencycheck-base-suppression.xml");
|
||||||
rules = parser.parseSuppressionRules(in);
|
rules = parser.parseSuppressionRules(in);
|
||||||
@@ -117,9 +116,24 @@ public abstract class AbstractSuppressionAnalyzer extends AbstractAnalyzer {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load all the suppression file paths
|
||||||
for (final String suppressionFilePath : suppressionFilePaths) {
|
for (final String suppressionFilePath : suppressionFilePaths) {
|
||||||
|
loadSuppressionFile(parser, suppressionFilePath);
|
||||||
|
}
|
||||||
|
LOGGER.debug("{} suppression rules were loaded.", rules.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load a single suppression rules file from the path provided using the parser provided.
|
||||||
|
*
|
||||||
|
* @param parser the parser to use for loading the file.
|
||||||
|
* @param suppressionFilePath the path to load.
|
||||||
|
* @throws SuppressionParseException thrown if the suppression file cannot be loaded and parsed.
|
||||||
|
*/
|
||||||
|
private void loadSuppressionFile(final SuppressionParser parser, final String suppressionFilePath) throws SuppressionParseException {
|
||||||
LOGGER.debug("Loading suppression rules from '{}'", suppressionFilePath);
|
LOGGER.debug("Loading suppression rules from '{}'", suppressionFilePath);
|
||||||
|
|
||||||
|
File file = null;
|
||||||
boolean deleteTempFile = false;
|
boolean deleteTempFile = false;
|
||||||
try {
|
try {
|
||||||
final Pattern uriRx = Pattern.compile("^(https?|file)\\:.*", Pattern.CASE_INSENSITIVE);
|
final Pattern uriRx = Pattern.compile("^(https?|file)\\:.*", Pattern.CASE_INSENSITIVE);
|
||||||
@@ -177,8 +191,6 @@ public abstract class AbstractSuppressionAnalyzer extends AbstractAnalyzer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOGGER.debug("{} suppression rules were loaded.", rules.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility method to throw parse exceptions.
|
* Utility method to throw parse exceptions.
|
||||||
|
|||||||
@@ -564,18 +564,6 @@ public final class Settings {
|
|||||||
LOGGER.debug("Setting: {}='{}'", key, value);
|
LOGGER.debug("Setting: {}='{}'", key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets a property value from an array.
|
|
||||||
* <p>
|
|
||||||
* Note: each value of the array will be joined by the delimiter {@link Settings#ARRAY_SEP}.
|
|
||||||
*
|
|
||||||
* @param key the key for the property
|
|
||||||
* @param value the value for the property
|
|
||||||
*/
|
|
||||||
static void setArray(String key, String[] value) {
|
|
||||||
setString(key, StringUtils.join(value, ARRAY_SEP));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a property value only if the value is not null.
|
* Sets a property value only if the value is not null.
|
||||||
*
|
*
|
||||||
@@ -608,7 +596,7 @@ public final class Settings {
|
|||||||
*/
|
*/
|
||||||
public static void setArrayIfNotEmpty(String key, String[] value) {
|
public static void setArrayIfNotEmpty(String key, String[] value) {
|
||||||
if (null != value && value.length > 0) {
|
if (null != value && value.length > 0) {
|
||||||
setArray(key, value);
|
setString(key, StringUtils.join(value, ARRAY_SEP));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -336,19 +336,4 @@ public class SettingsTest extends BaseTest {
|
|||||||
assertThat("Expected the property to be set", Settings.getString("key"), is("value1"));
|
assertThat("Expected the property to be set", Settings.getString("key"), is("value1"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Assert {@link Settings#setArray(String, String[])} with multiple values sets a delimited string.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testSetArraySetsADelimitedString() {
|
|
||||||
// GIVEN an array with values
|
|
||||||
final String[] array = { "value1", "value2" };
|
|
||||||
|
|
||||||
// WHEN setting the array
|
|
||||||
Settings.setArray("key", array);
|
|
||||||
|
|
||||||
// THEN the property is set
|
|
||||||
assertThat("Expected the property to be set", Settings.getString("key"), is("value1,value2"));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user