Author: snicoll Date: Wed Jan 25 05:15:31 2012 New Revision: 1235631 URL: http://svn.apache.org/viewvc?rev=1235631&view=rev Log: MEAR-141: support of env-entries in generated application.xml, based on a patch from Jim Brownfield.
Added: maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EnvEntry.java maven/plugins/trunk/maven-ear-plugin/src/site/apt/examples/specifying-env-entries-for-the-generated-application-xml.apt.vm maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/EnvEntryTest.java maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-074/ maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-074/expected-META-INF/ maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-074/expected-META-INF/application.xml maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-074/pom.xml maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-075/ maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-075/expected-META-INF/ maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-075/expected-META-INF/application.xml maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-075/pom.xml maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-076/ maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-076/expected-META-INF/ maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-076/expected-META-INF/application.xml maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-076/pom.xml maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-077/ maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-077/expected-META-INF/ maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-077/expected-META-INF/application.xml maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-077/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/ApplicationXmlWriter.java maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/ApplicationXmlWriterContext.java maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/GenerateApplicationXmlMojo.java maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/util/JavaEEVersion.java maven/plugins/trunk/maven-ear-plugin/src/site/apt/index.apt maven/plugins/trunk/maven-ear-plugin/src/site/apt/tests.apt maven/plugins/trunk/maven-ear-plugin/src/site/site.xml maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/it/EarMojoIT.java Modified: maven/plugins/trunk/maven-ear-plugin/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/pom.xml?rev=1235631&r1=1235630&r2=1235631&view=diff ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/pom.xml (original) +++ maven/plugins/trunk/maven-ear-plugin/pom.xml Wed Jan 25 05:15:31 2012 @@ -119,7 +119,7 @@ under the License. <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> - <version>3.8.1</version> + <version>4.8.1</version> <scope>test</scope> </dependency> </dependencies> 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=1235631&r1=1235630&r2=1235631&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 Wed Jan 25 05:15:31 2012 @@ -111,6 +111,14 @@ final class ApplicationXmlWriter securityRole.appendSecurityRole( writer ); } + if ( version.ge( JavaEEVersion.Six ) ) + { + for ( EnvEntry envEntry : context.getEnvEntries() ) + { + envEntry.appendEnvEntry( writer ); + } + } + if ( version.ge( JavaEEVersion.Five ) ) { writeLibraryDirectory( context.getLibraryDirectory(), writer ); Modified: 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=1235631&r1=1235630&r2=1235631&view=diff ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/ApplicationXmlWriterContext.java (original) +++ maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/ApplicationXmlWriterContext.java Wed Jan 25 05:15:31 2012 @@ -36,6 +36,8 @@ class ApplicationXmlWriterContext private final List<EarModule> earModules; private final List<SecurityRole> securityRoles; + + private final List<EnvEntry> envEntries; private final String displayName; @@ -47,13 +49,15 @@ class ApplicationXmlWriterContext private final Boolean initializeInOrder; - public ApplicationXmlWriterContext( File destinationFile, List<EarModule> earModules, List<SecurityRole> securityRoles, String displayName, + public ApplicationXmlWriterContext( File destinationFile, List<EarModule> earModules, List<SecurityRole> securityRoles, + List<EnvEntry> envEntries, String displayName, String description, String libraryDirectory, String applicationName, Boolean initializeInOrder ) { this.destinationFile = destinationFile; this.earModules = earModules; this.securityRoles = securityRoles; + this.envEntries = envEntries; this.displayName = displayName; this.description = description; this.libraryDirectory = libraryDirectory; @@ -92,6 +96,16 @@ class ApplicationXmlWriterContext } /** + * Returns the list of {@link EnvEntry} instances (as per JavaEE 6). + * + * @return the env-entry elements + */ + public List<EnvEntry> getEnvEntries() + { + return envEntries; + } + + /** * Returns the display name. * * @return the display name Added: maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EnvEntry.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EnvEntry.java?rev=1235631&view=auto ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EnvEntry.java (added) +++ maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EnvEntry.java Wed Jan 25 05:15:31 2012 @@ -0,0 +1,145 @@ +package org.apache.maven.plugin.ear; + +/* + * 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. + */ + +import org.codehaus.plexus.util.xml.XMLWriter; + +/** + * The representation of a env-entry entry within an + * application.xml file. + * + * @author Jim Brownfield based on code by <a href="snic...@apache.org">Stephane Nicoll</a> + * @version $Id$ + */ +class EnvEntry +{ + + static final String ENV_ENTRY = "env-entry"; + + static final String DESCRIPTION = "description"; + + static final String ENV_ENTRY_NAME = "env-entry-name"; + + static final String ENV_ENTRY_TYPE = "env-entry-type"; + + static final String ENV_ENTRY_VALUE = "env-entry-value"; + + private final String description; + + private final String name; + + private final String type; + + private final String value; + + public EnvEntry( String description, String name, String type, String value ) + { + if ( isNullOrEmpty( name ) ) + { + throw new IllegalArgumentException( ENV_ENTRY_NAME + " in " + ENV_ENTRY + " element cannot be null." ); + } + else if ( isNullOrEmpty( type ) && isNullOrEmpty( value ) ) + { + throw new IllegalArgumentException( + ENV_ENTRY_TYPE + " in " + ENV_ENTRY + " element cannot be null if no " + ENV_ENTRY_VALUE + + " was specified." ); + + } + + this.description = description; + this.name = name; + this.type = type; + this.value = value; + } + + public String getDescription() + { + return description; + } + + public String getName() + { + return name; + } + + public String getType() + { + return type; + } + + public String getValue() + { + return value; + } + + /** + * Appends the <tt>XML</tt> representation of this env-entry. + * + * @param writer the writer to use + */ + public void appendEnvEntry( XMLWriter writer ) + { + writer.startElement( ENV_ENTRY ); + + // description + if ( getDescription() != null ) + { + doWriteElement( writer, DESCRIPTION, getDescription() ); + } + + // env entry name + doWriteElement( writer, ENV_ENTRY_NAME, getName() ); + + // env entry type + if ( getType() != null ) + { + doWriteElement( writer, ENV_ENTRY_TYPE, getType() ); + } + + // env entry value + if ( getValue() != null ) + { + doWriteElement( writer, ENV_ENTRY_VALUE, getValue() ); + } + + // end of env-entry + writer.endElement(); + } + + + private void doWriteElement( XMLWriter writer, String element, String text ) + { + writer.startElement( element ); + writer.writeText( text ); + writer.endElement(); + } + + private boolean isNullOrEmpty( String s ) + { + return s == null || s.trim().isEmpty(); + } + + public String toString() + { + return "env-entry [name=" + getName() + ", type=" + getType() + ", value=" + getValue() + "]"; + } + + +} 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=1235631&r1=1235630&r2=1235631&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 Wed Jan 25 05:15:31 2012 @@ -104,7 +104,15 @@ public class GenerateApplicationXmlMojo * @parameter */ private PlexusConfiguration security; - + + /** + * The env-entries to be added to the auto-generated + * application.xml file. Since JavaEE6. + * + * @parameter alias="env-entries" + */ + private PlexusConfiguration envEntries; + public void execute() throws MojoExecutionException, MojoFailureException @@ -190,8 +198,8 @@ public class GenerateApplicationXmlMojo final ApplicationXmlWriter writer = new ApplicationXmlWriter( javaEEVersion, encoding, generateModuleId ); final ApplicationXmlWriterContext context = - new ApplicationXmlWriterContext( descriptor, getModules(), buildSecurityRoles(), displayName, description, - defaultLibBundleDir, applicationName, initializeInOrder ); + new ApplicationXmlWriterContext( descriptor, getModules(), buildSecurityRoles(), buildEnvEntries(), displayName, + description, defaultLibBundleDir, applicationName, initializeInOrder ); writer.write( context ); } @@ -259,4 +267,46 @@ public class GenerateApplicationXmlMojo } } + /** + * Builds the env-entries based on the configuration. + * + * @return a list of EnvEntry object(s) + * @throws EarPluginException if the configuration is invalid + */ + private List<EnvEntry> buildEnvEntries() + throws EarPluginException + { + final List<EnvEntry> result = new ArrayList<EnvEntry>(); + if ( envEntries == null ) + { + return result; + } + try + { + final PlexusConfiguration[] allEnvEntries = envEntries.getChildren( EnvEntry.ENV_ENTRY ); + + for ( PlexusConfiguration envEntry : allEnvEntries ) + { + final String description = envEntry.getChild( EnvEntry.DESCRIPTION ).getValue(); + final String envEntryName = envEntry.getChild( EnvEntry.ENV_ENTRY_NAME ).getValue(); + final String envEntryType = envEntry.getChild( EnvEntry.ENV_ENTRY_TYPE ).getValue(); + final String envEntryValue = envEntry.getChild( EnvEntry.ENV_ENTRY_VALUE ).getValue(); + + try + { + result.add( new EnvEntry( description, envEntryName, envEntryType, envEntryValue ) ); + } + catch ( IllegalArgumentException e ) + { + throw new EarPluginException( "Invalid env-entry [" + envEntry + "]", e ); + } + } + return result; + } + catch ( PlexusConfigurationException e ) + { + throw new EarPluginException( "Invalid env-entry configuration", e ); + } + + } } \ No newline at end of file Modified: maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/util/JavaEEVersion.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/util/JavaEEVersion.java?rev=1235631&r1=1235630&r2=1235631&view=diff ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/util/JavaEEVersion.java (original) +++ maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/util/JavaEEVersion.java Wed Jan 25 05:15:31 2012 @@ -45,22 +45,22 @@ public class JavaEEVersion /** * Represents the J2EE 1.3 version. */ - public static final JavaEEVersion OneDotThree = new JavaEEVersion( new Integer( 0 ), VERSION_1_3 ); + public static final JavaEEVersion OneDotThree = new JavaEEVersion( 0, VERSION_1_3 ); /** * Represents the J2EE 1.4 version. */ - public static final JavaEEVersion OneDotFour = new JavaEEVersion( new Integer( 1 ), VERSION_1_4 ); + public static final JavaEEVersion OneDotFour = new JavaEEVersion( 1, VERSION_1_4 ); /** * Represents the JavaEE 5 version. */ - public static final JavaEEVersion Five = new JavaEEVersion( new Integer( 2 ), VERSION_5 ); + public static final JavaEEVersion Five = new JavaEEVersion( 2, VERSION_5 ); /** * Represents the JavaEE 7 version. */ - public static final JavaEEVersion Six = new JavaEEVersion( new Integer( 3 ), VERSION_6 ); + public static final JavaEEVersion Six = new JavaEEVersion( 3, VERSION_6 ); private final Integer index; @@ -81,7 +81,7 @@ public class JavaEEVersion { throw new InvalidJavaEEVersion( "Invalid version [" + version + "]", version ); } - return (JavaEEVersion) versionsMap.get( version ); + return versionsMap.get( version ); } /** Added: maven/plugins/trunk/maven-ear-plugin/src/site/apt/examples/specifying-env-entries-for-the-generated-application-xml.apt.vm URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/site/apt/examples/specifying-env-entries-for-the-generated-application-xml.apt.vm?rev=1235631&view=auto ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/site/apt/examples/specifying-env-entries-for-the-generated-application-xml.apt.vm (added) +++ maven/plugins/trunk/maven-ear-plugin/src/site/apt/examples/specifying-env-entries-for-the-generated-application-xml.apt.vm Wed Jan 25 05:15:31 2012 @@ -0,0 +1,62 @@ + ------ + Specifying Security Roles For The Generated application.xml + ------ + Stephane Nicoll + <snic...@apache.org> + ------ + January 25, 2012 + +~~ Copyright 2006 The Apache Software Foundation. +~~ +~~ 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. + +~~ NOTE: For help with the syntax of this file, see: +~~ http://maven.apache.org/doxia/references/apt-format.html + + +Specifying Environment entries For The Generated application.xml + + Environment entries can be added as from the JavaEE 6 spec. For instance: + ++-------- + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-ear-plugin</artifactId> + <version>${project.version}</version> + <configuration> + [...] + <version>6</version> + [...] + <env-entries> + <env-entry> + <description>A complete entry.</description> + <env-entry-name>complete</env-entry-name> + <env-entry-type>java.lang.Integer</env-entry-type> + <env-entry-value>4</env-entry-value> + </env-entry> + <env-entry> + <env-entry-name>no-type</env-entry-name> + <env-entry-value>4</env-entry-value> + </env-entry> + <env-entry> + <env-entry-name>no-value</env-entry-name> + <env-entry-type>java.lang.String</env-entry-type> + </env-entry> + </env-entries> + </configuration> + </plugin> + </plugins> + </build> ++--------- Modified: maven/plugins/trunk/maven-ear-plugin/src/site/apt/index.apt URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/site/apt/index.apt?rev=1235631&r1=1235630&r2=1235631&view=diff ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/site/apt/index.apt (original) +++ maven/plugins/trunk/maven-ear-plugin/src/site/apt/index.apt Wed Jan 25 05:15:31 2012 @@ -124,6 +124,9 @@ Maven EAR Plugin * {{{./examples/specifying-security-roles-for-the-generated-application-xml.html} Specifying Security Roles For The Generated application.xml}} + * {{{./examples/specifying-env-entries-for-the-generated-application-xml.html} + Specifying Environment Entries For The Generated application.xml}} + * {{{./examples/generating-jboss-app.html} Generating the jboss-app.xml file}} * {{{./examples/generating-modules-id.html} Generating modules id}} 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=1235631&r1=1235630&r2=1235631&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 Wed Jan 25 05:15:31 2012 @@ -175,3 +175,11 @@ EAR Plugin Tests * project-072: builds an EAR with an application client module (app-client) * project-073: builds an EAR with an application client module (app-client) and a default bundle directory for _java_ modules + + * project-074: builds an EAR with custom env entries settings and J2EE 1.3 (Not supported by the specification) + + * project-075: builds an EAR with custom env entries settings and J2EE 1.4 (Not supported by the specification) + + * project-076: builds an EAR with custom env entries settings and JavaEE 5 (Not supported by the specification) + + * project-077: builds an EAR with custom env entries settings and JavaEE 6 Modified: maven/plugins/trunk/maven-ear-plugin/src/site/site.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/site/site.xml?rev=1235631&r1=1235630&r2=1235631&view=diff ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/site/site.xml (original) +++ maven/plugins/trunk/maven-ear-plugin/src/site/site.xml Wed Jan 25 05:15:31 2012 @@ -34,18 +34,19 @@ under the License. </menu> <menu name="Examples"> - <item name="Filtering EAR Resources" href="examples/filtering-sources.html"/> - <item name="Advanced Filtering Techniques" href="examples/filtering-advanced.html"/> - <item name="Creating Skinny WARs" href="examples/skinny-wars.html"/> - <item name="Customizing A Module Filename" href="examples/customizing-a-module-filename.html"/> - <item name="Customizing The Context Root" href="examples/customizing-context-root.html"/> - <item name="Customizing A Module Location" href="examples/customizing-module-location.html"/> - <item name="Customizing A Module URI" href="examples/customizing-module-uri.html"/> - <item name="Excluding A Module" href="examples/excluding-a-module.html"/> - <item name="Excluding Files From the EAR" href="examples/excluding-files-from-ear.html"/> - <item name="Unpacking A Module" href="examples/unpacking-a-module.html"/> - <item name="Including A Third Party Library In application.xml" href="examples/including-a-third-party-library-in-application-xml.html"/> - <item name="Specifying Security Roles For The Generated application.xml" href="examples/specifying-security-roles-for-the-generated-application-xml.html"/> + <item name="Filtering EAR resources" href="examples/filtering-sources.html"/> + <item name="Advanced filtering techniques" href="examples/filtering-advanced.html"/> + <item name="Creating skinny WARs" href="examples/skinny-wars.html"/> + <item name="Customizing a module filename" href="examples/customizing-a-module-filename.html"/> + <item name="Customizing the context root" href="examples/customizing-context-root.html"/> + <item name="Customizing a module location" href="examples/customizing-module-location.html"/> + <item name="Customizing a module URI" href="examples/customizing-module-uri.html"/> + <item name="Excluding a module" href="examples/excluding-a-module.html"/> + <item name="Excluding files from the EAR" href="examples/excluding-files-from-ear.html"/> + <item name="Unpacking a module" href="examples/unpacking-a-module.html"/> + <item name="Including a third party library in application.xml" href="examples/including-a-third-party-library-in-application-xml.html"/> + <item name="Specifying Security Roles in application.xml" href="examples/specifying-security-roles-for-the-generated-application-xml.html"/> + <item name="Specifying Environment Entries in application.xml" href="examples/specifying-env-entries-for-the-generated-application-xml.html"/> <item name="Generating jboss-app.xml" href="examples/generating-jboss-app.html"/> <item name="Customize file name mapping" href="examples/customize-file-name-mapping.html"/> <item name="Generating modules ID" href="examples/generating-modules-id.html"/> Added: maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/EnvEntryTest.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/EnvEntryTest.java?rev=1235631&view=auto ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/EnvEntryTest.java (added) +++ maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/EnvEntryTest.java Wed Jan 25 05:15:31 2012 @@ -0,0 +1,73 @@ +package org.apache.maven.plugin.ear; + +import org.junit.Test; + +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertNotNull; + +/** + * @author Stephane Nicoll + */ +public class EnvEntryTest +{ + + public static final String DESCRIPTION = "description"; + + public static final String NAME = "name"; + + public static final String TYPE = Integer.class.getName(); + + public static final String VALUE = "34"; + + @Test + public void createComplete() + { + final EnvEntry envEntry = new EnvEntry( DESCRIPTION, NAME, TYPE, VALUE ); + assertEnvEntry( envEntry, DESCRIPTION, NAME, TYPE, VALUE ); + } + + @Test + public void createWithoutTypeButValue() + { + final EnvEntry envEntry = new EnvEntry( null, NAME, null, VALUE ); + assertEnvEntry( envEntry, null, NAME, null, VALUE ); + } + + @Test( expected = IllegalArgumentException.class ) + public void createWithoutName() + { + new EnvEntry( DESCRIPTION, null, TYPE, VALUE ); + + } + + @Test( expected = IllegalArgumentException.class ) + public void createWithEmptyName() + { + new EnvEntry( DESCRIPTION, "", TYPE, VALUE ); + } + + @Test( expected = IllegalArgumentException.class ) + public void createWithNullTypeAndNoValue() + { + new EnvEntry( DESCRIPTION, NAME, null, null ); + + } + + @Test( expected = IllegalArgumentException.class ) + public void createWithEmptyTypeAndNoValue() + { + new EnvEntry( DESCRIPTION, NAME, "", null ); + + } + + private void assertEnvEntry( EnvEntry actual, String description, String name, String type, String value ) + { + assertNotNull( "Env entry could not be null", actual ); + assertNotNull( "ToString could not be null", actual.toString() ); + assertEquals( "Wrong env entry description for [" + actual + "]", description, actual.getDescription() ); + assertEquals( "Wrong env entry name for [" + actual + "]", name, actual.getName() ); + assertEquals( "Wrong env entry type for [" + actual + "]", type, actual.getType() ); + assertEquals( "Wrong env entry value for [" + actual + "]", value, actual.getValue() ); + + } +} 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=1235631&r1=1235630&r2=1235631&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 Wed Jan 25 05:15:31 2012 @@ -773,4 +773,43 @@ public class EarMojoIT "APP-INF/lib/jar-sample-one-1.0.jar", "APP-INF/lib/jar-sample-two-1.0.jar" } ); } + /** + * Builds an EAR with custom env entries settings and J2EE 1.3. Not supported by the specification + * so this should be ignored. + */ + public void testProject074() + throws Exception + { + doTestProject( "project-074", new String[]{ "ejb-sample-one-1.0.jar", "ejb-sample-two-1.0.jar" } ); + } + + /** + * Builds an EAR with custom env entries settings and J2EE 1.4. Not supported by the specification + * so this should be ignored. + */ + public void testProject075() + throws Exception + { + doTestProject( "project-075", new String[]{ "ejb-sample-one-1.0.jar", "ejb-sample-two-1.0.jar" } ); + } + + /** + * Builds an EAR with custom env entries settings and JavaEE 5. Not supported by the specification + * so this should be ignored. + */ + public void testProject076() + throws Exception + { + doTestProject( "project-076", new String[]{ "ejb-sample-one-1.0.jar", "ejb-sample-two-1.0.jar" } ); + } + + /** + * Builds an EAR with custom env entries settings and JavaEE 6. + */ + public void testProject077() + throws Exception + { + doTestProject( "project-077", new String[]{ "ejb-sample-one-1.0.jar", "ejb-sample-two-1.0.jar" } ); + } + } Added: maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-074/expected-META-INF/application.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-074/expected-META-INF/application.xml?rev=1235631&view=auto ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-074/expected-META-INF/application.xml (added) +++ maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-074/expected-META-INF/application.xml Wed Jan 25 05:15:31 2012 @@ -0,0 +1,32 @@ +<?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. +--> + +<!DOCTYPE application PUBLIC + "-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN" + "http://java.sun.com/dtd/application_1_3.dtd"> +<application> + <display-name>maven-ear-plugin-test-project-074</display-name> + <module> + <ejb>ejb-sample-one-1.0.jar</ejb> + </module> + <module> + <ejb>ejb-sample-two-1.0.jar</ejb> + </module> +</application> \ No newline at end of file Added: maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-074/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-074/pom.xml?rev=1235631&view=auto ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-074/pom.xml (added) +++ maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-074/pom.xml Wed Jan 25 05:15:31 2012 @@ -0,0 +1,63 @@ +<?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-074</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>ejb-sample-two</artifactId> + <version>1.0</version> + <type>ejb</type> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-ear-plugin</artifactId> + <version>@project.version@</version> + <configuration> + <!-- This is ignored with version 1.3 as this is not supported --> + <env-entries> + <env-entry> + <description>A complete entry.</description> + <env-entry-name>complete</env-entry-name> + <env-entry-type>java.lang.Integer</env-entry-type> + <env-entry-value>4</env-entry-value> + </env-entry> + </env-entries> + </configuration> + </plugin> + </plugins> + </build> +</project> Added: maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-075/expected-META-INF/application.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-075/expected-META-INF/application.xml?rev=1235631&view=auto ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-075/expected-META-INF/application.xml (added) +++ maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-075/expected-META-INF/application.xml Wed Jan 25 05:15:31 2012 @@ -0,0 +1,29 @@ +<?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/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd" version="1.4"> + <display-name>maven-ear-plugin-test-project-075</display-name> + <module> + <ejb>ejb-sample-one-1.0.jar</ejb> + </module> + <module> + <ejb>ejb-sample-two-1.0.jar</ejb> + </module> +</application> \ No newline at end of file Added: maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-075/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-075/pom.xml?rev=1235631&view=auto ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-075/pom.xml (added) +++ maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-075/pom.xml Wed Jan 25 05:15:31 2012 @@ -0,0 +1,64 @@ +<?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-075</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>ejb-sample-two</artifactId> + <version>1.0</version> + <type>ejb</type> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-ear-plugin</artifactId> + <version>@project.version@</version> + <configuration> + <version>1.4</version> + <!-- This is ignored with version 1.4 as this is not supported --> + <env-entries> + <env-entry> + <description>A complete entry.</description> + <env-entry-name>complete</env-entry-name> + <env-entry-type>java.lang.Integer</env-entry-type> + <env-entry-value>4</env-entry-value> + </env-entry> + </env-entries> + </configuration> + </plugin> + </plugins> + </build> +</project> Added: maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-076/expected-META-INF/application.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-076/expected-META-INF/application.xml?rev=1235631&view=auto ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-076/expected-META-INF/application.xml (added) +++ maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-076/expected-META-INF/application.xml Wed Jan 25 05:15:31 2012 @@ -0,0 +1,29 @@ +<?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-076</display-name> + <module> + <ejb>ejb-sample-one-1.0.jar</ejb> + </module> + <module> + <ejb>ejb-sample-two-1.0.jar</ejb> + </module> +</application> \ No newline at end of file Added: maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-076/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-076/pom.xml?rev=1235631&view=auto ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-076/pom.xml (added) +++ maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-076/pom.xml Wed Jan 25 05:15:31 2012 @@ -0,0 +1,64 @@ +<?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-076</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>ejb-sample-two</artifactId> + <version>1.0</version> + <type>ejb</type> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-ear-plugin</artifactId> + <version>@project.version@</version> + <configuration> + <version>5</version> + <!-- This is ignored with version 5 as this is not supported --> + <env-entries> + <env-entry> + <description>A complete entry.</description> + <env-entry-name>complete</env-entry-name> + <env-entry-type>java.lang.Integer</env-entry-type> + <env-entry-value>4</env-entry-value> + </env-entry> + </env-entries> + </configuration> + </plugin> + </plugins> + </build> +</project> Added: maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-077/expected-META-INF/application.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-077/expected-META-INF/application.xml?rev=1235631&view=auto ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-077/expected-META-INF/application.xml (added) +++ maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-077/expected-META-INF/application.xml Wed Jan 25 05:15:31 2012 @@ -0,0 +1,43 @@ +<?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_6.xsd" version="6"> + <display-name>maven-ear-plugin-test-project-077</display-name> + <module> + <ejb>ejb-sample-one-1.0.jar</ejb> + </module> + <module> + <ejb>ejb-sample-two-1.0.jar</ejb> + </module> + <env-entry> + <description>A complete entry.</description> + <env-entry-name>complete</env-entry-name> + <env-entry-type>java.lang.Integer</env-entry-type> + <env-entry-value>4</env-entry-value> + </env-entry> + <env-entry> + <env-entry-name>no-type</env-entry-name> + <env-entry-value>4</env-entry-value> + </env-entry> + <env-entry> + <env-entry-name>no-value</env-entry-name> + <env-entry-type>java.lang.String</env-entry-type> + </env-entry> +</application> + Added: maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-077/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-077/pom.xml?rev=1235631&view=auto ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-077/pom.xml (added) +++ maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-077/pom.xml Wed Jan 25 05:15:31 2012 @@ -0,0 +1,71 @@ +<?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-077</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>ejb-sample-two</artifactId> + <version>1.0</version> + <type>ejb</type> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-ear-plugin</artifactId> + <version>@project.version@</version> + <configuration> + <version>6</version> + <env-entries> + <env-entry> + <description>A complete entry.</description> + <env-entry-name>complete</env-entry-name> + <env-entry-type>java.lang.Integer</env-entry-type> + <env-entry-value>4</env-entry-value> + </env-entry> + <env-entry> + <env-entry-name>no-type</env-entry-name> + <env-entry-value>4</env-entry-value> + </env-entry> + <env-entry> + <env-entry-name>no-value</env-entry-name> + <env-entry-type>java.lang.String</env-entry-type> + </env-entry> + </env-entries> + </configuration> + </plugin> + </plugins> + </build> +</project>