Coverage Report - org.owasp.dependencycheck.analyzer.AbstractSuppressionAnalyzer
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractSuppressionAnalyzer
47%
10/21
50%
1/2
1.5
 
 1  
 /*
 2  
  * This file is part of dependency-check-core.
 3  
  *
 4  
  * Dependency-check-core is free software: you can redistribute it and/or modify it
 5  
  * under the terms of the GNU General Public License as published by the Free
 6  
  * Software Foundation, either version 3 of the License, or (at your option) any
 7  
  * later version.
 8  
  *
 9  
  * Dependency-check-core is distributed in the hope that it will be useful, but
 10  
  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  
  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 12  
  * details.
 13  
  *
 14  
  * You should have received a copy of the GNU General Public License along with
 15  
  * dependency-check-core. If not, see http://www.gnu.org/licenses/.
 16  
  *
 17  
  * Copyright (c) 2013 Jeremy Long. All Rights Reserved.
 18  
  */
 19  
 package org.owasp.dependencycheck.analyzer;
 20  
 
 21  
 import java.io.File;
 22  
 import java.util.List;
 23  
 import java.util.Set;
 24  
 import java.util.logging.Level;
 25  
 import java.util.logging.Logger;
 26  
 import org.owasp.dependencycheck.suppression.SuppressionParseException;
 27  
 import org.owasp.dependencycheck.suppression.SuppressionParser;
 28  
 import org.owasp.dependencycheck.suppression.SuppressionRule;
 29  
 import org.owasp.dependencycheck.utils.Settings;
 30  
 
 31  
 /**
 32  
  * Abstract base suppression analyzer that contains methods for parsing the
 33  
  * suppression xml file.
 34  
  *
 35  
  * @author Jeremy Long <jeremy.long@owasp.org>
 36  
  */
 37  2
 public abstract class AbstractSuppressionAnalyzer extends AbstractAnalyzer {
 38  
 
 39  
     //<editor-fold defaultstate="collapsed" desc="All standard implementation details of Analyzer">
 40  
     /**
 41  
      * Returns a list of file EXTENSIONS supported by this analyzer.
 42  
      *
 43  
      * @return a list of file EXTENSIONS supported by this analyzer.
 44  
      */
 45  
     public Set<String> getSupportedExtensions() {
 46  264
         return null;
 47  
     }
 48  
 
 49  
     /**
 50  
      * Returns whether or not this analyzer can process the given extension.
 51  
      *
 52  
      * @param extension the file extension to test for support.
 53  
      * @return whether or not the specified file extension is supported by this
 54  
      * analyzer.
 55  
      */
 56  
     @Override
 57  
     public boolean supportsExtension(String extension) {
 58  18
         return true;
 59  
     }
 60  
 
 61  
     //</editor-fold>
 62  
     /**
 63  
      * The initialize method loads the suppression XML file.
 64  
      *
 65  
      * @throws Exception thrown if there is an exception
 66  
      */
 67  
     @Override
 68  
     public void initialize() throws Exception {
 69  6
         super.initialize();
 70  6
         loadSuppressionData();
 71  6
     }
 72  
     /**
 73  
      * The list of suppression rules
 74  
      */
 75  
     private List<SuppressionRule> rules;
 76  
 
 77  
     /**
 78  
      * Get the value of rules.
 79  
      *
 80  
      * @return the value of rules
 81  
      */
 82  
     public List<SuppressionRule> getRules() {
 83  18
         return rules;
 84  
     }
 85  
 
 86  
     /**
 87  
      * Set the value of rules.
 88  
      *
 89  
      * @param rules new value of rules
 90  
      */
 91  
     public void setRules(List<SuppressionRule> rules) {
 92  0
         this.rules = rules;
 93  0
     }
 94  
 
 95  
     /**
 96  
      * Loads the suppression rules file.
 97  
      *
 98  
      * @throws SuppressionParseException thrown if the XML cannot be parsed.
 99  
      */
 100  
     private void loadSuppressionData() throws SuppressionParseException {
 101  6
         final File file = Settings.getFile(Settings.KEYS.SUPPRESSION_FILE);
 102  6
         if (file != null) {
 103  0
             final SuppressionParser parser = new SuppressionParser();
 104  
             try {
 105  0
                 rules = parser.parseSuppressionRules(file);
 106  0
             } catch (SuppressionParseException ex) {
 107  0
                 final String msg = String.format("Unable to parse suppression xml file '%s'", file.getPath());
 108  0
                 Logger.getLogger(AbstractSuppressionAnalyzer.class.getName()).log(Level.WARNING, msg);
 109  0
                 Logger.getLogger(AbstractSuppressionAnalyzer.class.getName()).log(Level.WARNING, ex.getMessage());
 110  0
                 Logger.getLogger(AbstractSuppressionAnalyzer.class.getName()).log(Level.FINE, null, ex);
 111  0
                 throw ex;
 112  0
             }
 113  
         }
 114  6
     }
 115  
 }