geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r439740 - in /geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo: AssemblyConfig.java ServerMojoSupport.java StartServerMojo.java StopServerMojo.java
Date Sun, 03 Sep 2006 08:13:04 GMT
Author: jdillon
Date: Sun Sep  3 01:13:03 2006
New Revision: 439740

URL: http://svn.apache.org/viewvc?rev=439740&view=rev
Log:
Hook up more configuration for picking an assembly, more than one assembly artifact can be
configured, and -DassemblyId can be used on the command-line to pick the assembly to be used.
Exposed more start options, quiet, verbose, etc... default to --long for better feedback
Port, username and password are now configurable
Using Ant's Java task to start/stop

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

Added: geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/AssemblyConfig.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/AssemblyConfig.java?rev=439740&view=auto
==============================================================================
--- geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/AssemblyConfig.java
(added)
+++ geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/AssemblyConfig.java
Sun Sep  3 01:13:03 2006
@@ -0,0 +1,45 @@
+/*
+ *  Copyright 2006 The Apache Software Foundation
+ *
+ *  Licensed 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;
+
+import org.apache.geronimo.plugin.ArtifactItem;
+
+/**
+ * Assembly artifact configuration.
+ *
+ * @version $Rev$ $Date$
+ */
+public class AssemblyConfig
+    extends ArtifactItem
+{
+    /**
+     * Assembly identifier.
+     *
+     * @parameter
+     */
+    private String id;
+
+    public void setId(final String id) {
+        assert id != null;
+
+        this.id = id;
+    }
+
+    public String getId() {
+        return id;
+    }
+}

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

