Author: khmarbaise
Date: Sat Dec 27 14:59:45 2014
New Revision: 1648055

URL: http://svn.apache.org/r1648055
Log:
[MEAR-181] Adding ejb-ref in application.xml
 Added ejb-ref first implementation.

Added:
    
maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EjbRef.java
    
maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-085/
    
maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-085/expected-META-INF/
    
maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-085/expected-META-INF/application.xml
    
maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-085/pom.xml
Modified:
    
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/EnvEntry.java
    
maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/GenerateApplicationXmlMojo.java
    
maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/it/EarMojoIT.java

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=1648055&r1=1648054&r2=1648055&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
 Sat Dec 27 14:59:45 2014
@@ -130,6 +130,10 @@ final class ApplicationXmlWriter
             {
                 envEntry.appendEnvEntry( writer );
             }
+            for ( EjbRef ejbEntry : context.getEjbEntries() )
+            {
+                ejbEntry.appendEjbRefEntry( writer );
+            }
         }
 
         writer.endElement();

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=1648055&r1=1648054&r2=1648055&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
 Sat Dec 27 14:59:45 2014
@@ -40,6 +40,8 @@ class ApplicationXmlWriterContext
     private final List<SecurityRole> securityRoles;
 
     private final List<EnvEntry> envEntries;
+    
+    private final List<EjbRef> ejbEntries;
 
     private final String displayName;
 
@@ -53,6 +55,7 @@ class ApplicationXmlWriterContext
 
     public ApplicationXmlWriterContext( File destinationFile, List<EarModule> 
earModules,
                                         List<SecurityRole> securityRoles, 
List<EnvEntry> envEntries,
+                                        List<EjbRef> ejbEntries,
                                         String displayName, String 
description, String libraryDirectory,
                                         String applicationName, Boolean 
initializeInOrder )
     {
@@ -60,6 +63,7 @@ class ApplicationXmlWriterContext
         this.earModules = earModules;
         this.securityRoles = securityRoles;
         this.envEntries = envEntries;
+        this.ejbEntries = ejbEntries;
         this.displayName = displayName;
         this.description = description;
         this.libraryDirectory = libraryDirectory;
@@ -119,6 +123,16 @@ class ApplicationXmlWriterContext
     }
 
     /**
+     * Returns the list of {@link EjbRef}.
+     * 
+     * @return the env-ref elements
+     */
+    public List<EjbRef> getEjbEntries()
+    {
+        return ejbEntries;
+    }
+
+    /**
      * Returns the display name.
      * 
      * @return the display name

Added: 
maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EjbRef.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EjbRef.java?rev=1648055&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EjbRef.java
 (added)
+++ 
maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EjbRef.java
 Sat Dec 27 14:59:45 2014
@@ -0,0 +1,147 @@
+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.StringUtils;
+import org.codehaus.plexus.util.xml.XMLWriter;
+
+/**
+ * Representation of {@code ejb-ref} element in {@code application.xml} file.
+ * 
+ * @author Karl Heinz Marbaise
+ * @since 2.10
+ */
+public class EjbRef
+{
+    static final String DESCRIPTION = "description";
+
+    static final String EJB_REF = "ejb-ref";
+
+    static final String EJB_NAME = "ejb-ref-name";
+
+    static final String EJB_TYPE = "ejb-ref-type";
+
+    static final String EJB_LOOKUP_NAME = "lookup-name";
+
+    private final String description;
+
+    private String name;
+
+    private String type;
+
+    private String lookupName;
+
+    public EjbRef( String description, String name, String type, String 
lookupName )
+    {
+        if ( StringUtils.isEmpty( name ) )
+        {
+            throw new IllegalArgumentException( EJB_NAME + " in " + EJB_REF + 
" element cannot be null." );
+        }
+        else if ( StringUtils.isEmpty( type ) && StringUtils.isEmpty( 
lookupName ) )
+        {
+            throw new IllegalArgumentException( EJB_TYPE + " in " + EJB_REF + 
" element cannot be null if no "
+                + EJB_LOOKUP_NAME + " was specified." );
+
+        }
+
+        this.description = description;
+        this.name = name;
+        this.type = type;
+        this.lookupName = lookupName;
+
+    }
+
+    /**
+     * Appends the <tt>XML</tt> representation of this env-entry.
+     * 
+     * @param writer the writer to use
+     */
+    public void appendEjbRefEntry( XMLWriter writer )
+    {
+        System.out.println( "appendEjbRefEntry()" );
+        writer.startElement( EJB_REF );
+
+        // description
+        if ( getDescription() != null )
+        {
+            doWriteElement( writer, DESCRIPTION, getDescription() );
+        }
+
+        // ejb name
+        doWriteElement( writer, EJB_NAME, getName() );
+
+        // ejb-type
+        if ( getType() != null )
+        {
+            doWriteElement( writer, EJB_TYPE, getType() );
+        }
+
+        // lookup-name
+        if ( getLookupName() != null )
+        {
+            doWriteElement( writer, EJB_LOOKUP_NAME, getLookupName() );
+        }
+
+        // end of ejb-ref
+        writer.endElement();
+    }
+
+    private void doWriteElement( XMLWriter writer, String element, String text 
)
+    {
+        writer.startElement( element );
+        writer.writeText( text );
+        writer.endElement();
+    }
+
+    public String getName()
+    {
+        return name;
+    }
+
+    public void setName( String name )
+    {
+        this.name = name;
+    }
+
+    public String getType()
+    {
+        return type;
+    }
+
+    public void setType( String type )
+    {
+        this.type = type;
+    }
+
+    public String getLookupName()
+    {
+        return lookupName;
+    }
+
+    public void setLookupName( String lookupName )
+    {
+        this.lookupName = lookupName;
+    }
+
+    public String getDescription()
+    {
+        return description;
+    }
+}

