geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r453458 - in /geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/server: OptionSet.java StartServerMojo.java
Date Fri, 06 Oct 2006 01:51:56 GMT
Author: jdillon
Date: Thu Oct  5 18:51:55 2006
New Revision: 453458

URL: http://svn.apache.org/viewvc?view=rev&rev=453458
Log:
Add support for optionSets, to allow for greater flexibility to configure the server

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

Added: geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/server/OptionSet.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/server/OptionSet.java?view=auto&rev=453458
==============================================================================
--- geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/server/OptionSet.java
(added)
+++ geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/server/OptionSet.java
Thu Oct  5 18:51:55 2006
@@ -0,0 +1,77 @@
+/*
+ * 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.util.Properties;
+import java.util.Arrays;
+
+/**
+ * Container for a set of options to be passed to a JVM.
+ *
+ * @version $Rev$ $Date$
+ */
+public class OptionSet
+{
+    /**
+     * @parameter
+     */
+    private String id = null;
+
+    /**
+     * @parameter
+     */
+    private String[] options = null;
+
+    /**
+     * @parameter
+     */
+    private Properties properties = null;
+
+    public String toString() {
+        return "{ id=" + id +
+               ", options=" + (options != null ? Arrays.asList(options) : null) +
+               ", properties=" + properties +
+               " }";
+    }
+
+    public void setId(final String id) {
+        this.id = id;
+    }
+
+    public String getId() {
+        return id;
+    }
+
+    public void setOptions(final String[] options) {
+        this.options = options;
+    }
+
+    public String[] getOptions() {
+        return options;
+    }
+
+    public Properties getProperties() {
+        return properties;
+    }
+
+    public void setProperties(final Properties properties) {
+        this.properties = properties;
+    }
+}

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

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

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

Modified: geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/server/StartServerMojo.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/server/StartServerMojo.java?view=diff&rev=453458&r1=453457&r2=453458
==============================================================================
--- geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/server/StartServerMojo.java
(original)
+++ geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/server/StartServerMojo.java
Thu Oct  5 18:51:55 2006
@@ -20,8 +20,13 @@
 package org.apache.geronimo.mavenplugins.geronimo.server;
 
 import java.io.File;
+
 import java.util.Timer;
 import java.util.TimerTask;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Properties;
+import java.util.Iterator;
 
 import org.apache.maven.plugin.MojoExecutionException;
 
@@ -30,6 +35,7 @@
 
 import org.apache.geronimo.genesis.ObjectHolder;
 import org.apache.geronimo.mavenplugins.geronimo.ServerProxy;
+
 import org.codehaus.plexus.util.FileUtils;
 
 /**
@@ -91,6 +97,10 @@
      */
     private int verifyTimeout = -1;
 
