Author: khmarbaise
Date: Tue Dec 29 11:41:23 2015
New Revision: 1722108

URL: http://svn.apache.org/viewvc?rev=1722108&view=rev
Log:
[MEJB-93] Prevent re-adding of main artifact twice

 o Main artifact will be checked if it exists already. This
   will prevent replacing main artifact by a second execution
   of the plugin. Added an appropriate integration test.

Added:
    maven/plugins/trunk/maven-ejb-plugin/src/it/mejb-93/
    maven/plugins/trunk/maven-ejb-plugin/src/it/mejb-93/invoker.properties
    maven/plugins/trunk/maven-ejb-plugin/src/it/mejb-93/pom.xml
    maven/plugins/trunk/maven-ejb-plugin/src/it/mejb-93/src/
    maven/plugins/trunk/maven-ejb-plugin/src/it/mejb-93/src/main/
    maven/plugins/trunk/maven-ejb-plugin/src/it/mejb-93/src/main/java/
    maven/plugins/trunk/maven-ejb-plugin/src/it/mejb-93/src/main/java/org/
    
maven/plugins/trunk/maven-ejb-plugin/src/it/mejb-93/src/main/java/org/apache/
    
maven/plugins/trunk/maven-ejb-plugin/src/it/mejb-93/src/main/java/org/apache/maven/
    
maven/plugins/trunk/maven-ejb-plugin/src/it/mejb-93/src/main/java/org/apache/maven/it0017/
    
maven/plugins/trunk/maven-ejb-plugin/src/it/mejb-93/src/main/java/org/apache/maven/it0017/Person.java
    maven/plugins/trunk/maven-ejb-plugin/src/it/mejb-93/src/main/resources/
    
maven/plugins/trunk/maven-ejb-plugin/src/it/mejb-93/src/main/resources/META-INF/
    
maven/plugins/trunk/maven-ejb-plugin/src/it/mejb-93/src/main/resources/META-INF/ejb-jar.xml
    maven/plugins/trunk/maven-ejb-plugin/src/it/mejb-93/verify.groovy
Modified:
    
maven/plugins/trunk/maven-ejb-plugin/src/main/java/org/apache/maven/plugins/ejb/EjbMojo.java

Added: maven/plugins/trunk/maven-ejb-plugin/src/it/mejb-93/invoker.properties
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ejb-plugin/src/it/mejb-93/invoker.properties?rev=1722108&view=auto
==============================================================================
--- maven/plugins/trunk/maven-ejb-plugin/src/it/mejb-93/invoker.properties 
(added)
+++ maven/plugins/trunk/maven-ejb-plugin/src/it/mejb-93/invoker.properties Tue 
Dec 29 11:41:23 2015
@@ -0,0 +1,18 @@
+# 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.
+
+invoker.buildResult = failure

Added: maven/plugins/trunk/maven-ejb-plugin/src/it/mejb-93/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ejb-plugin/src/it/mejb-93/pom.xml?rev=1722108&view=auto
==============================================================================
--- maven/plugins/trunk/maven-ejb-plugin/src/it/mejb-93/pom.xml (added)
+++ maven/plugins/trunk/maven-ejb-plugin/src/it/mejb-93/pom.xml Tue Dec 29 
11:41:23 2015
@@ -0,0 +1,67 @@
+<?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>
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.its.ejb.default</groupId>
+  <artifactId>maven-it-mejb93</artifactId>
+  <version>1.0</version>
+  <packaging>ejb</packaging>
+
+  <name>Maven Integration Test :: MEJB 93</name> 
+  <description>MEJB-93: Prevent re-adding the main artifact a second 
time.</description>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <build>
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-maven-compiler-plugin</artifactId>
+          <version>1.3</version>
+        </plugin>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-ejb-plugin</artifactId>
+          <version>@project.version@</version>
+        </plugin>
+      </plugins>
+      </pluginManagement>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-ejb-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>second-execution</id>
+            <goals>
+              <goal>ejb</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Added: 
maven/plugins/trunk/maven-ejb-plugin/src/it/mejb-93/src/main/java/org/apache/maven/it0017/Person.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ejb-plugin/src/it/mejb-93/src/main/java/org/apache/maven/it0017/Person.java?rev=1722108&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-ejb-plugin/src/it/mejb-93/src/main/java/org/apache/maven/it0017/Person.java
 (added)
+++ 
maven/plugins/trunk/maven-ejb-plugin/src/it/mejb-93/src/main/java/org/apache/maven/it0017/Person.java
 Tue Dec 29 11:41:23 2015
@@ -0,0 +1,35 @@
+package org.apache.maven.it0017;
+
+/*
+ * 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.
+ */
+
+public class Person
+{
+    private String name;
+    
+    public void setName( String name )
+    {
+        this.name = name;
+    }
+    
+    public String getName()
+    {
+        return name;
+    }
+}

Added: 
maven/plugins/trunk/maven-ejb-plugin/src/it/mejb-93/src/main/resources/META-INF/ejb-jar.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ejb-plugin/src/it/mejb-93/src/main/resources/META-INF/ejb-jar.xml?rev=1722108&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-ejb-plugin/src/it/mejb-93/src/main/resources/META-INF/ejb-jar.xml
 (added)
+++ 
maven/plugins/trunk/maven-ejb-plugin/src/it/mejb-93/src/main/resources/META-INF/ejb-jar.xml
 Tue Dec 29 11:41:23 2015
