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 12:00:03 UTC
svn commit: r439751 - in
/geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo:
ObjectHolder.java ServerMojoSupport.java StartServerMojo.java
StopServerMojo.java
Author: jdillon
Date: Sun Sep 3 03:00:02 2006
New Revision: 439751
URL: http://svn.apache.org/viewvc?rev=439751&view=rev
Log:
Start of support for plain file-based assembly install
Added install refresh support, either force with -Drefresh=true, or if the assembly zip was updated
Added verify timeout, to catch when startup hangs, pending better detect of start to be more effective
Added:
geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/ObjectHolder.java (with props)
Modified:
geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/ServerMojoSupport.java
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/ObjectHolder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/ObjectHolder.java?rev=439751&view=auto
==============================================================================
--- geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/ObjectHolder.java (added)
+++ geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/ObjectHolder.java Sun Sep 3 03:00:02 2006
@@ -0,0 +1,51 @@
+/*
+ * 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;
+
+/**
+ * Simple helper that holds an object.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ObjectHolder
+{
+ private Object object;
+
+ public ObjectHolder() {
+ super();
+ }
+
+ public ObjectHolder(final Object object) {
+ set(object);
+ }
+
+ public String toString() {
+ return String.valueOf(get());
+ }
+
+ public void set(final Object object) {
+ this.object = object;
+ }
+
+ public Object get() {
+ return object;
+ }
+
+ public boolean isSet() {
+ return get() != null;
+ }
+}
Propchange: geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/ObjectHolder.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/ObjectHolder.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/ObjectHolder.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: 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=439751&r1=439750&r2=439751&view=diff
==============================================================================
--- geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/ServerMojoSupport.java (original)
+++ geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/ServerMojoSupport.java Sun Sep 3 03:00:02 2006
@@ -22,6 +22,7 @@
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
import java.util.Map;
import java.util.HashMap;
@@ -84,6 +85,15 @@
protected String defaultAssemblyId = null;
/**
+ * A file which points to a specific assembly ZIP archive.
+ * If this parameter is set, then it will be used instead of from the
+ * assemblies configuration.
+ *
+ * @parameter expression="${assemblyArchive}"
+ */
+ protected File assemblyArchive = null;
+
+ /**
* Directory to extract the assembly into.
*
* @parameter expression="${project.build.directory}"
@@ -147,9 +157,42 @@
return artifactRepository;
}
- //
- // Mojo
- //
+ /**
+ * The assembly archive to use when installing.
+ */
+ protected File installArchive;
+
+ /**
+ * The directory where the assembly has been installed to.
+ */
+ protected File installDir;
+
+ protected void init() throws MojoExecutionException, MojoFailureException {
+ super.init();
+
+ // Determine which archive and directory to use... either manual or from artifacts
+ if (assemblyArchive != null) {
+ log.debug("Using non-artifact based assembly archive: " + installArchive);
+
+ installArchive = assemblyArchive;
+
+ //
+ // FIXME: This probably will not work...
+ //
+
+ installDir = new File(outputDirectory, "assembly-archive");
+ }
+ else {
+ Artifact artifact = getAssemblyArtifact();
+
+ if (!"zip".equals(artifact.getType())) {
+ throw new MojoExecutionException("Assembly file does not look like a ZIP archive");
+ }
+
+ installArchive = artifact.getFile();
+ installDir = new File(outputDirectory, artifact.getArtifactId() + "-" + artifact.getVersion());
+ }
+ }
protected Artifact getAssemblyArtifact() throws MojoExecutionException {
assert assemblies != null;
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=439751&r1=439750&r2=439751&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 03:00:02 2006
@@ -16,15 +16,18 @@
package org.apache.geronimo.mavenplugins.geronimo;
-import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import java.io.File;
import java.net.URL;
+import java.util.Timer;
+import java.util.TimerTask;
import org.apache.tools.ant.taskdefs.Expand;
import org.apache.tools.ant.taskdefs.Java;
+import org.codehaus.plexus.util.FileUtils;
+
/**
* Start the Geronimo server.
*
@@ -39,81 +42,120 @@
* Flag to control if we background the server or block Maven execution.
*
* @parameter expression="${background}" default-value="false"
- * @required
*/
private boolean background = false;
/**
* Set the maximum memory for the forked JVM.
*
- * @parameter expression="${maxMemory}"
+ * @parameter expression="${maximumMemory}"
*/
- private String maxMemory = null;
+ private String maximumMemory = null;
/**
- * Enable quiet mode..
+ * Enable quiet mode.
*
* @parameter expression="${quiet}" default-value="false"
- * @required
*/
private boolean quiet = false;
/**
- * Enable verbose mode..
+ * Enable verbose mode.
*
* @parameter expression="${verbose}" default-value="false"
- * @required
*/
private boolean verbose = false;
/**
- * Enable veryverbose mode..
+ * Enable veryverbose mode.
*
* @parameter expression="${veryverbose}" default-value="false"
- * @required
*/
private boolean veryverbose = false;
+ /**
+ * Enable forced install refresh.
+ *
+ * @parameter expression="${refresh}" default-value="false"
+ */
+ private boolean refresh = false;
+
+ /**
+ * Time in seconds to wait before terminating the forked JVM.
+ *
+ * @parameter expression="${timeout}" default-value="-1"
+ */
+ private int timeout = -1;
+
+ /**
+ * Time in seconds to wait while verifing that the server has started.
+ *
+ * @parameter expression="${verifyTimeout}" default-value="-1"
+ */
+ private int verifyTimeout = -1;
+
+ private Timer timer = new Timer(true);
+
protected void doExecute() throws Exception {
log.info("Starting Geronimo server...");
- Artifact artifact = getAssemblyArtifact();
-
- if (!"zip".equals(artifact.getType())) {
- throw new MojoExecutionException("Assembly file does not look like a ZIP archive");
+ // Check if there is a newer archive or missing marker to trigger assembly install
+ File installMarker = new File(installDir, ".installed");
+ boolean refresh = this.refresh; // don't override config state with local state
+
+ if (!refresh) {
+ if (!installMarker.exists()) {
+ refresh = true;
+ }
+ else if (installArchive.lastModified() > installMarker.lastModified()) {
+ log.debug("Detected new assembly archive");
+ refresh = true;
+ }
+ }
+ else {
+ log.debug("User requested installation refresh");
}
- File assemblyDir = new File(outputDirectory, artifact.getArtifactId() + "-" + artifact.getVersion());
+ if (refresh) {
+ if (installDir.exists()) {
+ log.debug("Removing: " + installDir);
+ FileUtils.forceDelete(installDir);
+ }
+ }
- //
- // TODO: Try a bit harder to determine when the assembly need to be reinstalled to pick up changes
- //
-
- if (!assemblyDir.exists()) {
- log.info("Extracting assembly: " + artifact.getFile());
+ // Install the assembly
+ if (!installMarker.exists()) {
+ log.info("Installing assembly...");
Expand unzip = (Expand)createTask("unzip");
- unzip.setSrc(artifact.getFile());
+ unzip.setSrc(installArchive);
unzip.setDest(outputDirectory);
unzip.execute();
+
+ installMarker.createNewFile();
}
else {
- log.debug("Assembly already unpacked... reusing");
+ log.debug("Assembly already installed... reusing");
}
+ // Setup the JVM to start the server with
final Java java = (Java)createTask("java");
- java.setJar(new File(assemblyDir, "bin/server.jar"));
- java.setDir(assemblyDir);
+ java.setJar(new File(installDir, "bin/server.jar"));
+ java.setDir(installDir);
java.setFailonerror(true);
java.setFork(true);
java.setLogError(true);
+ if (timeout > 0) {
+ java.setTimeout(new Long(timeout * 1000));
+ }
+
//
// TODO: Capture output/error to files
//
- if (maxMemory != null) {
- java.setMaxmemory(maxMemory);
+ if (maximumMemory != null) {
+ java.setMaxmemory(maximumMemory);
}
if (quiet) {
@@ -162,6 +204,21 @@
log.info("Waiting for Geronimo server...");
+ // Setup a callback to time out verification
+ final ObjectHolder verifyTimedOut = new ObjectHolder();
+
+ log.debug("Starting verify timeout task; triggers in: " + verifyTimeout + "s");
+
+ TimerTask timeoutTask = new TimerTask() {
+ public void run() {
+ verifyTimedOut.set(Boolean.TRUE);
+ }
+ };
+
+ if (verifyTimeout > 0) {
+ timer.schedule(timeoutTask, verifyTimeout * 1000);
+ }
+
//
// TODO: Check the status via JMX:
//
@@ -172,6 +229,10 @@
URL url = new URL("http://localhost:8080");
boolean started = false;
while (!started) {
+ if (verifyTimedOut.isSet()) {
+ throw new MojoExecutionException("Unable to verify if the server was started in the given time");
+ }
+
if (errorHolder.getCause() != null) {
throw new MojoExecutionException("Failed to start Geronimo server", errorHolder.getCause());
}
@@ -188,6 +249,9 @@
Thread.sleep(1000);
}
+
+ // Stop the timer, server should be up now
+ timeoutTask.cancel();
//
// HACK: Give it a few seconds... our detection method here is lossy
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=439751&r1=439750&r2=439751&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 03:00:02 2006
@@ -16,7 +16,6 @@
package org.apache.geronimo.mavenplugins.geronimo;
-import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import java.io.File;
@@ -44,17 +43,19 @@
protected void doExecute() throws Exception {
log.info("Stopping Geronimo server...");
- Artifact artifact = getAssemblyArtifact();
+ //
+ // TODO: Might want to add a marker to the build when start completes...
+ // so stop can pick up the right dir w/o assembly configuration
+ //
- File assemblyDir = new File(outputDirectory, artifact.getArtifactId() + "-" + artifact.getVersion());
- if (!assemblyDir.exists()) {
+ if (!installDir.exists()) {
// Complain if there is no assemblyDir, as that probably means that 'start' was not executed.
- throw new MojoExecutionException("Missing assembly directory: " + assemblyDir);
+ throw new MojoExecutionException("Missing assembly directory: " + installDir);
}
Java java = (Java)createTask("java");
- java.setJar(new File(assemblyDir, "bin/shutdown.jar"));
- java.setDir(assemblyDir);
+ java.setJar(new File(installDir, "bin/shutdown.jar"));
+ java.setDir(installDir);
java.setFailonerror(true);
java.setFork(true);
java.setLogError(true);