use of org.gradle.api.attributes.AttributeContainer in project gradle by gradle.
the class JvmPluginsHelper method configureDocumentationVariantWithArtifact.
public static void configureDocumentationVariantWithArtifact(String variantName, @Nullable String featureName, String docsType, List<Capability> capabilities, String jarTaskName, Object artifactSource, @Nullable AdhocComponentWithVariants component, ConfigurationContainer configurations, TaskContainer tasks, ObjectFactory objectFactory, FileResolver fileResolver) {
Configuration variant = maybeCreateInvisibleConfig(configurations, variantName, docsType + " elements for " + (featureName == null ? "main" : featureName) + ".", true);
AttributeContainer attributes = variant.getAttributes();
attributes.attribute(Usage.USAGE_ATTRIBUTE, objectFactory.named(Usage.class, Usage.JAVA_RUNTIME));
attributes.attribute(Category.CATEGORY_ATTRIBUTE, objectFactory.named(Category.class, Category.DOCUMENTATION));
attributes.attribute(Bundling.BUNDLING_ATTRIBUTE, objectFactory.named(Bundling.class, Bundling.EXTERNAL));
attributes.attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objectFactory.named(DocsType.class, docsType));
capabilities.forEach(variant.getOutgoing()::capability);
if (!tasks.getNames().contains(jarTaskName)) {
TaskProvider<Jar> jarTask = tasks.register(jarTaskName, Jar.class, jar -> {
jar.setDescription("Assembles a jar archive containing the " + (featureName == null ? "main " + docsType + "." : (docsType + " of the '" + featureName + "' feature.")));
jar.setGroup(BasePlugin.BUILD_GROUP);
jar.from(artifactSource);
jar.getArchiveClassifier().set(camelToKebabCase(featureName == null ? docsType : (featureName + "-" + docsType)));
});
if (tasks.getNames().contains(LifecycleBasePlugin.ASSEMBLE_TASK_NAME)) {
tasks.named(LifecycleBasePlugin.ASSEMBLE_TASK_NAME).configure(task -> task.dependsOn(jarTask));
}
}
TaskProvider<Task> jar = tasks.named(jarTaskName);
variant.getOutgoing().artifact(new LazyPublishArtifact(jar, fileResolver));
if (component != null) {
component.addVariantsFromConfiguration(variant, new JavaConfigurationVariantMapping("runtime", true));
}
}
use of org.gradle.api.attributes.AttributeContainer in project java-module-dependencies by jjohannes.
the class ModuleVersionRecommendation method report.
@TaskAction
public void report() {
Set<String> moduleVersionsPlatform = new TreeSet<>();
Set<String> moduleVersionsCatalog = new TreeSet<>();
AttributeContainer rtClasspathAttributes = configurations.getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME).getAttributes();
Configuration latestVersionsClasspath = configurations.create("latestVersionsClasspath", c -> {
c.setCanBeConsumed(false);
c.setCanBeResolved(true);
c.getAttributes().attribute(Usage.USAGE_ATTRIBUTE, Objects.requireNonNull(rtClasspathAttributes.getAttribute(Usage.USAGE_ATTRIBUTE)));
c.getAttributes().attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, Objects.requireNonNull(rtClasspathAttributes.getAttribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE)));
c.getResolutionStrategy().getDependencySubstitution().all(m -> {
ComponentSelector requested = m.getRequested();
if (requested instanceof ModuleComponentSelector) {
String group = ((ModuleComponentSelector) requested).getGroup();
String module = ((ModuleComponentSelector) requested).getModule();
m.useTarget(group + ":" + module + ":latest.release");
}
});
});
for (SourceSet sourceSet : sourceSets) {
latestVersionsClasspath.extendsFrom(configurations.getByName(sourceSet.getRuntimeClasspathConfigurationName()));
latestVersionsClasspath.extendsFrom(configurations.getByName(sourceSet.getCompileClasspathConfigurationName()));
}
components.all(c -> {
String lcVersion = c.getId().getVersion().toLowerCase();
if (lcVersion.contains("alpha") || lcVersion.contains("-b") || lcVersion.contains("beta") || lcVersion.contains("cr") || lcVersion.contains("m") || lcVersion.contains("rc")) {
c.setStatus("integration");
}
});
for (ResolvedComponentResult result : latestVersionsClasspath.getIncoming().getResolutionResult().getAllComponents()) {
ModuleVersionIdentifier moduleVersion = result.getModuleVersion();
if (moduleVersion != null && !(result.getId() instanceof ProjectComponentIdentifier)) {
String ga = moduleVersion.getGroup() + ":" + moduleVersion.getName();
String version = moduleVersion.getVersion();
String moduleName = javaModuleDependencies.moduleName(ga);
if (moduleName != null) {
moduleVersionsPlatform.add(" api(gav(\"" + moduleName + "\", \"" + version + "\"))");
moduleVersionsCatalog.add(moduleName.replace('.', '_') + " = \"" + version + "\"");
}
}
}
if (getPrintForPlatform().get()) {
p("");
p("Latest Stable Versions of Java Modules - use in your platform project's build.gradle(.kts)");
p("==========================================================================================");
p("dependencies.constraints {");
p(" javaModuleDependencies {");
for (String entry : moduleVersionsPlatform) {
p(entry);
}
p(" }");
p("}");
}
if (getPrintForCatalog().get()) {
p("");
p("Latest Stable Versions of Java Modules - use in [versions] section of 'gradle/libs.versions.toml'");
p("=================================================================================================");
for (String entry : moduleVersionsCatalog) {
p(entry);
}
}
p("");
}
use of org.gradle.api.attributes.AttributeContainer in project MyLuaApp-Build-Core by dingyi222666.
the class ResolvedVariantResultSerializer method read.
@Override
public ResolvedVariantResult read(Decoder decoder) throws IOException {
int index = decoder.readSmallInt();
if (index == -1) {
return null;
}
if (index == read.size()) {
ComponentIdentifier owner = componentIdentifierSerializer.read(decoder);
String variantName = decoder.readString();
AttributeContainer attributes = attributeContainerSerializer.read(decoder);
List<Capability> capabilities = readCapabilities(decoder);
read.add(null);
ResolvedVariantResult externalVariant = read(decoder);
DefaultResolvedVariantResult result = new DefaultResolvedVariantResult(owner, Describables.of(variantName), attributes, capabilities, externalVariant);
this.read.set(index, result);
return result;
}
return read.get(index);
}
use of org.gradle.api.attributes.AttributeContainer in project gradle by gradle.
the class VariantAttributeMatchingCache method matchAttributes.
private boolean matchAttributes(AttributeContainer actual, AttributeContainer requested, boolean ignoreAdditionalActualAttributes) {
Map<AttributeContainer, Boolean> cache;
AttributeMatcher schemaToMatchOn;
if (ignoreAdditionalActualAttributes) {
if (requested.isEmpty()) {
return true;
}
schemaToMatchOn = schema.ignoreAdditionalProducerAttributes();
cache = getCache(requested).ignoreExtraActual;
} else {
// ignore additional requested
if (actual.isEmpty()) {
return true;
}
schemaToMatchOn = schema.ignoreAdditionalConsumerAttributes();
cache = getCache(requested).ignoreExtraRequested;
}
Boolean match = cache.get(actual);
if (match == null) {
match = schemaToMatchOn.isMatching(actual, requested);
cache.put(actual, match);
}
return match;
}
use of org.gradle.api.attributes.AttributeContainer in project gradle by gradle.
the class ComponentAttributeMatcher method doMatchCandidate.
private void doMatchCandidate(AttributesSchemaInternal consumerAttributeSchema, AttributesSchemaInternal producerAttributeSchema, HasAttributes candidate, AttributeContainer requested, MatchDetails details) {
Set<Attribute<Object>> requestedAttributes = Cast.uncheckedCast(requested.keySet());
AttributeContainer candidateAttributesContainer = candidate.getAttributes();
Set<Attribute<Object>> candidateAttributes = Cast.uncheckedCast(candidateAttributesContainer.keySet());
Set<Attribute<Object>> allAttributes = Sets.union(requestedAttributes, candidateAttributes);
for (Attribute<Object> attribute : allAttributes) {
AttributeValue<Object> requestedValue = attributeValue(attribute, consumerAttributeSchema, requested);
AttributeValue<Object> actualValue = attributeValue(attribute, producerAttributeSchema, candidateAttributesContainer);
if (!requestedValue.isPresent() && ignoreAdditionalProducerAttributes) {
details.matchesByAttribute.put(attribute, actualValue.get());
continue;
}
if (!actualValue.isPresent() && ignoreAdditionalConsumerAttributes) {
continue;
}
details.update(attribute, consumerAttributeSchema, producerAttributeSchema, requestedValue, actualValue);
}
}
Aggregations