Search in sources :

Example 1 with EarModule

use of org.gradle.plugins.ear.descriptor.EarModule 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 2 with EarModule

use of org.gradle.plugins.ear.descriptor.EarModule in project gradle by gradle.

the class DefaultDeploymentDescriptor method toXmlNode.

private DomNode toXmlNode() {
    DomNode root = new DomNode(nodeNameFor("application"));
    root.attributes().put("version", version);
    if (!"1.3".equals(version)) {
        root.attributes().put("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
    }
    if ("1.3".equals(version)) {
        root.setPublicId("-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN");
        root.setSystemId("http://java.sun.com/dtd/application_1_3.dtd");
    } else if ("1.4".equals(version)) {
        root.attributes().put("xsi:schemaLocation", "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd");
    } else if ("5".equals(version) || "6".equals(version)) {
        root.attributes().put("xsi:schemaLocation", "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_" + version + ".xsd");
    } else if ("7".equals(version)) {
        root.attributes().put("xsi:schemaLocation", "http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/application_" + version + ".xsd");
    }
    if (applicationName != null) {
        new Node(root, nodeNameFor("application-name"), applicationName);
    }
    if (description != null) {
        new Node(root, nodeNameFor("description"), description);
    }
    if (displayName != null) {
        new Node(root, nodeNameFor("display-name"), displayName);
    }
    if (initializeInOrder != null && initializeInOrder) {
        new Node(root, nodeNameFor("initialize-in-order"), initializeInOrder);
    }
    for (EarModule module : modules) {
        Node moduleNode = new Node(root, nodeNameFor("module"));
        module.toXmlNode(moduleNode, moduleNameFor(module));
    }
    if (securityRoles != null) {
        for (EarSecurityRole role : securityRoles) {
            Node roleNode = new Node(root, nodeNameFor("security-role"));
            if (role.getDescription() != null) {
                new Node(roleNode, nodeNameFor("description"), role.getDescription());
            }
            new Node(roleNode, nodeNameFor("role-name"), role.getRoleName());
        }
    }
    if (libraryDirectory != null) {
        new Node(root, nodeNameFor("library-directory"), libraryDirectory);
    }
    return root;
}
Also used : EarSecurityRole(org.gradle.plugins.ear.descriptor.EarSecurityRole) DomNode(org.gradle.api.internal.DomNode) DomNode(org.gradle.api.internal.DomNode) Node(groovy.util.Node) EarModule(org.gradle.plugins.ear.descriptor.EarModule)

Aggregations

Node (groovy.util.Node)2 DomNode (org.gradle.api.internal.DomNode)2 EarModule (org.gradle.plugins.ear.descriptor.EarModule)2 IOException (java.io.IOException)1 List (java.util.List)1 UncheckedIOException (org.gradle.api.UncheckedIOException)1 XmlProvider (org.gradle.api.XmlProvider)1 UncheckedException (org.gradle.internal.UncheckedException)1 EarSecurityRole (org.gradle.plugins.ear.descriptor.EarSecurityRole)1 SAXException (org.xml.sax.SAXException)1