Author: snicoll
Date: Fri Jan  2 22:30:22 2009
New Revision: 730922

URL: http://svn.apache.org/viewvc?rev=730922&view=rev
Log:
MEAR-78: when specified, the library configuration is now written properly in a 
JavaEE5 application.xml. Thanks to Markus Knittig.

Updated to XmlUnit 1.2 to allow to diff an xml properly even if the order of 
the elements are not the same. Please note that due to a bug in 2.0.9, the ITs 
won't pass. 2.0.8 must be used (see http://tinyurl.com/7au53p)

Added:
    
maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/ApplicationXmlWriterContext.java
    
maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-044/
    
maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-044/expected-META-INF/
    
maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-044/expected-META-INF/application.xml
    
maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-044/pom.xml
Modified:
    maven/plugins/trunk/maven-ear-plugin/pom.xml
    
maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarMojo.java
    
maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/ApplicationXmlWriter.java
    
maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/GenerateApplicationXmlMojo.java
    maven/plugins/trunk/maven-ear-plugin/src/site/apt/tests.apt
    
maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/it/AbstractEarPluginIT.java
    
maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/it/EarMojoIT.java
    
maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-042/expected-META-INF/jboss-app.xml
    maven/plugins/trunk/maven-ear-plugin/src/test/resources/settings.xml

Modified: maven/plugins/trunk/maven-ear-plugin/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/pom.xml?rev=730922&r1=730921&r2=730922&view=diff
==============================================================================
--- maven/plugins/trunk/maven-ear-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-ear-plugin/pom.xml Fri Jan  2 22:30:22 2009
@@ -84,7 +84,7 @@
     <dependency>
       <groupId>xmlunit</groupId>
       <artifactId>xmlunit</artifactId>
-      <version>1.0</version>
+      <version>1.2</version>
       <scope>test</scope>
     </dependency>
   </dependencies>

Modified: 
maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarMojo.java?rev=730922&r1=730921&r2=730922&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarMojo.java
 Fri Jan  2 22:30:22 2009
@@ -93,7 +93,7 @@
      *
      * @parameter alias="defaultJavaBundleDir"
      */
