@@ -347,38 +347,12 @@ public Collection<ResolutionScope> getResolutionScopeUniverse() {
347
347
348
348
@ Override
349
349
public int getDependencyScopeWidth (DependencyScope dependencyScope ) {
350
- int result = 0 ;
351
- if (dependencyScope .isTransitive ()) {
352
- result += 1000 ;
353
- }
354
- for (BuildScope buildScope :
355
- buildScopeSource .query (translate (dependencyScope ).getPresence ())) {
356
- result += 1000
357
- / buildScope .getProjectPaths ().stream ()
358
- .map (ProjectPath ::order )
359
- .reduce (0 , Integer ::sum );
360
- }
361
- return result ;
350
+ return translate (dependencyScope ).getWidth ();
362
351
}
363
352
364
353
@ Override
365
354
public Optional <BuildScope > getDependencyScopeMainProjectBuildScope (DependencyScope dependencyScope ) {
366
- for (ProjectPath projectPath : buildScopeSource .allProjectPaths ().stream ()
367
- .sorted (Comparator .comparing (ProjectPath ::order ))
368
- .toList ()) {
369
- for (BuildPath buildPath : buildScopeSource .allBuildPaths ().stream ()
370
- .sorted (Comparator .comparing (BuildPath ::order ))
371
- .toList ()) {
372
- for (BuildScope buildScope :
373
- buildScopeSource .query (translate (dependencyScope ).getPresence ())) {
374
- if (buildScope .getProjectPaths ().contains (projectPath )
375
- && buildScope .getBuildPaths ().contains (buildPath )) {
376
- return Optional .of (buildScope );
377
- }
378
- }
379
- }
380
- }
381
- return Optional .empty ();
355
+ return translate (dependencyScope ).getMainBuildScope ();
382
356
}
383
357
384
358
@ Override
@@ -434,6 +408,40 @@ private Set<DependencyScope> collectScopes(Collection<BuildScopeQuery> wantedPre
434
408
return result ;
435
409
}
436
410
411
+ private int calculateDependencyScopeWidth (DependencyScopeImpl dependencyScope ) {
412
+ int result = 0 ;
413
+ if (dependencyScope .isTransitive ()) {
414
+ result += 1000 ;
415
+ }
416
+ for (BuildScope buildScope :
417
+ buildScopeSource .query (dependencyScope .getPresence ())) {
418
+ result += 1000
419
+ / buildScope .getProjectPaths ().stream ()
420
+ .map (ProjectPath ::order )
421
+ .reduce (0 , Integer ::sum );
422
+ }
423
+ return result ;
424
+ }
425
+
426
+ private Optional <BuildScope > calculateMainProjectBuildScope (DependencyScopeImpl dependencyScope ) {
427
+ for (ProjectPath projectPath : buildScopeSource .allProjectPaths ().stream ()
428
+ .sorted (Comparator .comparing (ProjectPath ::order ))
429
+ .toList ()) {
430
+ for (BuildPath buildPath : buildScopeSource .allBuildPaths ().stream ()
431
+ .sorted (Comparator .comparing (BuildPath ::order ))
432
+ .toList ()) {
433
+ for (BuildScope buildScope :
434
+ buildScopeSource .query (dependencyScope .getPresence ())) {
435
+ if (buildScope .getProjectPaths ().contains (projectPath )
436
+ && buildScope .getBuildPaths ().contains (buildPath )) {
437
+ return Optional .of (buildScope );
438
+ }
439
+ }
440
+ }
441
+ }
442
+ return Optional .empty ();
443
+ }
444
+
437
445
private Set <String > getDirectlyIncludedLabels (ResolutionScopeImpl resolutionScope ) {
438
446
return resolutionScope .getDirectlyIncluded ().stream ()
439
447
.map (DependencyScope ::getId )
@@ -479,15 +487,20 @@ public String toString() {
479
487
return id ;
480
488
}
481
489
482
- private static final class DependencyScopeImpl implements DependencyScope {
490
+ private final class DependencyScopeImpl implements DependencyScope {
483
491
private final String id ;
484
492
private final boolean transitive ;
485
493
private final Set <BuildScopeQuery > presence ;
494
+ private final Optional <BuildScope > mainBuildScope ;
495
+ private final int width ;
496
+
486
497
487
498
private DependencyScopeImpl (String id , boolean transitive , Collection <BuildScopeQuery > presence ) {
488
499
this .id = requireNonNull (id , "id" );
489
500
this .transitive = transitive ;
490
501
this .presence = Set .copyOf (presence );
502
+ this .mainBuildScope = calculateMainProjectBuildScope (this );
503
+ this .width = calculateDependencyScopeWidth (this );
491
504
}
492
505
493
506
@ Override
@@ -504,6 +517,14 @@ public Set<BuildScopeQuery> getPresence() {
504
517
return presence ;
505
518
}
506
519
520
+ public Optional <BuildScope > getMainBuildScope () {
521
+ return mainBuildScope ;
522
+ }
523
+
524
+ public int getWidth () {
525
+ return width ;
526
+ }
527
+
507
528
@ Override
508
529
public boolean equals (Object o ) {
509
530
if (this == o ) return true ;
@@ -547,7 +568,6 @@ enum Mode {
547
568
private final Set <BuildScopeQuery > wantedPresence ;
548
569
private final Set <DependencyScope > directlyIncluded ;
549
570
private final Set <DependencyScope > transitivelyExcluded ;
550
-
551
571
private ResolutionScopeImpl (
552
572
String id ,
553
573
Mode mode ,
0 commit comments