@@ -241,18 +241,36 @@ private static void collectDestinationDirs(Collection<SourceDir> sources, final
241
241
private void collectExtensionDependencies (Project project , Configuration deploymentConfiguration ,
242
242
ApplicationModelBuilder modelBuilder ) {
243
243
final ResolvedConfiguration rc = deploymentConfiguration .getResolvedConfiguration ();
244
+ final Set <ArtifactKey > processedDeps = new HashSet <>();
244
245
for (var dep : rc .getFirstLevelModuleDependencies ()) {
245
- processDeploymentDependency (project , dep , modelBuilder , false );
246
+ processDeploymentDependency (project , dep , modelBuilder , false , processedDeps );
246
247
}
247
248
}
248
249
249
250
private static void processDeploymentDependency (Project project , ResolvedDependency resolvedDep ,
250
- ApplicationModelBuilder modelBuilder , boolean clearReloadableFlag ) {
251
- boolean processChildren = false ;
252
- for (var a : resolvedDep .getModuleArtifacts ()) {
253
- ResolvedDependencyBuilder dep = modelBuilder .getDependency (getKey (a ));
251
+ ApplicationModelBuilder modelBuilder , boolean clearReloadableFlag , Set <ArtifactKey > processedDeps ) {
252
+ final Set <ResolvedArtifact > resolvedArtifacts = resolvedDep .getModuleArtifacts ();
253
+ boolean processChildren = resolvedArtifacts .isEmpty ();
254
+ for (var a : resolvedArtifacts ) {
255
+ final ArtifactKey artifactKey = getKey (a );
256
+ if (!processedDeps .add (artifactKey )) {
257
+ continue ;
258
+ }
259
+ processChildren = true ;
260
+ ResolvedDependencyBuilder dep = modelBuilder .getDependency (artifactKey );
254
261
if (dep == null ) {
255
- if (a .getId ().getComponentIdentifier () instanceof ProjectComponentIdentifier projectComponentIdentifier ) {
262
+ if (isApplicationRoot (modelBuilder , artifactKey )) {
263
+ // An application root artifact may be found among the dependencies in a could of cases:
264
+ // test fixtures in an application project and as a deployment module in an extension project
265
+ // running deployment module tests.
266
+ // In case of test fixtures, the root artifact does not have to be added to the model as a dependency,
267
+ // it can simply be skipped.
268
+ // In case of a deployment test, it has to be added as a dependency, since otherwise, the deployment
269
+ // module will appear to be missing.
270
+ // This part here looks like a hack but appears to work for both cases so far.
271
+ dep = modelBuilder .getApplicationArtifact ();
272
+ } else if (a .getId ()
273
+ .getComponentIdentifier () instanceof ProjectComponentIdentifier projectComponentIdentifier ) {
256
274
var includedBuild = ToolingUtils .includedBuild (project ,
257
275
projectComponentIdentifier .getBuild ().getBuildPath ());
258
276
final Project projectDep ;
@@ -297,22 +315,26 @@ private static void processDeploymentDependency(Project project, ResolvedDepende
297
315
}
298
316
}
299
317
if (dep != null ) {
300
- if (!dep .isDeploymentCp ()) {
301
- dep .setDeploymentCp ();
302
- processChildren = true ;
318
+ if (dep .isRuntimeExtensionArtifact ()) {
319
+ clearReloadableFlag = true ;
303
320
}
321
+ dep .setDeploymentCp ();
304
322
if (clearReloadableFlag ) {
305
323
dep .clearFlag (DependencyFlags .RELOADABLE );
306
324
}
307
325
}
308
326
}
309
327
if (processChildren ) {
310
328
for (var child : resolvedDep .getChildren ()) {
311
- processDeploymentDependency (project , child , modelBuilder , clearReloadableFlag );
329
+ processDeploymentDependency (project , child , modelBuilder , clearReloadableFlag , processedDeps );
312
330
}
313
331
}
314
332
}
315
333
334
+ private static boolean isApplicationRoot (ApplicationModelBuilder modelBuilder , ArtifactKey artifactKey ) {
335
+ return modelBuilder .getApplicationArtifact ().getKey ().equals (artifactKey );
336
+ }
337
+
316
338
private static ResolvedDependencyBuilder addArtifactDependency (Project project , ApplicationModelBuilder modelBuilder ,
317
339
ResolvedArtifact a ) {
318
340
ResolvedDependencyBuilder dep = modelBuilder .getDependency (getKey (a ));
@@ -350,9 +372,7 @@ private void collectDependencies(ResolvedConfiguration configuration, Resolvable
350
372
351
373
final Set <File > artifactFiles = getArtifactFilesOrNull (configuration , dependencies );
352
374
for (ResolvedDependency d : configuration .getFirstLevelModuleDependencies ()) {
353
- collectDependencies (d , workspaceDiscovery , project , artifactFiles , new HashSet <>(),
354
- modelBuilder ,
355
- wsModule ,
375
+ collectDependencies (d , workspaceDiscovery , project , artifactFiles , modelBuilder , wsModule ,
356
376
(byte ) (COLLECT_TOP_EXTENSION_RUNTIME_NODES | COLLECT_DIRECT_DEPS | COLLECT_RELOADABLE_MODULES ));
357
377
}
358
378
@@ -403,86 +423,94 @@ private static Set<File> getArtifactFilesOrNull(ResolvedConfiguration configurat
403
423
}
404
424
405
425
private void collectDependencies (org .gradle .api .artifacts .ResolvedDependency resolvedDep , boolean workspaceDiscovery ,
406
- Project project , Set <File > artifactFiles , Set < ArtifactKey > processedModules , ApplicationModelBuilder modelBuilder ,
426
+ Project project , Set <File > artifactFiles , ApplicationModelBuilder modelBuilder ,
407
427
WorkspaceModule .Mutable parentModule ,
408
428
byte flags ) {
409
429
WorkspaceModule .Mutable projectModule = null ;
410
- for (ResolvedArtifact a : resolvedDep .getModuleArtifacts ()) {
430
+ final Set <ResolvedArtifact > resolvedArtifacts = resolvedDep .getModuleArtifacts ();
431
+ boolean processChildren = resolvedArtifacts .isEmpty ();
432
+ for (ResolvedArtifact a : resolvedArtifacts ) {
411
433
if (!isDependency (a )) {
412
434
continue ;
413
435
}
414
- var depBuilder = modelBuilder .getDependency (getKey (a ));
415
- if (depBuilder != null ) {
416
- if (isFlagOn (flags , COLLECT_DIRECT_DEPS )) {
417
- depBuilder .setDirect (true );
418
- }
436
+ final ArtifactKey artifactKey = getKey (a );
437
+ if (isApplicationRoot (modelBuilder , artifactKey )) {
419
438
continue ;
420
439
}
421
- final ArtifactCoords depCoords = getArtifactCoords (a );
422
- depBuilder = ResolvedDependencyBuilder .newInstance ()
423
- .setCoords (depCoords )
424
- .setRuntimeCp ();
425
- if (isFlagOn (flags , COLLECT_DIRECT_DEPS )) {
426
- depBuilder .setDirect (true );
427
- flags = clearFlag (flags , COLLECT_DIRECT_DEPS );
428
- }
429
- if (parentModule != null ) {
430
- parentModule .addDependency (new ArtifactDependency (depCoords ));
431
- }
432
-
433
- PathCollection paths = null ;
434
- if (workspaceDiscovery && a .getId ().getComponentIdentifier () instanceof ProjectComponentIdentifier compId ) {
435
- Project projectDep = project .getRootProject ().findProject (compId .getProjectPath ());
440
+ var depBuilder = modelBuilder .getDependency (artifactKey );
441
+ if (depBuilder == null ) {
442
+ processChildren = true ;
443
+ final ArtifactCoords depCoords = getArtifactCoords (a );
444
+ depBuilder = ResolvedDependencyBuilder .newInstance ()
445
+ .setCoords (depCoords )
446
+ .setRuntimeCp ();
447
+ if (parentModule != null ) {
448
+ parentModule .addDependency (new ArtifactDependency (depCoords ));
449
+ }
436
450
437
- final String classifier = a .getClassifier ();
438
- if (classifier == null || classifier .isEmpty ()) {
439
- final IncludedBuild includedBuild = ToolingUtils .includedBuild (project .getRootProject (),
440
- compId .getBuild ().getBuildPath ());
441
- if (includedBuild != null ) {
442
- if (includedBuild instanceof IncludedBuildInternal ib ) {
443
- projectDep = ToolingUtils .includedBuildProject (ib , compId .getProjectPath ());
444
- }
445
- if (projectDep != null ) {
446
- initProjectModuleAndBuildPaths (projectDep , a , modelBuilder , depBuilder );
451
+ PathCollection paths = null ;
452
+ if (workspaceDiscovery && a .getId ().getComponentIdentifier () instanceof ProjectComponentIdentifier compId ) {
453
+ Project projectDep = project .getRootProject ().findProject (compId .getProjectPath ());
454
+
455
+ final String classifier = a .getClassifier ();
456
+ if (classifier == null || classifier .isEmpty ()) {
457
+ final IncludedBuild includedBuild = ToolingUtils .includedBuild (project .getRootProject (),
458
+ compId .getBuild ().getBuildPath ());
459
+ if (includedBuild != null ) {
460
+ if (includedBuild instanceof IncludedBuildInternal ib ) {
461
+ projectDep = ToolingUtils .includedBuildProject (ib , compId .getProjectPath ());
462
+ }
463
+ if (projectDep != null ) {
464
+ initProjectModuleAndBuildPaths (projectDep , a , modelBuilder , depBuilder );
465
+ } else {
466
+ final PathList .Builder pathBuilder = PathList .builder ();
467
+ addSubstitutedProject (pathBuilder , includedBuild .getProjectDir ());
468
+ paths = pathBuilder .build ();
469
+ }
447
470
} else {
448
- final PathList .Builder pathBuilder = PathList .builder ();
449
- addSubstitutedProject (pathBuilder , includedBuild .getProjectDir ());
450
- paths = pathBuilder .build ();
471
+ initProjectModuleAndBuildPaths (projectDep , a , modelBuilder , depBuilder );
451
472
}
452
473
} else {
453
474
initProjectModuleAndBuildPaths (projectDep , a , modelBuilder , depBuilder );
454
475
}
455
- } else {
456
- initProjectModuleAndBuildPaths (projectDep , a , modelBuilder , depBuilder );
457
476
}
458
- }
459
477
460
- depBuilder .setResolvedPaths (paths == null ? PathList .of (a .getFile ().toPath ()) : paths );
461
- if (processQuarkusDependency (depBuilder , modelBuilder )) {
462
- if (isFlagOn (flags , COLLECT_TOP_EXTENSION_RUNTIME_NODES )) {
478
+ depBuilder .setResolvedPaths (paths == null ? PathList .of (a .getFile ().toPath ()) : paths );
479
+ if (processQuarkusDependency (depBuilder , modelBuilder )) {
480
+ flags = clearFlag (flags , COLLECT_RELOADABLE_MODULES );
481
+ }
482
+ modelBuilder .addDependency (depBuilder );
483
+ if (projectModule == null && depBuilder .getWorkspaceModule () != null ) {
484
+ projectModule = depBuilder .getWorkspaceModule ().mutable ();
485
+ }
486
+
487
+ if (artifactFiles != null ) {
488
+ artifactFiles .add (a .getFile ());
489
+ }
490
+ }
491
+ if (isFlagOn (flags , COLLECT_DIRECT_DEPS )) {
492
+ depBuilder .setDirect (true );
493
+ flags = clearFlag (flags , COLLECT_DIRECT_DEPS );
494
+ }
495
+ if (depBuilder .isRuntimeExtensionArtifact ()) {
496
+ if (isFlagOn (flags , COLLECT_RELOADABLE_MODULES )) {
497
+ flags = clearFlag (flags , COLLECT_RELOADABLE_MODULES );
498
+ processChildren = true ;
499
+ }
500
+ if (isFlagOn (flags , COLLECT_TOP_EXTENSION_RUNTIME_NODES )
501
+ && !depBuilder .isFlagSet (DependencyFlags .TOP_LEVEL_RUNTIME_EXTENSION_ARTIFACT )) {
463
502
depBuilder .setFlags (DependencyFlags .TOP_LEVEL_RUNTIME_EXTENSION_ARTIFACT );
464
503
flags = clearFlag (flags , COLLECT_TOP_EXTENSION_RUNTIME_NODES );
465
504
}
466
- flags = clearFlag (flags , COLLECT_RELOADABLE_MODULES );
467
505
}
468
506
if (!isFlagOn (flags , COLLECT_RELOADABLE_MODULES )) {
469
507
depBuilder .clearFlag (DependencyFlags .RELOADABLE );
470
508
}
471
- modelBuilder .addDependency (depBuilder );
472
- if (projectModule == null && depBuilder .getWorkspaceModule () != null ) {
473
- projectModule = depBuilder .getWorkspaceModule ().mutable ();
474
- }
475
-
476
- if (artifactFiles != null ) {
477
- artifactFiles .add (a .getFile ());
478
- }
479
509
}
480
510
481
- processedModules .add (ArtifactKey .ga (resolvedDep .getModuleGroup (), resolvedDep .getModuleName ()));
482
- for (org .gradle .api .artifacts .ResolvedDependency child : resolvedDep .getChildren ()) {
483
- if (!processedModules .contains (ArtifactKey .ga (child .getModuleGroup (), child .getModuleName ()))) {
484
- collectDependencies (child , workspaceDiscovery , project , artifactFiles , processedModules ,
485
- modelBuilder , projectModule , flags );
511
+ if (processChildren ) {
512
+ for (org .gradle .api .artifacts .ResolvedDependency child : resolvedDep .getChildren ()) {
513
+ collectDependencies (child , workspaceDiscovery , project , artifactFiles , modelBuilder , projectModule , flags );
486
514
}
487
515
}
488
516
}
0 commit comments