checkstyle corrections

Former-commit-id: 8cf3b2001eef9cd73809cfc3036e4662e0912f9d
This commit is contained in:
Jeremy Long
2014-04-19 12:49:57 -04:00
parent dc2f1eabb2
commit 3728594f73
5 changed files with 41 additions and 34 deletions

View File

@@ -27,6 +27,7 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.owasp.dependencycheck.data.nvdcve.CveDB; import org.owasp.dependencycheck.data.nvdcve.CveDB;
import org.owasp.dependencycheck.data.update.NvdCveInfo; 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.DownloadFailedException;
import org.owasp.dependencycheck.utils.Downloader; import org.owasp.dependencycheck.utils.Downloader;
import org.owasp.dependencycheck.utils.Settings; import org.owasp.dependencycheck.utils.Settings;
@@ -44,8 +45,11 @@ public class CallableDownloadTask implements Callable<Future<ProcessTask>> {
* @param nvdCveInfo the NVD CVE info * @param nvdCveInfo the NVD CVE info
* @param processor the processor service to submit the downloaded files to * @param processor the processor service to submit the downloaded files to
* @param cveDB the CVE DB to use to store the vulnerability data * @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.nvdCveInfo = nvdCveInfo;
this.processorService = processor; this.processorService = processor;
this.cveDB = cveDB; this.cveDB = cveDB;
@@ -58,7 +62,7 @@ public class CallableDownloadTask implements Callable<Future<ProcessTask>> {
file1 = File.createTempFile("cve" + nvdCveInfo.getId() + "_", ".xml", Settings.getTempDirectory()); file1 = File.createTempFile("cve" + nvdCveInfo.getId() + "_", ".xml", Settings.getTempDirectory());
file2 = File.createTempFile("cve_1_2_" + nvdCveInfo.getId() + "_", ".xml", Settings.getTempDirectory()); file2 = File.createTempFile("cve_1_2_" + nvdCveInfo.getId() + "_", ".xml", Settings.getTempDirectory());
} catch (IOException ex) { } catch (IOException ex) {
return; throw new UpdateException("Unable to create temporary files", ex);
} }
this.first = file1; this.first = file1;
this.second = file2; this.second = file2;

View File

