Search in sources :

Example 1 with IvyPublicationInternal

use of org.gradle.api.publish.ivy.internal.publication.IvyPublicationInternal in project gradle by gradle.

the class IvyPluginPublishingRules method createIvyMarkerPublication.

private void createIvyMarkerPublication(PluginDeclaration declaration, final IvyPublication mainPublication, PublicationContainer publications) {
    String pluginId = declaration.getId();
    IvyPublicationInternal publication = (IvyPublicationInternal) publications.create(declaration.getName() + "PluginMarkerIvy", IvyPublication.class);
    publication.setAlias(true);
    publication.setOrganisation(pluginId);
    publication.setModule(pluginId + PLUGIN_MARKER_SUFFIX);
    publication.descriptor(new Action<IvyModuleDescriptorSpec>() {

        @Override
        public void execute(IvyModuleDescriptorSpec descriptor) {
            descriptor.withXml(new Action<XmlProvider>() {

                @Override
                public void execute(XmlProvider xmlProvider) {
                    Element root = xmlProvider.asElement();
                    Document document = root.getOwnerDocument();
                    Node dependencies = root.getElementsByTagName("dependencies").item(0);
                    Node dependency = dependencies.appendChild(document.createElement("dependency"));
                    Attr org = document.createAttribute("org");
                    org.setValue(mainPublication.getOrganisation());
                    dependency.getAttributes().setNamedItem(org);
                    Attr name = document.createAttribute("name");
                    name.setValue(mainPublication.getModule());
                    dependency.getAttributes().setNamedItem(name);
                    Attr rev = document.createAttribute("rev");
                    rev.setValue(mainPublication.getRevision());
                    dependency.getAttributes().setNamedItem(rev);
                }
            });
        }
    });
}
Also used : IvyPublicationInternal(org.gradle.api.publish.ivy.internal.publication.IvyPublicationInternal) Action(org.gradle.api.Action) XmlProvider(org.gradle.api.XmlProvider) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) IvyModuleDescriptorSpec(org.gradle.api.publish.ivy.IvyModuleDescriptorSpec) Document(org.w3c.dom.Document) Attr(org.w3c.dom.Attr) IvyPublication(org.gradle.api.publish.ivy.IvyPublication)

Example 2 with IvyPublicationInternal

use of org.gradle.api.publish.ivy.internal.publication.IvyPublicationInternal in project build-info by JFrogDev.

the class TaskHelperPublications method getArtifactDeployDetails.

