You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by gd...@apache.org on 2006/09/30 14:54:31 UTC

svn commit: r451591 - in /geronimo/server/trunk/maven-plugins: ./ car-maven-plugin/ car-maven-plugin/src/main/java/org/apache/geronimo/plugin/car/ car-maven-plugin/src/test/ car-maven-plugin/src/test/java/ car-maven-plugin/src/test/java/org/ car-maven-...

Author: gdamour
Date: Sat Sep 30 05:54:30 2006
New Revision: 451591

URL: http://svn.apache.org/viewvc?view=rev&rev=451591
Log:
GERONIMO-2453 - car-maven-plugin does not support empty plans

In the case of an empty document, the XmlCursor needs to be moved to the
end of the empty node such that XmlCursor.beginElement inserts inside it.

Added:
    geronimo/server/trunk/maven-plugins/car-maven-plugin/src/test/
    geronimo/server/trunk/maven-plugins/car-maven-plugin/src/test/java/
    geronimo/server/trunk/maven-plugins/car-maven-plugin/src/test/java/org/
    geronimo/server/trunk/maven-plugins/car-maven-plugin/src/test/java/org/apache/
    geronimo/server/trunk/maven-plugins/car-maven-plugin/src/test/java/org/apache/geronimo/
    geronimo/server/trunk/maven-plugins/car-maven-plugin/src/test/java/org/apache/geronimo/plugin/
    geronimo/server/trunk/maven-plugins/car-maven-plugin/src/test/java/org/apache/geronimo/plugin/car/
    geronimo/server/trunk/maven-plugins/car-maven-plugin/src/test/java/org/apache/geronimo/plugin/car/PlanProcessorMojoTest.java
    geronimo/server/trunk/maven-plugins/car-maven-plugin/src/test/resources/
    geronimo/server/trunk/maven-plugins/car-maven-plugin/src/test/resources/empty-plan.xml
    geronimo/server/trunk/maven-plugins/car-maven-plugin/src/test/resources/expected-empty-plan.xml
    geronimo/server/trunk/maven-plugins/car-maven-plugin/src/test/resources/expected-no-env-plan.xml
    geronimo/server/trunk/maven-plugins/car-maven-plugin/src/test/resources/no-env-plan.xml
Modified:
    geronimo/server/trunk/maven-plugins/car-maven-plugin/pom.xml
    geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/plugin/car/PlanProcessorMojo.java
    geronimo/server/trunk/maven-plugins/pom.xml

Modified: geronimo/server/trunk/maven-plugins/car-maven-plugin/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/maven-plugins/car-maven-plugin/pom.xml?view=diff&rev=451591&r1=451590&r2=451591
==============================================================================
--- geronimo/server/trunk/maven-plugins/car-maven-plugin/pom.xml (original)
+++ geronimo/server/trunk/maven-plugins/car-maven-plugin/pom.xml Sat Sep 30 05:54:30 2006
@@ -75,6 +75,15 @@
             <version>2.2</version>
         </dependency>
         
+<!--
+        <dependency>
+            <groupId>org.apache.maven</groupId>
+            <artifactId>maven-project</artifactId>
+            <version>2.0.4</version>
+            <scope>test</scope>
+        </dependency>
+-->
+
         <dependency>
             <groupId>velocity</groupId>
             <artifactId>velocity</artifactId>

Modified: geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/plugin/car/PlanProcessorMojo.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/plugin/car/PlanProcessorMojo.java?view=diff&rev=451591&r1=451590&r2=451591
==============================================================================
--- geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/plugin/car/PlanProcessorMojo.java (original)
+++ geronimo/server/trunk/maven-plugins/car-maven-plugin/src/main/java/org/apache/geronimo/plugin/car/PlanProcessorMojo.java Sat Sep 30 05:54:30 2006
@@ -43,6 +43,7 @@
 import org.apache.xmlbeans.XmlCursor;
 import org.apache.xmlbeans.XmlObject;
 import org.apache.xmlbeans.XmlOptions;
+import org.apache.xmlbeans.XmlCursor.TokenType;
 
 //
 // TODO: Rename to PreparePlanMojo
@@ -66,25 +67,25 @@
      * @parameter expression="${basedir}/src/plan"
      * @required
      */
-    private File sourceDir = null;
+    protected File sourceDir = null;
 
     /**
      * @parameter expression="${project.build.directory}/plan"
      * @required
      */
-    private File targetDir = null;
+    protected File targetDir = null;
 
     /**
      * @parameter default-value="plan.xml"
      * @required
      */
-    private String planFileName = null;
+    protected String planFileName = null;
 
     /**
      * @parameter expression="${project.build.directory}/plan/plan.xml"
      * @required
      */
