|
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,43 @@ 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"); |
| 199 | + List<SuppressionRule> ruleList = null; |
| 200 | + Iterator<URL> urls = null; |
| 201 | + try { |
| 202 | + urls = FileUtils.getResources(BASE_SUPPRESSION_FILE); |
| 203 | + } catch (IOException e) { |
| 204 | + LOGGER.warn("Base suppression rules `{}}` could not be loaded; {}", BASE_SUPPRESSION_FILE, e.getMessage()); |
| 205 | + return; |
| 206 | + } |
| 207 | + URL loc = AbstractSuppressionAnalyzer.class.getProtectionDomain().getCodeSource().getLocation(); |
| 208 | + String jarPath = loc.getFile(); |
| 209 | + URL validUrl = null; |
| 210 | + while (urls.hasNext()) { |
| 211 | + URL url = urls.next(); |
| 212 | + String path = url.toString(); |
| 213 | + if (path.equals("jar:" + jarPath + "!/dependencycheck-base-suppression.xml")) { |
| 214 | + validUrl = url; |
| 215 | + break; |
202 | 216 | } |
203 | | - ruleList = parser.parseSuppressionRules(in); |
204 | | - } catch (SAXException | IOException ex) { |
205 | | - throw new SuppressionParseException("Unable to parse the base suppression data file", ex); |
206 | 217 | } |
207 | | - if (!ruleList.isEmpty()) { |
| 218 | + if (validUrl != null) { |
| 219 | + try (InputStream in = validUrl.openStream()) { |
| 220 | + if (in == null) { |
| 221 | + throw new SuppressionParseException("Suppression rules `" + BASE_SUPPRESSION_FILE + "` could not be found"); |
| 222 | + } |
| 223 | + ruleList = parser.parseSuppressionRules(in); |
| 224 | + } catch (SAXException | IOException ex) { |
| 225 | + throw new SuppressionParseException("Unable to parse the base suppression data file", ex); |
| 226 | + } |
| 227 | + } |
| 228 | + if (ruleList != null && !ruleList.isEmpty()) { |
208 | 229 | if (engine.hasObject(SUPPRESSION_OBJECT_KEY)) { |
209 | 230 | @SuppressWarnings("unchecked") |
210 | 231 | final List<SuppressionRule> rules = (List<SuppressionRule>) engine.getObject(SUPPRESSION_OBJECT_KEY); |
|
0 commit comments