40
40
import org .gradle .api .tasks .Input ;
41
41
import org .gradle .api .tasks .Internal ;
42
42
import org .gradle .api .tasks .Nested ;
43
+ import org .gradle .api .tasks .Optional ;
43
44
import org .gradle .api .tasks .OutputFile ;
44
45
import org .gradle .api .tasks .TaskAction ;
45
46
49
50
import java .nio .file .Files ;
50
51
import java .security .MessageDigest ;
51
52
import java .security .NoSuchAlgorithmException ;
53
+ import java .util .Collections ;
52
54
import java .util .Comparator ;
53
55
import java .util .HashSet ;
54
56
import java .util .List ;
@@ -108,6 +110,10 @@ public final void dependencies(final String key, final NamedDomainObjectProvider
108
110
@ Internal
109
111
public abstract SetProperty <ResolvedArtifactResult > getExcludedDependencies ();
110
112
113
+ @ Input
114
+ @ Optional
115
+ protected abstract SetProperty <ModuleComponentIdentifier > getExcludedDependencyIdentifiers ();
116
+
111
117
public final void excludeDependencies (final NamedDomainObjectProvider <Configuration > config ) {
112
118
this .getExcludedDependencies ().addAll (config .flatMap (conf -> conf .getIncoming ().getArtifacts ().getResolvedArtifacts ()));
113
119
}
@@ -123,18 +129,21 @@ public final void excludeDependencies(final NamedDomainObjectProvider<Configurat
123
129
124
130
public OutputDependenciesToJson () {
125
131
this .getAllowedClassifiers ().add ("" );
132
+ this .getExcludedDependencyIdentifiers ().set (this .getExcludedDependencies ().map (artifacts -> {
133
+ final Set <ModuleComponentIdentifier > ids = new HashSet <>();
134
+ for (final ResolvedArtifactResult artifact : artifacts ) {
135
+ final ComponentIdentifier id = artifact .getId ().getComponentIdentifier ();
136
+ if (id instanceof ModuleComponentIdentifier ) {
137
+ ids .add ((ModuleComponentIdentifier ) id );
138
+ }
139
+ }
140
+ return ids ;
141
+ }));
126
142
}
127
143
128
144
@ TaskAction
129
145
public void generateDependenciesJson () {
130
- final Set <ModuleComponentIdentifier > excludedDeps = new HashSet <>();
131
- if (this .getExcludedDependencies ().isPresent ()) {
132
- for (final ResolvedArtifactResult result : this .getExcludedDependencies ().get ()) {
133
- if (result .getId ().getComponentIdentifier () instanceof ModuleComponentIdentifier ) {
134
- excludedDeps .add ((ModuleComponentIdentifier ) result .getId ().getComponentIdentifier ());
135
- }
136
- }
137
- }
146
+ final Set <ModuleComponentIdentifier > excludedDeps = this .getExcludedDependencyIdentifiers ().getOrElse (Collections .emptySet ());
138
147
139
148
final Map <String , ConfigurationHolder > inputConfigs = this .getDependencies ().get ();
140
149
final Map <String , List <DependencyDescriptor >> dependenciesMap = new TreeMap <>();
@@ -201,15 +210,29 @@ public static String toHexString(final byte[] bytes) {
201
210
}
202
211
203
212
public static class ConfigurationHolder {
204
- private final Provider <Set <ResolvedArtifactResult >> configuration ;
213
+ private final Provider <Set <ResolvedArtifactResult >> artifacts ;
205
214
206
215
public ConfigurationHolder (final Configuration configuration ) {
207
- this .configuration = configuration .getIncoming ().getArtifacts ().getResolvedArtifacts ();
216
+ this .artifacts = configuration .getIncoming ().getArtifacts ().getResolvedArtifacts ();
217
+ }
218
+
219
+ @ Input
220
+ public Provider <Set <String >> getIds () {
221
+ return this .artifacts .map (set -> {
222
+ final Set <String > ids = new HashSet <>();
223
+ for (final ResolvedArtifactResult artifact : set ) {
224
+ final ComponentIdentifier id = artifact .getId ().getComponentIdentifier ();
225
+ if (id instanceof ModuleComponentIdentifier ) {
226
+ ids .add (id .getDisplayName ());
227
+ }
228
+ }
229
+ return ids ;
230
+ });
208
231
}
209
232
210
233
@ Internal
211
234
public Provider <Set <ResolvedArtifactResult >> getArtifacts () {
212
- return this .configuration ;
235
+ return this .artifacts ;
213
236
}
214
237
}
215
238
}
0 commit comments