-    private File targetFile = null;
+    protected File targetFile = null;
 
     private VelocityContext createContext() {
         VelocityContext context = new VelocityContext();
@@ -152,19 +153,23 @@
     }
 
     void mergeEnvironment(final XmlCursor xmlCursor, final Artifact configId, final LinkedHashSet dependencies) {
-        xmlCursor.toFirstContentToken();
-        xmlCursor.toFirstChild();
+        moveToFirstStartElement(xmlCursor);
+
+        boolean atLeastOneChild = xmlCursor.toFirstChild();
+        if (!atLeastOneChild) {
+            // this is an empty element. Move to EndToken such XmlCursor.beginElement inserts an element inside it.
+            xmlCursor.toEndToken();
+        }
         QName childName = xmlCursor.getName();
         Environment oldEnvironment;
-
+        
         if (childName != null && childName.getLocalPart().equals(ENVIRONMENT_LOCAL_NAME)) {
             convertElement(xmlCursor, ENVIRONMENT_QNAME.getNamespaceURI());
             XmlObject xmlObject = xmlCursor.getObject();
             EnvironmentType environmentType = (EnvironmentType) xmlObject.copy().changeType(EnvironmentType.type);
             oldEnvironment = EnvironmentBuilder.buildEnvironment(environmentType);
             xmlCursor.removeXml();
-        }
-        else {
+        } else {
             oldEnvironment = new Environment();
         }
 
@@ -183,6 +188,19 @@
         }
         finally {
             element.dispose();
+        }
+    }
+
+    private void moveToFirstStartElement(XmlCursor xmlCursor) throws AssertionError {
+        xmlCursor.toStartDoc();
+        xmlCursor.toFirstChild();
+        while (!xmlCursor.currentTokenType().isStart()) {            
+            if (!xmlCursor.toNextSibling()) {
+                break;
+            }
+        } 
+        if (!xmlCursor.currentTokenType().isStart()) {
+            throw new AssertionError("Cannot find first start element");
         }
     }
 

Added: geronimo/server/trunk/maven-plugins/car-maven-plugin/src/test/java/org/apache/geronimo/plugin/car/PlanProcessorMojoTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/maven-plugins/car-maven-plugin/src/test/java/org/apache/geronimo/plugin/car/PlanProcessorMojoTest.java?view=auto&rev=451591
==============================================================================
--- geronimo/server/trunk/maven-plugins/car-maven-plugin/src/test/java/org/apache/geronimo/plugin/car/PlanProcessorMojoTest.java (added)
+++ geronimo/server/trunk/maven-plugins/car-maven-plugin/src/test/java/org/apache/geronimo/plugin/car/PlanProcessorMojoTest.java Sat Sep 30 05:54:30 2006
@@ -0,0 +1,87 @@
+/**
+ *
+ * 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.
+ */
+package org.apache.geronimo.plugin.car;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+
+import org.apache.geronimo.testsupport.TestSupport;
+import org.apache.maven.model.Model;
+import org.apache.maven.plugin.logging.SystemStreamLog;
+import org.apache.maven.project.MavenProject;
+
+/**
+ * @version $Rev: 433457 $ $Date: 2006-08-22 11:40:18 +1000 (Tue, 22 Aug 2006) $
+ */
+public class PlanProcessorMojoTest extends TestSupport {
+
+    private PlanProcessorMojo processorMojo;
+
+    protected void setUp() throws Exception {
+        processorMojo = new PlanProcessorMojoTester();
+        Model model = new Model();
+        MavenProject mavenProject = new MavenProject(model);
+        mavenProject.setGroupId("dummy-group");
+        mavenProject.setArtifactId("dummy-artifact-id");
+        mavenProject.setVersion("dummy-version");
+        processorMojo.project = mavenProject;
+        processorMojo.sourceDir = new File(BASEDIR, "src/test/resources");
+        processorMojo.targetDir = new File(BASEDIR, "target/PlanProcessorMojoTest");
+    }
+    
+    public void testEmptyPlanProcessing() throws Exception {
+        String planName = "empty-plan.xml";
+        processorMojo.planFileName = planName;
+        processorMojo.targetFile = new File(processorMojo.targetDir, "actual-" + planName);
+        
+        processorMojo.doExecute();
+        
+        assertResultingPlan(planName);
+    }
+
+    public void testNoEnvironmentPlanProcessing() throws Exception {
+        String planName = "no-env-plan.xml";
+        processorMojo.planFileName = planName;
+        processorMojo.targetFile = new File(processorMojo.targetDir, "actual-" + planName);
+        
+        processorMojo.doExecute();
+        
+        assertResultingPlan(planName);
+    }
+
+    private void assertResultingPlan(String planName) throws Exception {
+        InputStream expectedIn = new FileInputStream(new File(processorMojo.sourceDir, "expected-" + planName));
+        InputStream actualIn = new FileInputStream(new File(processorMojo.targetDir, "actual-" + planName));
+        
+        int read;
+        while (-1 == (read = expectedIn.read())) {
+            int actualRead = actualIn.read();
+            if (-1 == actualRead) {
+                fail();
+            }
+            assertEquals(read, actualRead);
+        }
+    }
+    
+    private class PlanProcessorMojoTester extends PlanProcessorMojo {
+        public PlanProcessorMojoTester() {
+            log = new SystemStreamLog();
+        }
+    }
+    
+}

