Search in sources :

Example 6 with SoftwareComponentContainer

use of org.gradle.api.component.SoftwareComponentContainer in project gradle by gradle.

the class MavenPluginPublishingRules method addMainPublication.

@Mutate
public void addMainPublication(PublishingExtension publishing, GradlePluginDevelopmentExtension pluginDevelopment, ServiceRegistry services) {
    if (!pluginDevelopment.isAutomatedPublishing()) {
        return;
    }
    SoftwareComponentContainer componentContainer = services.get(SoftwareComponentContainer.class);
    SoftwareComponent component = componentContainer.getByName("java");
    PublicationContainer publications = publishing.getPublications();
    createMavenPluginPublication(component, publications);
}
Also used : PublicationContainer(org.gradle.api.publish.PublicationContainer) SoftwareComponent(org.gradle.api.component.SoftwareComponent) SoftwareComponentContainer(org.gradle.api.component.SoftwareComponentContainer) Mutate(org.gradle.model.Mutate)

Example 7 with SoftwareComponentContainer

use of org.gradle.api.component.SoftwareComponentContainer in project gradle by gradle.

the class NativeBasePlugin method apply.

@Override
public void apply(final Project project) {
    project.getPluginManager().apply(LifecycleBasePlugin.class);
    addTargetMachineFactoryAsExtension(project.getExtensions(), targetMachineFactory);
    final TaskContainer tasks = project.getTasks();
    final DirectoryProperty buildDirectory = project.getLayout().getBuildDirectory();
    final SoftwareComponentContainer components = project.getComponents();
    addLifecycleTasks(project, tasks, components);
    // Add tasks to build various kinds of components
    addTasksForComponentWithExecutable(tasks, buildDirectory, components);
    addTasksForComponentWithSharedLibrary(tasks, buildDirectory, components);
    addTasksForComponentWithStaticLibrary(tasks, buildDirectory, components);
    // Add incoming artifact transforms
    final DependencyHandler dependencyHandler = project.getDependencies();
    final ObjectFactory objects = project.getObjects();
    addHeaderZipTransform(dependencyHandler, objects);
    // Add outgoing configurations and publications
    final ConfigurationContainer configurations = project.getConfigurations();
    project.getDependencies().getAttributesSchema().attribute(LINKAGE_ATTRIBUTE).getDisambiguationRules().add(LinkageSelectionRule.class);
    addOutgoingConfigurationForLinkUsage(components, configurations);
    addOutgoingConfigurationForRuntimeUsage(components, configurations);
    addPublicationsFromVariants(project, components);
}
Also used : DependencyHandler(org.gradle.api.artifacts.dsl.DependencyHandler) TaskContainer(org.gradle.api.tasks.TaskContainer) DirectoryProperty(org.gradle.api.file.DirectoryProperty) ObjectFactory(org.gradle.api.model.ObjectFactory) ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer) SoftwareComponentContainer(org.gradle.api.component.SoftwareComponentContainer)

Example 8 with SoftwareComponentContainer

use of org.gradle.api.component.SoftwareComponentContainer in project gradle by gradle.

the class NativeBasePlugin method addLifecycleTasks.