Modified: 
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=1648055&r1=1648054&r2=1648055&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EnvEntry.java
 (original)
+++ 
maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EnvEntry.java
 Sat Dec 27 14:59:45 2014
@@ -95,6 +95,7 @@ class EnvEntry
      */
     public void appendEnvEntry( XMLWriter writer )
     {
+        System.out.println( "appendEnvEntry()" );
         writer.startElement( ENV_ENTRY );
 
         // description

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=1648055&r1=1648054&r2=1648055&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
 Sat Dec 27 14:59:45 2014
@@ -147,6 +147,12 @@ public class GenerateApplicationXmlMojo
     private PlexusConfiguration envEntries;
 
     /**
+     * The {@code ejb-ref} entries.
+     */
+    @Parameter( alias = "ejb-refs" )
+    private PlexusConfiguration ejbRefs;
+
+    /**
      * {@inheritDoc}
      */
     public void execute()
@@ -236,8 +242,8 @@ public class GenerateApplicationXmlMojo
         final ApplicationXmlWriter writer = new ApplicationXmlWriter( 
javaEEVersion, encoding, generateModuleId );
         final ApplicationXmlWriterContext context =
             new ApplicationXmlWriterContext( descriptor, getModules(), 
buildSecurityRoles(), buildEnvEntries(),
-                                             displayName, description, 
getActualLibraryDirectory(), applicationName,
-                                             initializeInOrder 
).setApplicationId( applicationId );
+                                             buildEjbEntries(), displayName, 
description, getActualLibraryDirectory(),
+                                             applicationName, 
initializeInOrder ).setApplicationId( applicationId );
         writer.write( context );
     }
 
