Search in sources :

Example 1 with XmlProvider

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

the class IdeaScalaConfigurer method configure.

public void configure() {
    rootProject.getGradle().addBuildListener(new BuildAdapter() {

        public void projectsEvaluated(Gradle gradle) {
            VersionNumber ideaTargetVersion = findIdeaTargetVersion();
            final boolean useScalaSdk = ideaTargetVersion == null || IDEA_VERSION_WHEN_SCALA_SDK_WAS_INTRODUCED.compareTo(ideaTargetVersion) <= 0;
            final Collection<Project> scalaProjects = findProjectsApplyingIdeaAndScalaPlugins();
            final Map<String, ProjectLibrary> scalaCompilerLibraries = Maps.newHashMap();
            rootProject.getTasks().getByName("ideaProject").doFirst(new Action<Task>() {

                @Override
                public void execute(Task task) {
                    if (scalaProjects.size() > 0) {
                        scalaCompilerLibraries.clear();
                        scalaCompilerLibraries.putAll(resolveScalaCompilerLibraries(scalaProjects, useScalaSdk));
                        declareUniqueProjectLibraries(Sets.newLinkedHashSet(scalaCompilerLibraries.values()));
                    }
                }
            });
            rootProject.configure(scalaProjects, new Action<Project>() {

                @Override
                public void execute(final Project project) {
                    project.getExtensions().getByType(IdeaModel.class).getModule().getIml().withXml(new Action<XmlProvider>() {

                        @Override
                        public void execute(XmlProvider xmlProvider) {
                            if (useScalaSdk) {
                                declareScalaSdk(scalaCompilerLibraries.get(project.getPath()), xmlProvider.asNode());
                            } else {
                                declareScalaFacet(scalaCompilerLibraries.get(project.getPath()), xmlProvider.asNode());
                            }
                        }
                    });
                }
            });
        }
    });
}
Also used : Project(org.gradle.api.Project) Action(org.gradle.api.Action) Task(org.gradle.api.Task) IdeaModel(org.gradle.plugins.ide.idea.model.IdeaModel) XmlProvider(org.gradle.api.XmlProvider) FileCollection(org.gradle.api.file.FileCollection) Collection(java.util.Collection) BuildAdapter(org.gradle.BuildAdapter) Gradle(org.gradle.api.invocation.Gradle) Map(java.util.Map) VersionNumber(org.gradle.util.VersionNumber)

Example 2 with XmlProvider

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

the class DefaultDeploymentDescriptor method readFrom.

@Override
public DeploymentDescriptor readFrom(Reader reader) {
    try {
        Node appNode = createParser().parse(reader);
        version = (String) appNode.attribute("version");
        for (final Node child : Cast.<List<Node>>uncheckedCast(appNode.children())) {
            String childLocalName = localNameOf(child);
            if (childLocalName.equals("application-name")) {
                applicationName = child.text();
            } else if (childLocalName.equals("initialize-in-order")) {
                initializeInOrder = Boolean.valueOf(child.text());
            } else if (childLocalName.equals("description")) {
                description = child.text();
            } else if (childLocalName.equals("display-name")) {
                displayName = child.text();
            } else if (childLocalName.equals("library-directory")) {
                libraryDirectory = child.text();
            } else if (childLocalName.equals("module")) {
                EarModule module = null;
                for (Node moduleNode : Cast.<List<Node>>uncheckedCast(child.children())) {
                    String moduleNodeLocalName = localNameOf(moduleNode);
                    if (moduleNodeLocalName.equals("web")) {
                        String webUri = childNodeText(moduleNode, "web-uri");
                        String contextRoot = childNodeText(moduleNode, "context-root");
                        module = new DefaultEarWebModule(webUri, contextRoot);
                        modules.add(module);
                        moduleTypeMappings.put(module.getPath(), "web");
                    } else if (moduleNodeLocalName.equals("alt-dd")) {
                        assert module != null;
                        module.setAltDeployDescriptor(moduleNode.text());
                    } else {
                        module = new DefaultEarModule(moduleNode.text());
                        modules.add(module);
                        moduleTypeMappings.put(module.getPath(), moduleNodeLocalName);
                    }
                }
            } else if (childLocalName.equals("security-role")) {
                String roleName = childNodeText(child, "role-name");
                String description = childNodeText(child, "description");
                securityRoles.add(new DefaultEarSecurityRole(roleName, description));
            } else {
                withXml(new Action<XmlProvider>() {

                    @Override
                    public void execute(XmlProvider xmlProvider) {
                        xmlProvider.asNode().append(child);
                    }
                });
            }
        }
    } catch (IOException ex) {
        throw new UncheckedIOException(ex);
    } catch (SAXException ex) {
        throw new UncheckedException(ex);
    } finally {
        IOUtils.closeQuietly(reader);
    }
    return this;
}
Also used : DomNode(org.gradle.api.internal.DomNode) Node(groovy.util.Node) UncheckedIOException(org.gradle.api.UncheckedIOException) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) UncheckedException(org.gradle.internal.UncheckedException) XmlProvider(org.gradle.api.XmlProvider) EarModule(org.gradle.plugins.ear.descriptor.EarModule) List(java.util.List)

