@@ -172,6 +172,7 @@ private Content generateSbomFromEffectivePom() throws IOException {
172172 .filter (dep -> ignored .stream ().noneMatch (artifact -> artifact .isCoordinatesEquals (dep )))
173173 .forEach (d -> sbom .addDependency (sbom .getRoot (), d , null ));
174174
175+ String sbomString = sbom .getAsJsonString ();
175176 // build and return content for constructing request to the backend
176177 return new Content (sbom .getAsJsonString ().getBytes (), Api .CYCLONEDX_MEDIA_TYPE );
177178 }
@@ -238,11 +239,47 @@ private List<DependencyAggregator> getDependencies(final Path manifestPath) thro
238239 // when a "dependency" tag starts, it will be initiated,
239240 // when a "dependency" tag ends, it will be parsed, act upon, and reset
240241 DependencyAggregator dependencyAggregator = null ;
242+ boolean insideDependencyManagement = false ;
243+ boolean insideExclusions = false ;
244+ boolean insidePlugins = false ;
241245 while (reader .hasNext ()) {
242246 reader .next (); // get the next event
247+ if (reader .isStartElement () && "dependencyManagement" .equals (reader .getLocalName ())) {
248+ // entering dependencyManagement section
249+ insideDependencyManagement = true ;
250+ continue ;
251+ }
252+ if (reader .isEndElement () && "dependencyManagement" .equals (reader .getLocalName ())) {
253+ // exiting dependencyManagement section
254+ insideDependencyManagement = false ;
255+ continue ;
256+ }
257+ if (reader .isStartElement () && "plugins" .equals (reader .getLocalName ())) {
258+ // entering plugins section
259+ insidePlugins = true ;
260+ continue ;
261+ }
262+ if (reader .isEndElement () && "plugins" .equals (reader .getLocalName ())) {
263+ // exiting plugins section
264+ insidePlugins = false ;
265+ continue ;
266+ }
267+ if (reader .isStartElement () && "exclusions" .equals (reader .getLocalName ())) {
268+ // entering exclusions section
269+ insideExclusions = true ;
270+ continue ;
271+ }
272+ if (reader .isEndElement () && "exclusions" .equals (reader .getLocalName ())) {
273+ // exiting exclusions section
274+ insideExclusions = false ;
275+ continue ;
276+ }
243277 if (reader .isStartElement () && "dependency" .equals (reader .getLocalName ())) {
244- // starting "dependency" tag, initiate aggregator
245- dependencyAggregator = new DependencyAggregator ();
278+ // starting "dependency" tag, initiate aggregator only if not inside dependencyManagement
279+ // or plugins
280+ if (!insideDependencyManagement && !insidePlugins ) {
281+ dependencyAggregator = new DependencyAggregator ();
282+ }
246283 continue ;
247284 }
248285
@@ -256,9 +293,10 @@ private List<DependencyAggregator> getDependencies(final Path manifestPath) thro
256293 continue ;
257294 }
258295
259- if (reader .isStartElement ()) {
296+ if (reader .isStartElement () && ! insideExclusions ) {
260297 // NOTE if we want to include "scope" tags in ignore,
261298 // add a case here and a property in DependencyIgnore
299+ // Only process these elements if we're not inside exclusions
262300 switch (reader .getLocalName ()) {
263301 case "groupId" : // starting "groupId" tag, get next event and set to aggregator
264302 reader .next ();
@@ -282,8 +320,11 @@ private List<DependencyAggregator> getDependencies(final Path manifestPath) thro
282320 }
283321
284322 if (reader .isEndElement () && "dependency" .equals (reader .getLocalName ())) {
285- // add object to list and reset dependency aggregator
286- deps .add (dependencyAggregator );
323+ // add object to list and reset dependency aggregator only if not inside
324+ // dependencyManagement or plugins
325+ if (!insideDependencyManagement && !insidePlugins && dependencyAggregator != null ) {
326+ deps .add (dependencyAggregator );
327+ }
287328 dependencyAggregator = null ;
288329 }
289330 }
0 commit comments