88import java .util .Properties ;
99import java .util .concurrent .ConcurrentHashMap ;
1010
11+ import org .apache .maven .model .BuildBase ;
1112import org .apache .maven .model .Dependency ;
1213import org .apache .maven .model .Model ;
1314import org .apache .maven .model .Plugin ;
@@ -283,17 +284,58 @@ private ConfiguredBom locateBomImport(ArtifactCoords platformBom, boolean inPare
283284 throw new RuntimeException ("Failed to locate the source of " + platformBom .toCompactCoords () + " import" );
284285 }
285286
287+ private void getManagedPluginVersion (ArtifactKey pluginKey ) {
288+ var managedPlugins = getRawManagedPlugins ();
289+
290+ }
291+
292+ private List <Plugin > getRawManagedPlugins () {
293+ List <Plugin > managedPlugins = getRawManagedPlugins (module .getRawModel ().getBuild ());
294+ final List <Profile > profiles = getActivePomProfiles ();
295+ if (profiles .isEmpty ()) {
296+ return managedPlugins ;
297+ }
298+ List <Plugin > combined = null ;
299+ for (Profile p : profiles ) {
300+ var profileManagedPlugins = getRawManagedPlugins (p .getBuild ());
301+ if (!profileManagedPlugins .isEmpty ()) {
302+ if (combined == null ) {
303+ combined = new ArrayList <>();
304+ combined .addAll (managedPlugins );
305+ }
306+ combined .addAll (profileManagedPlugins );
307+ }
308+ }
309+ return combined == null ? managedPlugins : combined ;
310+ }
311+
312+ private static List <Plugin > getRawManagedPlugins (BuildBase build ) {
313+ if (build == null ) {
314+ return List .of ();
315+ }
316+ var pm = build .getPluginManagement ();
317+ return pm == null ? List .of () : pm .getPlugins ();
318+ }
319+
286320 private List <Dependency > getRawDirectDeps () {
287321 if (rawDirectDeps == null ) {
288322 final List <Profile > profiles = getActivePomProfiles ();
289323 if (profiles .isEmpty ()) {
290324 rawDirectDeps = module .getRawModel ().getDependencies ();
291325 } else {
292- rawDirectDeps = new ArrayList <>();
293- rawDirectDeps .addAll (module .getRawModel ().getDependencies ());
326+ List <Dependency > combined = null ;
294327 for (Profile p : profiles ) {
295- rawDirectDeps .addAll (p .getDependencies ());
328+ final List <Dependency > profileDeps = p .getDependencies ();
329+ if (!profileDeps .isEmpty ()) {
330+ if (combined == null ) {
331+ combined = new ArrayList <>();
332+ combined .addAll (module .getRawModel ().getDependencies ());
333+ }
334+ combined .addAll (profileDeps );
335+ }
336+
296337 }
338+ rawDirectDeps = combined == null ? module .getRawModel ().getDependencies () : combined ;
297339 }
298340 }
299341 return rawDirectDeps ;
@@ -305,32 +347,42 @@ private Properties getRawProperties() {
305347 if (profiles .isEmpty ()) {
306348 rawProperties = module .getRawModel ().getProperties ();
307349 } else {
308- rawProperties = new Properties ();
309- rawProperties .putAll (module .getRawModel ().getProperties ());
310- for (Profile p : profiles ) {
311- rawProperties .putAll (p .getProperties ());
350+ Properties combined = null ;
351+ for (Profile profile : profiles ) {
352+ if (!profile .getProperties ().isEmpty ()) {
353+ if (combined == null ) {
354+ combined = new Properties ();
355+ combined .putAll (module .getRawModel ().getProperties ());
356+ }
357+ combined .putAll (profile .getProperties ());
358+ }
312359 }
360+ rawProperties = combined == null ? module .getRawModel ().getProperties () : combined ;
313361 }
314362 }
315363 return rawProperties ;
316364 }
317365
318366 private List <Dependency > getRawManagedDeps () {
319367 if (rawManagedDeps == null ) {
368+ final List <Dependency > mainManagedDeps = module .getRawModel ().getDependencyManagement () == null ? List .of ()
369+ : module .getRawModel ().getDependencyManagement ().getDependencies ();
320370 final List <Profile > profiles = getActivePomProfiles ();
321371 if (profiles .isEmpty ()) {
322- rawManagedDeps = module .getRawModel ().getDependencyManagement () == null ? List .of ()
323- : module .getRawModel ().getDependencyManagement ().getDependencies ();
372+ rawManagedDeps = mainManagedDeps ;
324373 } else {
325- rawManagedDeps = new ArrayList <>();
326- if (module .getRawModel ().getDependencyManagement () != null ) {
327- rawManagedDeps .addAll (module .getRawModel ().getDependencyManagement ().getDependencies ());
328- }
329- for (Profile p : profiles ) {
330- if (p .getDependencyManagement () != null ) {
331- rawManagedDeps .addAll (p .getDependencyManagement ().getDependencies ());
374+ List <Dependency > combined = null ;
375+ for (Profile profile : profiles ) {
376+ final List <Dependency > profileManagedDeps = profile .getDependencyManagement () == null ? List .of ()
377+ : profile .getDependencyManagement ().getDependencies ();
378+ if (!profileManagedDeps .isEmpty ()) {
379+ if (combined == null ) {
380+ combined = new ArrayList <>(mainManagedDeps );
381+ }
382+ combined .addAll (profileManagedDeps );
332383 }
333384 }
385+ rawManagedDeps = combined == null ? mainManagedDeps : combined ;
334386 }
335387 }
336388 return rawManagedDeps ;
0 commit comments