You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2015/05/05 17:45:31 UTC

[1/2] tomee git commit: TOMEE-1578 more clever merge of tomee.xml to add deployment 'apps' in tomee maven plugin

Repository: tomee
Updated Branches:
  refs/heads/master 4aa900ca5 -> 87a2991de


TOMEE-1578 more clever merge of tomee.xml to add deployment 'apps' in tomee maven plugin


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/de6fa1cb
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/de6fa1cb
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/de6fa1cb

Branch: refs/heads/master
Commit: de6fa1cba4bcde9e6b35578fe4bd541e23b59b6c
Parents: 4aa900c
Author: Romain Manni-Bucau <rm...@apache.org>
Authored: Tue May 5 17:45:15 2015 +0200
Committer: Romain Manni-Bucau <rm...@apache.org>
Committed: Tue May 5 17:45:15 2015 +0200

----------------------------------------------------------------------
 .../openejb/maven/plugin/AbstractTomEEMojo.java | 52 +++++++++++++++++---
 .../maven/plugin/TomEEMavenPluginRule.java      |  4 +-
 2 files changed, 49 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/de6fa1cb/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/AbstractTomEEMojo.java
----------------------------------------------------------------------
diff --git a/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/AbstractTomEEMojo.java b/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/AbstractTomEEMojo.java
index 6c8b412..6149ce2 100644
--- a/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/AbstractTomEEMojo.java
+++ b/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/AbstractTomEEMojo.java
@@ -31,8 +31,12 @@ import org.apache.maven.plugins.annotations.Component;
 import org.apache.maven.plugins.annotations.Parameter;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.settings.Settings;
+import org.apache.openejb.OpenEJBException;
 import org.apache.openejb.OpenEJBRuntimeException;
 import org.apache.openejb.config.RemoteServer;
+import org.apache.openejb.config.sys.Deployments;
+import org.apache.openejb.config.sys.JaxbOpenejb;
+import org.apache.openejb.config.sys.Openejb;
 import org.apache.openejb.loader.Files;
 import org.apache.openejb.loader.IO;
 import org.apache.openejb.loader.Zips;