private void addLifecycleTasks(final Project project, final TaskContainer tasks, final SoftwareComponentContainer components) {
    components.withType(ComponentWithBinaries.class, component -> {
        // Register each child of each component
        component.getBinaries().whenElementKnown(binary -> components.add(binary));
        if (component instanceof ProductionComponent) {
            // Add an assemble task for each binary and also wire the development binary in to the `assemble` task
            component.getBinaries().whenElementFinalized(ComponentWithOutputs.class, binary -> {
                // Determine which output to produce at development time.
                final FileCollection outputs = binary.getOutputs();
                Names names = ((ComponentWithNames) binary).getNames();
                tasks.register(names.getTaskName("assemble"), task -> task.dependsOn(outputs));
                if (binary == ((ProductionComponent) component).getDevelopmentBinary().get()) {
                    tasks.named(LifecycleBasePlugin.ASSEMBLE_TASK_NAME, task -> task.dependsOn(outputs));
                }
            });
        }
        if (component instanceof ComponentWithTargetMachines) {
            ComponentWithTargetMachines componentWithTargetMachines = (ComponentWithTargetMachines) component;
            tasks.named(LifecycleBasePlugin.ASSEMBLE_TASK_NAME, task -> {
                task.dependsOn((Callable) () -> {
                    TargetMachine currentHost = ((DefaultTargetMachineFactory) targetMachineFactory).host();
                    boolean targetsCurrentMachine = componentWithTargetMachines.getTargetMachines().get().stream().anyMatch(targetMachine -> currentHost.getOperatingSystemFamily().equals(targetMachine.getOperatingSystemFamily()));
                    if (!targetsCurrentMachine) {
                        task.getLogger().warn("'" + component.getName() + "' component in project '" + project.getPath() + "' does not target this operating system.");
                    }
                    return Collections.emptyList();
                });
            });
        }
    });
}
Also used : ComponentWithNames(org.gradle.language.nativeplatform.internal.ComponentWithNames) Names(org.gradle.language.nativeplatform.internal.Names) ConfigurableComponentWithRuntimeUsage(org.gradle.language.nativeplatform.internal.ConfigurableComponentWithRuntimeUsage) ConfigurableComponentWithSharedLibrary(org.gradle.language.nativeplatform.internal.ConfigurableComponentWithSharedLibrary) ComponentWithVariants(org.gradle.api.component.ComponentWithVariants) LinkSharedLibrary(org.gradle.nativeplatform.tasks.LinkSharedLibrary) ComponentWithBinaries(org.gradle.language.ComponentWithBinaries) Task(org.gradle.api.Task) Provider(org.gradle.api.provider.Provider) PublishingExtension(org.gradle.api.publish.PublishingExtension) ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer) MultipleCandidatesDetails(org.gradle.api.attributes.MultipleCandidatesDetails) TaskProvider(org.gradle.api.tasks.TaskProvider) TargetMachineFactory(org.gradle.nativeplatform.TargetMachineFactory) Linkage(org.gradle.nativeplatform.Linkage) ExtensionContainer(org.gradle.api.plugins.ExtensionContainer) UnzipTransform(org.gradle.api.internal.artifacts.transform.UnzipTransform) Incubating(org.gradle.api.Incubating) SoftwareComponentContainer(org.gradle.api.component.SoftwareComponentContainer) PlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider) Project(org.gradle.api.Project) TargetMachine(org.gradle.nativeplatform.TargetMachine) ComponentWithNames(org.gradle.language.nativeplatform.internal.ComponentWithNames) Set(java.util.Set) MutableMavenProjectIdentity(org.gradle.api.publish.maven.internal.publisher.MutableMavenProjectIdentity) DIRECTORY_TYPE(org.gradle.api.artifacts.type.ArtifactTypeDefinition.DIRECTORY_TYPE) AttributeDisambiguationRule(org.gradle.api.attributes.AttributeDisambiguationRule) TaskContainer(org.gradle.api.tasks.TaskContainer) AbstractLinkTask(org.gradle.nativeplatform.tasks.AbstractLinkTask) ArtifactTypeDefinition(org.gradle.api.artifacts.type.ArtifactTypeDefinition) Names(org.gradle.language.nativeplatform.internal.Names) SoftwareComponent(org.gradle.api.component.SoftwareComponent) NativeToolChain(org.gradle.nativeplatform.toolchain.NativeToolChain) MavenPublicationInternal(org.gradle.api.publish.maven.internal.publication.MavenPublicationInternal) CreateStaticLibrary(org.gradle.nativeplatform.tasks.CreateStaticLibrary) ZIP_TYPE(org.gradle.api.artifacts.type.ArtifactTypeDefinition.ZIP_TYPE) ConfigurableComponentWithStaticLibrary(org.gradle.language.nativeplatform.internal.ConfigurableComponentWithStaticLibrary) StripSymbols(org.gradle.nativeplatform.tasks.StripSymbols) PublishableComponent(org.gradle.api.component.PublishableComponent) Callable(java.util.concurrent.Callable) MavenPublication(org.gradle.api.publish.maven.MavenPublication) NativePlatform(org.gradle.nativeplatform.platform.NativePlatform) FileCollection(org.gradle.api.file.FileCollection) ProductionComponent(org.gradle.language.ProductionComponent) ExtractSymbols(org.gradle.nativeplatform.tasks.ExtractSymbols) LinkExecutable(org.gradle.nativeplatform.tasks.LinkExecutable) Inject(javax.inject.Inject) Configuration(org.gradle.api.artifacts.Configuration) LifecycleBasePlugin(org.gradle.language.base.plugins.LifecycleBasePlugin) DependencyHandler(org.gradle.api.artifacts.dsl.DependencyHandler) AttributeContainer(org.gradle.api.attributes.AttributeContainer) DefaultTargetMachineFactory(org.gradle.nativeplatform.internal.DefaultTargetMachineFactory) Attribute(org.gradle.api.attributes.Attribute) DirectoryProperty(org.gradle.api.file.DirectoryProperty) DomainObjectSet(org.gradle.api.DomainObjectSet) Usage(org.gradle.api.attributes.Usage) ConfigurableComponentWithLinkUsage(org.gradle.language.nativeplatform.internal.ConfigurableComponentWithLinkUsage) ConfigurableComponentWithExecutable(org.gradle.language.nativeplatform.internal.ConfigurableComponentWithExecutable) PublicationAwareComponent(org.gradle.language.nativeplatform.internal.PublicationAwareComponent) InstallExecutable(org.gradle.nativeplatform.tasks.InstallExecutable) ComponentWithTargetMachines(org.gradle.language.ComponentWithTargetMachines) Cast(org.gradle.internal.Cast) LINKAGE_ATTRIBUTE(org.gradle.language.cpp.CppBinary.LINKAGE_ATTRIBUTE) ObjectFactory(org.gradle.api.model.ObjectFactory) RegularFile(org.gradle.api.file.RegularFile) ComponentWithOutputs(org.gradle.language.ComponentWithOutputs) Collections(java.util.Collections) Plugin(org.gradle.api.Plugin) ComponentWithTargetMachines(org.gradle.language.ComponentWithTargetMachines) TargetMachine(org.gradle.nativeplatform.TargetMachine) ProductionComponent(org.gradle.language.ProductionComponent) FileCollection(org.gradle.api.file.FileCollection) ComponentWithNames(org.gradle.language.nativeplatform.internal.ComponentWithNames)

