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-1626 supporting port placeholder for build mojo command
Date Tue, 11 Aug 2015 14:13:37 GMT
Repository: tomee
Updated Branches:
  refs/heads/master 9c7f827c1 -> 5e3670aa4


TOMEE-1626 supporting port placeholder for build mojo command


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

Branch: refs/heads/master
Commit: 5e3670aa439283c61c9898706a9e9482fd3e54f7
Parents: 9c7f827
Author: Romain Manni-Bucau <rmannibu@gmail.com>
Authored: Tue Aug 11 07:13:29 2015 -0700
Committer: Romain Manni-Bucau <rmannibu@gmail.com>
Committed: Tue Aug 11 07:13:29 2015 -0700

----------------------------------------------------------------------
 .../maven/plugin/AbstractAddressMojo.java       |  2 +-
 .../maven/plugin/AbstractCommandMojo.java       |  2 +-
 .../openejb/maven/plugin/AbstractTomEEMojo.java | 44 +++++++-------------
 .../maven/plugin/TomEEMavenPluginRule.java      | 33 +++++++++++++--
 .../maven/plugin/test/PortPlaceholderTest.java  | 43 +++++++++++++++++++
 .../openejb/server/httpd/OpenEJBHttpServer.java |  4 +-
 6 files changed, 93 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/5e3670aa/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/AbstractAddressMojo.java