@@ -91,6 +91,8 @@ public class ProcessTask implements Callable<ProcessTask> {
* *
* @param cveDB the data store object * @param cveDB the data store object
* @param filePair the download task that contains the URL references to download * @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) { public ProcessTask(final CveDB cveDB, final CallableDownloadTask filePair, Settings settings) {
this.cveDB = cveDB; this.cveDB = cveDB;

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2014 OWASP. * This file is part of dependency-check-core.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -12,6 +12,8 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*
* Copyright (c) 2014 Jeremy Long. All Rights Reserved.
*/ */
package org.owasp.dependencycheck.reporting; package org.owasp.dependencycheck.reporting;

View File

@@ -95,12 +95,12 @@ public class ReportGenerator {
engine.init(); engine.init();
DateFormat dateFormat = new SimpleDateFormat("MMM d, yyyy 'at' HH:mm:ss z"); final DateFormat dateFormat = new SimpleDateFormat("MMM d, yyyy 'at' HH:mm:ss z");
DateFormat dateFormatXML = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); final DateFormat dateFormatXML = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
Date d = new Date(); final Date d = new Date();
String scanDate = dateFormat.format(d); final String scanDate = dateFormat.format(d);
String scanDateXML = dateFormatXML.format(d); final String scanDateXML = dateFormatXML.format(d);
EscapeTool enc = new EscapeTool(); final EscapeTool enc = new EscapeTool();
context.put("applicationName", applicationName); context.put("applicationName", applicationName);
context.put("dependencies", dependencies); context.put("dependencies", dependencies);
@@ -136,9 +136,10 @@ public class ReportGenerator {
// final Context c = manager.createContext(); // final Context c = manager.createContext();
// final EasyFactoryConfiguration config = new EasyFactoryConfiguration(); // final EasyFactoryConfiguration config = new EasyFactoryConfiguration();
// config.addDefaultTools(); // 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); // manager.configure(config);
VelocityContext c = new VelocityContext(); final VelocityContext c = new VelocityContext();
return c; return c;
} }

View File

@@ -38,12 +38,7 @@ import java.util.logging.Logger;
*/ */
public final class Settings { public final class Settings {
/**
* The logger.
*/
private static final Logger LOGGER = Logger.getLogger(Settings.class.getName());
//<editor-fold defaultstate="collapsed" desc="KEYS used to access settings"> //<editor-fold defaultstate="collapsed" desc="KEYS used to access settings">
/** /**
* The collection of keys used within the properties file. * The collection of keys used within the properties file.
*/ */
@@ -201,19 +196,22 @@ public final class Settings {
} }
//</editor-fold> //</editor-fold>
/**
* The logger.
*/
private static final Logger LOGGER = Logger.getLogger(Settings.class.getName());
/** /**
* The properties file location. * The properties file location.
*/ */
private static final String PROPERTIES_FILE = "dependencycheck.properties"; private static final String PROPERTIES_FILE = "dependencycheck.properties";
/**
* Thread local settings.
*/
private static ThreadLocal<Settings> localSettings = new ThreadLocal();
/** /**
* The properties. * The properties.
*/ */
private Properties props = null; private Properties props = null;
/**
* Thread local settings.
*/
private static ThreadLocal<Settings> THREAD_LOCAL = new ThreadLocal();
/** /**
* Private constructor for the Settings class. This class loads the properties files. * 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. * However, you must also call Settings.cleanup() to properly release resources.
*/ */
public static void initialize() { 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() { public static void cleanup() {
try { try {
THREAD_LOCAL.remove(); localSettings.remove();
} catch (Throwable ex) { } catch (Throwable ex) {
LOGGER.log(Level.FINE, "Error cleaning up Settings", ex); LOGGER.log(Level.FINE, "Error cleaning up Settings", ex);
} }
@@ -264,7 +262,7 @@ public final class Settings {
* @return the Settings object * @return the Settings object
*/ */
public static Settings getInstance() { 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 * @param instance the instance of the settings object to use in this thread
*/ */
public static void setInstance(Settings instance) { 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 * @param value the value for the property
*/ */
public static void setString(String key, String value) { 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)) { if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine(String.format("Setting: %s='%s'", key, value)); 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) { public static void setBoolean(String key, boolean value) {
if (value) { if (value) {
THREAD_LOCAL.get().props.setProperty(key, Boolean.TRUE.toString()); localSettings.get().props.setProperty(key, Boolean.TRUE.toString());
} else { } else {
THREAD_LOCAL.get().props.setProperty(key, Boolean.FALSE.toString()); localSettings.get().props.setProperty(key, Boolean.FALSE.toString());
} }
if (LOGGER.isLoggable(Level.FINE)) { if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine(String.format("Setting: %s='%b'", key, value)); 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 * @throws IOException is thrown when there is an exception loading/merging the properties
*/ */
public static void mergeProperties(InputStream stream) throws IOException { public static void mergeProperties(InputStream stream) throws IOException {
THREAD_LOCAL.get().props.load(stream); localSettings.get().props.load(stream);
logProperties("Properties updated via merge", THREAD_LOCAL.get().props); logProperties("Properties updated via merge", localSettings.get().props);
} }
/** /**
@@ -460,7 +458,7 @@ public final class Settings {
* @return the property from the properties file * @return the property from the properties file
*/ */
public static String getString(String key, String defaultValue) { 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; return str;
} }
@@ -482,7 +480,7 @@ public final class Settings {
* @return the property from the properties file * @return the property from the properties file
*/ */
public static String getString(String key) { 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 * @param key the property key to remove
*/ */
public static void removeProperty(String key) { public static void removeProperty(String key) {
THREAD_LOCAL.get().props.remove(key); localSettings.get().props.remove(key);
} }
/** /**