Example 3 with XmlProvider

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

the class IvyPluginPublishingRules method createIvyMarkerPublication.

private void createIvyMarkerPublication(PluginDeclaration declaration, final IvyPublication mainPublication, PublicationContainer publications) {
    String pluginId = declaration.getId();
    IvyPublication publication = publications.create(declaration.getName() + "PluginMarkerIvy", IvyPublication.class);
    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 : 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 4 with XmlProvider

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

the class MavenPluginPublishingRules method createMavenMarkerPublication.

private void createMavenMarkerPublication(PluginDeclaration declaration, final MavenPublication coordinates, PublicationContainer publications) {
    String pluginId = declaration.getId();
    MavenPublication publication = publications.create(declaration.getName() + "PluginMarkerMaven", MavenPublication.class);
    publication.setArtifactId(pluginId + PLUGIN_MARKER_SUFFIX);
    publication.setGroupId(pluginId);
    publication.getPom().withXml(new Action<XmlProvider>() {

        @Override
        public void execute(XmlProvider xmlProvider) {
            Element root = xmlProvider.asElement();
            Document document = root.getOwnerDocument();
            Node dependencies = root.appendChild(document.createElement("dependencies"));
            Node dependency = dependencies.appendChild(document.createElement("dependency"));
            Node groupId = dependency.appendChild(document.createElement("groupId"));
            groupId.setTextContent(coordinates.getGroupId());
            Node artifactId = dependency.appendChild(document.createElement("artifactId"));
            artifactId.setTextContent(coordinates.getArtifactId());
            Node version = dependency.appendChild(document.createElement("version"));
            version.setTextContent(coordinates.getVersion());
        }
    });
}
Also used : XmlProvider(org.gradle.api.XmlProvider) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) MavenPublication(org.gradle.api.publish.maven.MavenPublication) Document(org.w3c.dom.Document)

Aggregations

XmlProvider (org.gradle.api.XmlProvider)4 Action (org.gradle.api.Action)2 Document (org.w3c.dom.Document)2 Element (org.w3c.dom.Element)2 Node (org.w3c.dom.Node)2 Node (groovy.util.Node)1 IOException (java.io.IOException)1 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 BuildAdapter (org.gradle.BuildAdapter)1 Project (org.gradle.api.Project)1 Task (org.gradle.api.Task)1 UncheckedIOException (org.gradle.api.UncheckedIOException)1 FileCollection (org.gradle.api.file.FileCollection)1 DomNode (org.gradle.api.internal.DomNode)1 Gradle (org.gradle.api.invocation.Gradle)1 IvyModuleDescriptorSpec (org.gradle.api.publish.ivy.IvyModuleDescriptorSpec)1 IvyPublication (org.gradle.api.publish.ivy.IvyPublication)1 MavenPublication (org.gradle.api.publish.maven.MavenPublication)1