Added: geronimo/server/trunk/maven-plugins/car-maven-plugin/src/test/resources/empty-plan.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/maven-plugins/car-maven-plugin/src/test/resources/empty-plan.xml?view=auto&rev=451591
==============================================================================
--- geronimo/server/trunk/maven-plugins/car-maven-plugin/src/test/resources/empty-plan.xml (added)
+++ geronimo/server/trunk/maven-plugins/car-maven-plugin/src/test/resources/empty-plan.xml Sat Sep 30 05:54:30 2006
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+
+<!-- $Rev: 446730 $ $Date: 2006-09-16 06:44:51 +1000 (Sat, 16 Sep 2006) $ -->
+
+<module xmlns="http://geronimo.apache.org/xml/ns/deployment-1.1">
+</module>

Added: geronimo/server/trunk/maven-plugins/car-maven-plugin/src/test/resources/expected-empty-plan.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/maven-plugins/car-maven-plugin/src/test/resources/expected-empty-plan.xml?view=auto&rev=451591
==============================================================================
--- geronimo/server/trunk/maven-plugins/car-maven-plugin/src/test/resources/expected-empty-plan.xml (added)
+++ geronimo/server/trunk/maven-plugins/car-maven-plugin/src/test/resources/expected-empty-plan.xml Sat Sep 30 05:54:30 2006
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--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.-->
+<!--$Rev: 446730 $ $Date: 2006-09-16 06:44:51 +1000 (Sat, 16 Sep 2006) $-->
+<module xmlns="http://geronimo.apache.org/xml/ns/deployment-1.1">
+  <dep:environment xmlns:dep="http://geronimo.apache.org/xml/ns/deployment-1.2">
+    <dep:moduleId>
+      <dep:groupId>dummy-group</dep:groupId>
+      <dep:artifactId>dummy-artifact-id</dep:artifactId>
+      <dep:version>dummy-version</dep:version>
+      <dep:type>car</dep:type>
+    </dep:moduleId>
+    <dep:dependencies/>
+    <dep:hidden-classes/>
+    <dep:non-overridable-classes/>
+  </dep:environment>
+</module>
\ No newline at end of file

Added: geronimo/server/trunk/maven-plugins/car-maven-plugin/src/test/resources/expected-no-env-plan.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/maven-plugins/car-maven-plugin/src/test/resources/expected-no-env-plan.xml?view=auto&rev=451591
==============================================================================
--- geronimo/server/trunk/maven-plugins/car-maven-plugin/src/test/resources/expected-no-env-plan.xml (added)
+++ geronimo/server/trunk/maven-plugins/car-maven-plugin/src/test/resources/expected-no-env-plan.xml Sat Sep 30 05:54:30 2006
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--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.-->
+<!--$Rev: 446730 $ $Date: 2006-09-16 06:44:51 +1000 (Sat, 16 Sep 2006) $-->
+<module xmlns="http://geronimo.apache.org/xml/ns/deployment-1.1">
+  <dep:environment xmlns:dep="http://geronimo.apache.org/xml/ns/deployment-1.2">
+    <dep:moduleId>
+      <dep:groupId>dummy-group</dep:groupId>
+      <dep:artifactId>dummy-artifact-id</dep:artifactId>
+      <dep:version>dummy-version</dep:version>
+      <dep:type>car</dep:type>
+    </dep:moduleId>
+    <dep:dependencies/>
+    <dep:hidden-classes/>
+    <dep:non-overridable-classes/>
+  </dep:environment>
+  <node/>
+</module>
\ No newline at end of file

Added: geronimo/server/trunk/maven-plugins/car-maven-plugin/src/test/resources/no-env-plan.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/maven-plugins/car-maven-plugin/src/test/resources/no-env-plan.xml?view=auto&rev=451591
==============================================================================
--- geronimo/server/trunk/maven-plugins/car-maven-plugin/src/test/resources/no-env-plan.xml (added)
+++ geronimo/server/trunk/maven-plugins/car-maven-plugin/src/test/resources/no-env-plan.xml Sat Sep 30 05:54:30 2006
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+
+<!-- $Rev: 446730 $ $Date: 2006-09-16 06:44:51 +1000 (Sat, 16 Sep 2006) $ -->
+
+<module xmlns="http://geronimo.apache.org/xml/ns/deployment-1.1">
+    <node />
+</module>

Modified: geronimo/server/trunk/maven-plugins/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/maven-plugins/pom.xml?view=diff&rev=451591&r1=451590&r2=451591
==============================================================================
--- geronimo/server/trunk/maven-plugins/pom.xml (original)
+++ geronimo/server/trunk/maven-plugins/pom.xml Sat Sep 30 05:54:30 2006
@@ -36,6 +36,13 @@
     <dependencies>
         
         <dependency>
+            <groupId>org.apache.geronimo.testsupport</groupId> 
+            <artifactId>testsupport-common</artifactId>
+            <version>${pom.version}</version> 
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
             <groupId>org.apache.geronimo.genesis.plugins</groupId>
             <artifactId>plugin-support</artifactId>
         </dependency>