| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| AbstractSuppressionAnalyzer |
|
| 1.5;1.5 |
| 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) 2013 Jeremy Long. All Rights Reserved. | |
| 17 | */ | |
| 18 | package org.owasp.dependencycheck.analyzer; | |
| 19 | ||
| 20 | import java.io.File; | |
| 21 | import java.util.List; | |
| 22 | import java.util.Set; | |
| 23 | import java.util.logging.Level; | |
| 24 | import java.util.logging.Logger; | |
| 25 | import org.owasp.dependencycheck.suppression.SuppressionParseException; | |
| 26 | import org.owasp.dependencycheck.suppression.SuppressionParser; | |
| 27 | import org.owasp.dependencycheck.suppression.SuppressionRule; | |
| 28 | import org.owasp.dependencycheck.utils.Settings; | |
| 29 | ||
| 30 | /** | |
| 31 | * Abstract base suppression analyzer that contains methods for parsing the suppression xml file. | |
| 32 | * | |
| 33 | * @author Jeremy Long <jeremy.long@owasp.org> | |
| 34 | */ | |
| 35 | 2 | public abstract class AbstractSuppressionAnalyzer extends AbstractAnalyzer { |
| 36 | ||
| 37 | //<editor-fold defaultstate="collapsed" desc="All standard implementation details of Analyzer"> | |
| 38 | /** | |
| 39 | * Returns a list of file EXTENSIONS supported by this analyzer. | |
| 40 | * | |
| 41 | * @return a list of file EXTENSIONS supported by this analyzer. | |
| 42 | */ | |
| 43 | public Set<String> getSupportedExtensions() { | |
| 44 | 264 | return null; |
| 45 | } | |
| 46 | ||
| 47 | /** | |
| 48 | * Returns whether or not this analyzer can process the given extension. | |
| 49 | * | |
| 50 | * @param extension the file extension to test for support. | |
| 51 | * @return whether or not the specified file extension is supported by this analyzer. | |
| 52 | */ | |
| 53 | @Override | |
| 54 | public boolean supportsExtension(String extension) { | |
| 55 | 18 | return true; |
| 56 | } | |
| 57 | ||
| 58 | //</editor-fold> | |
| 59 | /** | |
| 60 | * The initialize method loads the suppression XML file. | |
| 61 | * | |
| 62 | * @throws Exception thrown if there is an exception | |
| 63 | */ | |
| 64 | @Override | |
| 65 | public void initialize() throws Exception { | |
| 66 | 6 | super.initialize(); |
| 67 | 6 | loadSuppressionData(); |
| 68 | 6 | } |
| 69 | /** | |
| 70 | * The list of suppression rules | |
| 71 | */ | |
| 72 | private List<SuppressionRule> rules; | |
| 73 | ||
| 74 | /** | |
| 75 | * Get the value of rules. | |
| 76 | * | |
| 77 | * @return the value of rules | |
| 78 | */ | |
| 79 | public List<SuppressionRule> getRules() { | |
| 80 | 18 | return rules; |
| 81 | } | |
| 82 | ||
| 83 | /** | |
| 84 | * Set the value of rules. | |
| 85 | * | |
| 86 | * @param rules new value of rules | |
| 87 | */ | |
| 88 | public void setRules(List<SuppressionRule> rules) { | |
| 89 | 0 | this.rules = rules; |
| 90 | 0 | } |
| 91 | ||
| 92 | /** | |
| 93 | * Loads the suppression rules file. | |
| 94 | * | |
| 95 | * @throws SuppressionParseException thrown if the XML cannot be parsed. | |
| 96 | */ | |
| 97 | private void loadSuppressionData() throws SuppressionParseException { | |
| 98 | 6 | final File file = Settings.getFile(Settings.KEYS.SUPPRESSION_FILE); |
| 99 | 6 | if (file != null) { |
| 100 | 0 | final SuppressionParser parser = new SuppressionParser(); |
| 101 | try { | |
| 102 | 0 | rules = parser.parseSuppressionRules(file); |
| 103 | 0 | } catch (SuppressionParseException ex) { |
| 104 | 0 | final String msg = String.format("Unable to parse suppression xml file '%s'", file.getPath()); |
| 105 | 0 | Logger.getLogger(AbstractSuppressionAnalyzer.class.getName()).log(Level.WARNING, msg); |
| 106 | 0 | Logger.getLogger(AbstractSuppressionAnalyzer.class.getName()).log(Level.WARNING, ex.getMessage()); |
| 107 | 0 | Logger.getLogger(AbstractSuppressionAnalyzer.class.getName()).log(Level.FINE, null, ex); |
| 108 | 0 | throw ex; |
| 109 | 0 | } |
| 110 | } | |
| 111 | 6 | } |
| 112 | } |