Search in sources :

Example 1 with IvyModuleDescriptorSpec

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

use of org.gradle.api.publish.ivy.IvyModuleDescriptorSpec 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)2 XmlProvider (org.gradle.api.XmlProvider)2 IvyModuleDescriptorSpec (org.gradle.api.publish.ivy.IvyModuleDescriptorSpec)2 IvyPublication (org.gradle.api.publish.ivy.IvyPublication)2 IvyPublicationInternal (org.gradle.api.publish.ivy.internal.publication.IvyPublicationInternal)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 IvyModuleDescriptorDescription (org.gradle.api.publish.ivy.IvyModuleDescriptorDescription)1