-    private String defaultLibBundleDir;
+    protected String defaultLibBundleDir;
 
     /**
      * The file name mapping to use for all dependencies included

Modified: 
maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/ApplicationXmlWriter.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/ApplicationXmlWriter.java?rev=730922&r1=730921&r2=730922&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/ApplicationXmlWriter.java
 (original)
+++ 
maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/ApplicationXmlWriter.java
 Fri Jan  2 22:30:22 2009
@@ -51,46 +51,50 @@
         this.version = version;
     }
 
-    public void write( File destinationFile, List earModules, List 
securityRoles, String displayName,
-                       String description )
+    public void write( ApplicationXmlWriterContext context )
         throws EarPluginException
     {
-        Writer w = initializeWriter( destinationFile );
+        Writer w = initializeWriter( context.getDestinationFile() );
 
         XMLWriter writer = null;
         if ( GenerateApplicationXmlMojo.VERSION_1_3.equals( version ) )
         {
             writer = initializeRootElementOneDotThree( w );
-            writeDisplayName( displayName, writer );
-            writeDescription( description, writer );
+            writeDisplayName( context.getDisplayName(), writer );
+            writeDescription( context.getDescription(), writer );
         }
         else if ( GenerateApplicationXmlMojo.VERSION_1_4.equals( version ) )
         {
             writer = initializeRootElementOneDotFour( w );
-            writeDescription( description, writer );
-            writeDisplayName( displayName, writer );
+            writeDescription( context.getDescription(), writer );
+            writeDisplayName( context.getDisplayName(), writer );
         }
         else if ( GenerateApplicationXmlMojo.VERSION_5.equals( version ) )
         {
             writer = initializeRootElementFive( w );
-            writeDescription( description, writer );
-            writeDisplayName( displayName, writer );
+            writeDescription( context.getDescription(), writer );
+            writeDisplayName( context.getDisplayName(), writer );
         }
 
-        final Iterator moduleIt = earModules.iterator();
+        final Iterator moduleIt = context.getEarModules().iterator();
         while ( moduleIt.hasNext() )
         {
             EarModule module = (EarModule) moduleIt.next();
             module.appendModule( writer, version );
         }
 
-        final Iterator securityRoleIt = securityRoles.iterator();
+        final Iterator securityRoleIt = context.getSecurityRoles().iterator();
         while ( securityRoleIt.hasNext() )
         {
             SecurityRole securityRole = (SecurityRole) securityRoleIt.next();
             securityRole.appendSecurityRole( writer );
         }
 
+        if ( GenerateApplicationXmlMojo.VERSION_5.equals( version ) )
+        {
+               writeLibraryDirectory ( context.getLibraryDirectory(), writer );
+        }
+
         writer.endElement();
 
         close( w );
@@ -116,6 +120,16 @@
         }
     }
 
+    private void writeLibraryDirectory( String libraryDirectory, XMLWriter 
writer )
+    {
+        if ( libraryDirectory != null )
+        {
+            writer.startElement( "library-directory" );
+            writer.writeText( libraryDirectory );
+            writer.endElement();
+        }
+    }
+
     private XMLWriter initializeRootElementOneDotThree( Writer w )
     {
         XMLWriter writer = initializeXmlWriter( w, DOCTYPE_1_3 );

Added: 
maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/ApplicationXmlWriterContext.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/ApplicationXmlWriterContext.java?rev=730922&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/ApplicationXmlWriterContext.java
 (added)
+++ 
maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/ApplicationXmlWriterContext.java
 Fri Jan  2 22:30:22 2009
@@ -0,0 +1,103 @@
+package org.apache.maven.plugin.ear;
+
+import java.io.File;
+import java.util.List;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+/**
+ * A context for the {...@link ApplicationXmlWriter}.
+ *
+ * @author <a href="snic...@apache.org">Stephane Nicoll</a>
+ * @version $Id: ApplicationXmlWriter.java 728546 2008-12-21 22:56:51Z 
bentmann $
+ */
+class ApplicationXmlWriterContext {
+
+    private final File destinationFile;
+    private final List earModules;
+    private final List securityRoles;
+    private final String displayName;
+    private final String description;
+    private final String libraryDirectory;
+
+    public ApplicationXmlWriterContext(File destinationFile, List earModules, 
List securityRoles,
+                                       String displayName, String description, 
String libraryDirectory) {
+        this.destinationFile = destinationFile;
+        this.earModules = earModules;
+        this.securityRoles = securityRoles;
+        this.displayName = displayName;
+        this.description = description;
+        this.libraryDirectory = libraryDirectory;
+    }
+
+    /**
+     * Returns the name of the file to use to write application.xml to.
+     *
+     * @return the output file
+     */
+    public File getDestinationFile() {
+        return destinationFile;
+    }
+
+    /**
+     * Returns the  list of {...@link EarModule} instances.
+     *
+     * @return the ear modules
+     */
+    public List getEarModules() {
+        return earModules;
+    }
+
+    /**
+     * Returns the list of {ÂŽlink SecurityRole} instances.
+     *
+     * @return the security roles
+     */
+    public List getSecurityRoles() {
+        return securityRoles;
+    }
+
+    /**
+     * Returns the display name.
+     *
+     * @return the display name
+     */
+    public String getDisplayName() {
+        return displayName;
+    }
+
+    /**
+     * Returns the description.
+     *
+     * @return the description
+     */
+    public String getDescription() {
+        return description;
+    }
+
+    /**
+     * Returns the library directory (as per JavaEE 5).
+     *
+     * @return the library directory
+     */
+    public String getLibraryDirectory() {
+        return libraryDirectory;
+    }
+}

