Search in sources :

Example 1 with NamedDomainObjectList

use of org.gradle.api.NamedDomainObjectList in project gradle by gradle.

the class IvyPublishPlugin method createTasksLater.

private void createTasksLater(final Project project, final PublishingExtension publishingExtension, final DirectoryProperty buildDir) {
    final TaskContainer tasks = project.getTasks();
    final NamedDomainObjectSet<IvyPublicationInternal> publications = publishingExtension.getPublications().withType(IvyPublicationInternal.class);
    final NamedDomainObjectList<IvyArtifactRepository> repositories = publishingExtension.getRepositories().withType(IvyArtifactRepository.class);
    repositories.all(repository -> tasks.register(publishAllToSingleRepoTaskName(repository), publish -> {
        publish.setDescription("Publishes all Ivy publications produced by this project to the " + repository.getName() + " repository.");
        publish.setGroup(PublishingPlugin.PUBLISH_TASK_GROUP);
    }));
    publications.all(publication -> {
        final String publicationName = publication.getName();
        createGenerateIvyDescriptorTask(tasks, publicationName, publication, buildDir);
        createGenerateMetadataTask(tasks, publication, publications, buildDir, repositories);
        createPublishTaskForEachRepository(tasks, publication, publicationName, repositories);
    });
}
Also used : NamedDomainObjectFactory(org.gradle.api.NamedDomainObjectFactory) VersionMappingStrategyInternal(org.gradle.api.publish.internal.versionmapping.VersionMappingStrategyInternal) Path(org.gradle.model.Path) PluginManager(org.gradle.api.plugins.PluginManager) IvyArtifactNotationParserFactory(org.gradle.api.publish.ivy.internal.artifact.IvyArtifactNotationParserFactory) GenerateModuleMetadata(org.gradle.api.publish.tasks.GenerateModuleMetadata) NamedDomainObjectList(org.gradle.api.NamedDomainObjectList) Task(org.gradle.api.Task) PublishingExtension(org.gradle.api.publish.PublishingExtension) PublishingPlugin(org.gradle.api.publish.plugins.PublishingPlugin) IvyPublicationIdentity(org.gradle.api.publish.ivy.internal.publisher.IvyPublicationIdentity) TaskProvider(org.gradle.api.tasks.TaskProvider) ExtensionContainer(org.gradle.api.plugins.ExtensionContainer) IvyArtifact(org.gradle.api.publish.ivy.IvyArtifact) Project(org.gradle.api.Project) Set(java.util.Set) NamedDomainObjectSet(org.gradle.api.NamedDomainObjectSet) GenerateIvyDescriptor(org.gradle.api.publish.ivy.tasks.GenerateIvyDescriptor) IvyPublication(org.gradle.api.publish.ivy.IvyPublication) List(java.util.List) Spec(org.gradle.api.specs.Spec) TaskContainer(org.gradle.api.tasks.TaskContainer) AndSpec(org.gradle.api.specs.AndSpec) IvyRepositoryDescriptor(org.gradle.api.internal.artifacts.repositories.descriptor.IvyRepositoryDescriptor) NotationParser(org.gradle.internal.typeconversion.NotationParser) PublishToIvyRepository(org.gradle.api.publish.ivy.tasks.PublishToIvyRepository) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DefaultIvyPublicationIdentity(org.gradle.api.publish.ivy.internal.publication.DefaultIvyPublicationIdentity) Logger(org.gradle.api.logging.Logger) Module(org.gradle.api.internal.artifacts.Module) SourceSet(org.gradle.api.tasks.SourceSet) Inject(javax.inject.Inject) DefaultVersionMappingStrategy(org.gradle.api.publish.ivy.internal.versionmapping.DefaultVersionMappingStrategy) DirectoryProperty(org.gradle.api.file.DirectoryProperty) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer) DefaultIvyPublication(org.gradle.api.publish.ivy.internal.publication.DefaultIvyPublication) StringUtils.capitalize(org.apache.commons.lang.StringUtils.capitalize) Usage(org.gradle.api.attributes.Usage) TaskInternal(org.gradle.api.internal.TaskInternal) JavaPlatformPlugin(org.gradle.api.plugins.JavaPlatformPlugin) Cast(org.gradle.internal.Cast) RepositoryDescriptor(org.gradle.api.internal.artifacts.repositories.descriptor.RepositoryDescriptor) Instantiator(org.gradle.internal.reflect.Instantiator) IvyPublicationInternal(org.gradle.api.publish.ivy.internal.publication.IvyPublicationInternal) FileResolver(org.gradle.api.internal.file.FileResolver) ObjectFactory(org.gradle.api.model.ObjectFactory) Logging(org.gradle.api.logging.Logging) DefaultIvyArtifactRepository(org.gradle.api.internal.artifacts.repositories.DefaultIvyArtifactRepository) DependencyMetaDataProvider(org.gradle.api.internal.artifacts.configurations.DependencyMetaDataProvider) Plugin(org.gradle.api.Plugin) IvyArtifactRepository(org.gradle.api.artifacts.repositories.IvyArtifactRepository) IvyPublicationInternal(org.gradle.api.publish.ivy.internal.publication.IvyPublicationInternal) TaskContainer(org.gradle.api.tasks.TaskContainer) DefaultIvyArtifactRepository(org.gradle.api.internal.artifacts.repositories.DefaultIvyArtifactRepository) IvyArtifactRepository(org.gradle.api.artifacts.repositories.IvyArtifactRepository)

