Adding supports for encoding doctype/xschema declaration and the new provided scope.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@209016 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Emmanuel Venisse 2005-07-04 06:04:27 +00:00
parent a6eff8b8ce
commit e57cac7fc9
5 changed files with 59 additions and 20 deletions

View File

@ -8,12 +8,12 @@
<artifactId>maven-ear-plugin</artifactId> <artifactId>maven-ear-plugin</artifactId>
<packaging>maven-plugin</packaging> <packaging>maven-plugin</packaging>
<name>Maven Ear plugin</name> <name>Maven Ear plugin</name>
<version>2.0-alpha-1-SNAPSHOT</version> <version>2.0-beta-1-SNAPSHOT</version>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.apache.maven</groupId> <groupId>org.apache.maven</groupId>
<artifactId>maven-archiver</artifactId> <artifactId>maven-archiver</artifactId>
<version>2.0-alpha-2</version> <version>2.0-alpha-3</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.maven</groupId> <groupId>org.apache.maven</groupId>
@ -23,7 +23,7 @@
<dependency> <dependency>
<groupId>plexus</groupId> <groupId>plexus</groupId>
<artifactId>plexus-utils</artifactId> <artifactId>plexus-utils</artifactId>
<version>1.0-alpha-3</version> <version>1.0.1-SNAPSHOT</version>
</dependency> </dependency>
</dependencies> </dependencies>
</model> </model>

View File

@ -72,7 +72,8 @@ public abstract class AbstractEarMojo
for ( Iterator iter = artifacts.iterator(); iter.hasNext(); ) for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
{ {
Artifact artifact = (Artifact) iter.next(); 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 ); EarModule module = EarModuleFactory.newEarModule( artifact );
modules.add( module ); modules.add( module );

View File

@ -37,12 +37,21 @@ import java.util.List;
*/ */
public final class ApplicationXmlWriter 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; private final String version;
public ApplicationXmlWriter( String version ) private final String encoding;
public ApplicationXmlWriter( String version, String encoding )
{ {
this.version = version; this.version = version;
this.encoding = encoding;
} }
public void write( File destinationFile, List earModules, String displayName, String description ) public void write( File destinationFile, List earModules, String displayName, String description )
@ -59,10 +68,15 @@ public final class ApplicationXmlWriter
ex ); ex );
} }
// @todo Add DTD or XSchema reference based on version attribute XMLWriter writer = null;
if ( GenerateApplicationXmlMojo.VERSION_1_3.equals( version ) )
XMLWriter writer = new PrettyPrintXMLWriter( w ); {
writer.startElement( "application" ); writer = initializeRootElementOneDotThree( w );
}
else if ( GenerateApplicationXmlMojo.VERSION_1_4.equals( version ) )
{
writer = initializeRootElementOneDotFour( w );
}
if ( displayName != null ) if ( displayName != null )
{ {
@ -105,4 +119,23 @@ public final class ApplicationXmlWriter
// TODO: warn // 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;
}
} }

View File

@ -29,7 +29,7 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
/** /**
* The Ear Mojo. * Builds J2EE Enteprise Archive (EAR) files.
* *
* @author <a href="stephane.nicoll@gmail.com">Stephane Nicoll</a> * @author <a href="stephane.nicoll@gmail.com">Stephane Nicoll</a>
* @version $Id $ * @version $Id $
@ -77,7 +77,7 @@ public class EarMojo
* *
* @parameter alias="earName" expression="${project.build.finalName}" * @parameter alias="earName" expression="${project.build.finalName}"
* @required * @required
* @readonly * @readonly
*/ */
private String finalName; private String finalName;

View File

@ -23,8 +23,7 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
/** /**
* A <tt>Mojo</tt> used to build the <tt>application.xml</tt> file * A Mojo used to build the application.xml file.
* if necessary.
* *
* @author <a href="stephane.nicoll@gmail.com">Stephane Nicoll</a> * @author <a href="stephane.nicoll@gmail.com">Stephane Nicoll</a>
* @version $Id $ * @version $Id $
@ -44,14 +43,15 @@ public class GenerateApplicationXmlMojo
public static final String UTF_8 = "UTF-8"; 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}" * @parameter expression="${maven.ear.appxml.version}"
*/ */
private String version = VERSION_1_3; private String version = VERSION_1_3;
/** /**
* Display name of the application to be used when <tt>application.xml</tt> * Display name of the application to be used when application.xml
* file is autogenerated. * file is autogenerated.
* *
* @parameter expression="${project.artifactId}" * @parameter expression="${project.artifactId}"
@ -59,22 +59,22 @@ public class GenerateApplicationXmlMojo
private String displayName = null; private String displayName = null;
/** /**
* The description in generated <tt>application.xml</tt>. * Description of the application to be used when application.xml
* file is autogenerated.
* *
* @parameter * @parameter
*/ */
private String description = null; private String description = null;
/** /**
* Character encoding for the auto-generated <tt>application.xml</tt> file. * Character encoding for the auto-generated application.xml file.
* *
* @parameter * @parameter
* @TODO handle this field
*/ */
private String encoding = UTF_8; private String encoding = UTF_8;
/** /**
* Directory where the <tt>application.xml</tt> file will be auto-generated. * Directory where the application.xml file will be auto-generated.
* *
* @parameter expression="${project.build.directory}" * @parameter expression="${project.build.directory}"
*/ */
@ -90,6 +90,11 @@ public class GenerateApplicationXmlMojo
getLog().debug( "encoding[" + encoding + "]" ); getLog().debug( "encoding[" + encoding + "]" );
getLog().debug( "generatedDescriptorLocation[" + generatedDescriptorLocation + "]" ); getLog().debug( "generatedDescriptorLocation[" + generatedDescriptorLocation + "]" );
if ( !version.equals( VERSION_1_3 ) && version.equals( VERSION_1_4 ) )
{
throw new MojoExecutionException( "Invalid version[" + version + "]" );
}
// Generate deployment descriptor // Generate deployment descriptor
try try
{ {
@ -124,7 +129,7 @@ public class GenerateApplicationXmlMojo
descriptor.createNewFile(); descriptor.createNewFile();
} }
ApplicationXmlWriter writer = new ApplicationXmlWriter( version ); ApplicationXmlWriter writer = new ApplicationXmlWriter( version, encoding );
try try
{ {
writer.write( descriptor, getModules(), displayName, description ); writer.write( descriptor, getModules(), displayName, description );