@@ -0,0 +1,40 @@
+<?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.
+-->
+<ejb-jar>
+  <enterprise-beans>
+    <session>
+      <ejb-name>Hello</ejb-name>
+      <home>org.apache.maven.it0017.HelloHome</home>
+      <remote>org.apache.maven.it0017.Hello</remote>
+      <ejb-class>org.apache.maven.it0017.HelloBean</ejb-class>
+      <session-type>Stateless</session-type>
+      <transaction-type>Container</transaction-type>
+    </session>
+  </enterprise-beans>
+  <assembly-descriptor>
+    <container-transaction>
+      <method>
+        <ejb-name>Hello</ejb-name>
+        <method-name>*</method-name>
+      </method>
+      <trans-attribute>Required</trans-attribute>
+    </container-transaction>
+  </assembly-descriptor>
+</ejb-jar>
\ No newline at end of file

Added: maven/plugins/trunk/maven-ejb-plugin/src/it/mejb-93/verify.groovy
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ejb-plugin/src/it/mejb-93/verify.groovy?rev=1722108&view=auto
==============================================================================
--- maven/plugins/trunk/maven-ejb-plugin/src/it/mejb-93/verify.groovy (added)
+++ maven/plugins/trunk/maven-ejb-plugin/src/it/mejb-93/verify.groovy Tue Dec 
29 11:41:23 2015
@@ -0,0 +1,71 @@
+/*
+ * 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 java.io.*
+import java.util.*
+
+/**
+ * This will filter out the version of the
+ * maven-ejb-plugin which is configured
+ * within the integration test.
+ * @return Version information.
+ */
+def getProjectVersion() {
+    def pom = new XmlSlurper().parse(new File(basedir, 'pom.xml'))
+
+    def allPlugins = pom.build.pluginManagement.plugins.plugin
+
+    def mavenejb = allPlugins.find { item ->
+        item.groupId.equals("org.apache.maven.plugins") && 
item.artifactId.equals("maven-ejb-plugin")
+    }
+
+    return mavenejb.version;
+}
+
+def projectVersion = getProjectVersion();
+
+println "ProjectVersion:" + projectVersion
+
+
+def jarFile = new File( basedir, "target/maven-it-mejb93-1.0.jar" )
+if ( !jarFile.isFile() )
+{
+    println ( "FAILURE!" )
+    return false
+}
+
+def buildLog = new File( basedir, "build.log" ).getText('UTF-8')
+
+if (!buildLog.contains ('[INFO] --- maven-ejb-plugin:' + projectVersion + 
':ejb (default-ejb) @ maven-it-mejb93 ---')) {
+  println ( "default executions did not happen.")
+  return false
+}
+if (!buildLog.contains ('[INFO] --- maven-ejb-plugin:' + projectVersion + 
':ejb (second-execution) @ maven-it-mejb93 ---')) {
+  println ( "second executions did not happen.")
+  return false
+}
+if (!buildLog.contains ('[ERROR] Failed to execute goal 
org.apache.maven.plugins:maven-ejb-plugin:' + projectVersion 
+    + ':ejb (second-execution) on project maven-it-mejb93: ' 
+    + 'You have to use a classifier to attach supplemental artifacts to the ' 
+    + 'project instead of replacing them. -> [Help 1]')) {
+  println ( "exception message does not exists or the expected content does 
not exist.")
+  return false
+}
+
+return true;

Modified: 
maven/plugins/trunk/maven-ejb-plugin/src/main/java/org/apache/maven/plugins/ejb/EjbMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ejb-plugin/src/main/java/org/apache/maven/plugins/ejb/EjbMojo.java?rev=1722108&r1=1722107&r2=1722108&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-ejb-plugin/src/main/java/org/apache/maven/plugins/ejb/EjbMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-ejb-plugin/src/main/java/org/apache/maven/plugins/ejb/EjbMojo.java
 Tue Dec 29 11:41:23 2015
@@ -266,6 +266,10 @@ public class EjbMojo
     @Parameter( defaultValue = "${session}", readonly = true, required = true )
     private MavenSession session;
 
+    private static final String EJB_TYPE = "ejb";
+
+    private static final String EJB_CLIENT_TYPE = "ejb-client";
+
     /**
      * Generates an EJB jar and optionally an ejb-client jar.
      */
@@ -291,10 +295,18 @@ public class EjbMojo
                 throw new MojoExecutionException( message );
             }
 
-            projectHelper.attachArtifact( project, "ejb", getClassifier(), 
jarFile );
+            //TODO: We should check the attached artifacts to be sure we don't 
attach 
+            // the same file twice...
+            projectHelper.attachArtifact( project, EJB_TYPE, getClassifier(), 
jarFile );
         }
         else
         {
+            if ( projectHasAlreadySetAnArtifact() )
+            {
+                throw new MojoExecutionException( "You have to use a 
classifier "
+                    + "to attach supplemental artifacts to the project instead 
of replacing them." );
+            }
+
             project.getArtifact().setFile( jarFile );
         }
 
@@ -310,7 +322,7 @@ public class EjbMojo
                     throw new MojoExecutionException( message );
                 }
 
-                projectHelper.attachArtifact( project, "ejb-client", 
getClientClassifier(), clientJarFile );
+                projectHelper.attachArtifact( project, EJB_CLIENT_TYPE, 
getClientClassifier(), clientJarFile );
             }
             else
             {
@@ -322,6 +334,18 @@ public class EjbMojo
         }
     }
 
+    private boolean projectHasAlreadySetAnArtifact()
+    {
+        if ( getProject().getArtifact().getFile() != null )
+        {
+            return getProject().getArtifact().getFile().isFile();
+        }
+        else
+        {
+            return false;
+        }
+    }
+
     private File generateEjb()
         throws MojoExecutionException
     {
@@ -533,4 +557,9 @@ public class EjbMojo
         return clientClassifier;
     }
 
+    public MavenProject getProject()
+    {
+        return project;
+    }
+
 }


Reply via email to