29
29
import org .gradle .api .DefaultTask ;
30
30
import org .gradle .api .GradleException ;
31
31
import org .gradle .api .NamedDomainObjectProvider ;
32
- import org .gradle .api .artifacts .ArtifactCollection ;
33
32
import org .gradle .api .artifacts .Configuration ;
34
33
import org .gradle .api .artifacts .component .ComponentIdentifier ;
35
34
import org .gradle .api .artifacts .component .ModuleComponentIdentifier ;
36
35
import org .gradle .api .artifacts .result .ResolvedArtifactResult ;
37
36
import org .gradle .api .file .RegularFileProperty ;
38
37
import org .gradle .api .provider .MapProperty ;
39
- import org .gradle .api .provider .Property ;
38
+ import org .gradle .api .provider .Provider ;
40
39
import org .gradle .api .provider .SetProperty ;
41
40
import org .gradle .api .tasks .Input ;
42
- import org .gradle .api .tasks .InputFiles ;
41
+ import org .gradle .api .tasks .Internal ;
43
42
import org .gradle .api .tasks .Nested ;
44
43
import org .gradle .api .tasks .Optional ;
45
44
import org .gradle .api .tasks .OutputFile ;
@@ -161,12 +160,15 @@ public final void dependencies(final String key, final NamedDomainObjectProvider
161
160
* Excludes configuration, to remove certain entries from dependencies and
162
161
* transitive dependencies of {@link #getDependencies()}.
163
162
*/
163
+ @ Internal
164
+ public abstract SetProperty <ResolvedArtifactResult > getExcludedDependencies ();
165
+
164
166
@ Input
165
167
@ Optional
166
- public abstract Property < Configuration > getExcludedDependencies ();
168
+ protected abstract SetProperty < ModuleComponentIdentifier > getExcludedDependenciesBuildInput ();
167
169
168
170
public final void excludedDependencies (final NamedDomainObjectProvider <Configuration > config ) {
169
- this .getExcludedDependencies ().set (config );
171
+ this .getExcludedDependencies ().set (config . flatMap ( conf -> conf . getIncoming (). getArtifacts (). getResolvedArtifacts ()) );
170
172
}
171
173
172
174
/**
@@ -180,13 +182,20 @@ public final void excludedDependencies(final NamedDomainObjectProvider<Configura
180
182
181
183
public OutputDependenciesToJson () {
182
184
this .getAllowedClassifiers ().add ("" );
185
+ this .getExcludedDependenciesBuildInput ().set (this .getExcludedDependencies ().map (deps -> {
186
+ return deps .stream ()
187
+ .map (res -> res .getId ().getComponentIdentifier ())
188
+ .filter (res -> res instanceof ModuleComponentIdentifier )
189
+ .map (res -> (ModuleComponentIdentifier ) res )
190
+ .collect (Collectors .toSet ());
191
+ }));
183
192
}
184
193
185
194
@ TaskAction
186
195
public void generateDependenciesJson () {
187
196
final Set <ModuleComponentIdentifier > excludedDeps = new HashSet <>();
188
197
if (this .getExcludedDependencies ().isPresent ()) {
189
- for (final ResolvedArtifactResult result : this .getExcludedDependencies ().get (). getIncoming (). getArtifacts () ) {
198
+ for (final ResolvedArtifactResult result : this .getExcludedDependencies ().get ()) {
190
199
if (result .getId ().getComponentIdentifier () instanceof ModuleComponentIdentifier ) {
191
200
excludedDeps .add ((ModuleComponentIdentifier ) result .getId ().getComponentIdentifier ());
192
201
}
@@ -197,7 +206,7 @@ public void generateDependenciesJson() {
197
206
final Map <String , List <DependencyDescriptor >> dependenciesMap = new TreeMap <>();
198
207
199
208
for (final Map .Entry <String , ConfigurationHolder > entry : inputConfigs .entrySet ()) {
200
- dependenciesMap .put (entry .getKey (), this .configToDescriptor (entry .getValue ().getConfiguration ().getIncoming (). getArtifacts (), excludedDeps ));
209
+ dependenciesMap .put (entry .getKey (), this .configToDescriptor (entry .getValue ().getArtifacts ().get (), excludedDeps ));
201
210
}
202
211
final DependencyManifest manifest = new DependencyManifest (dependenciesMap );
203
212
@@ -212,8 +221,8 @@ public void generateDependenciesJson() {
212
221
}
213
222
}
214
223
215
- private List <DependencyDescriptor > configToDescriptor (final ArtifactCollection conf , final Set <ModuleComponentIdentifier > excludedDeps ) {
216
- return conf .getArtifacts (). stream ()
224
+ private List <DependencyDescriptor > configToDescriptor (final Set < ResolvedArtifactResult > conf , final Set <ModuleComponentIdentifier > excludedDeps ) {
225
+ return conf .stream ()
217
226
.filter (dep -> {
218
227
final ComponentIdentifier ident = dep .getId ().getComponentIdentifier ();
219
228
return ident instanceof ModuleComponentIdentifier && !excludedDeps .contains (ident );
@@ -260,14 +269,23 @@ public static String toHexString(final byte[] bytes) {
260
269
}
261
270
262
271
public static class ConfigurationHolder {
263
- private final Configuration configuration ;
272
+ private final Provider < Set < ResolvedArtifactResult >> configuration ;
264
273
265
274
public ConfigurationHolder (final Configuration configuration ) {
266
- this .configuration = configuration ;
275
+ this .configuration = configuration .getIncoming ().getArtifacts ().getResolvedArtifacts ();
276
+ }
277
+
278
+ @ Input
279
+ public Provider <Set <ModuleComponentIdentifier >> getIds () {
280
+ return this .getArtifacts ().map (set -> set .stream ()
281
+ .map (art -> art .getId ().getComponentIdentifier ())
282
+ .filter (id -> id instanceof ModuleComponentIdentifier )
283
+ .map (art -> (ModuleComponentIdentifier ) art )
284
+ .collect (Collectors .toSet ()));
267
285
}
268
286
269
- @ InputFiles
270
- public Configuration getConfiguration () {
287
+ @ Internal
288
+ public Provider < Set < ResolvedArtifactResult >> getArtifacts () {
271
289
return this .configuration ;
272
290
}
273
291
}
0 commit comments