-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
ComponentMetadataHandler.java
186 lines (175 loc) · 7.39 KB
/
ComponentMetadataHandler.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*
* Copyright 2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gradle.api.artifacts.dsl;
import groovy.lang.Closure;
import groovy.lang.DelegatesTo;
import org.gradle.api.Action;
import org.gradle.api.ActionConfiguration;
import org.gradle.api.artifacts.ComponentMetadataDetails;
import org.gradle.api.artifacts.ComponentMetadataRule;
import org.gradle.internal.HasInternalProtocol;
/**
* Allows the build to provide rules that modify the metadata of depended-on software components.
*
* Component metadata rules are applied in the components section of the dependencies block
* {@link DependencyHandler} of a build script. The rules can be defined in two different ways:
* <ol>
* <li>As an action directly when they are applied in the components section</li>
* <li>As an isolated class implementing the {@link ComponentMetadataRule} interface</li>
* </ol>
*
* <p>Example shows a basic way of removing certain transitive dependencies from one of our dependencies.</p>
* <pre class='autoTested'>
* plugins {
* id 'java'
* }
*
* repositories {
* mavenCentral()
* }
*
* dependencies {
* components {
* withModule("jaxen:jaxen") {
* allVariants {
* withDependencies {
* removeAll { it.group in ["dom4j", "jdom", "xerces", "maven-plugins", "xml-apis", "xom"] }
* }
* }
*
* }
* }
* implementation("jaxen:jaxen:1.1.3")
* }
* </pre>
*
* @since 1.8
*/
@HasInternalProtocol
public interface ComponentMetadataHandler {
/**
* Adds a rule action that may modify the metadata of any resolved software component.
*
* @param rule the rule to be added
* @return this
*/
ComponentMetadataHandler all(Action<? super ComponentMetadataDetails> rule);
/**
* Adds a rule closure that may modify the metadata of any resolved software component.
*
* <p>The supplied rule closure must declare a {@link ComponentMetadataDetails} as it's first parameter,
* allowing the component metadata to be modified.
*
* <p>In addition, the rule can declare additional (read-only) parameters, which may provide extra details
* about the component. The order of these additional parameters is not significant.
*
* <p>The following additional parameter types are supported:
* <ul>
* <li>{@link org.gradle.api.artifacts.ivy.IvyModuleDescriptor} - additional Ivy-specific
* metadata. Rules declaring this parameter will only be invoked for components packaged as an Ivy module.</li>
* <li>{@link org.gradle.api.artifacts.maven.PomModuleDescriptor} - additional Maven-specific
* metadata. Rules declaring this parameter will only be invoked for components packaged as a POM module.</li>
* </ul>
*
* @param rule the rule to be added
* @return this
*/
ComponentMetadataHandler all(@DelegatesTo(ComponentMetadataDetails.class) Closure<?> rule);
/**
* Adds a rule that may modify the metadata of any resolved software component.
*
* <p>The ruleSource is an Object that has a single rule method annotated with {@link org.gradle.model.Mutate}.
*
* <p>This rule method:
* <ul>
* <li>must return void.</li>
* <li>must have {@link ComponentMetadataDetails} as the first parameter.</li>
* <li>may have an additional parameter of type {@link org.gradle.api.artifacts.ivy.IvyModuleDescriptor} or {@link org.gradle.api.artifacts.maven.PomModuleDescriptor}.</li>
* </ul>
*
* @param ruleSource the rule source object to be added
* @return this
*/
ComponentMetadataHandler all(Object ruleSource);
/**
* Adds a class based rule that may modify the metadata of any resolved software component.
*
* @param rule the rule to be added
* @return this
*
* @since 4.9
*/
ComponentMetadataHandler all(Class<? extends ComponentMetadataRule> rule);
/**
* Adds a class based rule that may modify the metadata of any resolved software component.
* The rule itself is configured by the provided configure action.
*
* @param rule the rule to be added
* @param configureAction the rule configuration
* @return this
*
* @since 4.9
*/
ComponentMetadataHandler all(Class<? extends ComponentMetadataRule> rule, Action<? super ActionConfiguration> configureAction);
/**
* Adds a rule that may modify the metadata of any resolved software component belonging to the specified module.
*
* @param id the module to apply this rule to in "group:module" format or as a {@link org.gradle.api.artifacts.ModuleIdentifier}
* @param rule the rule to be added
* @return this
*/
ComponentMetadataHandler withModule(Object id, Action<? super ComponentMetadataDetails> rule);
/**
* Adds a rule that may modify the metadata of any resolved software component belonging to the specified module.
*
* <p>The rule closure parameter is subject to the same requirements as {@link #all(groovy.lang.Closure)}.
*
* @param id the module to apply this rule to in "group:module" format or as a {@link org.gradle.api.artifacts.ModuleIdentifier}
* @param rule the rule to be added
* @return this
*/
ComponentMetadataHandler withModule(Object id, @DelegatesTo(ComponentMetadataDetails.class) Closure<?> rule);
/**
* Adds a rule that may modify the metadata of any resolved software component belonging to the specified module.
*
* <p>The rule source parameter is subject to the same requirements as {@link #all(Object)}.
*
* @param id the module to apply this rule to in "group:module" format or as a {@link org.gradle.api.artifacts.ModuleIdentifier}
* @param ruleSource the rule source object to be added
* @return this
*/
ComponentMetadataHandler withModule(Object id, Object ruleSource);
/**
* Adds a class based rule that may modify the metadata of any resolved software component belonging to the specified module.
*
* @param id the module to apply this rule to in "group:module" format or as a {@link org.gradle.api.artifacts.ModuleIdentifier}
* @param rule the rule to be added
* @return this
*
* @since 4.9
*/
ComponentMetadataHandler withModule(Object id, Class<? extends ComponentMetadataRule> rule);
/**
* Adds a class based rule that may modify the metadata of any resolved software component belonging to the specified module.
*
* @param id the module to apply this rule to in "group:module" format or as a {@link org.gradle.api.artifacts.ModuleIdentifier}
* @param rule the rule to be added
* @return this
*
* @since 4.9
*/
ComponentMetadataHandler withModule(Object id, Class<? extends ComponentMetadataRule> rule, Action<? super ActionConfiguration> configureAction);
}