/
AbstractModuleComponentResolveMetadata.java
233 lines (205 loc) · 8.94 KB
/
AbstractModuleComponentResolveMetadata.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/*
* Copyright 2018 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.internal.component.external.model;
import com.google.common.base.Objects;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import org.gradle.api.artifacts.ModuleVersionIdentifier;
import org.gradle.api.artifacts.component.ModuleComponentIdentifier;
import org.gradle.api.internal.attributes.AttributeContainerInternal;
import org.gradle.api.internal.attributes.AttributesSchemaInternal;
import org.gradle.api.internal.attributes.ImmutableAttributes;
import org.gradle.api.internal.attributes.ImmutableAttributesFactory;
import org.gradle.api.internal.project.ProjectInternal;
import org.gradle.internal.component.model.ConfigurationMetadata;
import org.gradle.internal.component.model.DefaultIvyArtifactName;
import org.gradle.internal.component.model.ImmutableModuleSources;
import org.gradle.internal.component.model.IvyArtifactName;
import org.gradle.internal.component.model.ModuleSources;
import javax.annotation.Nullable;
import java.util.List;
abstract class AbstractModuleComponentResolveMetadata implements ModuleComponentResolveMetadata {
private final ImmutableAttributesFactory attributesFactory;
private final ModuleVersionIdentifier moduleVersionIdentifier;
private final ModuleComponentIdentifier componentIdentifier;
private final boolean changing;
private final boolean missing;
private final List<String> statusScheme;
private final ImmutableModuleSources moduleSources;
private final ImmutableList<? extends ComponentVariant> variants;
private final ImmutableAttributes attributes;
private final ImmutableList<? extends VirtualComponentIdentifier> platformOwners;
private final AttributesSchemaInternal schema;
private final VariantDerivationStrategy variantDerivationStrategy;
public AbstractModuleComponentResolveMetadata(AbstractMutableModuleComponentResolveMetadata metadata) {
this.componentIdentifier = metadata.getId();
this.moduleVersionIdentifier = metadata.getModuleVersionId();
changing = metadata.isChanging();
missing = metadata.isMissing();
statusScheme = metadata.getStatusScheme();
moduleSources = ImmutableModuleSources.of(metadata.getSources());
attributesFactory = metadata.getAttributesFactory();
schema = metadata.getAttributesSchema();
attributes = extractAttributes(metadata);
variants = metadata.getVariants();
platformOwners = metadata.getPlatformOwners() == null ? ImmutableList.of() : ImmutableList.copyOf(metadata.getPlatformOwners());
variantDerivationStrategy = metadata.getVariantDerivationStrategy();
}
public AbstractModuleComponentResolveMetadata(AbstractModuleComponentResolveMetadata metadata, ImmutableList<? extends ComponentVariant> variants) {
this.componentIdentifier = metadata.getId();
this.moduleVersionIdentifier = metadata.getModuleVersionId();
changing = metadata.isChanging();
missing = metadata.isMissing();
statusScheme = metadata.getStatusScheme();
moduleSources = ImmutableModuleSources.of(metadata.getSources());
attributesFactory = metadata.getAttributesFactory();
schema = metadata.getAttributesSchema();
attributes = metadata.getAttributes();
this.variants = variants;
this.platformOwners = metadata.getPlatformOwners();
this.variantDerivationStrategy = metadata.getVariantDerivationStrategy();
}
public AbstractModuleComponentResolveMetadata(AbstractModuleComponentResolveMetadata metadata) {
this.componentIdentifier = metadata.componentIdentifier;
this.moduleVersionIdentifier = metadata.moduleVersionIdentifier;
changing = metadata.changing;
missing = metadata.missing;
statusScheme = metadata.statusScheme;
moduleSources = metadata.moduleSources;
attributesFactory = metadata.attributesFactory;
schema = metadata.schema;
attributes = metadata.attributes;
variants = metadata.variants;
platformOwners = metadata.platformOwners;
variantDerivationStrategy = metadata.getVariantDerivationStrategy();
}
public AbstractModuleComponentResolveMetadata(AbstractModuleComponentResolveMetadata metadata, ModuleSources sources, VariantDerivationStrategy derivationStrategy) {
this.componentIdentifier = metadata.componentIdentifier;
this.moduleVersionIdentifier = metadata.moduleVersionIdentifier;
changing = metadata.changing;
missing = metadata.missing;
statusScheme = metadata.statusScheme;
attributesFactory = metadata.attributesFactory;
schema = metadata.schema;
attributes = metadata.attributes;
variants = metadata.variants;
platformOwners = metadata.platformOwners;
moduleSources = ImmutableModuleSources.of(sources);
variantDerivationStrategy = derivationStrategy;
}
private static ImmutableAttributes extractAttributes(AbstractMutableModuleComponentResolveMetadata metadata) {
return ((AttributeContainerInternal) metadata.getAttributes()).asImmutable();
}
@Override
public ImmutableAttributesFactory getAttributesFactory() {
return attributesFactory;
}
@Override
public boolean isChanging() {
return changing;
}
@Override
public boolean isMissing() {
return missing;
}
@Override
public List<String> getStatusScheme() {
return statusScheme;
}
@Override
public ModuleComponentIdentifier getId() {
return componentIdentifier;
}
@Override
public ModuleVersionIdentifier getModuleVersionId() {
return moduleVersionIdentifier;
}
@Override
public ModuleSources getSources() {
return moduleSources;
}
@Override
public String toString() {
return componentIdentifier.getDisplayName();
}
@Nullable
@Override
public AttributesSchemaInternal getAttributesSchema() {
return schema;
}
@Override
public ImmutableAttributes getAttributes() {
return attributes;
}
@Override
public String getStatus() {
return attributes.getAttribute(ProjectInternal.STATUS_ATTRIBUTE);
}
@Override
public ImmutableList<? extends ComponentVariant> getVariants() {
return variants;
}
@Override
public ModuleComponentArtifactMetadata artifact(String type, @Nullable String extension, @Nullable String classifier) {
IvyArtifactName ivyArtifactName = new DefaultIvyArtifactName(getModuleVersionId().getName(), type, extension, classifier);
return new DefaultModuleComponentArtifactMetadata(getId(), ivyArtifactName);
}
/**
* If there are no variants defined in the metadata, but the implementation knows how to provide variants it can do that here.
* If it can not provide variants, absent must be returned to fall back to traditional configuration selection.
*/
protected Optional<ImmutableList<? extends ConfigurationMetadata>> maybeDeriveVariants() {
return Optional.absent();
}
@Override
public ImmutableList<? extends VirtualComponentIdentifier> getPlatformOwners() {
return platformOwners;
}
@Override
public VariantDerivationStrategy getVariantDerivationStrategy() {
return variantDerivationStrategy;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
AbstractModuleComponentResolveMetadata that = (AbstractModuleComponentResolveMetadata) o;
return changing == that.changing
&& missing == that.missing
&& Objects.equal(moduleVersionIdentifier, that.moduleVersionIdentifier)
&& Objects.equal(componentIdentifier, that.componentIdentifier)
&& Objects.equal(statusScheme, that.statusScheme)
&& Objects.equal(moduleSources, that.moduleSources)
&& Objects.equal(attributes, that.attributes)
&& Objects.equal(variants, that.variants);
}
@Override
public int hashCode() {
return Objects.hashCode(
moduleVersionIdentifier,
componentIdentifier,
changing,
missing,
statusScheme,
moduleSources,
attributes,
variants);
}
}