@@ -382,6 +388,61 @@ public class GenerateApplicationXmlMojo
         }
         catch ( InterpolationException e )
         {
+            throw new EarPluginException( "Interpolation exception:", e );
+        }
+
+    }
+
+    /**
+     * Builds the ejb-ref based on the configuration.
+     * 
+     * @return a list of EjbRef object(s)
+     * @throws EarPluginException if the configuration is invalid
+     */
+    private List<EjbRef> buildEjbEntries()
+        throws EarPluginException
+    {
+        final List<EjbRef> result = new ArrayList<EjbRef>();
+        if ( ejbRefs == null )
+        {
+            return result;
+        }
+        try
+        {
+            StringSearchInterpolator ssi = new StringSearchInterpolator();
+            ValueSource vs = new MapBasedValueSource( project.getProperties() 
);
+            ssi.addValueSource( vs );
+
+            final PlexusConfiguration[] allEjbEntries = ejbRefs.getChildren( 
EjbRef.EJB_REF );
+
+            for ( PlexusConfiguration ejbEntry : allEjbEntries )
+            {
+                // CHECKSTYLE_OFF: LineLength
+                final String childDescription = interpolate( ssi, 
ejbEntry.getChild( EnvEntry.DESCRIPTION ).getValue() );
+                final String childEjbEntryName = interpolate( ssi, 
ejbEntry.getChild( EjbRef.EJB_NAME ).getValue() );
+                final String childEjbEntryType = interpolate( ssi, 
ejbEntry.getChild( EjbRef.EJB_TYPE ).getValue() );
+                final String childEjbLookupNameValue =
+                    interpolate( ssi, ejbEntry.getChild( 
EjbRef.EJB_LOOKUP_NAME ).getValue() );
+                // CHECKSTYLE_ON: LineLength
+
+                try
+                {
+                    result.add( new EjbRef( childDescription, 
childEjbEntryName, childEjbEntryType,
+                                            childEjbLookupNameValue ) );
+                }
+                catch ( IllegalArgumentException e )
+                {
+                    throw new EarPluginException( "Invalid ejb-ref [" + 
ejbEntry + "]", e );
+                }
+            }
+            return result;
+        }
+        catch ( PlexusConfigurationException e )
+        {
+            throw new EarPluginException( "Invalid ejb-ref configuration", e );
+        }
+        catch ( InterpolationException e )
+        {
             throw new EarPluginException( "Interpolation exception:", e );
         }
 

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=1648055&r1=1648054&r2=1648055&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
 Sat Dec 27 14:59:45 2014
@@ -873,4 +873,15 @@ public class EarMojoIT
     {
         doTestProject( "project-084", new String[] { "ejb-sample-one-1.0.jar" 
} );
     }
+    
+    /**
+     * Builds an EAR with custom ejbRef entries settings and JavaEE 6.
+     */
+    public void testProject085()
+        throws Exception
+    {
+        doTestProject( "project-085", 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-085/expected-META-INF/application.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-085/expected-META-INF/application.xml?rev=1648055&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-085/expected-META-INF/application.xml
 (added)
+++ 
maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-085/expected-META-INF/application.xml
 Sat Dec 27 14:59:45 2014
@@ -0,0 +1,48 @@
+<?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-085</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>
+  <ejb-ref>
+    <description>A description test</description>
+    <ejb-ref-name>first-name</ejb-ref-name>
+    <ejb-ref-type>java.lang.String</ejb-ref-type>
+    <lookup-name>java-test</lookup-name>
+  </ejb-ref>
+</application>

Added: 
maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-085/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-085/pom.xml?rev=1648055&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-085/pom.xml
 (added)
+++ 
maven/plugins/trunk/maven-ear-plugin/src/test/resources/projects/project-085/pom.xml
 Sat Dec 27 14:59:45 2014
@@ -0,0 +1,79 @@
+<?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-085</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>
+          <envEntries>
+            <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>
+          </envEntries>
+          <ejbRefs>
+                 <ejb-ref>
+                               <description>A description test</description>
+                               <ejb-ref-name>first-name</ejb-ref-name>
+                               <ejb-ref-type>java.lang.String</ejb-ref-type>
+                               <lookup-name>java-test</lookup-name>
+                 </ejb-ref>
+          </ejbRefs>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>


Reply via email to