Modified: 
maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/GenerateApplicationXmlMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/GenerateApplicationXmlMojo.java?rev=730922&r1=730921&r2=730922&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/GenerateApplicationXmlMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/GenerateApplicationXmlMojo.java
 Fri Jan  2 22:30:22 2009
@@ -175,8 +175,10 @@
 
         File descriptor = new File( outputDir, "application.xml" );
 
-        ApplicationXmlWriter writer = new ApplicationXmlWriter( version, 
encoding );
-        writer.write( descriptor, getModules(), buildSecurityRoles(), 
displayName, description );
+        final ApplicationXmlWriter writer = new ApplicationXmlWriter( version, 
encoding );
+        final ApplicationXmlWriterContext context = new 
ApplicationXmlWriterContext(descriptor, getModules(), 
+                buildSecurityRoles(), displayName, description, 
defaultLibBundleDir);
+        writer.write( context );
     }
 
     /**

Modified: maven/plugins/trunk/maven-ear-plugin/src/site/apt/tests.apt
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/site/apt/tests.apt?rev=730922&r1=730921&r2=730922&view=diff
==============================================================================
--- maven/plugins/trunk/maven-ear-plugin/src/site/apt/tests.apt (original)
+++ maven/plugins/trunk/maven-ear-plugin/src/site/apt/tests.apt Fri Jan  2 
22:30:22 2009
@@ -112,4 +112,9 @@
 
   * project-041: builds an EAR with a Jboss 4.2 configuration specifying the 
module order to use
 
+  * project-042: builds an EAR with a Jboss 4.2 configuration specifying a 
datasource to add
+
+  * project-043: builds an EAR with a custom descriptor location 
(generatedDescriptorLocation setting)
+
+  * project-044: builds an EAR with a custom library-directory
    
\ No newline at end of file

Modified: 
maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/it/AbstractEarPluginIT.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/it/AbstractEarPluginIT.java?rev=730922&r1=730921&r2=730922&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/it/AbstractEarPluginIT.java
 (original)
+++ 
maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/it/AbstractEarPluginIT.java
 Fri Jan  2 22:30:22 2009
@@ -24,6 +24,8 @@
 import org.apache.maven.it.VerificationException;
 import org.apache.maven.it.util.ResourceExtractor;
 import org.custommonkey.xmlunit.XMLAssert;
+import org.custommonkey.xmlunit.Diff;
+import org.custommonkey.xmlunit.examples.RecursiveElementNameAndTextQualifier;
 
 import java.io.File;
 import java.io.FileReader;
@@ -384,10 +386,14 @@
             {
                 expected = new FileReader( expectedDeploymentDescriptor );
                 actual = new FileReader( actualDeploymentDescriptor );
+
+                // Make sure that it matches even if the elements are not in
+                // the exact same order
+                final Diff myDiff = new Diff(expected, actual);
+                myDiff.overrideElementQualifier(new 
RecursiveElementNameAndTextQualifier());
                 XMLAssert.assertXMLEqual(
                     "Wrong deployment descriptor generated for[" + 
expectedDeploymentDescriptor.getName() + "]",
-                    expected, actual );
-            }
+                     myDiff, true);             }
             catch ( Exception e )
             {
                 e.printStackTrace();

Modified: 
maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/it/EarMojoIT.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/it/EarMojoIT.java?rev=730922&r1=730921&r2=730922&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/it/EarMojoIT.java
 (original)
+++ 
maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/it/EarMojoIT.java
 Fri Jan  2 22:30:22 2009
@@ -462,4 +462,13 @@
         assertFalse("Application.xml file should not be empty", 
expectedApplicationXml.length() == 0);
     }
 
+    /**
+     * Builds an EAR with a custom library-directory.
+     */
+    public void testProject044()
+        throws Exception
+    {
+        doTestProject( "project-044", new String[]{"ejb-sample-one-1.0.jar", 
"myLibs/jar-sample-one-1.0.jar"} );
+    }
+
 }