Example 2 with NamedDomainObjectList

use of org.gradle.api.NamedDomainObjectList in project gradle by gradle.

the class IvyPublishPlugin method disableGradleMetadataGenerationIfCustomLayout.

private void disableGradleMetadataGenerationIfCustomLayout(NamedDomainObjectList<IvyArtifactRepository> repositories, GenerateModuleMetadata generateTask) {
    AtomicBoolean didWarn = new AtomicBoolean();
    Spec<? super Task> checkStandardLayout = task -> {
        boolean standard = repositories.stream().allMatch(this::hasStandardPattern);
        if (!standard && !didWarn.getAndSet(true)) {
            LOGGER.warn("Publication of Gradle Module Metadata is disabled because you have configured an Ivy repository with a non-standard layout");
        }
        return standard;
    };
    Spec<TaskInternal> spec = new AndSpec<TaskInternal>(generateTask.getOnlyIf(), checkStandardLayout);
    generateTask.setOnlyIf(Cast.<Spec<? super Task>>uncheckedCast(spec));
}
Also used : NamedDomainObjectFactory(org.gradle.api.NamedDomainObjectFactory) VersionMappingStrategyInternal(org.gradle.api.publish.internal.versionmapping.VersionMappingStrategyInternal) Path(org.gradle.model.Path) PluginManager(org.gradle.api.plugins.PluginManager) IvyArtifactNotationParserFactory(org.gradle.api.publish.ivy.internal.artifact.IvyArtifactNotationParserFactory) GenerateModuleMetadata(org.gradle.api.publish.tasks.GenerateModuleMetadata) NamedDomainObjectList(org.gradle.api.NamedDomainObjectList) Task(org.gradle.api.Task) PublishingExtension(org.gradle.api.publish.PublishingExtension) PublishingPlugin(org.gradle.api.publish.plugins.PublishingPlugin) IvyPublicationIdentity(org.gradle.api.publish.ivy.internal.publisher.IvyPublicationIdentity) TaskProvider(org.gradle.api.tasks.TaskProvider) ExtensionContainer(org.gradle.api.plugins.ExtensionContainer) IvyArtifact(org.gradle.api.publish.ivy.IvyArtifact) Project(org.gradle.api.Project) Set(java.util.Set) NamedDomainObjectSet(org.gradle.api.NamedDomainObjectSet) GenerateIvyDescriptor(org.gradle.api.publish.ivy.tasks.GenerateIvyDescriptor) IvyPublication(org.gradle.api.publish.ivy.IvyPublication) List(java.util.List) Spec(org.gradle.api.specs.Spec) TaskContainer(org.gradle.api.tasks.TaskContainer) AndSpec(org.gradle.api.specs.AndSpec) IvyRepositoryDescriptor(org.gradle.api.internal.artifacts.repositories.descriptor.IvyRepositoryDescriptor) NotationParser(org.gradle.internal.typeconversion.NotationParser) PublishToIvyRepository(org.gradle.api.publish.ivy.tasks.PublishToIvyRepository) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DefaultIvyPublicationIdentity(org.gradle.api.publish.ivy.internal.publication.DefaultIvyPublicationIdentity) Logger(org.gradle.api.logging.Logger) Module(org.gradle.api.internal.artifacts.Module) SourceSet(org.gradle.api.tasks.SourceSet) Inject(javax.inject.Inject) DefaultVersionMappingStrategy(org.gradle.api.publish.ivy.internal.versionmapping.DefaultVersionMappingStrategy) DirectoryProperty(org.gradle.api.file.DirectoryProperty) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer) DefaultIvyPublication(org.gradle.api.publish.ivy.internal.publication.DefaultIvyPublication) StringUtils.capitalize(org.apache.commons.lang.StringUtils.capitalize) Usage(org.gradle.api.attributes.Usage) TaskInternal(org.gradle.api.internal.TaskInternal) JavaPlatformPlugin(org.gradle.api.plugins.JavaPlatformPlugin) Cast(org.gradle.internal.Cast) RepositoryDescriptor(org.gradle.api.internal.artifacts.repositories.descriptor.RepositoryDescriptor) Instantiator(org.gradle.internal.reflect.Instantiator) IvyPublicationInternal(org.gradle.api.publish.ivy.internal.publication.IvyPublicationInternal) FileResolver(org.gradle.api.internal.file.FileResolver) ObjectFactory(org.gradle.api.model.ObjectFactory) Logging(org.gradle.api.logging.Logging) DefaultIvyArtifactRepository(org.gradle.api.internal.artifacts.repositories.DefaultIvyArtifactRepository) DependencyMetaDataProvider(org.gradle.api.internal.artifacts.configurations.DependencyMetaDataProvider) Plugin(org.gradle.api.Plugin) IvyArtifactRepository(org.gradle.api.artifacts.repositories.IvyArtifactRepository) AndSpec(org.gradle.api.specs.AndSpec) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TaskInternal(org.gradle.api.internal.TaskInternal)

