diff --git a/sandbox/maven-ear-plugin/pom.xml b/sandbox/maven-ear-plugin/pom.xml index c4beab5f7f..3f7ac99fc9 100644 --- a/sandbox/maven-ear-plugin/pom.xml +++ b/sandbox/maven-ear-plugin/pom.xml @@ -8,12 +8,12 @@ maven-ear-plugin maven-plugin Maven Ear plugin - 2.0-alpha-1-SNAPSHOT + 2.0-beta-1-SNAPSHOT org.apache.maven maven-archiver - 2.0-alpha-2 + 2.0-alpha-3 org.apache.maven @@ -23,7 +23,7 @@ plexus plexus-utils - 1.0-alpha-3 + 1.0.1-SNAPSHOT diff --git a/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarMojo.java b/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarMojo.java index 7b36e06c27..12450e5169 100644 --- a/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarMojo.java +++ b/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarMojo.java @@ -72,7 +72,8 @@ public abstract class AbstractEarMojo for ( Iterator iter = artifacts.iterator(); iter.hasNext(); ) { Artifact artifact = (Artifact) iter.next(); - if ( !Artifact.SCOPE_TEST.equals( artifact.getScope() ) ) + if ( !Artifact.SCOPE_TEST.equals( artifact.getScope()) || + !Artifact.SCOPE_PROVIDED.equals( artifact.getScope()) ) { EarModule module = EarModuleFactory.newEarModule( artifact ); modules.add( module ); diff --git a/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/ApplicationXmlWriter.java b/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/ApplicationXmlWriter.java index 8f1e05d3bb..050c583f7b 100644 --- a/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/ApplicationXmlWriter.java +++ b/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/ApplicationXmlWriter.java @@ -37,12 +37,21 @@ import java.util.List; */ public final class ApplicationXmlWriter { + public static final String DOCTYPE_1_3 = "application PUBLIC\n" + + "\t\"-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN\"\n" + + "\t\"http://java.sun.com/dtd/application_1_3.dtd\""; + + private static final String APPLICATION_ELEMENT = "application"; + private final String version; - public ApplicationXmlWriter( String version ) + private final String encoding; + + public ApplicationXmlWriter( String version, String encoding ) { this.version = version; + this.encoding = encoding; } public void write( File destinationFile, List earModules, String displayName, String description ) @@ -59,10 +68,15 @@ public final class ApplicationXmlWriter ex ); } - // @todo Add DTD or XSchema reference based on version attribute - - XMLWriter writer = new PrettyPrintXMLWriter( w ); - writer.startElement( "application" ); + XMLWriter writer = null; + if ( GenerateApplicationXmlMojo.VERSION_1_3.equals( version ) ) + { + writer = initializeRootElementOneDotThree( w ); + } + else if ( GenerateApplicationXmlMojo.VERSION_1_4.equals( version ) ) + { + writer = initializeRootElementOneDotFour( w ); + } if ( displayName != null ) { @@ -105,4 +119,23 @@ public final class ApplicationXmlWriter // TODO: warn } } + + private XMLWriter initializeRootElementOneDotThree( FileWriter w ) + { + XMLWriter writer = new PrettyPrintXMLWriter( w, encoding, DOCTYPE_1_3 ); + writer.startElement( APPLICATION_ELEMENT ); + return writer; + } + + private XMLWriter initializeRootElementOneDotFour( FileWriter w ) + { + XMLWriter writer = new PrettyPrintXMLWriter( w, encoding, null ); + writer.startElement( APPLICATION_ELEMENT ); + writer.addAttribute( "xmlns", "http://java.sun.com/xml/ns/j2ee" ); + writer.addAttribute( "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance" ); + writer.addAttribute( "xsi:schemaLocation", + "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd" ); + writer.addAttribute( "version", "1.4" ); + return writer; + } } diff --git a/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarMojo.java b/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarMojo.java index 85e74e09a5..8f4ca107d4 100644 --- a/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarMojo.java +++ b/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarMojo.java @@ -29,7 +29,7 @@ import java.util.Iterator; import java.util.List; /** - * The Ear Mojo. + * Builds J2EE Enteprise Archive (EAR) files. * * @author Stephane Nicoll * @version $Id $ @@ -77,7 +77,7 @@ public class EarMojo * * @parameter alias="earName" expression="${project.build.finalName}" * @required - * @readonly + * @readonly */ private String finalName; diff --git a/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/GenerateApplicationXmlMojo.java b/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/GenerateApplicationXmlMojo.java index 7e701180f8..5c2857cd31 100644 --- a/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/GenerateApplicationXmlMojo.java +++ b/sandbox/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/GenerateApplicationXmlMojo.java @@ -23,8 +23,7 @@ import java.io.File; import java.io.IOException; /** - * A Mojo used to build the application.xml file - * if necessary. + * A Mojo used to build the application.xml file. * * @author Stephane Nicoll * @version $Id $ @@ -44,14 +43,15 @@ public class GenerateApplicationXmlMojo public static final String UTF_8 = "UTF-8"; /** - * Inserts the doctype header depending on the specified version. + * The version of the application.xml to generate. Valid values + * are 1.3 and 1.4. * * @parameter expression="${maven.ear.appxml.version}" */ private String version = VERSION_1_3; /** - * Display name of the application to be used when application.xml + * Display name of the application to be used when application.xml * file is autogenerated. * * @parameter expression="${project.artifactId}" @@ -59,22 +59,22 @@ public class GenerateApplicationXmlMojo private String displayName = null; /** - * The description in generated application.xml. + * Description of the application to be used when application.xml + * file is autogenerated. * * @parameter */ private String description = null; /** - * Character encoding for the auto-generated application.xml file. + * Character encoding for the auto-generated application.xml file. * * @parameter - * @TODO handle this field */ private String encoding = UTF_8; /** - * Directory where the application.xml file will be auto-generated. + * Directory where the application.xml file will be auto-generated. * * @parameter expression="${project.build.directory}" */ @@ -90,6 +90,11 @@ public class GenerateApplicationXmlMojo getLog().debug( "encoding[" + encoding + "]" ); getLog().debug( "generatedDescriptorLocation[" + generatedDescriptorLocation + "]" ); + if ( !version.equals( VERSION_1_3 ) && version.equals( VERSION_1_4 ) ) + { + throw new MojoExecutionException( "Invalid version[" + version + "]" ); + } + // Generate deployment descriptor try { @@ -124,7 +129,7 @@ public class GenerateApplicationXmlMojo descriptor.createNewFile(); } - ApplicationXmlWriter writer = new ApplicationXmlWriter( version ); + ApplicationXmlWriter writer = new ApplicationXmlWriter( version, encoding ); try { writer.write( descriptor, getModules(), displayName, description );