tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject tomee git commit: TOMEE-1539 inliedServerXml config for tomee mvn plugins
Date Fri, 03 Apr 2015 11:24:53 GMT
Repository: tomee
Updated Branches:
  refs/heads/master fe957d9bd -> 7d6b82dfb


TOMEE-1539 inliedServerXml config for tomee mvn plugins


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

Branch: refs/heads/master
Commit: 7d6b82dfb2d1d3c32460c4b22787cc06b6068629
Parents: fe957d9
Author: Romain Manni-Bucau <rmannibucau@apache.org>
Authored: Fri Apr 3 13:24:17 2015 +0200
Committer: Romain Manni-Bucau <rmannibucau@apache.org>
Committed: Fri Apr 3 13:24:17 2015 +0200

----------------------------------------------------------------------
 .../apache/openejb/maven/util/XmlFormatter.java | 65 ++++++++++++++++++++
 .../openejb/maven/util/XmlFormatterTest.java    | 14 +++++
 .../maven/plugins/TomEEEmbeddedMojo.java        | 22 ++++++-
 maven/tomee-maven-plugin/pom.xml                |  5 ++
 .../openejb/maven/plugin/AbstractTomEEMojo.java | 15 +++++
 5 files changed, 120 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/7d6b82df/maven/maven-util/src/main/java/org/apache/openejb/maven/util/XmlFormatter.java
