From 275d1bdbf9e92e5a3c680a777b540388ec00fe9a Mon Sep 17 00:00:00 2001 From: Jeremy Long Date: Sun, 21 Jan 2018 09:12:36 -0500 Subject: [PATCH] improved logging to assist in resolving #1061 --- .../dependencycheck/analyzer/ArchiveAnalyzer.java | 10 ++++++---- .../owasp/dependencycheck/analyzer/JarAnalyzer.java | 5 +++-- .../owasp/dependencycheck/utils/ExtractionUtil.java | 5 +++-- .../java/org/owasp/dependencycheck/utils/Settings.java | 4 +++- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/dependency-check-core/src/main/java/org/owasp/dependencycheck/analyzer/ArchiveAnalyzer.java b/dependency-check-core/src/main/java/org/owasp/dependencycheck/analyzer/ArchiveAnalyzer.java index d6d2e8fb2..873ea263c 100644 --- a/dependency-check-core/src/main/java/org/owasp/dependencycheck/analyzer/ArchiveAnalyzer.java +++ b/dependency-check-core/src/main/java/org/owasp/dependencycheck/analyzer/ArchiveAnalyzer.java @@ -206,12 +206,13 @@ public class ArchiveAnalyzer extends AbstractFileTypeAnalyzer { @Override public void closeAnalyzer() throws Exception { if (tempFileLocation != null && tempFileLocation.exists()) { - LOGGER.debug("Attempting to delete temporary files"); + LOGGER.debug("Attempting to delete temporary files from `{}`", tempFileLocation.toString()); final boolean success = FileUtils.delete(tempFileLocation); if (!success && tempFileLocation.exists()) { final String[] l = tempFileLocation.list(); if (l != null && l.length > 0) { - LOGGER.warn("Failed to delete some temporary files, see the log for more details"); + LOGGER.warn("Failed to delete the Archive Analyzer's temporary files from `{}`, " + + "see the log for more details", tempFileLocation.toString()); } } } @@ -388,8 +389,9 @@ public class ArchiveAnalyzer extends AbstractFileTypeAnalyzer { try { fis = new FileInputStream(archive); } catch (FileNotFoundException ex) { - LOGGER.debug("", ex); - throw new AnalysisException("Archive file was not found.", ex); + final String msg = String.format("Error extracting file `%s`: %s", archive.toString(), ex.getMessage()); + LOGGER.debug(msg, ex); + throw new AnalysisException(msg); } BufferedInputStream in = null; ZipArchiveInputStream zin = null; diff --git a/dependency-check-core/src/main/java/org/owasp/dependencycheck/analyzer/JarAnalyzer.java b/dependency-check-core/src/main/java/org/owasp/dependencycheck/analyzer/JarAnalyzer.java index 48c5fb701..fa39b9973 100644 --- a/dependency-check-core/src/main/java/org/owasp/dependencycheck/analyzer/JarAnalyzer.java +++ b/dependency-check-core/src/main/java/org/owasp/dependencycheck/analyzer/JarAnalyzer.java @@ -970,12 +970,13 @@ public class JarAnalyzer extends AbstractFileTypeAnalyzer { @Override public void closeAnalyzer() { if (tempFileLocation != null && tempFileLocation.exists()) { - LOGGER.debug("Attempting to delete temporary files"); + LOGGER.debug("Attempting to delete temporary files from `{}`", tempFileLocation.toString()); final boolean success = FileUtils.delete(tempFileLocation); if (!success && tempFileLocation.exists()) { final String[] l = tempFileLocation.list(); if (l != null && l.length > 0) { - LOGGER.warn("Failed to delete some temporary files, see the log for more details"); + LOGGER.warn("Failed to delete the JAR Analyzder's temporary files from `{}`, " + + "see the log for more details", tempFileLocation.toString()); } } } diff --git a/dependency-check-core/src/main/java/org/owasp/dependencycheck/utils/ExtractionUtil.java b/dependency-check-core/src/main/java/org/owasp/dependencycheck/utils/ExtractionUtil.java index 08a0465bd..fd1962b64 100644 --- a/dependency-check-core/src/main/java/org/owasp/dependencycheck/utils/ExtractionUtil.java +++ b/dependency-check-core/src/main/java/org/owasp/dependencycheck/utils/ExtractionUtil.java @@ -139,8 +139,9 @@ public final class ExtractionUtil { extractArchive(new ZipArchiveInputStream(new BufferedInputStream( fis)), destination, filter); } catch (FileNotFoundException ex) { - LOGGER.debug("", ex); - throw new ExtractionException("Archive file was not found.", ex); + final String msg = String.format("Error extracting file `%s` with filter: %s",archive.toString(), ex.getMessage()); + LOGGER.debug(msg, ex); + throw new ExtractionException(msg); } catch (IOException | ArchiveExtractionException ex) { LOGGER.warn("Exception extracting archive '{}'.", archive.getName()); LOGGER.debug("", ex); diff --git a/dependency-check-utils/src/main/java/org/owasp/dependencycheck/utils/Settings.java b/dependency-check-utils/src/main/java/org/owasp/dependencycheck/utils/Settings.java index b35677f3c..758766a72 100644 --- a/dependency-check-utils/src/main/java/org/owasp/dependencycheck/utils/Settings.java +++ b/dependency-check-utils/src/main/java/org/owasp/dependencycheck/utils/Settings.java @@ -457,7 +457,8 @@ public final class Settings { */ public static final String MAX_BATCH_SIZE = "database.batchinsert.maxsize"; /** - * The key that specifies the class name of the H2 database shutdown hook. + * The key that specifies the class name of the H2 database shutdown + * hook. */ public static final String H2DB_SHUTDOWN_HOOK = "data.h2.shutdownhook"; @@ -522,6 +523,7 @@ public final class Settings { */ public synchronized void cleanup(boolean deleteTemporary) { if (deleteTemporary && tempDirectory != null && tempDirectory.exists()) { + LOGGER.debug("Deleting ALL temporary files from `{}`", tempDirectory.toString()); FileUtils.delete(tempDirectory); tempDirectory = null; }