From a855d53542d6489ccbe307bbd589af864f59b183 Mon Sep 17 00:00:00 2001 From: Jeremy Long Date: Sat, 19 Apr 2014 12:49:57 -0400 Subject: [PATCH] checkstyle corrections Former-commit-id: 8caae0e4f0dd1828419c84b081fbc32d4d7be93c --- .../update/task/CallableDownloadTask.java | 8 +++- .../data/update/task/ProcessTask.java | 2 + .../dependencycheck/reporting/EscapeTool.java | 6 ++- .../reporting/ReportGenerator.java | 17 ++++---- .../owasp/dependencycheck/utils/Settings.java | 42 +++++++++---------- 5 files changed, 41 insertions(+), 34 deletions(-) diff --git a/dependency-check-core/src/main/java/org/owasp/dependencycheck/data/update/task/CallableDownloadTask.java b/dependency-check-core/src/main/java/org/owasp/dependencycheck/data/update/task/CallableDownloadTask.java index 6a016dd55..c0ad0a3fa 100644 --- a/dependency-check-core/src/main/java/org/owasp/dependencycheck/data/update/task/CallableDownloadTask.java +++ b/dependency-check-core/src/main/java/org/owasp/dependencycheck/data/update/task/CallableDownloadTask.java @@ -27,6 +27,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import org.owasp.dependencycheck.data.nvdcve.CveDB; import org.owasp.dependencycheck.data.update.NvdCveInfo; +import org.owasp.dependencycheck.data.update.exception.UpdateException; import org.owasp.dependencycheck.utils.DownloadFailedException; import org.owasp.dependencycheck.utils.Downloader; import org.owasp.dependencycheck.utils.Settings; @@ -44,8 +45,11 @@ public class CallableDownloadTask implements Callable> { * @param nvdCveInfo the NVD CVE info * @param processor the processor service to submit the downloaded files to * @param cveDB the CVE DB to use to store the vulnerability data + * @param settings a reference to the global settings object; this is necessary so that when the thread is started + * the dependencies have a correct reference to the global settings. + * @throws UpdateException thrown if temporary files could not be created */ - public CallableDownloadTask(NvdCveInfo nvdCveInfo, ExecutorService processor, CveDB cveDB, Settings settings) { + public CallableDownloadTask(NvdCveInfo nvdCveInfo, ExecutorService processor, CveDB cveDB, Settings settings) throws UpdateException { this.nvdCveInfo = nvdCveInfo; this.processorService = processor; this.cveDB = cveDB; @@ -58,7 +62,7 @@ public class CallableDownloadTask implements Callable> { file1 = File.createTempFile("cve" + nvdCveInfo.getId() + "_", ".xml", Settings.getTempDirectory()); file2 = File.createTempFile("cve_1_2_" + nvdCveInfo.getId() + "_", ".xml", Settings.getTempDirectory()); } catch (IOException ex) { - return; + throw new UpdateException("Unable to create temporary files", ex); } this.first = file1; this.second = file2; diff --git a/dependency-check-core/src/main/java/org/owasp/dependencycheck/data/update/task/ProcessTask.java b/dependency-check-core/src/main/java/org/owasp/dependencycheck/data/update/task/ProcessTask.java index 7ea150b40..b63f8fee5 100644 --- a/dependency-check-core/src/main/java/org/owasp/dependencycheck/data/update/task/ProcessTask.java +++ b/dependency-check-core/src/main/java/org/owasp/dependencycheck/data/update/task/ProcessTask.java @@ -91,6 +91,8 @@ public class ProcessTask implements Callable { * * @param cveDB the data store object * @param filePair the download task that contains the URL references to download + * @param settings a reference to the global settings object; this is necessary so that when the thread is started + * the dependencies have a correct reference to the global settings. */ public ProcessTask(final CveDB cveDB, final CallableDownloadTask filePair, Settings settings) { this.cveDB = cveDB; diff --git a/dependency-check-core/src/main/java/org/owasp/dependencycheck/reporting/EscapeTool.java b/dependency-check-core/src/main/java/org/owasp/dependencycheck/reporting/EscapeTool.java index 11e112faf..3026f8190 100644 --- a/dependency-check-core/src/main/java/org/owasp/dependencycheck/reporting/EscapeTool.java +++ b/dependency-check-core/src/main/java/org/owasp/dependencycheck/reporting/EscapeTool.java @@ -1,17 +1,19 @@ /* - * Copyright 2014 OWASP. + * This file is part of dependency-check-core. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * + * Copyright (c) 2014 Jeremy Long. All Rights Reserved. */ package org.owasp.dependencycheck.reporting; diff --git a/dependency-check-core/src/main/java/org/owasp/dependencycheck/reporting/ReportGenerator.java b/dependency-check-core/src/main/java/org/owasp/dependencycheck/reporting/ReportGenerator.java index 5c5a8bee1..17aa5b56a 100644 --- a/dependency-check-core/src/main/java/org/owasp/dependencycheck/reporting/ReportGenerator.java +++ b/dependency-check-core/src/main/java/org/owasp/dependencycheck/reporting/ReportGenerator.java @@ -95,12 +95,12 @@ public class ReportGenerator { engine.init(); - DateFormat dateFormat = new SimpleDateFormat("MMM d, yyyy 'at' HH:mm:ss z"); - DateFormat dateFormatXML = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); - Date d = new Date(); - String scanDate = dateFormat.format(d); - String scanDateXML = dateFormatXML.format(d); - EscapeTool enc = new EscapeTool(); + final DateFormat dateFormat = new SimpleDateFormat("MMM d, yyyy 'at' HH:mm:ss z"); + final DateFormat dateFormatXML = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); + final Date d = new Date(); + final String scanDate = dateFormat.format(d); + final String scanDateXML = dateFormatXML.format(d); + final EscapeTool enc = new EscapeTool(); context.put("applicationName", applicationName); context.put("dependencies", dependencies); @@ -136,9 +136,10 @@ public class ReportGenerator { // final Context c = manager.createContext(); // final EasyFactoryConfiguration config = new EasyFactoryConfiguration(); // config.addDefaultTools(); -// config.toolbox("application").tool("esc", "org.apache.velocity.tools.generic.EscapeTool").tool("org.apache.velocity.tools.generic.DateTool"); +// config.toolbox("application").tool("esc", "org.apache.velocity.tools.generic.EscapeTool"). +// tool("org.apache.velocity.tools.generic.DateTool"); // manager.configure(config); - VelocityContext c = new VelocityContext(); + final VelocityContext c = new VelocityContext(); return c; } diff --git a/dependency-check-core/src/main/java/org/owasp/dependencycheck/utils/Settings.java b/dependency-check-core/src/main/java/org/owasp/dependencycheck/utils/Settings.java index d5b09f641..0fba42db3 100644 --- a/dependency-check-core/src/main/java/org/owasp/dependencycheck/utils/Settings.java +++ b/dependency-check-core/src/main/java/org/owasp/dependencycheck/utils/Settings.java @@ -38,12 +38,7 @@ import java.util.logging.Logger; */ public final class Settings { - /** - * The logger. - */ - private static final Logger LOGGER = Logger.getLogger(Settings.class.getName()); // - /** * The collection of keys used within the properties file. */ @@ -201,19 +196,22 @@ public final class Settings { } // + /** + * The logger. + */ + private static final Logger LOGGER = Logger.getLogger(Settings.class.getName()); /** * The properties file location. */ private static final String PROPERTIES_FILE = "dependencycheck.properties"; - + /** + * Thread local settings. + */ + private static ThreadLocal localSettings = new ThreadLocal(); /** * The properties. */ private Properties props = null; - /** - * Thread local settings. - */ - private static ThreadLocal THREAD_LOCAL = new ThreadLocal(); /** * Private constructor for the Settings class. This class loads the properties files. @@ -244,7 +242,7 @@ public final class Settings { * However, you must also call Settings.cleanup() to properly release resources. */ public static void initialize() { - THREAD_LOCAL.set(new Settings()); + localSettings.set(new Settings()); } /** @@ -252,7 +250,7 @@ public final class Settings { */ public static void cleanup() { try { - THREAD_LOCAL.remove(); + localSettings.remove(); } catch (Throwable ex) { LOGGER.log(Level.FINE, "Error cleaning up Settings", ex); } @@ -264,7 +262,7 @@ public final class Settings { * @return the Settings object */ public static Settings getInstance() { - return THREAD_LOCAL.get(); + return localSettings.get(); } /** @@ -273,7 +271,7 @@ public final class Settings { * @param instance the instance of the settings object to use in this thread */ public static void setInstance(Settings instance) { - THREAD_LOCAL.set(instance); + localSettings.set(instance); } /** @@ -319,7 +317,7 @@ public final class Settings { * @param value the value for the property */ public static void setString(String key, String value) { - THREAD_LOCAL.get().props.setProperty(key, value); + localSettings.get().props.setProperty(key, value); if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine(String.format("Setting: %s='%s'", key, value)); } @@ -333,9 +331,9 @@ public final class Settings { */ public static void setBoolean(String key, boolean value) { if (value) { - THREAD_LOCAL.get().props.setProperty(key, Boolean.TRUE.toString()); + localSettings.get().props.setProperty(key, Boolean.TRUE.toString()); } else { - THREAD_LOCAL.get().props.setProperty(key, Boolean.FALSE.toString()); + localSettings.get().props.setProperty(key, Boolean.FALSE.toString()); } if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine(String.format("Setting: %s='%b'", key, value)); @@ -379,8 +377,8 @@ public final class Settings { * @throws IOException is thrown when there is an exception loading/merging the properties */ public static void mergeProperties(InputStream stream) throws IOException { - THREAD_LOCAL.get().props.load(stream); - logProperties("Properties updated via merge", THREAD_LOCAL.get().props); + localSettings.get().props.load(stream); + logProperties("Properties updated via merge", localSettings.get().props); } /** @@ -460,7 +458,7 @@ public final class Settings { * @return the property from the properties file */ public static String getString(String key, String defaultValue) { - final String str = System.getProperty(key, THREAD_LOCAL.get().props.getProperty(key, defaultValue)); + final String str = System.getProperty(key, localSettings.get().props.getProperty(key, defaultValue)); return str; } @@ -482,7 +480,7 @@ public final class Settings { * @return the property from the properties file */ public static String getString(String key) { - return System.getProperty(key, THREAD_LOCAL.get().props.getProperty(key)); + return System.getProperty(key, localSettings.get().props.getProperty(key)); } /** @@ -491,7 +489,7 @@ public final class Settings { * @param key the property key to remove */ public static void removeProperty(String key) { - THREAD_LOCAL.get().props.remove(key); + localSettings.get().props.remove(key); } /**