-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
ComponentSelectionRules.java
132 lines (124 loc) · 5.52 KB
/
ComponentSelectionRules.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
/*
* Copyright 2014 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;
import groovy.lang.Closure;
import groovy.lang.DelegatesTo;
import org.gradle.api.Action;
import org.gradle.internal.HasInternalProtocol;
/**
* Represents a container for component selection rules. Rules can be applied as part of the
* resolutionStrategy of a configuration and individual components can be explicitly accepted
* or rejected by rule. Components that are neither accepted or rejected will be subject to
* the default version matching strategies.
*
* <pre class='autoTested'>
* configurations {
* conf {
* resolutionStrategy {
* componentSelection {
* all { ComponentSelection selection ->
* if (selection.candidate.module == 'someModule' && selection.candidate.version == '1.1') {
* selection.reject("bad version '1.1' for 'someModule'")
* }
* }
* all { ComponentSelection selection ->
* if (selection.candidate.module == 'someModule' && selection.getDescriptor(IvyModuleDescriptor)?.branch == 'testing') {
* if (selection.metadata == null || selection.metadata.status != 'milestone') {
* selection.reject("only use milestones for someModule:testing")
* }
* }
* }
* withModule("org.sample:api") { ComponentSelection selection ->
* if (selection.candidate.version == "1.1") {
* selection.reject("known bad version")
* }
* }
* }
* }
* }
* }
* </pre>
*/
@HasInternalProtocol
public interface ComponentSelectionRules {
/**
* Adds a simple component selection rule that will apply to all resolved components.
* Each rule will receive a {@link ComponentSelection} object as an argument.
*
* @param selectionAction the Action that implements a rule to be applied
* @return this
*/
ComponentSelectionRules all(Action<? super ComponentSelection> selectionAction);
/**
* Adds a component selection rule that will apply to all resolved components.
*
* Each rule will receive a {@link ComponentSelection} object as an argument.
*
* @param closure the Closure that implements a rule to be applied
* @return this
*/
ComponentSelectionRules all(@DelegatesTo(ComponentSelection.class) Closure<?> closure);
/**
* Adds a rule-source backed component selection rule that will apply to all resolved components.
*
* The ruleSource provides the rule as exactly one rule method annotated with {@link org.gradle.model.Mutate}.
*
* This rule method:
* <ul>
* <li>must return void.</li>
* <li>must have {@link org.gradle.api.artifacts.ComponentSelection} as its parameter.</li>
* </ul>
*
* @param ruleSource an instance providing a rule implementation
* @return this
*/
ComponentSelectionRules all(Object ruleSource);
/**
* Adds a component selection rule that will apply to the specified module.
* Each rule will receive a {@link ComponentSelection} object as an argument.
*
* @param id the module to apply this rule to in "group:module" format or as a {@link org.gradle.api.artifacts.ModuleIdentifier}
* @param selectionAction the Action that implements a rule to be applied
* @return this
*/
ComponentSelectionRules withModule(Object id, Action<? super ComponentSelection> selectionAction);
/**
* Adds a component selection rule that will apply to the specified module.
*
* Each rule will receive a {@link ComponentSelection} object as an argument.
*
* @param id the module to apply this rule to in "group:module" format or as a {@link org.gradle.api.artifacts.ModuleIdentifier}
* @param closure the Closure that implements a rule to be applied
* @return this
*/
ComponentSelectionRules withModule(Object id, @DelegatesTo(ComponentSelection.class) Closure<?> closure);
/**
* Adds a rule-source backed component selection rule that will apply to the specified module.
*
* The ruleSource provides the rule as exactly one rule method annotated with {@link org.gradle.model.Mutate}.
*
* This rule method:
* <ul>
* <li>must return void.</li>
* <li>must have {@link org.gradle.api.artifacts.ComponentSelection} as its parameter.</li>
* </ul>
*
* @param id the module to apply this rule to in "group:module" format or as a {@link org.gradle.api.artifacts.ModuleIdentifier}
* @param ruleSource an instance providing a rule implementation
* @return this
*/
ComponentSelectionRules withModule(Object id, Object ruleSource);
}