Example 3 with NamedDomainObjectList

use of org.gradle.api.NamedDomainObjectList in project gradle by gradle.

the class MavenPublishPlugin method realizePublishingTasksLater.

private void realizePublishingTasksLater(final Project project, final PublishingExtension extension) {
    final NamedDomainObjectSet<MavenPublicationInternal> mavenPublications = extension.getPublications().withType(MavenPublicationInternal.class);
    final TaskContainer tasks = project.getTasks();
    final DirectoryProperty buildDirectory = project.getLayout().getBuildDirectory();
    final TaskProvider<Task> publishLifecycleTask = tasks.named(PublishingPlugin.PUBLISH_LIFECYCLE_TASK_NAME);
    final TaskProvider<Task> publishLocalLifecycleTask = tasks.named(PUBLISH_LOCAL_LIFECYCLE_TASK_NAME);
    final NamedDomainObjectList<MavenArtifactRepository> repositories = extension.getRepositories().withType(MavenArtifactRepository.class);
    repositories.all(repository -> tasks.register(publishAllToSingleRepoTaskName(repository), publish -> {
        publish.setDescription("Publishes all Maven publications produced by this project to the " + repository.getName() + " repository.");
        publish.setGroup(PublishingPlugin.PUBLISH_TASK_GROUP);
    }));
    mavenPublications.all(publication -> {
        createGenerateMetadataTask(tasks, publication, mavenPublications, buildDirectory);
        createGeneratePomTask(tasks, publication, buildDirectory, project);
        createLocalInstallTask(tasks, publishLocalLifecycleTask, publication);
        createPublishTasksForEachMavenRepo(tasks, publishLifecycleTask, publication, repositories);
    });
}
Also used : NamedDomainObjectFactory(org.gradle.api.NamedDomainObjectFactory) VersionMappingStrategyInternal(org.gradle.api.publish.internal.versionmapping.VersionMappingStrategyInternal) MavenArtifactNotationParserFactory(org.gradle.api.publish.maven.internal.artifact.MavenArtifactNotationParserFactory) PluginManager(org.gradle.api.plugins.PluginManager) GenerateModuleMetadata(org.gradle.api.publish.tasks.GenerateModuleMetadata) NamedDomainObjectList(org.gradle.api.NamedDomainObjectList) MavenPublication(org.gradle.api.publish.maven.MavenPublication) PublishToMavenLocal(org.gradle.api.publish.maven.tasks.PublishToMavenLocal) PublishToMavenRepository(org.gradle.api.publish.maven.tasks.PublishToMavenRepository) Module(org.gradle.api.internal.artifacts.Module) SourceSet(org.gradle.api.tasks.SourceSet) Inject(javax.inject.Inject) Task(org.gradle.api.Task) WritableMavenProjectIdentity(org.gradle.api.publish.maven.internal.publication.WritableMavenProjectIdentity) PublishingExtension(org.gradle.api.publish.PublishingExtension) PublishingPlugin(org.gradle.api.publish.plugins.PublishingPlugin) TaskProvider(org.gradle.api.tasks.TaskProvider) DirectoryProperty(org.gradle.api.file.DirectoryProperty) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer) ExtensionContainer(org.gradle.api.plugins.ExtensionContainer) DefaultVersionMappingStrategy(org.gradle.api.publish.internal.versionmapping.DefaultVersionMappingStrategy) StringUtils.capitalize(org.apache.commons.lang.StringUtils.capitalize) Usage(org.gradle.api.attributes.Usage) ImmutableAttributesFactory(org.gradle.api.internal.attributes.ImmutableAttributesFactory) MavenArtifact(org.gradle.api.publish.maven.MavenArtifact) JavaPlatformPlugin(org.gradle.api.plugins.JavaPlatformPlugin) Project(org.gradle.api.Project) MavenArtifactRepository(org.gradle.api.artifacts.repositories.MavenArtifactRepository) InstantiatorFactory(org.gradle.internal.instantiation.InstantiatorFactory) Set(java.util.Set) NamedDomainObjectSet(org.gradle.api.NamedDomainObjectSet) DefaultMavenPublication(org.gradle.api.publish.maven.internal.publication.DefaultMavenPublication) MutableMavenProjectIdentity(org.gradle.api.publish.maven.internal.publisher.MutableMavenProjectIdentity) Instantiator(org.gradle.internal.reflect.Instantiator) ProviderFactory(org.gradle.api.provider.ProviderFactory) GenerateMavenPom(org.gradle.api.publish.maven.tasks.GenerateMavenPom) FileResolver(org.gradle.api.internal.file.FileResolver) ObjectFactory(org.gradle.api.model.ObjectFactory) TaskContainer(org.gradle.api.tasks.TaskContainer) DependencyMetaDataProvider(org.gradle.api.internal.artifacts.configurations.DependencyMetaDataProvider) Plugin(org.gradle.api.Plugin) MavenPublicationInternal(org.gradle.api.publish.maven.internal.publication.MavenPublicationInternal) NotationParser(org.gradle.internal.typeconversion.NotationParser) Task(org.gradle.api.Task) TaskContainer(org.gradle.api.tasks.TaskContainer) DirectoryProperty(org.gradle.api.file.DirectoryProperty) MavenArtifactRepository(org.gradle.api.artifacts.repositories.MavenArtifactRepository) MavenPublicationInternal(org.gradle.api.publish.maven.internal.publication.MavenPublicationInternal)

