|
26 | 26 | import java.nio.file.Path; |
27 | 27 | import java.nio.file.StandardCopyOption; |
28 | 28 | import java.util.ArrayList; |
| 29 | +import java.util.Iterator; |
29 | 30 | import java.util.List; |
30 | 31 | import java.util.Set; |
31 | 32 | import java.util.regex.Pattern; |
@@ -188,23 +189,33 @@ private void loadSuppressionBaseData(final Engine engine) throws SuppressionPars |
188 | 189 | } |
189 | 190 |
|
190 | 191 | /** |
191 | | - * Loads all the base suppression rules packaged with the application. |
| 192 | + * Loads the base suppression rules packaged with the application. |
192 | 193 | * |
193 | 194 | * @param parser The suppression parser to use |
194 | 195 | * @param engine a reference the dependency-check engine |
195 | 196 | * @throws SuppressionParseException thrown if the XML cannot be parsed. |
196 | 197 | */ |
197 | 198 | private void loadPackagedSuppressionBaseData(final SuppressionParser parser, final Engine engine) throws SuppressionParseException { |
198 | | - final List<SuppressionRule> ruleList; |
199 | | - try (InputStream in = FileUtils.getResourceAsStream(BASE_SUPPRESSION_FILE)) { |
200 | | - if (in == null) { |
201 | | - throw new SuppressionParseException("Suppression rules `" + BASE_SUPPRESSION_FILE + "` could not be found"); |
202 | | - } |
| 199 | + List<SuppressionRule> ruleList = null; |
| 200 | + URL jarLocation = AbstractSuppressionAnalyzer.class.getProtectionDomain().getCodeSource().getLocation(); |
| 201 | + String suppressionFileLocation = jarLocation.getFile(); |
| 202 | + if (suppressionFileLocation.endsWith(".jar")) { |
| 203 | + suppressionFileLocation = "jar:file:" + suppressionFileLocation + "!/" + BASE_SUPPRESSION_FILE; |
| 204 | + } else { |
| 205 | + suppressionFileLocation = "file:" + suppressionFileLocation + BASE_SUPPRESSION_FILE; |
| 206 | + } |
| 207 | + URL baseSuppresssionURL = null; |
| 208 | + try { |
| 209 | + baseSuppresssionURL = new URL(suppressionFileLocation); |
| 210 | + } catch (MalformedURLException e) { |
| 211 | + throw new SuppressionParseException("Unable to load the base suppression data file", e); |
| 212 | + } |
| 213 | + try (InputStream in = baseSuppresssionURL.openStream()) { |
203 | 214 | ruleList = parser.parseSuppressionRules(in); |
204 | 215 | } catch (SAXException | IOException ex) { |
205 | 216 | throw new SuppressionParseException("Unable to parse the base suppression data file", ex); |
206 | 217 | } |
207 | | - if (!ruleList.isEmpty()) { |
| 218 | + if (ruleList != null && !ruleList.isEmpty()) { |
208 | 219 | if (engine.hasObject(SUPPRESSION_OBJECT_KEY)) { |
209 | 220 | @SuppressWarnings("unchecked") |
210 | 221 | final List<SuppressionRule> rules = (List<SuppressionRule>) engine.getObject(SUPPRESSION_OBJECT_KEY); |
|
0 commit comments