geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dwo...@apache.org
Subject svn commit: r668799 [2/2] - in /geronimo/server/branches/2.1: testsuite/ testsuite/commands-testsuite/ testsuite/commands-testsuite/deploy/ testsuite/commands-testsuite/deploy/src/ testsuite/commands-testsuite/deploy/src/test/ testsuite/commands-testsu...
Date Tue, 17 Jun 2008 19:11:33 GMT
Added: geronimo/server/branches/2.1/testsupport/testsupport-commands/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.1/testsupport/testsupport-commands/pom.xml?rev=668799&view=auto
==============================================================================
--- geronimo/server/branches/2.1/testsupport/testsupport-commands/pom.xml (added)
+++ geronimo/server/branches/2.1/testsupport/testsupport-commands/pom.xml Tue Jun 17 12:11:32
2008
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<!-- $Rev: 649297 $ $Date: 2008-04-17 17:54:06 -0400 (Thu, 17 Apr 2008) $ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    
+    <parent>
+        <groupId>org.apache.geronimo.testsupport</groupId>
+        <artifactId>testsupport</artifactId>
+        <version>2.1.2-SNAPSHOT</version>
+    </parent>
+    
+    <artifactId>testsupport-commands</artifactId>
+    <name>Geronimo Test Support :: Commands</name>
+    
+    <dependencies>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>compile</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.geronimo.testsupport</groupId>
+            <artifactId>testsupport-common</artifactId>
+            <version>${version}</version>
+            <scope>compile</scope>
+        </dependency>
+        
+        <dependency>
+            <groupId>org.apache.geronimo.buildsupport</groupId>
+            <artifactId>geronimo-maven-plugin</artifactId>
+            <version>${version}</version>
+        </dependency>
+         
+        <dependency>
+            <groupId>org.apache.ant</groupId>
+            <artifactId>ant</artifactId>
+        </dependency>
+    </dependencies>
+
+</project>

Propchange: geronimo/server/branches/2.1/testsupport/testsupport-commands/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: geronimo/server/branches/2.1/testsupport/testsupport-commands/src/main/java/org/apache/geronimo/testsupport/commands/CommandTestSupport.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.1/testsupport/testsupport-commands/src/main/java/org/apache/geronimo/testsupport/commands/CommandTestSupport.java?rev=668799&view=auto
==============================================================================
--- geronimo/server/branches/2.1/testsupport/testsupport-commands/src/main/java/org/apache/geronimo/testsupport/commands/CommandTestSupport.java
(added)
+++ geronimo/server/branches/2.1/testsupport/testsupport-commands/src/main/java/org/apache/geronimo/testsupport/commands/CommandTestSupport.java
Tue Jun 17 12:11:32 2008
@@ -0,0 +1,132 @@
+/**
+ *  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.testsupport.commands;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.geronimo.mavenplugins.geronimo.ServerProxy;
+import org.apache.tools.ant.taskdefs.Execute;
+import org.apache.tools.ant.taskdefs.ExecuteStreamHandler;
+import org.apache.tools.ant.taskdefs.ExecuteWatchdog;
+import org.apache.tools.ant.taskdefs.PumpStreamHandler;
+import org.apache.tools.ant.taskdefs.condition.Os;
+
+public class CommandTestSupport {
+        
+    public static final String GSH = "gsh";
+    public static final String DEPLOY = "deploy";
+    
+    protected static final long timeout = 30000;    
+    protected static String geronimoHome;
+    
+    static {
+        geronimoHome = getGeronimoHome();
+    }
+        
+    private static String getGeronimoHome() {
+        ServerProxy server = null;
+        try {
+            server = new ServerProxy("localhost", 1099, "system", "manager");           
+        } catch (Exception e) {
+            throw new RuntimeException("Unable to setup ServerProxy", e);
+        }
+        
+        String home = server.getGeronimoHome();
+        Throwable exception = server.getLastError();
+        
+        server.closeConnection();
+        
+        if (exception != null) {
+            throw new RuntimeException("Failed to get Geronimo home", exception);
+        } else {
+            return home;
+        }
+    }
+        
+    public CommandTestSupport() {
+    }
+    
+    public void execute(String command, String[] args, InputStream in, OutputStream out)
throws Exception {
+        execute(command, (args == null) ? null : Arrays.asList(args), in, out);
+    }
+        
+    public void execute(String command, List<String> args, InputStream in, OutputStream
out) throws Exception {
+        List<String> cmdLine = new ArrayList<String>();
+        if (isWindows()) {
+            cmdLine.add("cmd.exe");
+            cmdLine.add("/c");
+        }
+        cmdLine.add(resolveCommandForOS(command));
+        // add command-specific arguments
+        cmdLine.addAll(getCommandArguments(command));
+        // add user arguments
+        if (args != null) {
+            cmdLine.addAll(args);
+        }
+        
+        ExecuteWatchdog watchdog = new ExecuteWatchdog( timeout );
+        ExecuteStreamHandler streamHandler = new PumpStreamHandler( out, out, in );
+        Execute exec = new Execute( streamHandler, watchdog );
+        exec.setCommandline( cmdLine.toArray(new String[] {}) );
+        List<String> env = getCommandEnvironment(command);
+        if (!env.isEmpty()) {
+            exec.setEnvironment(env.toArray(new String[] {}) );
+        }
+        exec.execute();
+    }
+    
+    protected List<String> getCommandArguments(String command) {
+        if (GSH.equals(command)) {
+            return Arrays.asList("-T", "false");
+        } else {
+            return Collections.emptyList();
+        }
+    }
+        
+    protected List<String> getCommandEnvironment(String command) {
+        if (DEPLOY.equals(command)) {
+            //this makes the output can be captured in Linux
+            return Arrays.asList("JAVA_OPTS=-Djline.terminal=jline.UnsupportedTerminal");
+        } else {
+            return Collections.emptyList();
+        }
+    }
+
+    protected String resolveCommandForOS(String command) {      
+        if (isWindows()) {
+            return geronimoHome + "/bin/" + command + ".bat";            
+        } else {
+            if (GSH.equals(command)) {
+                return geronimoHome + "/bin/" + command;
+            } else {
+                return geronimoHome + "/bin/" + command + ".sh";
+            }
+        }     
+    }
+        
+    public boolean isWindows() {
+        return Os.isFamily("windows");
+    }
+    
+}

Propchange: geronimo/server/branches/2.1/testsupport/testsupport-commands/src/main/java/org/apache/geronimo/testsupport/commands/CommandTestSupport.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message