geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r439723 - in /geronimo/server/trunk/maven-plugins/server-maven-plugin: pom.xml src/main/java/org/apache/geronimo/mavenplugins/server/StartServerMojo.java
Date Sun, 03 Sep 2006 05:24:01 GMT
Author: jdillon
Date: Sat Sep  2 22:24:01 2006
New Revision: 439723

URL: http://svn.apache.org/viewvc?rev=439723&view=rev
Log:
Add background flag to allow the server to be started from the command line for development

Modified:
    geronimo/server/trunk/maven-plugins/server-maven-plugin/pom.xml
    geronimo/server/trunk/maven-plugins/server-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/server/StartServerMojo.java

Modified: geronimo/server/trunk/maven-plugins/server-maven-plugin/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/maven-plugins/server-maven-plugin/pom.xml?rev=439723&r1=439722&r2=439723&view=diff
==============================================================================
--- geronimo/server/trunk/maven-plugins/server-maven-plugin/pom.xml (original)
+++ geronimo/server/trunk/maven-plugins/server-maven-plugin/pom.xml Sat Sep  2 22:24:01 2006
@@ -27,10 +27,25 @@
         <version>1.2-SNAPSHOT</version>
         <relativePath>../pom.xml</relativePath>
     </parent>
-
+    
+    <!--
+    TODO: Rename to geronimo-maven-plugin
+    -->
+    
     <artifactId>server-maven-plugin</artifactId>
     <name>Geronimo Maven2 Plugins :: Server</name>
     <packaging>maven-plugin</packaging>
+    
+    <build>
+        <plugins>
+            <plugin>
+                <artifactId>maven-plugin-plugin</artifactId>
+                <configuration>
+                    <goalPrefix>server</goalPrefix>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
     
 </project>
 

Modified: geronimo/server/trunk/maven-plugins/server-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/server/StartServerMojo.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/maven-plugins/server-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/server/StartServerMojo.java?rev=439723&r1=439722&r2=439723&view=diff
==============================================================================
--- geronimo/server/trunk/maven-plugins/server-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/server/StartServerMojo.java
(original)
+++ geronimo/server/trunk/maven-plugins/server-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/server/StartServerMojo.java
Sat Sep  2 22:24:01 2006
@@ -21,11 +21,11 @@
 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.io.IOException;
 import java.net.URL;
-import java.net.ConnectException;
+import java.net.URLConnection;
 
 import org.apache.geronimo.genesis.AntMojoSupport;
 import org.apache.geronimo.plugin.ArtifactItem;
@@ -59,6 +59,14 @@
      */
     private File outputDirectory = null;
 
+    /**
+     * Flag to control if we background the server or block Maven execution.
+     *
+     * @parameter default-value="false"
+     * @required
+     */
+    private boolean background = false;
+
     //
     // MojoSupport Hooks
     //
@@ -128,10 +136,7 @@
         // 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" : "");
-
+        File workDir = new File(outputDirectory, artifact.getArtifactId() + "-" + artifact.getVersion());
         if (!workDir.exists()) {
             log.info("Extracting assembly: " + artifact.getFile());
 
@@ -144,42 +149,58 @@
             log.debug("Assembly already unpacked... reusing");
         }
 
+        //
+        // TODO: Change to Java task
+        //
+
+        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);
+
+        // Holds any exception that was thrown during startup (as the cause)
+        final Throwable errorHolder = new Throwable();
+
         // Start the server int a seperate thread
-        Thread t = new Thread("Server Runner") {
+        Thread t = new Thread("Geronimo Server Runner") {
             public void run() {
                 try {
-                    ExecTask exec = (ExecTask)createTask("exec");
-                    exec.setExecutable(executable);
-                    exec.createArg().setValue("-jar");
-                    exec.createArg().setFile(new File(workDir, "bin/server.jar"));
-                    exec.createArg().setValue("--quiet");
-                    exec.setDir(workDir);
-                    exec.setLogError(true);
                     exec.execute();
-
-                    synchronized(this) {
-                        wait();
-                    }
                 }
                 catch (Exception e) {
-                    // ignore
+                    errorHolder.initCause(e);
+
+                    //
+                    // NOTE: Don't log here, as when the JVM exists an exception will get
thrown by Ant
+                    //       but that should be fine.
+                    //
                 }
             }
         };
         t.start();
-        
+
+        log.info("Waiting for Geronimo server...");
+
         //
         // TODO: Check the status via JMX
         //
-        
+
         // Verify server started
         URL url = new URL("http://localhost:8080");
         boolean started = false;
         while (!started) {
+            if (errorHolder.getCause() != null) {
+                throw new MojoExecutionException("Failed to start Geronimo server", errorHolder.getCause());
+            }
+
             log.debug("Trying connection to: " + url);
 
             try {
-                Object input = url.openConnection().getContent();
+                URLConnection c = url.openConnection();
+                Object input = c.getContent();
                 log.debug("Input: " + input);
                 started = true;
             }
@@ -191,5 +212,12 @@
         }
 
         log.info("Server started");
+
+        if (!background) {
+            log.info("Waiting for Geronimo to shutdown...");
+            synchronized (this) {
+                wait();
+            }
+        }
     }
 }



Mime
View raw message