use of org.gradle.api.internal.attributes.ImmutableAttributes in project gradle by gradle.
the class JavaEcosystemVariantDerivationStrategy method derive.
@Override
public ImmutableList<? extends ConfigurationMetadata> derive(ModuleComponentResolveMetadata metadata) {
if (metadata instanceof DefaultMavenModuleResolveMetadata) {
DefaultMavenModuleResolveMetadata md = (DefaultMavenModuleResolveMetadata) metadata;
ImmutableAttributes attributes = md.getAttributes();
MavenImmutableAttributesFactory attributesFactory = (MavenImmutableAttributesFactory) md.getAttributesFactory();
DefaultConfigurationMetadata compileConfiguration = (DefaultConfigurationMetadata) md.getConfiguration("compile");
DefaultConfigurationMetadata runtimeConfiguration = (DefaultConfigurationMetadata) md.getConfiguration("runtime");
ModuleComponentIdentifier componentId = md.getId();
ImmutableCapabilities shadowedPlatformCapability = buildShadowPlatformCapability(componentId, false);
ImmutableCapabilities shadowedEnforcedPlatformCapability = buildShadowPlatformCapability(componentId, true);
return ImmutableList.of(// component we cannot mix precise usages with more generic ones)
libraryWithUsageAttribute(compileConfiguration, attributes, attributesFactory, Usage.JAVA_API), libraryWithUsageAttribute(runtimeConfiguration, attributes, attributesFactory, Usage.JAVA_RUNTIME), libraryWithSourcesVariant(runtimeConfiguration, attributes, attributesFactory, metadata), libraryWithJavadocVariant(runtimeConfiguration, attributes, attributesFactory, metadata), platformWithUsageAttribute(compileConfiguration, attributes, attributesFactory, Usage.JAVA_API, false, shadowedPlatformCapability), platformWithUsageAttribute(runtimeConfiguration, attributes, attributesFactory, Usage.JAVA_RUNTIME, false, shadowedPlatformCapability), platformWithUsageAttribute(compileConfiguration, attributes, attributesFactory, Usage.JAVA_API, true, shadowedEnforcedPlatformCapability), platformWithUsageAttribute(runtimeConfiguration, attributes, attributesFactory, Usage.JAVA_RUNTIME, true, shadowedEnforcedPlatformCapability));
}
return null;
}
use of org.gradle.api.internal.attributes.ImmutableAttributes in project gradle by gradle.
the class JavaEcosystemVariantDerivationStrategy method platformWithUsageAttribute.
private static ConfigurationMetadata platformWithUsageAttribute(DefaultConfigurationMetadata conf, ImmutableAttributes originAttributes, MavenImmutableAttributesFactory attributesFactory, String usage, boolean enforcedPlatform, ImmutableCapabilities shadowedPlatformCapability) {
ImmutableAttributes attributes = attributesFactory.platformWithUsage(originAttributes, usage, enforcedPlatform);
String prefix = enforcedPlatform ? "enforced-platform-" : "platform-";
DefaultConfigurationMetadata.Builder builder = conf.mutate().withName(prefix + conf.getName()).withAttributes(attributes).withConstraintsOnly().withCapabilities(shadowedPlatformCapability);
if (enforcedPlatform) {
builder = builder.withForcedDependencies();
}
return builder.build();
}
use of org.gradle.api.internal.attributes.ImmutableAttributes in project gradle by gradle.
the class LazyToRealisedModuleComponentResolveMetadataHelper method addVariantsFromRules.
private static ImmutableList<AbstractRealisedModuleComponentResolveMetadata.ImmutableRealisedVariantImpl> addVariantsFromRules(ModuleComponentResolveMetadata componentMetadata, List<AbstractRealisedModuleComponentResolveMetadata.ImmutableRealisedVariantImpl> declaredVariants, VariantMetadataRules variantMetadataRules) {
List<AdditionalVariant> additionalVariants = variantMetadataRules.getAdditionalVariants();
if (additionalVariants.isEmpty()) {
return ImmutableList.copyOf(declaredVariants);
}
ImmutableList.Builder<AbstractRealisedModuleComponentResolveMetadata.ImmutableRealisedVariantImpl> builder = new ImmutableList.Builder<>();
builder.addAll(declaredVariants);
Map<String, ComponentVariant> variantsByName = declaredVariants.stream().collect(Collectors.toMap(ComponentVariant::getName, Function.identity()));
for (AdditionalVariant additionalVariant : additionalVariants) {
String baseName = additionalVariant.getBase();
ImmutableAttributes attributes;
ImmutableCapabilities capabilities;
ImmutableList<? extends ComponentVariant.Dependency> dependencies;
ImmutableList<? extends ComponentVariant.DependencyConstraint> dependencyConstraints;
ImmutableList<? extends ComponentVariant.File> files;
ComponentVariant baseVariant = variantsByName.get(baseName);
boolean isExternalVariant;
if (baseVariant == null) {
attributes = componentMetadata.getAttributes();
capabilities = ImmutableCapabilities.EMPTY;
dependencies = ImmutableList.of();
dependencyConstraints = ImmutableList.of();
files = ImmutableList.of();
isExternalVariant = false;
} else {
attributes = (ImmutableAttributes) baseVariant.getAttributes();
capabilities = (ImmutableCapabilities) baseVariant.getCapabilities();
dependencies = baseVariant.getDependencies();
dependencyConstraints = baseVariant.getDependencyConstraints();
files = baseVariant.getFiles();
isExternalVariant = baseVariant.isExternalVariant();
}
if (baseName == null || baseVariant != null) {
AbstractRealisedModuleComponentResolveMetadata.ImmutableRealisedVariantImpl variant = applyRules(new AbstractMutableModuleComponentResolveMetadata.ImmutableVariantImpl(componentMetadata.getId(), additionalVariant.getName(), attributes, dependencies, dependencyConstraints, files, capabilities, isExternalVariant), variantMetadataRules, componentMetadata.getId());
builder.add(variant);
} else if (!additionalVariant.isLenient()) {
throw new InvalidUserDataException("Variant '" + baseName + "' not defined in module " + componentMetadata.getId().getDisplayName());
}
}
return builder.build();
}
use of org.gradle.api.internal.attributes.ImmutableAttributes in project gradle by gradle.
the class RealisedIvyModuleResolveMetadataSerializationHelper method readIvyConfigurations.
private Map<String, ConfigurationMetadata> readIvyConfigurations(Decoder decoder, DefaultIvyModuleResolveMetadata metadata) throws IOException {
IvyConfigurationHelper configurationHelper = new IvyConfigurationHelper(metadata.getArtifactDefinitions(), new IdentityHashMap<>(), metadata.getExcludes(), metadata.getDependencies(), metadata.getId());
ImmutableMap<String, Configuration> configurationDefinitions = metadata.getConfigurationDefinitions();
int configurationsCount = decoder.readSmallInt();
Map<String, ConfigurationMetadata> configurations = Maps.newHashMapWithExpectedSize(configurationsCount);
for (int i = 0; i < configurationsCount; i++) {
String configurationName = decoder.readString();
boolean transitive = true;
boolean visible = true;
ImmutableSet<String> hierarchy = ImmutableSet.of(configurationName);
ImmutableList<ExcludeMetadata> excludes;
Configuration configuration = configurationDefinitions.get(configurationName);
if (configuration != null) {
// if the configuration represents a variant added by a rule, it is not in the definition list
transitive = configuration.isTransitive();
visible = configuration.isVisible();
hierarchy = LazyToRealisedModuleComponentResolveMetadataHelper.constructHierarchy(configuration, configurationDefinitions);
excludes = configurationHelper.filterExcludes(hierarchy);
} else {
excludes = ImmutableList.of();
}
ImmutableAttributes attributes = getAttributeContainerSerializer().read(decoder);
ImmutableCapabilities capabilities = readCapabilities(decoder);
boolean isExternalVariant = decoder.readBoolean();
boolean hasExplicitExcludes = decoder.readBoolean();
if (hasExplicitExcludes) {
excludes = ImmutableList.copyOf(readMavenExcludes(decoder));
}
ImmutableList<? extends ModuleComponentArtifactMetadata> artifacts = readFiles(decoder, metadata.getId());
RealisedConfigurationMetadata configurationMetadata = new RealisedConfigurationMetadata(metadata.getId(), configurationName, transitive, visible, hierarchy, artifacts, excludes, attributes, capabilities, false, isExternalVariant);
ImmutableList.Builder<ModuleDependencyMetadata> builder = ImmutableList.builder();
int dependenciesCount = decoder.readSmallInt();
for (int j = 0; j < dependenciesCount; j++) {
byte dependencyType = decoder.readByte();
switch(dependencyType) {
case GRADLE_DEPENDENCY_METADATA:
builder.add(readDependencyMetadata(decoder));
break;
case IVY_DEPENDENCY_METADATA:
IvyDependencyDescriptor ivyDependency = readIvyDependency(decoder);
ModuleDependencyMetadata dependencyMetadata = configurationHelper.contextualize(configurationMetadata, metadata.getId(), ivyDependency);
builder.add(dependencyMetadata.withReason(decoder.readNullableString()));
break;
case MAVEN_DEPENDENCY_METADATA:
throw new IllegalStateException("Unexpected Maven dependency for Ivy module");
default:
throw new IllegalStateException("Unknown dependency type " + dependencyType);
}
}
ImmutableList<ModuleDependencyMetadata> dependencies = builder.build();
configurationMetadata.setDependencies(dependencies);
configurations.put(configurationName, configurationMetadata);
}
return configurations;
}
use of org.gradle.api.internal.attributes.ImmutableAttributes in project gradle by gradle.
the class RealisedIvyModuleResolveMetadata method applyRules.
private static RealisedConfigurationMetadata applyRules(ModuleComponentIdentifier id, String configurationName, VariantMetadataRules variantMetadataRules, ImmutableAttributes attributes, ImmutableCapabilities capabilities, ImmutableList<? extends ModuleComponentArtifactMetadata> artifacts, ImmutableList<ExcludeMetadata> excludes, boolean transitive, boolean visible, ImmutableSet<String> hierarchy, IvyConfigurationHelper configurationHelper, @Nullable List<ModuleDependencyMetadata> dependenciesOverride, boolean addedByRule, boolean isExternalVariant) {
NameOnlyVariantResolveMetadata variant = new NameOnlyVariantResolveMetadata(configurationName);
ImmutableAttributes variantAttributes = variantMetadataRules.applyVariantAttributeRules(variant, attributes);
CapabilitiesMetadata capabilitiesMetadata = variantMetadataRules.applyCapabilitiesRules(variant, capabilities);
ImmutableList<? extends ModuleComponentArtifactMetadata> artifactsMetadata = variantMetadataRules.applyVariantFilesMetadataRulesToArtifacts(variant, artifacts, id);
return createConfiguration(id, configurationName, transitive, visible, hierarchy, artifactsMetadata, excludes, variantAttributes, ImmutableCapabilities.of(capabilitiesMetadata.getCapabilities()), variantMetadataRules, configurationHelper, dependenciesOverride, addedByRule, isExternalVariant);
}
Aggregations