public Set<GradleDeployDetails> getArtifactDeployDetails() {
    Set<GradleDeployDetails> deployDetails = Sets.newLinkedHashSet();
    if (!hasPublications()) {
        log.info("No publications to publish for project '{}'.", getProject().getPath());
        return deployDetails;
    }
    for (IvyPublication ivyPublication : ivyPublications) {
        String publicationName = ivyPublication.getName();
        if (!(ivyPublication instanceof IvyPublicationInternal)) {
            // TODO: Check how the descriptor file can be extracted without using asNormalisedPublication
            log.warn("Ivy publication name '{}' is of unsupported type '{}'!", publicationName, ivyPublication.getClass());
            continue;
        }
        IvyPublicationInternal ivyPublicationInternal = (IvyPublicationInternal) ivyPublication;
        IvyNormalizedPublication ivyNormalizedPublication = ivyPublicationInternal.asNormalisedPublication();
        IvyPublicationIdentity projectIdentity = ivyNormalizedPublication.getProjectIdentity();
        Map<QName, String> extraInfo = ivyPublication.getDescriptor().getExtraInfo().asMap();
        // First adding the Ivy descriptor (if the build is configured to add it):
        if (isPublishIvy()) {
            File file = getIvyDescriptorFile(ivyNormalizedPublication);
            DeployDetails.Builder builder = createBuilder(file, publicationName);
            if (builder != null) {
                PublishArtifactInfo artifactInfo = new PublishArtifactInfo(projectIdentity.getModule(), "xml", "ivy", null, extraInfo, file);
                addIvyArtifactToDeployDetails(deployDetails, publicationName, projectIdentity, builder, artifactInfo);
            }
        }
        IvyArtifactSet artifacts = ivyPublication.getArtifacts();
        for (IvyArtifact artifact : artifacts) {
            File file = artifact.getFile();
            DeployDetails.Builder builder = createBuilder(file, publicationName);
            if (builder == null)
                continue;
            PublishArtifactInfo artifactInfo = new PublishArtifactInfo(artifact.getName(), artifact.getExtension(), artifact.getType(), artifact.getClassifier(), extraInfo, file);
            addIvyArtifactToDeployDetails(deployDetails, publicationName, projectIdentity, builder, artifactInfo);
        }
    }
    for (MavenPublication mavenPublication : mavenPublications) {
        String publicationName = mavenPublication.getName();
        if (!(mavenPublication instanceof MavenPublicationInternal)) {
            // TODO: Check how the descriptor file can be extracted without using asNormalisedPublication
            log.warn("Maven publication name '{}' is of unsupported type '{}'!", publicationName, mavenPublication.getClass());
            continue;
        }
        MavenPublicationInternal mavenPublicationInternal = (MavenPublicationInternal) mavenPublication;
        MavenNormalizedPublication mavenNormalizedPublication = mavenPublicationInternal.asNormalisedPublication();
        MavenProjectIdentity projectIdentity = mavenNormalizedPublication.getProjectIdentity();
        // First adding the Maven descriptor (if the build is configured to add it):
        if (isPublishMaven()) {
            File file = mavenNormalizedPublication.getPomFile();
            DeployDetails.Builder builder = createBuilder(file, publicationName);
            if (builder != null) {
                PublishArtifactInfo artifactInfo = new PublishArtifactInfo(projectIdentity.getArtifactId(), "pom", "pom", null, file);
                addMavenArtifactToDeployDetails(deployDetails, publicationName, projectIdentity, builder, artifactInfo);
            }
        }
        MavenArtifactSet artifacts = mavenPublication.getArtifacts();
        for (MavenArtifact artifact : artifacts) {
            File file = artifact.getFile();
            DeployDetails.Builder builder = createBuilder(file, publicationName);
            if (builder == null)
                continue;
            PublishArtifactInfo artifactInfo = new PublishArtifactInfo(projectIdentity.getArtifactId(), artifact.getExtension(), artifact.getExtension(), artifact.getClassifier(), file);
            addMavenArtifactToDeployDetails(deployDetails, publicationName, projectIdentity, builder, artifactInfo);
        }
    }
    return deployDetails;
}
Also used : DeployDetails(org.jfrog.build.client.DeployDetails) GradleDeployDetails(org.jfrog.gradle.plugin.artifactory.extractor.GradleDeployDetails) PublishArtifactInfo(org.jfrog.gradle.plugin.artifactory.extractor.PublishArtifactInfo) QName(javax.xml.namespace.QName) MavenPublication(org.gradle.api.publish.maven.MavenPublication) MavenPublicationInternal(org.gradle.api.publish.maven.internal.publication.MavenPublicationInternal) MavenProjectIdentity(org.gradle.api.publish.maven.internal.publisher.MavenProjectIdentity) IvyPublicationIdentity(org.gradle.api.publish.ivy.internal.publisher.IvyPublicationIdentity) MavenNormalizedPublication(org.gradle.api.publish.maven.internal.publisher.MavenNormalizedPublication) IvyArtifactSet(org.gradle.api.publish.ivy.IvyArtifactSet) GradleDeployDetails(org.jfrog.gradle.plugin.artifactory.extractor.GradleDeployDetails) IvyNormalizedPublication(org.gradle.api.publish.ivy.internal.publisher.IvyNormalizedPublication) IvyPublicationInternal(org.gradle.api.publish.ivy.internal.publication.IvyPublicationInternal) MavenArtifactSet(org.gradle.api.publish.maven.MavenArtifactSet) IvyArtifact(org.gradle.api.publish.ivy.IvyArtifact) File(java.io.File) MavenArtifact(org.gradle.api.publish.maven.MavenArtifact) IvyPublication(org.gradle.api.publish.ivy.IvyPublication)

Example 3 with IvyPublicationInternal

use of org.gradle.api.publish.ivy.internal.publication.IvyPublicationInternal in project build-info by JFrogDev.

the class TaskHelperPublications method checkDependsOnArtifactsToPublish.

public void checkDependsOnArtifactsToPublish() {
    // If no publications in the list
    if (!hasPublications()) {
        // If some were declared => Warning
        if (publishPublicationsSpecified) {
            log.warn("None of the specified publications matched for project '{}' - nothing to publish.", getProject().getPath());
        } else {
            log.debug("No publications specified for project '{}'", getProject().getPath());
        }
        return;
    }
    for (IvyPublication ivyPublication : ivyPublications) {
        if (!(ivyPublication instanceof IvyPublicationInternal)) {
            // TODO: Check how the output files can be extracted without using getPublishableFiles
            log.warn("Ivy publication name '{}' is of unsupported type '{}'!", ivyPublication.getName(), ivyPublication.getClass());
            continue;
        }
        dependsOn(((IvyPublicationInternal) ivyPublication).getPublishableFiles());
        String capitalizedPublicationName = ivyPublication.getName().substring(0, 1).toUpperCase() + ivyPublication.getName().substring(1);
        dependsOn(String.format("%s:generateDescriptorFileFor%sPublication", getProject().getPath(), capitalizedPublicationName));
    }
    for (MavenPublication mavenPublication : mavenPublications) {
        if (!(mavenPublication instanceof MavenPublicationInternal)) {
            // TODO: Check how the output files can be extracted without using getPublishableFiles
            log.warn("Maven publication name '{}' is of unsupported type '{}'!", mavenPublication.getName(), mavenPublication.getClass());
            continue;
        }
        dependsOn(((MavenPublicationInternal) mavenPublication).getPublishableFiles());
        String capitalizedPublicationName = mavenPublication.getName().substring(0, 1).toUpperCase() + mavenPublication.getName().substring(1);
        dependsOn(String.format("%s:generatePomFileFor%sPublication", getProject().getPath(), capitalizedPublicationName));
    }
}
Also used : IvyPublicationInternal(org.gradle.api.publish.ivy.internal.publication.IvyPublicationInternal) MavenPublication(org.gradle.api.publish.maven.MavenPublication) MavenPublicationInternal(org.gradle.api.publish.maven.internal.publication.MavenPublicationInternal) IvyPublication(org.gradle.api.publish.ivy.IvyPublication)

