Skip to content

Commit

Permalink
[SHRINKDESC-167] Add modified feature-pack.xsd and generate from it, …
Browse files Browse the repository at this point in the history
…plus a test.
  • Loading branch information
bobmcwhirter authored and ALRubinger committed Mar 11, 2016
1 parent 0910fb0 commit 08fad02
Show file tree
Hide file tree
Showing 5 changed files with 264 additions and 0 deletions.
39 changes: 39 additions & 0 deletions gen/pom.xml
Expand Up @@ -1993,6 +1993,45 @@
<goal>parse</goal>
</goals>
</execution>
<execution>
<id>executionWildFlyFeaturePack11</id>
<phase>validate</phase>
<configuration>
<verbose>false</verbose>
<javadocs>
<javadoc>
<tag>@author</tag>
<value>&lt;a href="mailto:bmcwhirt@redhat.com"&gt;Bob McWhirter&lt;/a&gt;</value>
</javadoc>
<javadoc>
<tag>@author</tag>
<value>&lt;a href="mailto:alr@jboss.org"&gt;Andrew Lee Rubinger&lt;/a&gt;</value>
</javadoc>
</javadocs>
<path>
<pathToApi>${basedir}/../api-jboss/src/main/java</pathToApi>
<pathToImpl>${basedir}/../impl-jboss/src/main/java</pathToImpl>
</path>
<descriptors>
<descriptor>
<pathToXsd>${basedir}/src/main/resources/xsd/wildfly-feature-pack-1_1.xsd</pathToXsd>
<nameSpace>wildfly</nameSpace>
<packageApi>org.jboss.shrinkwrap.descriptor.api.wildflyfeaturepack11</packageApi>
<packageImpl>org.jboss.shrinkwrap.descriptor.impl.wildflyfeaturepack11</packageImpl>
<descriptorName>WildFlyFeaturePackDescriptor</descriptorName>
<elementName>feature-pack</elementName>
<elementType>wildfly:feature-pack-type</elementType>
<namespaces>
<property><name>xmlns</name><value>urn:wildfly:feature-pack:1.1</value></property>
</namespaces>
<generateCommonClasses>false</generateCommonClasses>
</descriptor>
</descriptors>
</configuration>
<goals>
<goal>parse</goal>
</goals>
</execution>

<execution>
<id>executionMisc</id>
Expand Down
109 changes: 109 additions & 0 deletions gen/src/main/resources/xsd/wildfly-feature-pack-1_1.xsd
@@ -0,0 +1,109 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
~ Copyright 2014 Red Hat, Inc.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="urn:wildfly:feature-pack:1.1"
targetNamespace="urn:wildfly:feature-pack:1.1"
elementFormDefault="qualified"
attributeFormDefault="unqualified">

<xs:element name="feature-pack" type="feature-pack-type">
</xs:element>

<xs:complexType name="feature-pack-type">
<xs:sequence>
<xs:element name="dependencies" type="dependencies-type" minOccurs="0" maxOccurs="1" />
<xs:element name="artifact-versions" type="artifact-versions-type" minOccurs="0" maxOccurs="1" />
<xs:element name="config" type="config-type" minOccurs="0" maxOccurs="1" />
<xs:element name="copy-artifacts" type="copy-artifacts-type" minOccurs="0" maxOccurs="1"/>
<xs:element name="file-permissions" type="file-permissions-type" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="dependencies-type">
<xs:sequence>
<xs:element name="artifact" type="named-type" maxOccurs="unbounded" minOccurs="0" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="named-type">
<xs:attribute name="name" type="xs:string"/>
</xs:complexType>

<xs:complexType name="artifact-versions-type">
<xs:sequence>
<xs:element name="artifact" type="artifact-type" maxOccurs="unbounded" minOccurs="0" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="artifact-type">
<xs:attribute name="groupId" use="required" type="xs:string"/>
<xs:attribute name="artifactId" use="required" type="xs:string"/>
<xs:attribute name="classifier" type="xs:string"/>
<xs:attribute name="extension" type="xs:string"/>
<xs:attribute name="version" use="required" type="xs:string"/>
</xs:complexType>

<xs:complexType name="config-type">
<xs:sequence>
<xs:element name="standalone" type="config-file-type" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="domain" type="config-file-type" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="host" type="config-file-type" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="config-file-type">
<xs:sequence>
<xs:element name="property" type="property-type" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="template" use="required" type="xs:string"/>
<xs:attribute name="subsystems" use="required" type="xs:string"/>
<xs:attribute name="output-file" use="required" type="xs:string" />
</xs:complexType>
<xs:complexType name="property-type">
<xs:attribute name="name" use="required" type="xs:string"/>
<xs:attribute name="value" use="required" type="xs:string"/>
</xs:complexType>

<xs:complexType name="copy-artifacts-type">
<xs:sequence>
<xs:element name="copy-artifact" type="copy-artifact-type" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="copy-artifact-type">
<xs:sequence>
<xs:element name="filter" type="filter-type" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute name="artifact" type="xs:string"/>
<xs:attribute name="to-location" type="xs:string"/>
<xs:attribute name="extract" use="optional" default="false" type="xs:boolean"/>
</xs:complexType>
<xs:complexType name="filter-type">
<xs:attribute name="pattern" type="xs:string" use="required" />
<xs:attribute name="include" type="xs:boolean" use="required" />
</xs:complexType>

