tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject [1/2] tomee git commit: TOMEE-1578 more clever merge of tomee.xml to add deployment 'apps' in tomee maven plugin
Date Tue, 05 May 2015 15:45:31 GMT
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 <rmannibucau@apache.org>
Authored: Tue May 5 17:45:15 2015 +0200
Committer: Romain Manni-Bucau <rmannibucau@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());


Mime
View raw message