+    //
+    // TODO: Remove this debug stuff... make it use optionSet, maybe -Ddebug=true will enable
the "debug" optionSet?
+    //
+    
     /**
      * JVM arguments to be applied when debug is enabled.
      *
@@ -106,6 +116,20 @@
     private boolean debug = false;
 
     /**
+     * An array of option sets which can be enabled by setting optionSetId.
+     *
+     * @parameter
+     */
+    private OptionSet[] optionSets = null;
+
+    /**
+     * The optionSet to be enabled.
+     *
+     * @parameter expression="${optionSetId}"
+     */
+    private String optionSetId = null;
+
+    /**
      * A list of module names to be started using --override.
      *
      * @parameter
@@ -114,13 +138,6 @@
 
     private Timer timer = new Timer(true);
 
-    private String appendSystemPath(final String name, final File file) {
-        assert name != null;
-        assert file != null;
-
-        return System.getProperty(name) + File.pathSeparator + file.getPath();
-    }
-
     protected void doExecute() throws Exception {
         installAssembly();
 
@@ -132,8 +149,7 @@
         java.setDir(geronimoHome);
         java.setFailonerror(true);
         java.setFork(true);
-        java.setLogError(true);
-
+        
         if (timeout > 0) {
             java.setTimeout(new Long(timeout * 1000));
         }
@@ -157,29 +173,52 @@
             }
         }
 
-        // Set the properties which we pass to the JVM from the startup script
+        // Apply option sets
+        if (optionSetId != null  && (optionSets == null || optionSets.length == 0))
{
+            throw new MojoExecutionException("At least one optionSet must be defined to select
one using optionSetId");
+        }
+        else if (optionSetId == null) {
+            optionSetId = "default";
+        }
+        
+        if (optionSets != null && optionSets.length != 0) {
+            //
+            // TODO: Support selecting a comma seperated list of optionSet ids
+            //
+            
+            OptionSet set = selectOptionSet(optionSetId);
 
-        Environment.Variable var;
+            if (log.isDebugEnabled()) {
+                log.debug("Selected option set: " + set);
+            }
+            else {
+                log.info("Selected option set: " + optionSetId);    
+            }
 
-        var = new Environment.Variable();
-        var.setKey("org.apache.geronimo.base.dir");
-        var.setFile(geronimoHome);
-        java.addSysproperty(var);
+            String[] options = set.getOptions();
+            if (options != null) {
+                for (int i=0; i<options.length; i++) {
+                    java.createJvmarg().setValue(options[i]);
+                }
+            }
 
-        var = new Environment.Variable();
-        var.setKey("java.io.tmpdir");
-        var.setFile(new File(geronimoHome, "var/temp"));
-        java.addSysproperty(var);
+            Properties props = set.getProperties();
+            if (props != null) {
+                Iterator iter = props.keySet().iterator();
+                while (iter.hasNext()) {
+                    String name = (String)iter.next();
+                    String value = props.getProperty(name);
 
-        var = new Environment.Variable();
-        var.setKey("java.endorsed.dirs");
-        var.setValue(appendSystemPath("java.endorsed.dirs", new File(geronimoHome, "lib/endorsed")));
-        java.addSysproperty(var);
+                    setSystemProperty(java, name, value);
+                }
+            }
+        }
 
-        var = new Environment.Variable();
-        var.setKey("java.ext.dirs");
-        var.setValue(appendSystemPath("java.ext.dirs", new File(geronimoHome, "lib/ext")));
-        java.addSysproperty(var);
+        // 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")));
         
         if (quiet) {
             java.createArg().setValue("--quiet");
@@ -295,6 +334,64 @@
 
             t.join();
         }
+    }
+
+    private String appendSystemPath(final String name, final File file) {
+        assert name != null;
+        assert file != null;
+
+        return System.getProperty(name) + File.pathSeparator + file.getPath();
+    }
+
+    private OptionSet selectOptionSet(final String targetId) throws MojoExecutionException
{
+        // Make a map of the option sets and validate ids
+        Map map = new HashMap();
+        for (int i=0; i<optionSets.length; i++) {
+            if (log.isDebugEnabled()) {
+                log.debug("Checking option set: " + optionSets[i]);
+            }
+            
+            String id = optionSets[i].getId();
+
+            if (id == null && optionSets.length > 1) {
+                throw new MojoExecutionException("Must specify id for optionSet when more
than one optionSet is configured");
+            }
+            else if (id == null && optionSets.length == 1) {
+                id = "default";
+                optionSets[i].setId(id);
+            }
+
+            if (map.containsKey(id)) {
+                throw new MojoExecutionException("Must specify unique id for optionSet: "
+ id);
+            }
+            map.put(id, optionSets[i]);
+        }
+
+        OptionSet set = (OptionSet)map.get(targetId);
+        if (set == null) {
+            if ("default".equals(targetId)) {
+                log.warn("Default optionSet selected, but no optionSet defined with that
id; ignoring");
+            }
+            else {
+                throw new MojoExecutionException("Missing optionSet for id: " + targetId);
+            }
+        }
+
+        return set;
+    }
+
+    private void setSystemProperty(final Java java, final String name, final String value)
{
+        Environment.Variable var = new Environment.Variable();
+        var.setKey(name);
+        var.setValue(value);
+        java.addSysproperty(var);
+    }
+
+    private void setSystemProperty(final Java java, final String name, final File value)
{
+        Environment.Variable var = new Environment.Variable();
+        var.setKey(name);
+        var.setFile(value);
+        java.addSysproperty(var);
     }
 
     protected String getGoalName() {



Mime
View raw message