Modified: 
maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-042/expected-META-INF/jboss-app.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-042/expected-META-INF/jboss-app.xml?rev=730922&r1=730921&r2=730922&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-042/expected-META-INF/jboss-app.xml
 (original)
+++ 
maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-042/expected-META-INF/jboss-app.xml
 Fri Jan  2 22:30:22 2009
@@ -21,4 +21,8 @@
 <!DOCTYPE jboss-app PUBLIC
        "-//JBoss//DTD J2EE Application 1.4//EN"
        "http://www.jboss.org/j2ee/dtd/jboss-app_4_2.dtd";>
-<jboss-app/>
\ No newline at end of file
+<jboss-app>
+  <module>
+    <service>my-ds.xml</service>
+  </module>
+</jboss-app>
\ No newline at end of file

Added: 
maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-044/expected-META-INF/application.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-044/expected-META-INF/application.xml?rev=730922&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-044/expected-META-INF/application.xml
 (added)
+++ 
maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-044/expected-META-INF/application.xml
 Fri Jan  2 22:30:22 2009
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you 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.
+-->
+
+<application xmlns="http://java.sun.com/xml/ns/javaee"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/application_5.xsd"; version="5">
+  <display-name>maven-ear-plugin-test-project-044</display-name>
+  <module>
+    <ejb>ejb-sample-one-1.0.jar</ejb>
+  </module>
+  <library-directory>myLibs</library-directory>
+</application>
\ No newline at end of file

Added: 
maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-044/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-044/pom.xml?rev=730922&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-044/pom.xml
 (added)
+++ 
maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-044/pom.xml
 Fri Jan  2 22:30:22 2009
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you 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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>ear</groupId>
+  <artifactId>maven-ear-plugin-test-project-044</artifactId>
+  <version>99.0</version>
+  <name>Maven</name>
+  <packaging>ear</packaging>
+  <dependencies>
+    <dependency>
+      <groupId>eartest</groupId>
+      <artifactId>ejb-sample-one</artifactId>
+      <version>1.0</version>
+      <type>ejb</type>
+    </dependency>
+    <dependency>
+      <groupId>eartest</groupId>
+      <artifactId>jar-sample-one</artifactId>
+      <version>1.0</version>
+    </dependency>
+  </dependencies>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-ear-plugin</artifactId>
+        <configuration>
+          <version>5</version>
+          <defaultLibBundleDir>myLibs</defaultLibBundleDir>         
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Modified: maven/plugins/trunk/maven-ear-plugin/src/test/resources/settings.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/test/resources/settings.xml?rev=730922&r1=730921&r2=730922&view=diff
==============================================================================
--- maven/plugins/trunk/maven-ear-plugin/src/test/resources/settings.xml 
(original)
+++ maven/plugins/trunk/maven-ear-plugin/src/test/resources/settings.xml Fri 
Jan  2 22:30:22 2009
@@ -20,18 +20,18 @@
 <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0";
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
           xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 
http://maven.apache.org/xsd/settings-1.0.0.xsd";>
-  <profiles>
-    <profile>
-      <activation>
-        <activeByDefault>true</activeByDefault>
-      </activation>
-      <id>test</id>
-      <pluginRepositories>
-        <pluginRepository>
-          <id>apache.snapshots</id>
-          <url>http://people.apache.org/repo/m2-snapshot-repository</url>
-        </pluginRepository>
-      </pluginRepositories>
-    </profile>
-  </profiles>
+    <activeProfiles>
+        <activeProfile>test</activeProfile>
+    </activeProfiles>
+    <profiles>
+        <profile>
+            <id>test</id>
+            <pluginRepositories>
+                <pluginRepository>
+                    <id>apache.snapshots</id>
+                    
<url>http://people.apache.org/repo/m2-snapshot-repository</url>
+                </pluginRepository>
+            </pluginRepositories>
+        </profile>
+    </profiles>
 </settings>
\ No newline at end of file


Reply via email to