You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jd...@apache.org on 2006/09/03 05:49:51 UTC

svn commit: r439713 - in /geronimo/server/trunk/maven-plugins/selenium-maven-plugin/src/main: java/org/apache/geronimo/mavenplugins/selenium/StartServerMojo.java resources/org/apache/geronimo/mavenplugins/selenium/log4j.properties

Author: jdillon
Date: Sat Sep  2 20:49:50 2006
New Revision: 439713

URL: http://svn.apache.org/viewvc?rev=439713&view=rev
Log:
Hooked up Log4j to capture Jetty logs
Capture server.out and server.err to keep bits from showing up in the mvn output

Added:
    geronimo/server/trunk/maven-plugins/selenium-maven-plugin/src/main/resources/org/apache/geronimo/mavenplugins/selenium/log4j.properties   (with props)
Modified:
    geronimo/server/trunk/maven-plugins/selenium-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/selenium/StartServerMojo.java

Modified: geronimo/server/trunk/maven-plugins/selenium-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/selenium/StartServerMojo.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/maven-plugins/selenium-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/selenium/StartServerMojo.java?rev=439713&r1=439712&r2=439713&view=diff
==============================================================================
--- geronimo/server/trunk/maven-plugins/selenium-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/selenium/StartServerMojo.java (original)
+++ geronimo/server/trunk/maven-plugins/selenium-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/selenium/StartServerMojo.java Sat Sep  2 20:49:50 2006
@@ -111,13 +111,29 @@
     private File workingDirectory = null;
 
     /**
-     * The file that Selenium server output will be written to.
+     * The file that Selenium server logs will be written to.
+     *
+     * @parameter expression="${project.build.directory}/selenium/server.log"
+     * @required
+     */
+    private File logFile = null;
+
+    /**
+     * The file that Selenium server STDOUT will be written to.
      *
      * @parameter expression="${project.build.directory}/selenium/server.out"
      * @required
      */
     private File outputFile = null;
 
+    /**
+     * The file that Selenium server STDERR will be written to.
+     *
+     * @parameter expression="${project.build.directory}/selenium/server.err"
+     * @required
+     */
+    private File errorFile = null;
+
     //
     // MojoSupport Hooks
     //
@@ -178,34 +194,50 @@
     // Mojo
     //
 
-    protected void doExecute() throws Exception {
-        log.info("Starting Selenium server...");
+    private File getPluginArchive() {
+        String path = getClass().getProtectionDomain().getCodeSource().getLocation().getFile();
+        return new File(path);
+    }
 
-        Artifact seleniumArtifact = (Artifact)pluginArtifactMap.get("org.openqa.selenium.server:selenium-server");
-        if (seleniumArtifact == null) {
-            throw new MojoExecutionException("Unable to locate 'selenium-server' in the list of plugin artifacts");
+    private Artifact getPluginArtifact(final String name) throws MojoExecutionException {
+        Artifact artifact = (Artifact)pluginArtifactMap.get(name);
+        if (artifact == null) {
+            throw new MojoExecutionException("Unable to locate '" + name + "' in the list of plugin artifacts");
         }
 
+        return artifact;
+    }
+
+    protected void doExecute() throws Exception {
+        log.info("Starting Selenium server...");
+
         final Java java = (Java)createTask("java");
 
         java.setFork(true);
         mkdir(workingDirectory);
         java.setDir(workingDirectory);
-        java.setOutput(outputFile);
         java.setFailonerror(true);
+        java.setOutput(outputFile);
+        java.setError(errorFile);
         java.setLogError(true);
 
         java.setClassname("org.openqa.selenium.server.SeleniumServer");
 
         Path classpath = java.createClasspath();
-        classpath.createPathElement().setLocation(seleniumArtifact.getFile());
+        classpath.createPathElement().setLocation(getPluginArchive());
+        classpath.createPathElement().setLocation(getPluginArtifact("log4j:log4j").getFile());
+        classpath.createPathElement().setLocation(getPluginArtifact("org.openqa.selenium.server:selenium-server").getFile());
+
+        Environment.Variable var;
+
+        var = new Environment.Variable();
+        var.setKey("selenium.log");
+        var.setFile(logFile);
+        java.addSysproperty(var);
 
-        //
-        // HACK: Use Simple log instead of evil JDK 1.4 logging
-        //
-        Environment.Variable var = new Environment.Variable();
-        var.setKey("org.apache.commons.logging.Log");
-        var.setValue("org.apache.commons.logging.impl.SimpleLog");
+        var = new Environment.Variable();
+        var.setKey("log4j.configuration");
+        var.setValue("org/apache/geronimo/mavenplugins/selenium/log4j.properties");
         java.addSysproperty(var);
 
         // Server arguments
@@ -232,6 +264,7 @@
             java.createArg().setFile(userExtentionsFile);
         }
 
+        // Holds any exception that was thrown during startup (as the cause)
         final Throwable errorHolder = new Throwable();
 
         // Start the server int a seperate thread
@@ -243,7 +276,10 @@
                 catch (Exception e) {
                     errorHolder.initCause(e);
 
-                    log.error("Failed to start Selenium server", e);
+                    //
+                    // NOTE: Don't log here, as when the JVM exists an exception will get thrown by Ant
+                    //       but that should be fine.
+                    //
                 }
             }
         };

Added: geronimo/server/trunk/maven-plugins/selenium-maven-plugin/src/main/resources/org/apache/geronimo/mavenplugins/selenium/log4j.properties
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/maven-plugins/selenium-maven-plugin/src/main/resources/org/apache/geronimo/mavenplugins/selenium/log4j.properties?rev=439713&view=auto
==============================================================================
--- geronimo/server/trunk/maven-plugins/selenium-maven-plugin/src/main/resources/org/apache/geronimo/mavenplugins/selenium/log4j.properties (added)
+++ geronimo/server/trunk/maven-plugins/selenium-maven-plugin/src/main/resources/org/apache/geronimo/mavenplugins/selenium/log4j.properties Sat Sep  2 20:49:50 2006
@@ -0,0 +1,31 @@
+##
+## 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$ $Date$
+##
+
+log4j.rootLogger=INFO, FILE
+
+log4j.appender.FILE=org.apache.log4j.FileAppender
+log4j.appender.FILE.File=${selenium.log}
+log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
+log4j.appender.FILE.layout.ConversionPattern=%d{ABSOLUTE} %-5p [%c] %m%n
+
+#log4j.logger.org.mortbay=INFO
\ No newline at end of file

Propchange: geronimo/server/trunk/maven-plugins/selenium-maven-plugin/src/main/resources/org/apache/geronimo/mavenplugins/selenium/log4j.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/maven-plugins/selenium-maven-plugin/src/main/resources/org/apache/geronimo/mavenplugins/selenium/log4j.properties
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/server/trunk/maven-plugins/selenium-maven-plugin/src/main/resources/org/apache/geronimo/mavenplugins/selenium/log4j.properties
------------------------------------------------------------------------------
    svn:mime-type = text/plain