Home » geronimo-2.2-source-release » org.apache.geronimo.mavenplugins.geronimo.server » [javadoc | source]

    1   /**
    2    *  Licensed to the Apache Software Foundation (ASF) under one
    3    *  or more contributor license agreements.  See the NOTICE file
    4    *  distributed with this work for additional information
    5    *  regarding copyright ownership.  The ASF licenses this file
    6    *  to you under the Apache License, Version 2.0 (the
    7    *  "License"); you may not use this file except in compliance
    8    *  with the License.  You may obtain a copy of the License at
    9    *
   10    *    http://www.apache.org/licenses/LICENSE-2.0
   11    *
   12    *  Unless required by applicable law or agreed to in writing,
   13    *  software distributed under the License is distributed on an
   14    *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   15    *  KIND, either express or implied.  See the License for the
   16    *  specific language governing permissions and limitations
   17    *  under the License.
   18    */
   19   
   20   package org.apache.geronimo.mavenplugins.geronimo.server;
   21   
   22   import java.io.File;
   23   
   24   import org.apache.tools.ant.taskdefs.Java;
   25   
   26   import org.apache.maven.plugin.MojoExecutionException;
   27   
   28   import org.apache.geronimo.mavenplugins.geronimo.ServerProxy;
   29   import org.apache.geronimo.mavenplugins.geronimo.reporting.ReportingMojoSupport;
   30   
   31   import org.codehaus.plexus.util.FileUtils;
   32   
   33   /**
   34    * Execute application client.
   35    *
   36    * @goal run-client
   37    *
   38    * @version $Rev: 723370 $ $Date: 2008-12-04 08:29:37 -0800 (Thu, 04 Dec 2008) $
   39    */
   40   public class RunClientMojo extends ReportingMojoSupport
   41   {
   42       /**
   43        * The id of the client module to be executed
   44        *
   45        * @parameter expression="${moduleId}
   46        * @required
   47        */
   48       protected String moduleId = null;
   49   
   50       /**
   51        * Set the maximum memory for the forked JVM.
   52        *
   53        * @parameter expression="${maximumMemory}"
   54        */
   55       private String maximumMemory = null;
   56   
   57       /**
   58        * The location of the Java Virtual Machine executable to launch the client with.
   59        *
   60        * @paramter
   61        */
   62       private File javaVirtualMachine;
   63       
   64       /**
   65        * Time in seconds to wait before terminating the forked JVM.
   66        *
   67        * @parameter expression="${timeout}" default-value="-1"
   68        */
   69       private int timeout = -1;
   70   
   71       /**
   72        * The arguments
   73        *
   74        * @parameter expression="${arg}
   75        * @optional
   76        */
   77       protected String[] arg = null;
   78   
   79       protected void doExecute() throws Exception {
   80           ServerProxy server =
   81               new ServerProxy(hostname, port, username, password);
   82   
   83           String geronimoHomeStr = server.getGeronimoHome();
   84   
   85           server.closeConnection();
   86           
   87           log.info("Geronimo Home: " + geronimoHomeStr);
   88   
   89           if (geronimoHomeStr == null) {
   90               throw new MojoExecutionException("Unable to determine Geronimo installation directory");
   91           }
   92   
   93           File geronimoHome = new File(geronimoHomeStr);
   94   
   95           if (!geronimoHome.exists()) {
   96               throw new MojoExecutionException("Geronimo installation directory does not exist: " + geronimoHomeStr);
   97           }
   98   
   99           log.info("Starting Geronimo client...");
  100   
  101           Java java = (Java)createTask("java");
  102           java.setJar(new File(geronimoHome, "bin/client.jar"));
  103           java.setDir(geronimoHome);
  104           java.setFailonerror(true);
  105           java.setFork(true);
  106   
  107           if (javaVirtualMachine != null) {
  108               if (!javaVirtualMachine.exists()) {
  109                   throw new MojoExecutionException("Java virtual machine is not valid: " + javaVirtualMachine);
  110               }
  111               
  112               log.info("Using Java virtual machine: " + javaVirtualMachine);
  113               java.setJvm(javaVirtualMachine.getCanonicalPath());
  114           }
  115           
  116           if (timeout > 0) {
  117               java.setTimeout(new Long(timeout * 1000));
  118           }
  119   
  120           if (maximumMemory != null) {
  121               java.setMaxmemory(maximumMemory);
  122           }
  123   
  124           // Set the properties which we pass to the JVM from the startup script
  125           setSystemProperty(java, "org.apache.geronimo.home.dir", geronimoHome);
  126           setSystemProperty(java, "java.io.tmpdir", "var/temp");
  127           setSystemProperty(java, "java.endorsed.dirs", prefixSystemPath("java.endorsed.dirs", new File(geronimoHome, "lib/endorsed")));
  128           setSystemProperty(java, "java.ext.dirs", prefixSystemPath("java.ext.dirs", new File(geronimoHome, "lib/ext")));
  129   
  130           java.createArg().setValue(moduleId);
  131   
  132           for (int i=0;arg != null && i<arg.length;i++) {
  133               java.createArg().setValue(arg[i]);
  134           }
  135   
  136           if (logOutput) {
  137               File file = getLogFile();
  138               FileUtils.forceMkdir(file.getParentFile());
  139   
  140               log.info("Redirecting output to: " + file);
  141   
  142               java.setOutput(file);
  143           }
  144   
  145           java.execute();
  146       }
  147   
  148       private String prefixSystemPath(final String name, final File file) {
  149           assert name != null;
  150           assert file != null;
  151   
  152           String dirs = file.getPath();
  153           String prop = System.getProperty(name, "");
  154           if (prop.length() > 0) {
  155               dirs += File.pathSeparator;
  156               dirs += prop;
  157           }
  158           return dirs;
  159       }
  160   
  161       protected String getFullClassName() {
  162           return this.getClass().getName();
  163       }
  164   }

Home » geronimo-2.2-source-release » org.apache.geronimo.mavenplugins.geronimo.server » [javadoc | source]