Search in sources :

Example 11 with AttributeContainer

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));
    }
}
Also used : Bundling(org.gradle.api.attributes.Bundling) Usage(org.gradle.api.attributes.Usage) Task(org.gradle.api.Task) Category(org.gradle.api.attributes.Category) LazyPublishArtifact(org.gradle.api.internal.artifacts.dsl.LazyPublishArtifact) Configuration(org.gradle.api.artifacts.Configuration) AttributeContainer(org.gradle.api.attributes.AttributeContainer) DocsType(org.gradle.api.attributes.DocsType) Jar(org.gradle.api.tasks.bundling.Jar)

Example 12 with AttributeContainer

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("");
}
Also used : ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) SourceSet(org.gradle.api.tasks.SourceSet) Configuration(org.gradle.api.artifacts.Configuration) ComponentSelector(org.gradle.api.artifacts.component.ComponentSelector) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) TreeSet(java.util.TreeSet) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) AttributeContainer(org.gradle.api.attributes.AttributeContainer) ResolvedComponentResult(org.gradle.api.artifacts.result.ResolvedComponentResult) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) TaskAction(org.gradle.api.tasks.TaskAction)

Example 13 with AttributeContainer

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);
}
Also used : ImmutableCapability(org.gradle.internal.component.external.model.ImmutableCapability) Capability(org.gradle.api.capabilities.Capability) DefaultResolvedVariantResult(org.gradle.api.internal.artifacts.result.DefaultResolvedVariantResult) DefaultResolvedVariantResult(org.gradle.api.internal.artifacts.result.DefaultResolvedVariantResult) ResolvedVariantResult(org.gradle.api.artifacts.result.ResolvedVariantResult) ComponentIdentifier(org.gradle.api.artifacts.component.ComponentIdentifier) AttributeContainer(org.gradle.api.attributes.AttributeContainer)

Example 14 with AttributeContainer

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;
}
Also used : AttributeMatcher(org.gradle.internal.component.model.AttributeMatcher) AttributeContainer(org.gradle.api.attributes.AttributeContainer)

Example 15 with AttributeContainer

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);
    }
}
Also used : Attribute(org.gradle.api.attributes.Attribute) AttributeContainer(org.gradle.api.attributes.AttributeContainer)

Aggregations

AttributeContainer (org.gradle.api.attributes.AttributeContainer)34 Usage (org.gradle.api.attributes.Usage)14 Configuration (org.gradle.api.artifacts.Configuration)13 Project (org.gradle.api.Project)7 DefaultUsageContext (org.gradle.language.cpp.internal.DefaultUsageContext)7 NativeVariantIdentity (org.gradle.language.cpp.internal.NativeVariantIdentity)7 Bundling (org.gradle.api.attributes.Bundling)6 Callable (java.util.concurrent.Callable)5 Action (org.gradle.api.Action)5 ObjectFactory (org.gradle.api.model.ObjectFactory)5 Provider (org.gradle.api.provider.Provider)5 OperatingSystemFamily (org.gradle.nativeplatform.OperatingSystemFamily)5 File (java.io.File)4 Set (java.util.Set)4 Attribute (org.gradle.api.attributes.Attribute)4 Category (org.gradle.api.attributes.Category)4 Task (org.gradle.api.Task)3 ConfigurationContainer (org.gradle.api.artifacts.ConfigurationContainer)3 LibraryElements (org.gradle.api.attributes.LibraryElements)3 Capability (org.gradle.api.capabilities.Capability)3