Propchange: geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/AssemblyConfig.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/AssemblyConfig.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/ServerMojoSupport.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/ServerMojoSupport.java?rev=439740&view=auto
==============================================================================
--- geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/ServerMojoSupport.java
(added)
+++ geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/ServerMojoSupport.java
Sun Sep  3 01:13:03 2006
@@ -0,0 +1,207 @@
+/*
+ *  Copyright 2006 The Apache Software Foundation
+ *
+ *  Licensed 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;
+
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.artifact.resolver.ArtifactResolver;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.plugin.MojoExecutionException;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.io.File;
+
+import org.apache.geronimo.genesis.AntMojoSupport;
+
+/**
+ * Support for Geronimo {start, stop} server mojos.
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class ServerMojoSupport
+    extends AntMojoSupport
+{
+    /**
+     * The port number to connect to the server..
+     *
+     * @parameter expression="${port}" default-value="1099"
+     * @required
+     */
+    protected int port = -1;
+
+    /**
+     * The username to authenticate with.
+     *
+     * @parameter expression="${username}" default-value="system"
+     * @required
+     */
+    protected String username = null;
+
+    /**
+     * The password to authenticate with.
+     *
+     * @parameter expression="${password}" default-value="manager"
+     * @required
+     */
+    protected String password = null;
+
+    /**
+     * List of assembly artifact configurations.  Artifacts need to point to ZIP archives.
+     *
+     * @parameter
+     * @required
+     */
+    protected AssemblyConfig[] assemblies = null;
+
+    /**
+     * Identifer of the assembly configuration to use.
+     *
+     * @parameter expression="${assemblyId}"
+     */
+    protected String assemblyId = null;
+
+    /**
+     * The default assemblyId to use when no assemblyId configured.
+     *
+     * @parameter
+     */
+    protected String defaultAssemblyId = null;
+
+    /**
+     * Directory to extract the assembly into.
+     *
+     * @parameter expression="${project.build.directory}"
+     * @required
+     */
+    protected File outputDirectory = null;
+
+    //
+    // MojoSupport Hooks
+    //
+
+    /**
+     * The maven project.
+     *
+     * @parameter expression="${project}"
+     * @required
+     * @readonly
+     */
+    protected MavenProject project = null;
+
+    protected MavenProject getProject() {
+        return project;
+    }
+
+    /**
+     * ???
+     *
+     * @component
+     * @required
+     * @readonly
+     */
+    protected ArtifactFactory artifactFactory = null;
+
+    protected ArtifactFactory getArtifactFactory() {
+        return artifactFactory;
+    }
+
+    /**
+     * ???
+     *
+     * @component
+     * @required
+     * @readonly
+     */
+    protected ArtifactResolver artifactResolver = null;
+
+    protected ArtifactResolver getArtifactResolver() {
+        return artifactResolver;
+    }
+
+    /**
+     * ???
+     *
+     * @parameter expression="${localRepository}"
+     * @readonly
+     * @required
+     */
+    protected ArtifactRepository artifactRepository = null;
+
+    protected ArtifactRepository getArtifactRepository() {
+        return artifactRepository;
+    }
+
+    //
+    // Mojo
+    //
+
+    protected Artifact getAssemblyArtifact() throws MojoExecutionException {
+        assert assemblies != null;
+
+        AssemblyConfig config;
+
+        if (assemblies.length == 0) {
+            throw new MojoExecutionException("At least one assembly configuration must be
specified");
+        }
+        else if (assemblies.length > 1 && assemblyId == null && defaultAssemblyId
== null) {
+            throw new MojoExecutionException("Must specify assemblyId (or defaultAssemblyId)
when more than on assembly configuration is given");
+        }
+        else if (assemblies.length == 1) {
+            config = assemblies[0];
+        }
+        else {
+            if (assemblyId == null) {
+                assemblyId = defaultAssemblyId;
+            }
+
+            log.debug("Searching for assembly config for id: " + assemblyId);
+
+            // Make sure there are no duplicate ids
+            Map idMap = new HashMap();
+
+            for (int i=0; i < assemblies.length; i++) {
+                String id = assemblies[i].getId();
+
+                if (id == null) {
+                    throw new MojoExecutionException("Missing id for assembly configuration:
" + assemblies[i]);
+                }
+
+                if (idMap.containsKey(id)) {
+                    throw new MojoExecutionException("Duplicate assembly id: " + id);
+                }
+
+                idMap.put(id, assemblies[i]);
+            }
+
+            config = (AssemblyConfig) idMap.get(assemblyId);
+            if (config == null) {
+                throw new MojoExecutionException("Missing assembly configuration for id:
" + assemblyId);
+            }
+        }
+
+        log.info("Using assembly configuration: " + config);
+        Artifact artifact = getArtifact(config);
+
+        if (artifact.getFile() == null) {
+            throw new MojoExecutionException("Assembly artifact does not have an attached
file: " + artifact);
+        }
+
+        return artifact;
+    }
+}

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

Propchange: geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/ServerMojoSupport.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/ServerMojoSupport.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/StartServerMojo.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/StartServerMojo.java?rev=439740&r1=439739&r2=439740&view=diff
==============================================================================
--- geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/StartServerMojo.java
(original)
+++ geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/StartServerMojo.java
Sun Sep  3 01:13:03 2006
@@ -16,128 +16,75 @@
 
 package org.apache.geronimo.mavenplugins.geronimo;
 
-import org.apache.maven.project.MavenProject;
-import org.apache.maven.artifact.resolver.ArtifactResolver;
 import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.plugin.MojoExecutionException;
 
 import java.io.File;
 import java.net.URL;
-import java.net.URLConnection;
 
-import org.apache.geronimo.genesis.AntMojoSupport;
-import org.apache.geronimo.plugin.ArtifactItem;
-import org.apache.commons.lang.SystemUtils;
-import org.apache.tools.ant.taskdefs.ExecTask;
 import org.apache.tools.ant.taskdefs.Expand;
+import org.apache.tools.ant.taskdefs.Java;
 
 /**
  * Start the Geronimo server.
  *
  * @goal start
  *
- * @version $Id$
+ * @version $Rev$ $Date$
  */
 public class StartServerMojo
-    extends AntMojoSupport
+    extends ServerMojoSupport
 {
     /**
-     * The assembly to unpack which contains the server to start.
-     *
-     * @parameter
-     * @required
-     */
-    private ArtifactItem assembly = null;
-
-    /**
-     * Directory to extract the assembly into.
-     *
-     * @parameter expression="${project.build.directory}"
-     * @required
-     */
-    private File outputDirectory = null;
-
-    /**
      * Flag to control if we background the server or block Maven execution.
      *
-     * @parameter default-value="false"
+     * @parameter expression="${background}" default-value="false"
      * @required
      */
     private boolean background = false;
 
-    //
-    // MojoSupport Hooks
-    //
-
     /**
-     * The maven project.
+     * Set the maximum memory for the forked JVM.
      *
-     * @parameter expression="${project}"
-     * @required
-     * @readonly
+     * @parameter expression="${maxMemory}"
      */
-    private MavenProject project = null;
-
-
-    protected MavenProject getProject() {
-        return project;
-    }
+    private String maxMemory = null;
 
     /**
-     * ???
+     * Enable quiet mode..
      *
-     * @component
+     * @parameter expression="${quiet}" default-value="false"
      * @required
-     * @readonly
      */
-    private ArtifactFactory artifactFactory = null;
-
-    protected ArtifactFactory getArtifactFactory() {
-        return artifactFactory;
-    }
+    private boolean quiet = false;
 
     /**
-     * ???
+     * Enable verbose mode..
      *
-     * @component
+     * @parameter expression="${verbose}" default-value="false"
      * @required
-     * @readonly
      */
-    private ArtifactResolver artifactResolver = null;
-
-    protected ArtifactResolver getArtifactResolver() {
-        return artifactResolver;
-    }
+    private boolean verbose = false;
 
     /**
-     * ???
+     * Enable veryverbose mode..
      *
-     * @parameter expression="${localRepository}"
-     * @readonly
+     * @parameter expression="${veryverbose}" default-value="false"
      * @required
      */
-    private ArtifactRepository artifactRepository = null;
-
-    protected ArtifactRepository getArtifactRepository() {
-        return artifactRepository;
-    }
-
-    //
-    // Mojo
-    //
+    private boolean veryverbose = false;
 
     protected void doExecute() throws Exception {
         log.info("Starting Geronimo server...");
 
-        log.debug("Using assembly: " + assembly);
+        Artifact artifact = getAssemblyArtifact();
 
-        // Unzip the assembly
-        Artifact artifact = getArtifact(assembly);
+        if (!"zip".equals(artifact.getType())) {
+            throw new MojoExecutionException("Assembly file does not look like a ZIP archive");
+        }
 
-        File workDir = new File(outputDirectory, artifact.getArtifactId() + "-" + artifact.getVersion());
-        if (!workDir.exists()) {
+        File assemblyDir = new File(outputDirectory, artifact.getArtifactId() + "-" + artifact.getVersion());
+        if (!assemblyDir.exists()) {
             log.info("Extracting assembly: " + artifact.getFile());
 
             Expand unzip = (Expand)createTask("unzip");
@@ -149,17 +96,43 @@
             log.debug("Assembly already unpacked... reusing");
         }
 
+        final Java java = (Java)createTask("java");
+        java.setJar(new File(assemblyDir, "bin/server.jar"));
+        java.setDir(assemblyDir);
+        java.setFailonerror(true);
+        java.setFork(true);
+        java.setLogError(true);
+
         //
-        // TODO: Change to Java task
+        // TODO: Capture output/error to files
         //
 
-        final ExecTask exec = (ExecTask)createTask("exec");
-        exec.setExecutable("java" +  (SystemUtils.IS_OS_WINDOWS ? ".exe" : ""));
-        exec.createArg().setValue("-jar");
-        exec.createArg().setFile(new File(workDir, "bin/server.jar"));
-        exec.createArg().setValue("--quiet");
-        exec.setDir(workDir);
-        exec.setLogError(true);
+        if (maxMemory != null) {
+            java.setMaxmemory(maxMemory);
+        }
+
+        if (quiet) {
+            java.createArg().setValue("--quiet");
+        }
+        else {
+            java.createArg().setValue("--long");
+        }
+
+        if (verbose) {
+            java.createArg().setValue("--verbose");
+        }
+
+        if (veryverbose) {
+            java.createArg().setValue("--veryverbose");
+        }
+
+        //
+        // TODO: Support --override
+        //
+
+        //
+        // TODO: Support JVM args for debug mode, add debug flag to enable or disable
+        //
 
         // Holds any exception that was thrown during startup (as the cause)
         final Throwable errorHolder = new Throwable();
@@ -168,7 +141,7 @@
         Thread t = new Thread("Geronimo Server Runner") {
             public void run() {
                 try {
-                    exec.execute();
+                    java.execute();
                 }
                 catch (Exception e) {
                     errorHolder.initCause(e);
@@ -185,7 +158,9 @@
         log.info("Waiting for Geronimo server...");
 
         //
-        // TODO: Check the status via JMX
+        // TODO: Check the status via JMX:
+        //
+        //       "service:jmx:rmi://localhost/jndi/rmi://localhost:" + port + "/JMXConnector"
         //
 
         // Verify server started
@@ -199,9 +174,7 @@
             log.debug("Trying connection to: " + url);
 
             try {
-                URLConnection c = url.openConnection();
-                Object input = c.getContent();
-                log.debug("Input: " + input);
+                url.openConnection().getContent();
                 started = true;
             }
             catch (Exception e) {
@@ -210,6 +183,12 @@
 
             Thread.sleep(1000);
         }
+
+        //
+        // HACK: Give it a few seconds... our detection method here is lossy
+        //
+
+        Thread.sleep(10000);
 
         log.info("Geronimo server started");
 

Modified: geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/StopServerMojo.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/StopServerMojo.java?rev=439740&r1=439739&r2=439740&view=diff
==============================================================================
--- geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/StopServerMojo.java
(original)
+++ geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/StopServerMojo.java
Sun Sep  3 01:13:03 2006
@@ -16,129 +16,73 @@
 
 package org.apache.geronimo.mavenplugins.geronimo;
 
-import org.apache.maven.project.MavenProject;
-import org.apache.maven.artifact.resolver.ArtifactResolver;
 import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.plugin.MojoExecutionException;
 
 import java.io.File;
 
-import org.apache.geronimo.genesis.AntMojoSupport;
-import org.apache.geronimo.plugin.ArtifactItem;
-import org.apache.commons.lang.SystemUtils;
-import org.apache.tools.ant.taskdefs.ExecTask;
+import org.apache.tools.ant.taskdefs.Java;
 
 /**
  * Stop the Geronimo server.
  *
  * @goal stop
  *
- * @version $Id$
+ * @version $Rev$ $Date$
  */
 public class StopServerMojo
-    extends AntMojoSupport
+    extends ServerMojoSupport
 {
     /**
-     * The assembly to unpack which contains the server to stop.
+     * Time in seconds to wait before timing out the stop operation.
      *
-     * @parameter
+     * @parameter default-value="60"
      * @required
      */
-    private ArtifactItem assembly = null;
-
-    /**
-     * Directory to extract the assembly into.
-     *
-     * @parameter expression="${project.build.directory}"
-     * @required
-     */
-    private File outputDirectory = null;
-
-    //
-    // MojoSupport Hooks
-    //
-
-    /**
-     * The maven project.
-     *
-     * @parameter expression="${project}"
-     * @required
-     * @readonly
-     */
-    private MavenProject project = null;
-
-    protected MavenProject getProject() {
-        return project;
-    }
-
-    /**
-     * ???
-     *
-     * @component
-     * @required
-     * @readonly
-     */
-    private ArtifactFactory artifactFactory = null;
-
-    protected ArtifactFactory getArtifactFactory() {
-        return artifactFactory;
-    }
-
-    /**
-     * ???
-     *
-     * @component
-     * @required
-     * @readonly
-     */
-    private ArtifactResolver artifactResolver = null;
-
-    protected ArtifactResolver getArtifactResolver() {
-        return artifactResolver;
-    }
-
-    /**
-     * ???
-     *
-     * @parameter expression="${localRepository}"
-     * @readonly
-     * @required
-     */
-    private ArtifactRepository artifactRepository = null;
-
-    protected ArtifactRepository getArtifactRepository() {
-        return artifactRepository;
-    }
-
-    //
-    // Mojo
-    //
+    private int timeout = -1;
 
     protected void doExecute() throws Exception {
         log.info("Stopping Geronimo server...");
 
-        log.debug("Using assembly: " + assembly);
-
-        // Unzip the assembly
-        Artifact artifact = getArtifact(assembly);
-
-        // What are we running... where?
-        final File workDir = new File(outputDirectory, artifact.getArtifactId() + "-" + artifact.getVersion());
-        final String executable = "java" +  (SystemUtils.IS_OS_WINDOWS ? ".exe" : "");
-
-        ExecTask exec = (ExecTask)createTask("exec");
-        exec.setExecutable(executable);
-        exec.createArg().setValue("-jar");
-        exec.createArg().setFile(new File(workDir, "bin/shutdown.jar"));
-        exec.createArg().setValue("--user");
-        exec.createArg().setValue("system");
-        exec.createArg().setValue("--password");
-        exec.createArg().setValue("manager");
-        exec.setDir(workDir);
-        exec.setLogError(true);
-        exec.execute();
+        Artifact artifact = getAssemblyArtifact();
 
-        log.info("Geronimo server stopped");
+        File assemblyDir = new File(outputDirectory, artifact.getArtifactId() + "-" + artifact.getVersion());
+        if (!assemblyDir.exists()) {
+            // Complain if there is no assemblyDir, as that probably means that 'start' was
not executed.
+            throw new MojoExecutionException("Missing assembly directory: " + assemblyDir);
+        }
+
+        Java java = (Java)createTask("java");
+        java.setJar(new File(assemblyDir, "bin/shutdown.jar"));
+        java.setDir(assemblyDir);
+        java.setFailonerror(true);
+        java.setFork(true);
+        java.setLogError(true);
+
+        if (timeout > 0) {
+            // Convert to milliseconds
+            java.setTimeout(new Long(timeout * 1000));
+        }
+
+        if (port > 0) {
+            java.createArg().setValue("--port");
+            java.createArg().setValue(String.valueOf(port));
+        }
+
+        if (username != null) {
+            java.createArg().setValue("--user");
+            java.createArg().setValue(username);
+        }
+
+        if (password != null) {
+            java.createArg().setValue("--password");
+            java.createArg().setValue(password);
+        }
+
+        java.execute();
+
+        //
+        // TODO: Verify that it actually stopped?
+        //
     }
 }



Mime
View raw message