Search in sources :

Example 1 with IvyModuleDescriptorDescription

use of org.gradle.api.publish.ivy.IvyModuleDescriptorDescription 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

Action (org.gradle.api.Action)1 XmlProvider (org.gradle.api.XmlProvider)1 IvyModuleDescriptorDescription (org.gradle.api.publish.ivy.IvyModuleDescriptorDescription)1 IvyModuleDescriptorSpec (org.gradle.api.publish.ivy.IvyModuleDescriptorSpec)1 IvyPublication (org.gradle.api.publish.ivy.IvyPublication)1 IvyPublicationInternal (org.gradle.api.publish.ivy.internal.publication.IvyPublicationInternal)1 Attr (org.w3c.dom.Attr)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1