Aggregations

SoftwareComponentContainer (org.gradle.api.component.SoftwareComponentContainer)8 ConfigurationContainer (org.gradle.api.artifacts.ConfigurationContainer)6 SoftwareComponent (org.gradle.api.component.SoftwareComponent)6 DirectoryProperty (org.gradle.api.file.DirectoryProperty)6 TaskContainer (org.gradle.api.tasks.TaskContainer)6 DependencyHandler (org.gradle.api.artifacts.dsl.DependencyHandler)5 ObjectFactory (org.gradle.api.model.ObjectFactory)5 Collections (java.util.Collections)4 Set (java.util.Set)4 Callable (java.util.concurrent.Callable)4 Inject (javax.inject.Inject)4 DomainObjectSet (org.gradle.api.DomainObjectSet)4 Incubating (org.gradle.api.Incubating)4 Plugin (org.gradle.api.Plugin)4 Project (org.gradle.api.Project)4 Task (org.gradle.api.Task)4 Configuration (org.gradle.api.artifacts.Configuration)4 ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)4 ArtifactTypeDefinition (org.gradle.api.artifacts.type.ArtifactTypeDefinition)4 DIRECTORY_TYPE (org.gradle.api.artifacts.type.ArtifactTypeDefinition.DIRECTORY_TYPE)4