2020import java .util .HashMap ;
2121import java .util .HashSet ;
2222import java .util .LinkedList ;
23- import java .util .List ;
2423import java .util .Map ;
2524import java .util .Set ;
2625
3938import org .gradle .api .artifacts .result .ResolutionResult ;
4039import org .gradle .api .artifacts .result .ResolvedComponentResult ;
4140import org .gradle .api .artifacts .result .ResolvedDependencyResult ;
42- import org .gradle .api .artifacts .result .ResolvedVariantResult ;
4341import org .gradle .api .artifacts .result .UnresolvedDependencyResult ;
44- import org .gradle .api .attributes .Attribute ;
45- import org .gradle .api .attributes .AttributeContainer ;
46- import org .gradle .api .attributes .Category ;
4742import org .slf4j .Logger ;
4843import org .slf4j .LoggerFactory ;
4944
@@ -107,7 +102,7 @@ private Set<DependencyCandidate> findExcludedDependencies() {
107102 resolutionResult .allDependencies ((dependencyResult ) -> {
108103 if (dependencyResult instanceof ResolvedDependencyResult ) {
109104 ResolvedDependencyResult resolved = (ResolvedDependencyResult ) dependencyResult ;
110- if (!isPlatform ( resolved .getSelected () )) {
105+ if (!resolved .isConstraint ( )) {
111106 excludedDependencies .add (new DependencyCandidate (resolved .getSelected ().getModuleVersion ()));
112107 }
113108 }
@@ -137,21 +132,19 @@ private Configuration copyConfiguration() {
137132 private Set <DependencyCandidate > determineIncludedComponents (ResolvedComponentResult root ,
138133 Map <String , Exclusions > pomExclusionsById ) {
139134 LinkedList <Node > queue = new LinkedList <>();
140- queue .add (new Node (root , getId (root ), new HashSet <>(), false ));
135+ queue .add (new Node (root , getId (root ), new HashSet <>()));
141136 Set <ResolvedComponentResult > seen = new HashSet <>();
142137 Set <DependencyCandidate > includedComponents = new HashSet <>();
143138 while (!queue .isEmpty ()) {
144139 Node node = queue .remove ();
145140 includedComponents .add (new DependencyCandidate (node .component .getModuleVersion ()));
146- if (!node .platform ) {
147- for (DependencyResult dependency : node .component .getDependencies ()) {
148- if (dependency instanceof ResolvedDependencyResult ) {
149- handleResolvedDependency ((ResolvedDependencyResult ) dependency , node , pomExclusionsById , queue ,
150- seen );
151- }
152- else if (dependency instanceof UnresolvedDependencyResult ) {
153- handleUnresolvedDependency ((UnresolvedDependencyResult ) dependency , node , includedComponents );
154- }
141+ for (DependencyResult dependency : node .component .getDependencies ()) {
142+ if (dependency instanceof ResolvedDependencyResult ) {
143+ handleResolvedDependency ((ResolvedDependencyResult ) dependency , node , pomExclusionsById , queue ,
144+ seen );
145+ }
146+ else if (dependency instanceof UnresolvedDependencyResult ) {
147+ handleUnresolvedDependency ((UnresolvedDependencyResult ) dependency , node , includedComponents );
155148 }
156149 }
157150 }
@@ -162,25 +155,11 @@ private void handleResolvedDependency(ResolvedDependencyResult dependency, Node
162155 Map <String , Exclusions > pomExclusionsById , LinkedList <Node > queue , Set <ResolvedComponentResult > seen ) {
163156 ResolvedComponentResult child = dependency .getSelected ();
164157 String childId = getId (child );
165- if (!node .excluded (childId ) && seen .add (child )) {
166- boolean platform = isPlatform (child );
167- queue .add (new Node (child , childId , getChildExclusions (node , childId , pomExclusionsById ), platform ));
158+ if (!node .excluded (childId ) && seen .add (child ) && !dependency .isConstraint ()) {
159+ queue .add (new Node (child , childId , getChildExclusions (node , childId , pomExclusionsById )));
168160 }
169161 }
170162
171- private boolean isPlatform (ResolvedComponentResult component ) {
172- List <ResolvedVariantResult > variants = component .getVariants ();
173- for (ResolvedVariantResult variant : variants ) {
174- AttributeContainer attributes = variant .getAttributes ();
175- String category = attributes .getAttribute (Attribute .of ("org.gradle.category" , String .class ));
176- if (category == null
177- || (!Category .REGULAR_PLATFORM .equals (category ) && !Category .ENFORCED_PLATFORM .equals (category ))) {
178- return false ;
179- }
180- }
181- return true ;
182- }
183-
184163 private void handleUnresolvedDependency (UnresolvedDependencyResult dependency , Node node ,
185164 Set <DependencyCandidate > includedComponents ) {
186165 DependencyCandidate dependencyCandidate = toDependencyCandidate (dependency );
@@ -227,13 +206,10 @@ private static final class Node {
227206
228207 private final Set <Exclusion > exclusions ;
229208
230- private final boolean platform ;
231-
232- private Node (ResolvedComponentResult component , String id , Set <Exclusion > exclusions , boolean platform ) {
209+ private Node (ResolvedComponentResult component , String id , Set <Exclusion > exclusions ) {
233210 this .component = component ;
234211 this .id = id ;
235212 this .exclusions = exclusions ;
236- this .platform = platform ;
237213 }
238214
239215 private boolean excluded (String id ) {
0 commit comments