<xs:complexType name="file-permissions-type">
<xs:sequence>
<xs:element name="permission" type="file-permission-type" maxOccurs="unbounded" minOccurs="0" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="file-permission-type">
<xs:sequence>
<xs:element name="filter" type="filter-type" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute name="value" use="required" type="xs:string"/>
</xs:complexType>

</xs:schema>
@@ -0,0 +1,3 @@
implClass=org.jboss.shrinkwrap.descriptor.impl.wildflyfeaturepack.WildFlyFeaturePackDescriptorImpl
importerClass=org.jboss.shrinkwrap.descriptor.spi.node.dom.XmlDomNodeDescriptorImporterImpl
defaultName=wildfly-feature-pack.xml
@@ -0,0 +1,83 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2009, Red Hat Middleware LLC, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.shrinkwrap.descriptor.test.wildflyfeaturepack;


import java.io.BufferedReader;
import java.io.FileReader;

import org.jboss.shrinkwrap.descriptor.api.Descriptors;
import org.jboss.shrinkwrap.descriptor.api.wildflyfeaturepack11.WildFlyFeaturePackDescriptor;
import org.jboss.shrinkwrap.descriptor.test.util.XmlAssert;
import org.junit.Test;

/**
* Test Case to verify that the {@link WildFlyFeaturePackDescriptor}
* impl produces the correct XML Descriptor output.
*
* @author <a href="mailto:toby@tcrawley.org">Toby Crawley</a>
*/

public class WildFlyFeaturePackTestcase {

@Test
public void testNothing() throws Exception {
WildFlyFeaturePackDescriptor featurePack = Descriptors.create(WildFlyFeaturePackDescriptor.class);

featurePack.getOrCreateArtifactVersions()
.createArtifact().groupId("io.undertow").artifactId("undertow-core").version("1.3.0.CR2").up()
.createArtifact().groupId("org.codehaus.woodstox").artifactId("stax2-api").version("3.1.4").up()
.createArtifact().groupId("org.codehaus.woodstox").artifactId("woodstox-core-api").version("4.4.1").up();

featurePack.getOrCreateConfig()
.createStandalone().template("configuration/standalone/template.xml").subsystems("configuration/standalone/subsystems.xml").outputFile("standalone/configuration/standalone.xml").up()
.createDomain().template("configuration/domain/template.xml").subsystems("configuration/domain/subsystems.xml").outputFile("domain/configuration/domain.xml").up()
.createHost().template("configuration/host/host.xml").subsystems("configuration/host/subsystems.xml").outputFile("domain/configuration/host.xml").up();

featurePack.getOrCreateCopyArtifacts()
.createCopyArtifact().artifact("org.jboss.modules:jboss-modules").toLocation("jboss-modules.jar").up()
.createCopyArtifact().artifact("org.wildfly.core:wildfly-launcher").toLocation("bin/wildfly-launcher.jar").up();

featurePack.getOrCreateFilePermissions()
.createPermission().value("755").createFilter().pattern(".sh").include(true).up().up()
.createPermission().value("700").createFilter().pattern("*/tmp/auth").include(true).up().up()
.createPermission().value("600").createFilter().pattern("*-users.properties").include(true).up()
.createFilter().pattern("*/.installation").include(true);

String featurePackGenerated = featurePack.exportAsString();
String featurePackExpected = getResourceContents( "src/test/resources/test-wildfly-feature-pack11.xml");

XmlAssert.assertIdentical( featurePackExpected, featurePackGenerated );
}

// -------------------------------------------------------------------------------------||
// Internal Helper ---------------------------------------------------------------------||
// -------------------------------------------------------------------------------------||

private String getResourceContents(String resource) throws Exception {
assert resource != null && resource.length() > 0 : "Resource must be specified";
final BufferedReader reader = new BufferedReader(new FileReader(resource));
final StringBuilder builder = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
builder.append(line);
builder.append("\n");
}
return builder.toString();
}

}
30 changes: 30 additions & 0 deletions test/src/test/resources/test-wildfly-feature-pack11.xml
@@ -0,0 +1,30 @@
<?xml version="1.0" ?>

<feature-pack xmlns="urn:wildfly:feature-pack:1.1">
<artifact-versions>
<artifact groupId="io.undertow" artifactId="undertow-core" version="1.3.0.CR2"/>
<artifact groupId="org.codehaus.woodstox" artifactId="stax2-api" version="3.1.4"/>
<artifact groupId="org.codehaus.woodstox" artifactId="woodstox-core-asl" version="4.4.1"/>
</artifact-versions>
<config>
<standalone template="configuration/standalone/template.xml" subsystems="configuration/standalone/subsystems.xml" output-file="standalone/configuration/standalone.xml"/>
<domain template="configuration/domain/template.xml" subsystems="configuration/domain/subsystems.xml" output-file="domain/configuration/domain.xml"/>
<host template="configuration/host/host.xml" subsystems="configuration/host/subsystems.xml" output-file="domain/configuration/host.xml"/>
</config>
<copy-artifacts>
<copy-artifact artifact="org.jboss.modules:jboss-modules" to-location="jboss-modules.jar"/>
<copy-artifact artifact="org.wildfly.core:wildfly-launcher" to-location="bin/wildfly-launcher.jar"/>
</copy-artifacts>
<file-permissions>
<permission value="755">
<filter pattern="*.sh" include="true"/>
</permission>
<permission value="700">
<filter pattern="*/tmp/auth" include="true"/>
</permission>
<permission value="600">
<filter pattern="*-users.properties" include="true"/>
<filter pattern="*/.installation" include="true"/>
</permission>
</file-permissions>
</feature-pack>

0 comments on commit 08fad02

Please sign in to comment.