----------------------------------------------------------------------
diff --git a/maven/maven-util/src/main/java/org/apache/openejb/maven/util/XmlFormatter.java
b/maven/maven-util/src/main/java/org/apache/openejb/maven/util/XmlFormatter.java
new file mode 100644
index 0000000..7d36f13
--- /dev/null
+++ b/maven/maven-util/src/main/java/org/apache/openejb/maven/util/XmlFormatter.java
@@ -0,0 +1,65 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.util;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.bootstrap.DOMImplementationRegistry;
+import org.w3c.dom.ls.DOMImplementationLS;
+import org.w3c.dom.ls.LSOutput;
+import org.w3c.dom.ls.LSSerializer;
+import org.xml.sax.InputSource;
+
+import java.io.StringReader;
+import java.io.StringWriter;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+public final class XmlFormatter {
+    public static String format(final String in) {
+        try {
+            final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+            final DocumentBuilder db = dbf.newDocumentBuilder();
+            final InputSource is = new InputSource(new StringReader(in));
+            final Document document = db.parse(is);
+
+            final DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
+            final DOMImplementationLS impl = DOMImplementationLS.class.cast(registry.getDOMImplementation("XML
3.0 LS 3.0"));
+            if (impl == null) {
+                return in;
+            }
+
+            final LSSerializer serializer = impl.createLSSerializer();
+            if (serializer.getDomConfig().canSetParameter("format-pretty-print", Boolean.TRUE))
{
+                serializer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE);
+                final LSOutput lsOutput = impl.createLSOutput();
+                lsOutput.setEncoding("UTF-8");
+                final StringWriter stringWriter = new StringWriter();
+                lsOutput.setCharacterStream(stringWriter);
+                serializer.write(document, lsOutput);
+                return stringWriter.toString();
+            }
+
+            return in;
+        } catch (final Throwable t) {
+            return in; // just to be more sexy so ignore it and use ugly xml
+        }
+    }
+
+    private XmlFormatter() {
+        // no-op
+    }
+}

http://git-wip-us.apache.org/repos/asf/tomee/blob/7d6b82df/maven/maven-util/src/test/java/org/apache/openejb/maven/util/XmlFormatterTest.java
----------------------------------------------------------------------
diff --git a/maven/maven-util/src/test/java/org/apache/openejb/maven/util/XmlFormatterTest.java
b/maven/maven-util/src/test/java/org/apache/openejb/maven/util/XmlFormatterTest.java
new file mode 100644
index 0000000..9f41522
--- /dev/null
+++ b/maven/maven-util/src/test/java/org/apache/openejb/maven/util/XmlFormatterTest.java
@@ -0,0 +1,14 @@
+package org.apache.openejb.maven.util;
+
+import org.junit.Test;
+
+public class XmlFormatterTest {
+    @Test
+    public void format() {
+        System.out.println(XmlFormatter.format("" +
+                "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
+                "<root>\n" +
+                "    <foo id=\"bar\"/>\n" +
+                "</root>"));
+    }
+}

http://git-wip-us.apache.org/repos/asf/tomee/blob/7d6b82df/maven/tomee-embedded-maven-plugin/src/main/java/org/apache/openejb/maven/plugins/TomEEEmbeddedMojo.java
----------------------------------------------------------------------
diff --git a/maven/tomee-embedded-maven-plugin/src/main/java/org/apache/openejb/maven/plugins/TomEEEmbeddedMojo.java
b/maven/tomee-embedded-maven-plugin/src/main/java/org/apache/openejb/maven/plugins/TomEEEmbeddedMojo.java
index 371b7a2..a5eff6f 100644
--- a/maven/tomee-embedded-maven-plugin/src/main/java/org/apache/openejb/maven/plugins/TomEEEmbeddedMojo.java
+++ b/maven/tomee-embedded-maven-plugin/src/main/java/org/apache/openejb/maven/plugins/TomEEEmbeddedMojo.java
@@ -39,6 +39,8 @@ import org.apache.openejb.maven.util.MavenLogStreamFactory;
 import org.apache.openejb.util.JuliLogStreamFactory;
 import org.apache.tomee.embedded.Configuration;
 import org.apache.tomee.embedded.Container;
+import org.codehaus.plexus.configuration.PlexusConfiguration;
+import org.codehaus.plexus.util.FileUtils;
 
 import java.io.File;
 import java.lang.reflect.Field;
@@ -176,6 +178,12 @@ public class TomEEEmbeddedMojo extends AbstractMojo {
     @Parameter(property = "tomee-plugin.application-copy", defaultValue = "${project.build.directory}/tomee-embedded/applications")
     private File applicationCopyFolder;
 
+    @Parameter(property = "tomee-plugin.work", defaultValue = "${project.build.directory}/tomee-embedded-work")
+    private File workDir;
+
+    @Parameter
+    protected PlexusConfiguration inlinedServerXml;
+
     @Override
     public void execute() throws MojoExecutionException, MojoFailureException {
         if (!classpathAsWar && "pom".equals(packaging)) {
@@ -200,6 +208,19 @@ public class TomEEEmbeddedMojo extends AbstractMojo {
             System.setProperty("openejb.jul.forceReload", "true");
         }
 
+        if (inlinedServerXml != null && inlinedServerXml.getChildCount() > 0)
{
+            if (serverXml != null && serverXml.exists()) {
+                throw new MojoFailureException("you can't define a server.xml and an inlinedServerXml");
+            }
+            try {
+                FileUtils.forceMkdir(workDir);
+                serverXml = new File(workDir, "server.xml_dump");
+                FileUtils.fileWrite(serverXml, inlinedServerXml.getChild(0).toString());
+            } catch (final Exception e) {
+                throw new MojoExecutionException(e.getMessage(), e);
+            }
+        }
+
         final Container container = new Container();
         final Configuration config = getConfig();
         container.setup(config);
@@ -391,7 +412,6 @@ public class TomEEEmbeddedMojo extends AbstractMojo {
             } catch (final Exception e) {
                 getLog().warn("can't initialize attribute " + field.getName());
             }
-
         }
         if (containerProperties != null) {
             final Properties props = new Properties();

http://git-wip-us.apache.org/repos/asf/tomee/blob/7d6b82df/maven/tomee-maven-plugin/pom.xml
----------------------------------------------------------------------
diff --git a/maven/tomee-maven-plugin/pom.xml b/maven/tomee-maven-plugin/pom.xml
index 7c4d5bb..5404e56 100644
--- a/maven/tomee-maven-plugin/pom.xml
+++ b/maven/tomee-maven-plugin/pom.xml
@@ -70,6 +70,11 @@
       <groupId>org.apache.commons</groupId>
       <artifactId>commons-compress</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.openejb.maven</groupId>
+      <artifactId>maven-util</artifactId>
+      <version>${project.version}</version>
+    </dependency>
 
     <dependency>
       <groupId>org.apache.openejb</groupId>

http://git-wip-us.apache.org/repos/asf/tomee/blob/7d6b82df/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 d28f204..1bb887c 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
@@ -37,9 +37,12 @@ import org.apache.openejb.loader.Files;
 import org.apache.openejb.loader.IO;
 import org.apache.openejb.loader.Zips;
 import org.apache.openejb.maven.plugin.cli.Args;
+import org.apache.openejb.maven.util.XmlFormatter;
 import org.apache.openejb.util.Join;
 import org.apache.openejb.util.OpenEjbVersion;
 import org.apache.tomee.util.QuickServerXmlParser;
+import org.codehaus.plexus.configuration.PlexusConfiguration;
+import org.codehaus.plexus.util.FileUtils;
 
 import java.io.BufferedInputStream;
 import java.io.BufferedOutputStream;
@@ -326,6 +329,9 @@ public abstract class AbstractTomEEMojo extends AbstractAddressMojo {
     @Parameter
     protected List<File> externalRepositories;
 
+    @Parameter
+    protected PlexusConfiguration inlinedServerXml;
+
     protected File deployedFile = null;
     protected RemoteServer server = null;
     protected String container = TOM_EE;
@@ -374,6 +380,15 @@ public abstract class AbstractTomEEMojo extends AbstractAddressMojo {
                 activateSimpleLog();
             }
 
+            if (inlinedServerXml != null && inlinedServerXml.getChildCount() >
0) {
+                final File serverXml = new File(catalinaBase, "conf/server.xml");
+                try {
+                    FileUtils.forceMkdir(serverXml.getParentFile());
+                    FileUtils.fileWrite(serverXml, XmlFormatter.format(inlinedServerXml.getChild(0).toString()));
+                } catch (final Exception e) {
+                    throw new MojoExecutionException(e.getMessage(), e);
+                }
+            }
             if (!keepServerXmlAsthis) {
                 overrideAddresses();
             }


Mime
View raw message