----------------------------------------------------------------------
diff --git a/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/AbstractAddressMojo.java
b/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/AbstractAddressMojo.java
index 1339b28..eede86a 100644
--- a/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/AbstractAddressMojo.java
+++ b/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/AbstractAddressMojo.java
@@ -22,7 +22,7 @@ import org.apache.maven.plugins.annotations.Parameter;
 
 public abstract class AbstractAddressMojo extends AbstractMojo {
     @Parameter(property = "tomee-plugin.http")
-    protected Integer tomeeHttpPort;
+    protected String tomeeHttpPort;
 
     @Parameter(property = "tomee-plugin.host")
     protected String tomeeHost;

http://git-wip-us.apache.org/repos/asf/tomee/blob/5e3670aa/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/AbstractCommandMojo.java
----------------------------------------------------------------------
diff --git a/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/AbstractCommandMojo.java
b/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/AbstractCommandMojo.java
index eecc1ae..6aa3489 100644
--- a/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/AbstractCommandMojo.java
+++ b/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/AbstractCommandMojo.java
@@ -24,7 +24,7 @@ import java.util.Properties;
 public abstract class AbstractCommandMojo extends AbstractAddressMojo {
     protected Object lookup(final String name) {
         if (tomeeHttpPort == null) {
-            tomeeHttpPort = 8080;
+            tomeeHttpPort = "8080";
         }
         if (tomeeHost == null) {
             tomeeHost = "localhost";

http://git-wip-us.apache.org/repos/asf/tomee/blob/5e3670aa/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 53d4a3e..9c4ce56 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
@@ -142,7 +142,7 @@ public abstract class AbstractTomEEMojo extends AbstractAddressMojo {
     protected String tomeeClassifier;
 
     @Parameter(property = "tomee-plugin.shutdown")
-    protected Integer tomeeShutdownPort;
+    protected String tomeeShutdownPort;
 
     @Parameter(property = "tomee-plugin.shutdown.attempts", defaultValue = "60")
     protected int tomeeShutdownAttempts;
@@ -151,10 +151,10 @@ public abstract class AbstractTomEEMojo extends AbstractAddressMojo
{
     protected String tomeeShutdownCommand;
 
     @Parameter(property = "tomee-plugin.ajp")
-    protected Integer tomeeAjpPort;
+    protected String tomeeAjpPort;
 
     @Parameter(property = "tomee-plugin.https")
-    protected Integer tomeeHttpsPort;
+    protected String tomeeHttpsPort;
 
     @Parameter(property = "tomee-plugin.args")
     protected String args;
@@ -503,22 +503,10 @@ public abstract class AbstractTomEEMojo extends AbstractAddressMojo
{
         final File sXml = new File(catalinaBase, "conf/server.xml");
         if (sXml.isFile()) {
             final QuickServerXmlParser quickServerXmlParser = QuickServerXmlParser.parse(sXml,
false);
-            final String http = quickServerXmlParser.value("HTTP", null);
-            if (http != null) {
-                tomeeHttpPort = Integer.parseInt(http);
-            }
-            final String https = quickServerXmlParser.value("HTTPS", null);
-            if (https != null) {
-                tomeeHttpsPort = Integer.parseInt(https);
-            }
-            final String ajp = quickServerXmlParser.value("AJP", null);
-            if (ajp != null) {
-                tomeeAjpPort = Integer.parseInt(ajp);
-            }
-            final String stop = quickServerXmlParser.value("STOP", null);
-            if (stop != null) {
-                tomeeShutdownPort = Integer.parseInt(stop);
-            }
+            tomeeHttpPort = quickServerXmlParser.value("HTTP", null);
+            tomeeHttpsPort = quickServerXmlParser.value("HTTPS", null);
+            tomeeAjpPort = quickServerXmlParser.value("AJP", null);
+            tomeeShutdownPort = quickServerXmlParser.value("STOP", null);
             final String host = quickServerXmlParser.value("host", null);
             if (host != null) {
                 tomeeHost = host;
@@ -559,8 +547,8 @@ public abstract class AbstractTomEEMojo extends AbstractAddressMojo {
             tomeeArtifactId = "openejb-standalone";
             tomeeClassifier = null;
             tomeeShutdownCommand = "Q";
-            if (8005 == tomeeShutdownPort) { // default admin port
-                tomeeShutdownPort = 4200;
+            if ("8005".equals(tomeeShutdownPort)) { // default admin port
+                tomeeShutdownPort = "4200";
             }
             if (tomeeVersion.startsWith("2.")) {
                 tomeeVersion = OpenEjbVersion.get().getVersion();
@@ -872,7 +860,7 @@ public abstract class AbstractTomEEMojo extends AbstractAddressMojo {
         final String original = read(serverXml);
         String value = original;
 
-        if (tomeeHttpsPort != null && tomeeHttpsPort > 0 && parser.value("HTTPS",
null) == null) {
+        if (tomeeHttpsPort != null && tomeeHttpsPort.length() > 0 && parser.value("HTTPS",
null) == null) {
             String keystorePath = keystore != null ? keystore : parser.keystore();
             if (keystorePath == null) {
                 final File conf = new File(catalinaBase, "conf");
@@ -903,16 +891,16 @@ public abstract class AbstractTomEEMojo extends AbstractAddressMojo
{
         }
 
         if (tomeeHttpPort != null) {
-            value = value.replace("\"" + parser.http() + '"', '"' + Integer.toString(tomeeHttpPort)
+ '"');
+            value = value.replace("\"" + parser.http() + '"', '"' + tomeeHttpPort + '"');
         }
         if (tomeeHttpsPort != null) {
-            value = value.replace("\"" + parser.https() + '"', '"' + Integer.toString(tomeeHttpsPort)
+ '"');
+            value = value.replace("\"" + parser.https() + '"', '"' + tomeeHttpsPort + '"');
         }
         if (tomeeAjpPort != null) {
-            value = value.replace("\"" + parser.ajp() + '"', '"' + Integer.toString(tomeeAjpPort)
+ '"');
+            value = value.replace("\"" + parser.ajp() + '"', '"' + tomeeAjpPort + '"');
         }
         if (tomeeShutdownPort != null) {
-            value = value.replace("\"" + parser.stop() + '"', '"' + Integer.toString(tomeeShutdownPort)
+ '"');
+            value = value.replace("\"" + parser.stop() + '"', '"' + tomeeShutdownPort + '"');
         }
         if (webappDir != null) {
             value = value.replace("\"" + parser.value("app-base", "webapps") + '"', '"' +
webappDir + '"');
@@ -1012,7 +1000,7 @@ public abstract class AbstractTomEEMojo extends AbstractAddressMojo
{
             System.setProperty("openejb.server.debug", "true");
             System.setProperty("server.debug.port", Integer.toString(debugPort));
         }
-        System.setProperty("server.shutdown.port", Integer.toString(tomeeShutdownPort));
+        System.setProperty("server.shutdown.port", tomeeShutdownPort);
         System.setProperty("server.shutdown.command", tomeeShutdownCommand);
 
         server = new RemoteServer(getConnectAttempts(), debug);
@@ -1022,7 +1010,7 @@ public abstract class AbstractTomEEMojo extends AbstractAddressMojo
{
 
         if (TOM_EE.equals(container)) {
 
-            server.setPortStartup(tomeeHttpPort == null ? tomeeHttpsPort : tomeeHttpPort);
+            server.setPortStartup(Integer.parseInt(tomeeHttpPort == null ? tomeeHttpsPort
: tomeeHttpPort));
 
             getLog().info("Running '" + getClass().getName().replace("TomEEMojo", "").toLowerCase(Locale.ENGLISH)
                     + "'. Configured TomEE in plugin is " + tomeeHost + ":" + server.getPortStartup()

http://git-wip-us.apache.org/repos/asf/tomee/blob/5e3670aa/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 dead8a1..689ccee 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
@@ -72,6 +72,13 @@ assertThat(IO.slurp(new URL(url + "/docs")), containsString("Apache Tomcat"));
  * @Config specifies you want to configure the backend mojo with the value specifies on the
test instance
  */
 public class TomEEMavenPluginRule implements MethodRule {
+    private boolean run = true;
+
+    public TomEEMavenPluginRule noRun() {
+        run = false;
+        return this;
+    }
+
     @Override
     public Statement apply(final Statement base, final FrameworkMethod ignored, final Object
target) {
         return new RunTest(target, base);
@@ -101,7 +108,12 @@ public class TomEEMavenPluginRule implements MethodRule {
                 } else if (f.getAnnotation(Config.class) != null) {
                     f.setAccessible(true);
 
-                    final Field mojoField = AbstractTomEEMojo.class.getDeclaredField(f.getName());
+                    Field mojoField;
+                    try {
+                        mojoField = AbstractTomEEMojo.class.getDeclaredField(f.getName());
+                    } catch (final Exception e) {
+                        mojoField = AbstractAddressMojo.class.getDeclaredField(f.getName());
+                    }
                     mojoField.setAccessible(true);
                     mojoField.set(testMojo, f.get(testInstance));
                 }
@@ -116,6 +128,19 @@ public class TomEEMavenPluginRule implements MethodRule {
                 protected void asserts() throws Throwable {
                     next.evaluate();
                 }
+
+                @Override
+                protected void run() {
+                    if (run) {
+                        super.run();
+                    } else {
+                        try {
+                            next.evaluate();
+                        } catch (Throwable throwable) {
+                            throw new RuntimeException(throwable);
+                        }
+                    }
+                }
             });
         }
     }
@@ -201,9 +226,9 @@ public class TomEEMavenPluginRule implements MethodRule {
         tomEEMojo.config = new File(tomEEMojo.catalinaBase.getPath() + "-conf");
         tomEEMojo.lib = new File(tomEEMojo.catalinaBase.getPath() + "-lib");
 
-        tomEEMojo.tomeeHttpPort = NetworkUtil.getNextAvailablePort();
-        tomEEMojo.tomeeAjpPort = NetworkUtil.getNextAvailablePort();
-        tomEEMojo.tomeeShutdownPort = NetworkUtil.getNextAvailablePort();
+        tomEEMojo.tomeeHttpPort = Integer.toString(NetworkUtil.getNextAvailablePort());
+        tomEEMojo.tomeeAjpPort = Integer.toString(NetworkUtil.getNextAvailablePort());
+        tomEEMojo.tomeeShutdownPort = Integer.toString(NetworkUtil.getNextAvailablePort());
         tomEEMojo.tomeeShutdownCommand = "SHUTDOWN";
         tomEEMojo.tomeeHost = "localhost";
 

http://git-wip-us.apache.org/repos/asf/tomee/blob/5e3670aa/maven/tomee-maven-plugin/src/test/java/org/apache/openejb/maven/plugin/test/PortPlaceholderTest.java
----------------------------------------------------------------------
diff --git a/maven/tomee-maven-plugin/src/test/java/org/apache/openejb/maven/plugin/test/PortPlaceholderTest.java
b/maven/tomee-maven-plugin/src/test/java/org/apache/openejb/maven/plugin/test/PortPlaceholderTest.java
new file mode 100644
index 0000000..e3156d1
--- /dev/null
+++ b/maven/tomee-maven-plugin/src/test/java/org/apache/openejb/maven/plugin/test/PortPlaceholderTest.java
@@ -0,0 +1,43 @@
+/*
+ * 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.test;
+
+import org.apache.openejb.loader.IO;
+import org.apache.openejb.maven.plugin.Config;
+import org.apache.openejb.maven.plugin.TomEEMavenPluginRule;
+import org.junit.Rule;
+import org.junit.Test;
+
+import java.io.File;
+
+import static org.junit.Assert.assertTrue;
+
+public class PortPlaceholderTest {
+    @Rule
+    public final TomEEMavenPluginRule TMPRule = new TomEEMavenPluginRule().noRun();
+
+    @Config
+    private final String tomeeHttpPort = "${http.port}";
+
+    @Config
+    private final File catalinaBase = new File("target/tomee-placeholder");
+
+    @Test
+    public void run() throws Exception {
+        assertTrue(IO.slurp(new File(catalinaBase, "conf/server.xml")).contains("<Connector
port=\"" + tomeeHttpPort + "\""));
+    }
+}

http://git-wip-us.apache.org/repos/asf/tomee/blob/5e3670aa/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/OpenEJBHttpServer.java
----------------------------------------------------------------------
diff --git a/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/OpenEJBHttpServer.java
b/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/OpenEJBHttpServer.java
index 16277fb..2290884 100644
--- a/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/OpenEJBHttpServer.java
+++ b/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/OpenEJBHttpServer.java
@@ -159,7 +159,9 @@ public class OpenEJBHttpServer implements HttpServer {
         final Options options = new Options(props);
         options.setLogger(new OptionsLog(log));
         print = options.getAll("print", OpenEJBHttpServer.Output.class);
-        indent = print.size() > 0 && options.get("indent.xml", false);
+        indent = print.size() > 0 && options.get("" +
+            "" +
+            ".xml", false);
 
     }
 


Mime
View raw message