@@ -329,12 +333,24 @@ public abstract class AbstractTomEEMojo extends AbstractAddressMojo {
     @Parameter
     protected List<File> externalRepositories;
 
+    /**
+     * server.xml configured inlined (is Server tag is the first child of inlinedServerXml)
+     */
     @Parameter
     protected PlexusConfiguration inlinedServerXml;
 
+    /**
+     * tomee.xml configured inlined (is tomee tag is the first child of inlinedTomEEXml)
+     */
     @Parameter
     protected PlexusConfiguration inlinedTomEEXml;
 
+    /**
+     * if a file is already there when unpacking tomee zip should it be overriden?
+     */
+    @Parameter(property = "tomee-plugin.override-on-unzip", defaultValue = "true")
+    protected boolean overrideOnUnzip;
+
     protected File deployedFile = null;
     protected RemoteServer server = null;
     protected String container = TOM_EE;
@@ -1272,6 +1288,8 @@ public abstract class AbstractTomEEMojo extends AbstractAddressMojo {
                             || (!parent.canRead() && !parent.setReadable(true))) {
                         throw new RuntimeException("Failed to create or set permissions on: " + parent);
                     }
+                } else if (!overrideOnUnzip) {
+                    continue;
                 }
                 if (entry.isDirectory()) {
                     if (!dest.exists() && !dest.mkdir()) {
@@ -1330,13 +1348,35 @@ public abstract class AbstractTomEEMojo extends AbstractAddressMojo {
                 && (
                 (apps != null && !apps.isEmpty())
                         || (!"pom".equals(packaging) && !"war".equals(packaging))))) { // webapps doesn't need apps folder in tomee
-            final FileWriter writer = new FileWriter(file);
             final String rootTag = container.toLowerCase(Locale.ENGLISH);
-            writer.write("<?xml version=\"1.0\"?>\n" +
-                    "<" + rootTag + ">\n" +
-                    "  <Deployments dir=\"apps\" />\n" +
-                    "</" + rootTag + ">\n");
-            writer.close();
+            if (file.isFile())  { // can be not existing since we dont always deploy tomee but shouldn't since then apps/ is not guaranteed to work
+                try {
+                    final Openejb jaxb = JaxbOpenejb.readConfig(file.getAbsolutePath());
+                    boolean needAdd = true;
+                    for (final Deployments d : jaxb.getDeployments()) {
+                        if ("apps".equals(d.getDir())) {
+                            needAdd = false;
+                            break;
+                        }
+                    }
+                    if (needAdd) {
+                        final String content = IO.slurp(file);
+                        final FileWriter writer = new FileWriter(file);
+                        final String end = "</" + rootTag + ">";
+                        writer.write(content.replace(end, "  <Deployments dir=\"apps\" />\n" + end));
+                        writer.close();
+                    }
+                } catch (final OpenEJBException e) {
+                    throw new IllegalStateException("illegal tomee.xml:\n" + IO.slurp(file), e);
+                }
+            } else {
+                final FileWriter writer = new FileWriter(file);
+                writer.write("<?xml version=\"1.0\"?>\n" +
+                        "<" + rootTag + ">\n" +
+                        "  <Deployments dir=\"apps\" />\n" +
+                        "</" + rootTag + ">\n");
+                writer.close();
+            }
 
             final File appsFolder = new File(catalinaBase, "apps");
             if (!appsFolder.exists() && !appsFolder.mkdirs()) {

http://git-wip-us.apache.org/repos/asf/tomee/blob/de6fa1cb/maven/tomee-maven-plugin/src/test/java/org/apache/openejb/maven/plugin/TomEEMavenPluginRule.java
----------------------------------------------------------------------
diff --git a/maven/tomee-maven-plugin/src/test/java/org/apache/openejb/maven/plugin/TomEEMavenPluginRule.java b/maven/tomee-maven-plugin/src/test/java/org/apache/openejb/maven/plugin/TomEEMavenPluginRule.java
index e898dbd..b8d4e48 100644
--- a/maven/tomee-maven-plugin/src/test/java/org/apache/openejb/maven/plugin/TomEEMavenPluginRule.java
+++ b/maven/tomee-maven-plugin/src/test/java/org/apache/openejb/maven/plugin/TomEEMavenPluginRule.java
@@ -73,7 +73,7 @@ assertThat(IO.slurp(new URL(url + "/docs")), containsString("Apache Tomcat"));
  */
 public class TomEEMavenPluginRule implements MethodRule {
     @Override
-    public Statement apply(final Statement base, final FrameworkMethod method, final Object target) {
+    public Statement apply(final Statement base, final FrameworkMethod ignored, final Object target) {
         return new RunTest(target, base);
     }
 
@@ -211,6 +211,8 @@ public class TomEEMavenPluginRule implements MethodRule {
         tomEEMojo.useConsole = true;
         tomEEMojo.checkStarted = true;
 
+        tomEEMojo.overrideOnUnzip = true;
+
         // we mock all the artifact resolution in test
         tomEEMojo.remoteRepos = new LinkedList<ArtifactRepository>();
         tomEEMojo.local = new DefaultArtifactRepository("local", tomEEMojo.settings.getLocalRepository(), new DefaultRepositoryLayout());


[2/2] tomee git commit: TOMEE-1578 more clever merge of tomee.xml to add deployment 'apps' in tomee maven plugin - the test

Posted by rm...@apache.org.
TOMEE-1578 more clever merge of tomee.xml to add deployment 'apps' in tomee maven plugin - the test


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/87a2991d
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/87a2991d
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/87a2991d

Branch: refs/heads/master
Commit: 87a2991dea31f569bb0d4260e6e8f60f617d1e49
Parents: de6fa1c
Author: Romain Manni-Bucau <rm...@apache.org>
Authored: Tue May 5 17:45:23 2015 +0200
Committer: Romain Manni-Bucau <rm...@apache.org>
Committed: Tue May 5 17:45:23 2015 +0200

----------------------------------------------------------------------
 .../maven/plugin/PreconfiguredTomEEXMlTest.java | 68 ++++++++++++++++++++
 1 file changed, 68 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/87a2991d/maven/tomee-maven-plugin/src/test/java/org/apache/openejb/maven/plugin/PreconfiguredTomEEXMlTest.java
----------------------------------------------------------------------
diff --git a/maven/tomee-maven-plugin/src/test/java/org/apache/openejb/maven/plugin/PreconfiguredTomEEXMlTest.java b/maven/tomee-maven-plugin/src/test/java/org/apache/openejb/maven/plugin/PreconfiguredTomEEXMlTest.java
new file mode 100644
index 0000000..5c3cfba
--- /dev/null
+++ b/maven/tomee-maven-plugin/src/test/java/org/apache/openejb/maven/plugin/PreconfiguredTomEEXMlTest.java
@@ -0,0 +1,68 @@
+/*
+ * 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.
+ */
+package org.apache.openejb.maven.plugin;
+
+import org.apache.openejb.loader.Files;
+import org.apache.openejb.loader.IO;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.RuleChain;
+import org.junit.rules.TestRule;
+import org.junit.runner.Description;
+import org.junit.runners.model.Statement;
+
+import java.io.File;
+
+import static org.junit.Assert.assertEquals;
+
+public class PreconfiguredTomEEXMlTest {
+    @Rule
+    public TestRule TMPRule = RuleChain
+            .outerRule(new TestRule() {
+                @Override
+                public Statement apply(final Statement base, final Description description) {
+                    return new Statement() {
+                        @Override
+                        public void evaluate() throws Throwable {
+                            IO.writeString(
+                                    new File(Files.mkdirs(new File(PreconfiguredTomEEXMlTest.this.catalinaBase, "conf")), "tomee.xml"),
+                                    "<tomee><Resource id=\"foo\" type=\"DataSource\" /><Deployments dir=\"missing\" /></tomee>");
+                            base.evaluate();
+                        }
+                    };
+                }
+            })
+            .around(new TestRule() {
+                @Override
+                public Statement apply(final Statement base, final Description description) {
+                    return new TomEEMavenPluginRule().apply(base, null, PreconfiguredTomEEXMlTest.this);
+                }
+            });
+
+    @Config
+    public final File catalinaBase = new File("target/PreconfiguredTomEEXMlTest");
+
+    @Config
+    public final boolean overrideOnUnzip = false;
+
+    @Test
+    public void confIsCorrectEvenIfWeEnrichedTheTomEEXmlForApps() throws Exception {
+        assertEquals(
+                "<tomee><Resource id=\"foo\" type=\"DataSource\" /><Deployments dir=\"missing\" />  <Deployments dir=\"apps\" /></tomee>",
+                IO.slurp(new File(catalinaBase, "conf/tomee.xml")).replace("\n", "").replace("\r", ""));
+    }
+}