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);
}
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);
}
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();
});
});
}
});
}
Aggregations