geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r497116 - in /geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo: ServerProxy.java server/RunClientMojo.java
Date Wed, 17 Jan 2007 18:32:41 GMT
Author: djencks
Date: Wed Jan 17 10:32:40 2007
New Revision: 497116

URL: http://svn.apache.org/viewvc?view=rev&rev=497116
Log:
GERONIMO-2736 add ability to run app clients in integration tests

Added:
    geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/server/RunClientMojo.java
  (with props)
Modified:
    geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/ServerProxy.java

Modified: geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/ServerProxy.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/ServerProxy.java?view=diff&rev=497116&r1=497115&r2=497116
==============================================================================
--- geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/ServerProxy.java
(original)
+++ geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/ServerProxy.java
Wed Jan 17 10:32:40 2007
@@ -29,6 +29,7 @@
 import javax.management.remote.JMXConnector;
 import javax.management.remote.JMXConnectorFactory;
 import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
 
 //
 // FIXME: It should be possible to query state with-out any Geronimo classes,
@@ -135,6 +136,32 @@
         }
         
         return fullyStarted;
+    }
+
+    public String getGeronimoHome() {
+        String home = null;
+
+        try {
+            ObjectName systemInfoQuery = new ObjectName("*:name=ServerInfo,j2eeType=GBean,*");
+
+            getConnection();
+           
+            Set set = this.mbeanConnection.queryNames(systemInfoQuery, null);
+
+            if (set.size() > 0) {
+                ObjectName found = (ObjectName)set.iterator().next();
+                home = (String)this.mbeanConnection.getAttribute(found, "currentBaseDirectory");
+            } 
+
+        } catch (IOException e) {
+            log.debug("Connection failure; ignoring", e);
+            lastError = e;
+        } catch (Exception e) {
+            log.debug("Unable to determine if the server home directory", e);
+            lastError = e;
+        }
+        
+        return home;
     }
 
     public Throwable getLastError() {

Added: geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/server/RunClientMojo.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/server/RunClientMojo.java?view=auto&rev=497116
==============================================================================
--- geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/server/RunClientMojo.java
(added)
+++ geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/server/RunClientMojo.java
Wed Jan 17 10:32:40 2007
@@ -0,0 +1,140 @@
+/**
+ *  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.geronimo.mavenplugins.geronimo.server;
+
+import java.io.File;
+
+import org.apache.tools.ant.taskdefs.Java;
+
+import org.apache.maven.plugin.MojoExecutionException;
+
+import org.apache.geronimo.mavenplugins.geronimo.ServerProxy;
+import org.apache.geronimo.mavenplugins.geronimo.reporting.ReportingMojoSupport;
+
+import org.codehaus.plexus.util.FileUtils;
+
+/**
+ * Execute application client.
+ *
+ * @goal run-client
+ *
+ * @version $Rev$ $Date$
+ */
+public class RunClientMojo extends ReportingMojoSupport
+{
+    /**
+     * The id of the client module to be executed
+     *
+     * @parameter expression="${moduleId}
+     * @required
+     */
+    protected String moduleId = null;
+    
+    /**
+     * Set the maximum memory for the forked JVM.
+     *
+     * @parameter expression="${maximumMemory}"
+     */
+    private String maximumMemory = null;
+
+    /**
+     * Time in seconds to wait before terminating the forked JVM.
+     *
+     * @parameter expression="${timeout}" default-value="-1"
+     */
+    private int timeout = -1;
+    
+    /**
+     * The arguments
+     *
+     * @parameter expression="${arg}
+     * @optional
+     */
+    protected String[] arg = null;
+
+    protected void doExecute() throws Exception {
+        ServerProxy server = 
+            new ServerProxy(hostname, port, username, password);
+
+        String geronimoHomeStr = server.getGeronimoHome();
+        
+        log.info("Geronimo Home: " + geronimoHomeStr);
+
+        if (geronimoHomeStr == null) {
+            throw new MojoExecutionException("Unable to determine Geronimo installation directory");
+        }
+
+        File geronimoHome = new File(geronimoHomeStr);
+        
+        if (!geronimoHome.exists()) {
+            throw new MojoExecutionException("Geronimo installation directory does not exist:
" + geronimoHomeStr);
+        }
+
+        log.info("Starting Geronimo client...");
+        
+        Java java = (Java)createTask("java");
+        java.setJar(new File(geronimoHome, "bin/client.jar"));
+        java.setDir(geronimoHome);
+        java.setFailonerror(true);
+        java.setFork(true);
+        
+        if (timeout > 0) {
+            java.setTimeout(new Long(timeout * 1000));
+        }
+
+        if (maximumMemory != null) {
+            java.setMaxmemory(maximumMemory);
+        }
+
+        // Set the properties which we pass to the JVM from the startup script
+        setSystemProperty(java, "org.apache.geronimo.base.dir", geronimoHome);
+        setSystemProperty(java, "java.io.tmpdir", new File(geronimoHome, "var/temp"));
+        setSystemProperty(java, "java.endorsed.dirs", appendSystemPath("java.endorsed.dirs",
new File(geronimoHome, "lib/endorsed")));
+        setSystemProperty(java, "java.ext.dirs", appendSystemPath("java.ext.dirs", new File(geronimoHome,
"lib/ext")));
+        
+        java.createArg().setValue(moduleId);
+
+        for (int i=0;arg != null && i<arg.length;i++) {
+            java.createArg().setValue(arg[i]);
+        }
+       
+        if (logOutput) {
+            File file = getLogFile();
+            FileUtils.forceMkdir(file.getParentFile());
+        
+            log.info("Redirecting output to: " + file);
+            
+            java.setOutput(file);
+        }
+        
+        java.execute();
+    }
+
+    private String appendSystemPath(final String name, final File file) {
+        assert name != null;
+        assert file != null;
+
+        return System.getProperty(name) + File.pathSeparator + file.getPath();
+    }
+
+    protected String getFullClassName() {
+        return this.getClass().getName();
+    } 
+}

Propchange: geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/server/RunClientMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/server/RunClientMojo.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/server/RunClientMojo.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message