Coverage Report - org.owasp.dependencycheck.utils.Settings
 
Classes in this File Line Coverage Branch Coverage Complexity
Settings
52%
72/137
44%
17/38
2.583
Settings$KEYS
N/A
N/A
2.583
 
 1  
 /*
 2  
  * This file is part of dependency-check-core.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  *
 16  
  * Copyright (c) 2012 Jeremy Long. All Rights Reserved.
 17  
  */
 18  
 package org.owasp.dependencycheck.utils;
 19  
 
 20  
 import java.io.File;
 21  
 import java.io.FileInputStream;
 22  
 import java.io.FileNotFoundException;
 23  
 import java.io.IOException;
 24  
 import java.io.InputStream;
 25  
 import java.io.PrintWriter;
 26  
 import java.io.StringWriter;
 27  
 import java.io.UnsupportedEncodingException;
 28  
 import java.net.URLDecoder;
 29  
 import java.util.Enumeration;
 30  
 import java.util.Properties;
 31  
 import java.util.logging.Level;
 32  
 import java.util.logging.Logger;
 33  
 
 34  
 /**
 35  
  * A simple settings container that wraps the dependencycheck.properties file.
 36  
  *
 37  
  * @author Jeremy Long <jeremy.long@owasp.org>
 38  
  */
 39  
 public final class Settings {
 40  
 
 41  
     //<editor-fold defaultstate="collapsed" desc="KEYS used to access settings">
 42  
     /**
 43  
      * The collection of keys used within the properties file.
 44  
      */
 45  
     public static final class KEYS {
 46  
 
 47  
         /**
 48  
          * private constructor because this is a "utility" class containing constants
 49  
          */
 50  
         private KEYS() {
 51  
             //do nothing
 52  
         }
 53  
         /**
 54  
          * The properties key indicating whether or not the cached data sources should be updated.
 55  
          */
 56  
         public static final String AUTO_UPDATE = "autoupdate";
 57  
         /**
 58  
          * The database driver class name. If this is not in the properties file the embedded database is used.
 59  
          */
 60  
         public static final String DB_DRIVER_NAME = "data.driver_name";
 61  
         /**
 62  
          * The database driver class name. If this is not in the properties file the embedded database is used.
 63  
          */
 64  
         public static final String DB_DRIVER_PATH = "data.driver_path";
 65  
         /**
 66  
          * The database connection string. If this is not in the properties file the embedded database is used.
 67  
          */
 68  
         public static final String DB_CONNECTION_STRING = "data.connection_string";
 69  
         /**
 70  
          * The username to use when connecting to the database.
 71  
          */
 72  
         public static final String DB_USER = "data.user";
 73  
         /**
 74  
          * The password to authenticate to the database.
 75  
          */
 76  
         public static final String DB_PASSWORD = "data.password";
 77  
         /**
 78  
          * The base path to use for the data directory (for embedded db).
 79  
          */
 80  
         public static final String DATA_DIRECTORY = "data.directory";
 81  
         /**
 82  
          * The properties key for the URL to retrieve the "meta" data from about the CVE entries.
 83  
          */
 84  
         public static final String CVE_META_URL = "cve.url.meta";
 85  
         /**
 86  
          * The properties key for the URL to retrieve the recently modified and added CVE entries (last 8 days) using
 87  
          * the 2.0 schema.
 88  
          */
 89  
         public static final String CVE_MODIFIED_20_URL = "cve.url-2.0.modified";
 90  
         /**
 91  
          * The properties key for the URL to retrieve the recently modified and added CVE entries (last 8 days) using
 92  
          * the 1.2 schema.
 93  
          */
 94  
         public static final String CVE_MODIFIED_12_URL = "cve.url-1.2.modified";
 95  
         /**
 96  
          * The properties key for the URL to retrieve the recently modified and added CVE entries (last 8 days).
 97  
          */
 98  
         public static final String CVE_MODIFIED_VALID_FOR_DAYS = "cve.url.modified.validfordays";
 99  
         /**
 100  
          * The properties key for the telling us how many cvr.url.* URLs exists. This is used in combination with
 101  
          * CVE_BASE_URL to be able to retrieve the URLs for all of the files that make up the NVD CVE listing.
 102  
          */
 103  
         public static final String CVE_START_YEAR = "cve.startyear";
 104  
         /**
 105  
          * The properties key for the CVE schema version 1.2.
 106  
          */
 107  
         public static final String CVE_SCHEMA_1_2 = "cve.url-1.2.base";
 108  
         /**
 109  
          * The properties key for the CVE schema version 2.0.
 110  
          */
 111  
         public static final String CVE_SCHEMA_2_0 = "cve.url-2.0.base";
 112  
         /**
 113  
          * The properties key for the proxy url.
 114  
          */
 115  
         public static final String PROXY_URL = "proxy.url";
 116  
         /**
 117  
          * The properties key for the proxy port - this must be an integer value.
 118  
          */
 119  
         public static final String PROXY_PORT = "proxy.port";
 120  
         /**
 121  
          * The properties key for the proxy username.
 122  
          */
 123  
         public static final String PROXY_USERNAME = "proxy.username";
 124  
         /**
 125  
          * The properties key for the proxy password.
 126  
          */
 127  
         public static final String PROXY_PASSWORD = "proxy.password";
 128  
         /**
 129  
          * The properties key for the connection timeout.
 130  
          */
 131  
         public static final String CONNECTION_TIMEOUT = "connection.timeout";
 132  
         /**
 133  
          * The location of the temporary directory.
 134  
          */
 135  
         public static final String TEMP_DIRECTORY = "temp.directory";
 136  
         /**
 137  
          * The maximum number of threads to allocate when downloading files.
 138  
          */
 139  
         public static final String MAX_DOWNLOAD_THREAD_POOL_SIZE = "max.download.threads";
 140  
         /**
 141  
          * The key for a list of suppression files.
 142  
          */
 143  
         public static final String SUPPRESSION_FILE = "suppression.file";
 144  
         /**
 145  
          * The properties key for whether the Jar Analyzer is enabled.
 146  
          */
 147  
         public static final String ANALYZER_JAR_ENABLED = "analyzer.jar.enabled";
 148  
         /**
 149  
          * The properties key for whether the Archive analyzer is enabled.
 150  
          */
 151  
         public static final String ANALYZER_ARCHIVE_ENABLED = "analyzer.archive.enabled";
 152  
         /**
 153  
          * The properties key for whether the .NET Assembly analyzer is enabled.
 154  
          */
 155  
         public static final String ANALYZER_ASSEMBLY_ENABLED = "analyzer.assembly.enabled";
 156  
         /**
 157  
          * The properties key for whether the .NET Nuspec analyzer is enabled.
 158  
          */
 159  
         public static final String ANALYZER_NUSPEC_ENABLED = "analyzer.nuspec.enabled";
 160  
         /**
 161  
          * The properties key for whether the JavaScript analyzer is enabled.
 162  
          */
 163  
         public static final String ANALYZER_JAVASCRIPT_ENABLED = "analyzer.javascript.enabled";
 164  
         /**
 165  
          * The properties key for whether the Nexus analyzer is enabled.
 166  
          */
 167  
         public static final String ANALYZER_NEXUS_ENABLED = "analyzer.nexus.enabled";
 168  
         /**
 169  
          * The properties key for the Nexus search URL.
 170  
          */
 171  
         public static final String ANALYZER_NEXUS_URL = "analyzer.nexus.url";
 172  
         /**
 173  
          * The properties key for using the proxy to reach Nexus.
 174  
          */
 175  
         public static final String ANALYZER_NEXUS_PROXY = "analyzer.nexus.proxy";
 176  
         /**
 177  
          * The path to mono, if available.
 178  
          */
 179  
         public static final String ANALYZER_ASSEMBLY_MONO_PATH = "analyzer.assembly.mono.path";
 180  
         /**
 181  
          * The additional configured zip file extensions, if available.
 182  
          */
 183  
         public static final String ADDITIONAL_ZIP_EXTENSIONS = "extensions.zip";
 184  
         /**
 185  
          * The properties key for whether Test Scope dependencies should be skipped.
 186  
          */
 187  
         public static final String SKIP_TEST_SCOPE = "skip.test.scope";
 188  
         /**
 189  
          * The properties key for whether Runtime Scope dependencies should be skipped.
 190  
          */
 191  
         public static final String SKIP_RUNTIME_SCOPE = "skip.runtime.scope";
 192  
         /**
 193  
          * The properties key for whether Provided Scope dependencies should be skipped.
 194  
          */
 195  
         public static final String SKIP_PROVIDED_SCOPE = "skip.provided.scope";
 196  
     }
 197  
     //</editor-fold>
 198  
 
 199  
     /**
 200  
      * The logger.
 201  
      */
 202  1
     private static final Logger LOGGER = Logger.getLogger(Settings.class.getName());
 203  
     /**
 204  
      * The properties file location.
 205  
      */
 206  
     private static final String PROPERTIES_FILE = "dependencycheck.properties";
 207  
     /**
 208  
      * Thread local settings.
 209  
      */
 210  1
     private static ThreadLocal<Settings> localSettings = new ThreadLocal();
 211  
     /**
 212  
      * The properties.
 213  
      */
 214  15
     private Properties props = null;
 215  
 
 216  
     /**
 217  
      * Private constructor for the Settings class. This class loads the properties files.
 218  
      */
 219  15
     private Settings() {
 220  15
         InputStream in = null;
 221  15
         props = new Properties();
 222  
         try {
 223  15
             in = this.getClass().getClassLoader().getResourceAsStream(PROPERTIES_FILE);
 224  15
             props.load(in);
 225  0
         } catch (IOException ex) {
 226  0
             LOGGER.log(Level.SEVERE, "Unable to load default settings.");
 227  0
             LOGGER.log(Level.FINE, null, ex);
 228  
         } finally {
 229  15
             if (in != null) {
 230  
                 try {
 231  15
                     in.close();
 232  0
                 } catch (IOException ex) {
 233  0
                     LOGGER.log(Level.FINEST, null, ex);
 234  15
                 }
 235  
             }
 236  
         }
 237  15
         logProperties("Properties loaded", props);
 238  15
     }
 239  
 
 240  
     /**
 241  
      * Initializes the thread local settings object. Note, to use the settings object you must call this method.
 242  
      * However, you must also call Settings.cleanup() to properly release resources.
 243  
      */
 244  
     public static void initialize() {
 245  15
         localSettings.set(new Settings());
 246  15
     }
 247  
 
 248  
     /**
 249  
      * Cleans up resources to prevent memory leaks.
 250  
      *
 251  
      * @param deleteTemporary flag indicating whether any temporary directories generated should be removed
 252  
      */
 253  
     public static void cleanup(boolean deleteTemporary) {
 254  15
         if (deleteTemporary && tempDirectory != null && tempDirectory.exists()) {
 255  4
             FileUtils.delete(tempDirectory);
 256  
         }
 257  
         try {
 258  15
             localSettings.remove();
 259  0
         } catch (Throwable ex) {
 260  0
             LOGGER.log(Level.FINE, "Error cleaning up Settings", ex);
 261  15
         }
 262  15
     }
 263  
 
 264  
     /**
 265  
      * Gets the underlying instance of the Settings object.
 266  
      *
 267  
      * @return the Settings object
 268  
      */
 269  
     public static Settings getInstance() {
 270  0
         return localSettings.get();
 271  
     }
 272  
 
 273  
     /**
 274  
      * Sets the instance of the Settings object to use in this thread.
 275  
      *
 276  
      * @param instance the instance of the settings object to use in this thread
 277  
      */
 278  
     public static void setInstance(Settings instance) {
 279  0
         localSettings.set(instance);
 280  0
     }
 281  
 
 282  
     /**
 283  
      * Logs the properties. This will not log any properties that contain 'password' in the key.
 284  
      *
 285  
      * @param header the header to print with the log message
 286  
      * @param properties the properties to log
 287  
      */
 288  
     private static void logProperties(String header, Properties properties) {
 289  16
         if (LOGGER.isLoggable(Level.FINE)) {
 290  0
             final StringWriter sw = new StringWriter();
 291  0
             PrintWriter pw = null;
 292  
             try {
 293  0
                 pw = new PrintWriter(sw);
 294  0
                 pw.format("%s:%n%n", header);
 295  0
                 final Enumeration e = properties.propertyNames();
 296  0
                 while (e.hasMoreElements()) {
 297  0
                     final String key = (String) e.nextElement();
 298  0
                     if (key.contains("password")) {
 299  0
                         pw.format("%s='*****'%n", key);
 300  
                     } else {
 301  0
                         final String value = properties.getProperty(key);
 302  0
                         if (value != null) {
 303  0
                             pw.format("%s='%s'%n", key, value);
 304  
                         }
 305  
                     }
 306  0
                 }
 307  0
                 pw.flush();
 308  0
                 LOGGER.fine(sw.toString());
 309  
             } finally {
 310  0
                 if (pw != null) {
 311  0
                     pw.close();
 312  
                 }
 313  
             }
 314  
 
 315  
         }
 316  16
     }
 317  
 
 318  
     /**
 319  
      * Sets a property value.
 320  
      *
 321  
      * @param key the key for the property
 322  
      * @param value the value for the property
 323  
      */
 324  
     public static void setString(String key, String value) {
 325  8
         localSettings.get().props.setProperty(key, value);
 326  8
         if (LOGGER.isLoggable(Level.FINE)) {
 327  0
             LOGGER.fine(String.format("Setting: %s='%s'", key, value));
 328  
         }
 329  8
     }
 330  
 
 331  
     /**
 332  
      * Sets a property value.
 333  
      *
 334  
      * @param key the key for the property
 335  
      * @param value the value for the property
 336  
      */
 337  
     public static void setBoolean(String key, boolean value) {
 338  2
         if (value) {
 339  0
             localSettings.get().props.setProperty(key, Boolean.TRUE.toString());
 340  
         } else {
 341  2
             localSettings.get().props.setProperty(key, Boolean.FALSE.toString());
 342  
         }
 343  2
         if (LOGGER.isLoggable(Level.FINE)) {
 344  0
             LOGGER.fine(String.format("Setting: %s='%b'", key, value));
 345  
         }
 346  2
     }
 347  
 
 348  
     /**
 349  
      * Merges a new properties file into the current properties. This method allows for the loading of a user provided
 350  
      * properties file.<br/><br/>
 351  
      * Note: even if using this method - system properties will be loaded before properties loaded from files.
 352  
      *
 353  
      * @param filePath the path to the properties file to merge.
 354  
      * @throws FileNotFoundException is thrown when the filePath points to a non-existent file
 355  
      * @throws IOException is thrown when there is an exception loading/merging the properties
 356  
      */
 357  
     public static void mergeProperties(File filePath) throws FileNotFoundException, IOException {
 358  0
         final FileInputStream fis = new FileInputStream(filePath);
 359  0
         mergeProperties(fis);
 360  0
     }
 361  
 
 362  
     /**
 363  
      * Merges a new properties file into the current properties. This method allows for the loading of a user provided
 364  
      * properties file.<br/><br/>
 365  
      * Note: even if using this method - system properties will be loaded before properties loaded from files.
 366  
      *
 367  
      * @param filePath the path to the properties file to merge.
 368  
      * @throws FileNotFoundException is thrown when the filePath points to a non-existent file
 369  
      * @throws IOException is thrown when there is an exception loading/merging the properties
 370  
      */
 371  
     public static void mergeProperties(String filePath) throws FileNotFoundException, IOException {
 372  1
         final FileInputStream fis = new FileInputStream(filePath);
 373  1
         mergeProperties(fis);
 374  1
     }
 375  
 
 376  
     /**
 377  
      * Merges a new properties file into the current properties. This method allows for the loading of a user provided
 378  
      * properties file.<br/><br/>
 379  
      * Note: even if using this method - system properties will be loaded before properties loaded from files.
 380  
      *
 381  
      * @param stream an Input Stream pointing at a properties file to merge
 382  
      * @throws IOException is thrown when there is an exception loading/merging the properties
 383  
      */
 384  
     public static void mergeProperties(InputStream stream) throws IOException {
 385  1
         localSettings.get().props.load(stream);
 386  1
         logProperties("Properties updated via merge", localSettings.get().props);
 387  1
     }
 388  
 
 389  
     /**
 390  
      * Returns a value from the properties file as a File object. If the value was specified as a system property or
 391  
      * passed in via the -Dprop=value argument - this method will return the value from the system properties before the
 392  
      * values in the contained configuration file.
 393  
      *
 394  
      * @param key the key to lookup within the properties file
 395  
      * @return the property from the properties file converted to a File object
 396  
      */
 397  
     public static File getFile(String key) {
 398  0
         final String file = getString(key);
 399  0
         if (file == null) {
 400  0
             return null;
 401  
         }
 402  0
         return new File(file);
 403  
     }
 404  
 
 405  
     /**
 406  
      * Returns a value from the properties file as a File object. If the value was specified as a system property or
 407  
      * passed in via the -Dprop=value argument - this method will return the value from the system properties before the
 408  
      * values in the contained configuration file.
 409  
      *
 410  
      * This method will check the configured base directory and will use this as the base of the file path.
 411  
      * Additionally, if the base directory begins with a leading "[JAR]\" sequence with the path to the folder
 412  
      * containing the JAR file containing this class.
 413  
      *
 414  
      * @param key the key to lookup within the properties file
 415  
      * @return the property from the properties file converted to a File object
 416  
      */
 417  
     public static File getDataFile(String key) {
 418  6
         final String file = getString(key);
 419  6
         LOGGER.log(Level.FINE, String.format("Settings.getDataFile() - file: '%s'", file));
 420  6
         if (file == null) {
 421  0
             return null;
 422  
         }
 423  6
         if (file.startsWith("[JAR]")) {
 424  0
             LOGGER.log(Level.FINE, "Settings.getDataFile() - transforming filename");
 425  0
             final File jarPath = getJarPath();
 426  0
             LOGGER.log(Level.FINE, String.format("Settings.getDataFile() - jar file: '%s'", jarPath.toString()));
 427  0
             final File retVal = new File(jarPath, file.substring(6));
 428  0
             LOGGER.log(Level.FINE, String.format("Settings.getDataFile() - returning: '%s'", retVal.toString()));
 429  0
             return retVal;
 430  
         }
 431  6
         return new File(file);
 432  
     }
 433  
 
 434  
     /**
 435  
      * Attempts to retrieve the folder containing the Jar file containing the Settings class.
 436  
      *
 437  
      * @return a File object
 438  
      */
 439  
     private static File getJarPath() {
 440  0
         final String jarPath = Settings.class.getProtectionDomain().getCodeSource().getLocation().getPath();
 441  0
         String decodedPath = ".";
 442  
         try {
 443  0
             decodedPath = URLDecoder.decode(jarPath, "UTF-8");
 444  0
         } catch (UnsupportedEncodingException ex) {
 445  0
             LOGGER.log(Level.FINEST, null, ex);
 446  0
         }
 447  
 
 448  0
         final File path = new File(decodedPath);
 449  0
         if (path.getName().toLowerCase().endsWith(".jar")) {
 450  0
             return path.getParentFile();
 451  
         } else {
 452  0
             return new File(".");
 453  
         }
 454  
     }
 455  
 
 456  
     /**
 457  
      * Returns a value from the properties file. If the value was specified as a system property or passed in via the
 458  
      * -Dprop=value argument - this method will return the value from the system properties before the values in the
 459  
      * contained configuration file.
 460  
      *
 461  
      * @param key the key to lookup within the properties file
 462  
      * @param defaultValue the default value for the requested property
 463  
      * @return the property from the properties file
 464  
      */
 465  
     public static String getString(String key, String defaultValue) {
 466  17
         final String str = System.getProperty(key, localSettings.get().props.getProperty(key, defaultValue));
 467  17
         return str;
 468  
     }
 469  
 
 470  
     /**
 471  
      * A reference to the temporary directory; used incase it needs to be deleted during cleanup.
 472  
      */
 473  1
     private static File tempDirectory = null;
 474  
 
 475  
     /**
 476  
      * Returns the temporary directory.
 477  
      *
 478  
      * @return the temporary directory
 479  
      * @throws java.io.IOException thrown if the temporary directory does not exist and cannot be created
 480  
      */
 481  
     public static File getTempDirectory() throws IOException {
 482  10
         final File tmpDir = new File(Settings.getString(Settings.KEYS.TEMP_DIRECTORY, System.getProperty("java.io.tmpdir")));
 483  10
         if (!tmpDir.exists()) {
 484  4
             if (!tmpDir.mkdirs()) {
 485  0
                 final String msg = String.format("Unable to make a temporary folder '%s'", tmpDir.getPath());
 486  0
                 throw new IOException(msg);
 487  
             } else {
 488  4
                 tempDirectory = tmpDir;
 489  
             }
 490  
         }
 491  10
         return tmpDir;
 492  
     }
 493  
 
 494  
     /**
 495  
      * Returns a value from the properties file. If the value was specified as a system property or passed in via the
 496  
      * -Dprop=value argument - this method will return the value from the system properties before the values in the
 497  
      * contained configuration file.
 498  
      *
 499  
      * @param key the key to lookup within the properties file
 500  
      * @return the property from the properties file
 501  
      */
 502  
     public static String getString(String key) {
 503  68
         return System.getProperty(key, localSettings.get().props.getProperty(key));
 504  
     }
 505  
 
 506  
     /**
 507  
      * Removes a property from the local properties collection. This is mainly used in test cases.
 508  
      *
 509  
      * @param key the property key to remove
 510  
      */
 511  
     public static void removeProperty(String key) {
 512  1
         localSettings.get().props.remove(key);
 513  1
     }
 514  
 
 515  
     /**
 516  
      * Returns an int value from the properties file. If the value was specified as a system property or passed in via
 517  
      * the -Dprop=value argument - this method will return the value from the system properties before the values in the
 518  
      * contained configuration file.
 519  
      *
 520  
      * @param key the key to lookup within the properties file
 521  
      * @return the property from the properties file
 522  
      * @throws InvalidSettingException is thrown if there is an error retrieving the setting
 523  
      */
 524  
     public static int getInt(String key) throws InvalidSettingException {
 525  
         int value;
 526  
         try {
 527  1
             value = Integer.parseInt(Settings.getString(key));
 528  0
         } catch (NumberFormatException ex) {
 529  0
             throw new InvalidSettingException("Could not convert property '" + key + "' to an int.", ex);
 530  1
         }
 531  1
         return value;
 532  
     }
 533  
 
 534  
     /**
 535  
      * Returns an int value from the properties file. If the value was specified as a system property or passed in via
 536  
      * the -Dprop=value argument - this method will return the value from the system properties before the values in the
 537  
      * contained configuration file.
 538  
      *
 539  
      * @param key the key to lookup within the properties file
 540  
      * @param defaultValue the default value to return
 541  
      * @return the property from the properties file or the defaultValue if the property does not exist or cannot be
 542  
      * converted to an integer
 543  
      */
 544  
     public static int getInt(String key, int defaultValue) {
 545  
         int value;
 546  
         try {
 547  7
             value = Integer.parseInt(Settings.getString(key));
 548  7
         } catch (NumberFormatException ex) {
 549  7
             final String msg = String.format("Could not convert property '%s' to an int.", key);
 550  7
             LOGGER.log(Level.FINEST, msg, ex);
 551  7
             value = defaultValue;
 552  0
         }
 553  7
         return value;
 554  
     }
 555  
 
 556  
     /**
 557  
      * Returns a long value from the properties file. If the value was specified as a system property or passed in via
 558  
      * the -Dprop=value argument - this method will return the value from the system properties before the values in the
 559  
      * contained configuration file.
 560  
      *
 561  
      * @param key the key to lookup within the properties file
 562  
      * @return the property from the properties file
 563  
      * @throws InvalidSettingException is thrown if there is an error retrieving the setting
 564  
      */
 565  
     public static long getLong(String key) throws InvalidSettingException {
 566  
         long value;
 567  
         try {
 568  1
             value = Long.parseLong(Settings.getString(key));
 569  0
         } catch (NumberFormatException ex) {
 570  0
             throw new InvalidSettingException("Could not convert property '" + key + "' to an int.", ex);
 571  1
         }
 572  1
         return value;
 573  
     }
 574  
 
 575  
     /**
 576  
      * Returns a boolean value from the properties file. If the value was specified as a system property or passed in
 577  
      * via the <code>-Dprop=value</code> argument this method will return the value from the system properties before
 578  
      * the values in the contained configuration file.
 579  
      *
 580  
      * @param key the key to lookup within the properties file
 581  
      * @return the property from the properties file
 582  
      * @throws InvalidSettingException is thrown if there is an error retrieving the setting
 583  
      */
 584  
     public static boolean getBoolean(String key) throws InvalidSettingException {
 585  
         boolean value;
 586  
         try {
 587  2
             value = Boolean.parseBoolean(Settings.getString(key));
 588  0
         } catch (NumberFormatException ex) {
 589  0
             throw new InvalidSettingException("Could not convert property '" + key + "' to an int.", ex);
 590  2
         }
 591  2
         return value;
 592  
     }
 593  
 
 594  
     /**
 595  
      * Returns a boolean value from the properties file. If the value was specified as a system property or passed in
 596  
      * via the <code>-Dprop=value</code> argument this method will return the value from the system properties before
 597  
      * the values in the contained configuration file.
 598  
      *
 599  
      * @param key the key to lookup within the properties file
 600  
      * @param defaultValue the default value to return if the setting does not exist
 601  
      * @return the property from the properties file
 602  
      * @throws InvalidSettingException is thrown if there is an error retrieving the setting
 603  
      */
 604  
     public static boolean getBoolean(String key, boolean defaultValue) throws InvalidSettingException {
 605  
         boolean value;
 606  
         try {
 607  30
             final String strValue = Settings.getString(key);
 608  30
             if (strValue == null) {
 609  28
                 return defaultValue;
 610  
             }
 611  2
             value = Boolean.parseBoolean(strValue);
 612  0
         } catch (NumberFormatException ex) {
 613  0
             throw new InvalidSettingException("Could not convert property '" + key + "' to an int.", ex);
 614  2
         }
 615  2
         return value;
 616  
     }
 617  
 }