Example 4 with IvyPublicationInternal

use of org.gradle.api.publish.ivy.internal.publication.IvyPublicationInternal 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 5 with IvyPublicationInternal

use of org.gradle.api.publish.ivy.internal.publication.IvyPublicationInternal in project gradle by gradle.

the class IvyPluginPublishingPlugin method createIvyMarkerPublication.

private void createIvyMarkerPublication(final PluginDeclaration declaration, final IvyPublication mainPublication, PublicationContainer publications) {
    String pluginId = declaration.getId();
    IvyPublicationInternal publication = (IvyPublicationInternal) publications.create(declaration.getName() + "PluginMarkerIvy", IvyPublication.class);
    publication.setAlias(true);
    publication.setOrganisation(pluginId);
    publication.setModule(pluginId + PLUGIN_MARKER_SUFFIX);
    publication.descriptor(new Action<IvyModuleDescriptorSpec>() {

        @Override
        public void execute(IvyModuleDescriptorSpec descriptor) {
            descriptor.description(new Action<IvyModuleDescriptorDescription>() {

                @Override
                public void execute(IvyModuleDescriptorDescription description) {
                    description.getText().set(declaration.getDescription());
                }
            });
            descriptor.withXml(new Action<XmlProvider>() {

                @Override
                public void execute(XmlProvider xmlProvider) {
                    Element root = xmlProvider.asElement();
                    Document document = root.getOwnerDocument();
                    Node dependencies = root.getElementsByTagName("dependencies").item(0);
                    Node dependency = dependencies.appendChild(document.createElement("dependency"));
                    Attr org = document.createAttribute("org");
                    org.setValue(mainPublication.getOrganisation());
                    dependency.getAttributes().setNamedItem(org);
                    Attr name = document.createAttribute("name");
                    name.setValue(mainPublication.getModule());
                    dependency.getAttributes().setNamedItem(name);
                    Attr rev = document.createAttribute("rev");
                    rev.setValue(mainPublication.getRevision());
                    dependency.getAttributes().setNamedItem(rev);
                }
            });
        }
    });
}
Also used : Action(org.gradle.api.Action) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) IvyModuleDescriptorSpec(org.gradle.api.publish.ivy.IvyModuleDescriptorSpec) Document(org.w3c.dom.Document) Attr(org.w3c.dom.Attr) IvyPublicationInternal(org.gradle.api.publish.ivy.internal.publication.IvyPublicationInternal) XmlProvider(org.gradle.api.XmlProvider) IvyModuleDescriptorDescription(org.gradle.api.publish.ivy.IvyModuleDescriptorDescription) IvyPublication(org.gradle.api.publish.ivy.IvyPublication)

Aggregations

IvyPublicationInternal (org.gradle.api.publish.ivy.internal.publication.IvyPublicationInternal)6 IvyPublication (org.gradle.api.publish.ivy.IvyPublication)5 Action (org.gradle.api.Action)2 XmlProvider (org.gradle.api.XmlProvider)2 IvyArtifactRepository (org.gradle.api.artifacts.repositories.IvyArtifactRepository)2 IvyArtifact (org.gradle.api.publish.ivy.IvyArtifact)2 IvyModuleDescriptorSpec (org.gradle.api.publish.ivy.IvyModuleDescriptorSpec)2 IvyPublicationIdentity (org.gradle.api.publish.ivy.internal.publisher.IvyPublicationIdentity)2 MavenPublication (org.gradle.api.publish.maven.MavenPublication)2 MavenPublicationInternal (org.gradle.api.publish.maven.internal.publication.MavenPublicationInternal)2 Attr (org.w3c.dom.Attr)2 Document (org.w3c.dom.Document)2 Element (org.w3c.dom.Element)2 Node (org.w3c.dom.Node)2 File (java.io.File)1 List (java.util.List)1 Set (java.util.Set)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Inject (javax.inject.Inject)1 QName (javax.xml.namespace.QName)1