Aggregations

Set (java.util.Set)3 Inject (javax.inject.Inject)3 StringUtils.capitalize (org.apache.commons.lang.StringUtils.capitalize)3 NamedDomainObjectFactory (org.gradle.api.NamedDomainObjectFactory)3 NamedDomainObjectList (org.gradle.api.NamedDomainObjectList)3 NamedDomainObjectSet (org.gradle.api.NamedDomainObjectSet)3 Plugin (org.gradle.api.Plugin)3 Project (org.gradle.api.Project)3 Task (org.gradle.api.Task)3 Usage (org.gradle.api.attributes.Usage)3 DirectoryProperty (org.gradle.api.file.DirectoryProperty)3 Module (org.gradle.api.internal.artifacts.Module)3 DependencyMetaDataProvider (org.gradle.api.internal.artifacts.configurations.DependencyMetaDataProvider)3 FileResolver (org.gradle.api.internal.file.FileResolver)3 ObjectFactory (org.gradle.api.model.ObjectFactory)3 ExtensionContainer (org.gradle.api.plugins.ExtensionContainer)3 JavaPlatformPlugin (org.gradle.api.plugins.JavaPlatformPlugin)3 PluginManager (org.gradle.api.plugins.PluginManager)3 PublishingExtension (org.gradle.api.publish.PublishingExtension)3 VersionMappingStrategyInternal (org.gradle.api.publish.internal.versionmapping.VersionMappingStrategyInternal)3