mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-03-22 17:19:30 +01:00
organized imports
extracted exception handling Former-commit-id: 2ec171b680d77c0db1dca9ec667e72040040eab9
This commit is contained in:
@@ -17,16 +17,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.owasp.dependencycheck.analyzer;
|
package org.owasp.dependencycheck.analyzer;
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
import org.owasp.dependencycheck.suppression.SuppressionParseException;
|
import org.owasp.dependencycheck.suppression.SuppressionParseException;
|
||||||
import org.owasp.dependencycheck.suppression.SuppressionParser;
|
import org.owasp.dependencycheck.suppression.SuppressionParser;
|
||||||
import org.owasp.dependencycheck.suppression.SuppressionRule;
|
import org.owasp.dependencycheck.suppression.SuppressionRule;
|
||||||
@@ -35,6 +25,17 @@ import org.owasp.dependencycheck.utils.Downloader;
|
|||||||
import org.owasp.dependencycheck.utils.FileUtils;
|
import org.owasp.dependencycheck.utils.FileUtils;
|
||||||
import org.owasp.dependencycheck.utils.Settings;
|
import org.owasp.dependencycheck.utils.Settings;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract base suppression analyzer that contains methods for parsing the suppression xml file.
|
* Abstract base suppression analyzer that contains methods for parsing the suppression xml file.
|
||||||
*
|
*
|
||||||
@@ -48,6 +49,7 @@ public abstract class AbstractSuppressionAnalyzer extends AbstractAnalyzer {
|
|||||||
private static final Logger LOGGER = Logger.getLogger(AbstractSuppressionAnalyzer.class.getName());
|
private static final Logger LOGGER = Logger.getLogger(AbstractSuppressionAnalyzer.class.getName());
|
||||||
|
|
||||||
//<editor-fold defaultstate="collapsed" desc="All standard implementation details of Analyzer">
|
//<editor-fold defaultstate="collapsed" desc="All standard implementation details of Analyzer">
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of file EXTENSIONS supported by this analyzer.
|
* Returns a list of file EXTENSIONS supported by this analyzer.
|
||||||
*
|
*
|
||||||
@@ -58,6 +60,7 @@ public abstract class AbstractSuppressionAnalyzer extends AbstractAnalyzer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//</editor-fold>
|
//</editor-fold>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The initialize method loads the suppression XML file.
|
* The initialize method loads the suppression XML file.
|
||||||
*
|
*
|
||||||
@@ -68,6 +71,7 @@ public abstract class AbstractSuppressionAnalyzer extends AbstractAnalyzer {
|
|||||||
super.initialize();
|
super.initialize();
|
||||||
loadSuppressionData();
|
loadSuppressionData();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The list of suppression rules
|
* The list of suppression rules
|
||||||
*/
|
*/
|
||||||
@@ -124,9 +128,7 @@ public abstract class AbstractSuppressionAnalyzer extends AbstractAnalyzer {
|
|||||||
try {
|
try {
|
||||||
org.apache.commons.io.FileUtils.copyInputStreamToFile(suppressionsFromClasspath, file);
|
org.apache.commons.io.FileUtils.copyInputStreamToFile(suppressionsFromClasspath, file);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
LOGGER.log(Level.WARNING, "Unable to locate suppressions file in classpath");
|
throwSuppressionParseException("Unable to locate suppressions file in classpath", ex);
|
||||||
LOGGER.log(Level.FINE, "", ex);
|
|
||||||
throw new SuppressionParseException("Unable to locate suppressions file in classpath", ex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -146,24 +148,21 @@ public abstract class AbstractSuppressionAnalyzer extends AbstractAnalyzer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (DownloadFailedException ex) {
|
} catch (DownloadFailedException ex) {
|
||||||
LOGGER.log(Level.WARNING,
|
throwSuppressionParseException("Unable to fetch the configured suppression file", ex);
|
||||||
"Unable to fetch the configured suppression file");
|
|
||||||
LOGGER.log(Level.FINE, "", ex);
|
|
||||||
throw new SuppressionParseException("Unable to fetch the configured suppression file", ex);
|
|
||||||
} catch (MalformedURLException ex) {
|
} catch (MalformedURLException ex) {
|
||||||
LOGGER.log(Level.WARNING,
|
throwSuppressionParseException("Configured suppression file has an invalid URL", ex);
|
||||||
"Configured suppression file has an invalid URL");
|
|
||||||
LOGGER.log(Level.FINE, "", ex);
|
|
||||||
throw new SuppressionParseException("Configured suppression file has an invalid URL", ex);
|
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
LOGGER.log(Level.WARNING,
|
throwSuppressionParseException("Unable to create temp file for suppressions", ex);
|
||||||
"Unable to create temp file for suppressions");
|
|
||||||
LOGGER.log(Level.FINE, "", ex);
|
|
||||||
throw new SuppressionParseException("Unable to create temp file for suppressions", ex);
|
|
||||||
} finally {
|
} finally {
|
||||||
if (deleteTempFile && file != null) {
|
if (deleteTempFile && file != null) {
|
||||||
FileUtils.delete(file);
|
FileUtils.delete(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void throwSuppressionParseException(String message, Exception exception) throws SuppressionParseException {
|
||||||
|
LOGGER.log(Level.WARNING, message);
|
||||||
|
LOGGER.log(Level.FINE, "", exception);
|
||||||
|
throw new SuppressionParseException(message, exception);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user