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/04 15:13:55 UTC

svn commit: r440064 - in /geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo: InstallAssemblyMojo.java InstallerMojoSupport.java StartServerMojo.java

Author: jdillon
Date: Mon Sep  4 06:13:54 2006
New Revision: 440064

URL: http://svn.apache.org/viewvc?view=rev&rev=440064
Log:
Allow -DgeronimoHome= to be used to point to a pre-installed assembly, when used no installation will happen, install goal can still be used to verify that the value looks like a server assembly
Using discovery for geronimoHome if not set (for both artifact and non-artifact based installs)... now married to zip format to discover
Cleaned up logging

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

Modified: geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/InstallAssemblyMojo.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/InstallAssemblyMojo.java?view=diff&rev=440064&r1=440063&r2=440064
==============================================================================
--- geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/InstallAssemblyMojo.java (original)
+++ geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/InstallAssemblyMojo.java Mon Sep  4 06:13:54 2006
@@ -30,6 +30,6 @@
     extends InstallerMojoSupport
 {
     protected void doExecute() throws Exception {
-        doInstall();
+        installAssembly();
     }
 }

Modified: geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/InstallerMojoSupport.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/InstallerMojoSupport.java?view=diff&rev=440064&r1=440063&r2=440064
==============================================================================
--- geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/InstallerMojoSupport.java (original)
+++ geronimo/server/trunk/maven-plugins/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/InstallerMojoSupport.java Mon Sep  4 06:13:54 2006
@@ -59,7 +59,6 @@
      * List of assembly artifact configurations.  Artifacts need to point to ZIP archives.
      *
      * @parameter
-     * @required
      */
     protected AssemblyConfig[] assemblies = null;
 
@@ -94,6 +93,25 @@
      */
     protected File installDirectory = null;
 
+    /**
+     * The directory where the assembly has been installed to.
+     *
+     * Normally this value is detected,
+     * but if it is set, then it is assumed to be the location where a pre-installed assembly exists
+     * and no installation will be done.
+     *
+     * @parameter expression="${geronimoHome}"
+     */
+    protected File geronimoHome;
+
+    protected static final int INSTALL_FROM_ARTIFACT = 0;
+
+    protected static final int INSTALL_FROM_FILE = 1;
+
+    protected static final int INSTALL_ALREADY_EXISTS = 2;
+
+    protected int installType;
+
     //
     // MojoSupport Hooks
     //
@@ -137,70 +155,86 @@
         return artifactRepository;
     }
 
-    /**
-     * The assembly archive to use when installing.
-     */
-    protected File installArchive;
+    private File discoverGeronimoHome(final File archive) throws MojoExecutionException {
+        log.debug("Attempting to discover geronimoHome...");
 
-    /**
-     * The directory where the assembly has been installed to.
-     */
-    protected File geronimoHome;
+        File dir = null;
 
-    protected void init() throws MojoExecutionException, MojoFailureException {
-        super.init();
+        try {
+            ZipFile zipFile = new ZipFile(archive);
 
-        // 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;
-
-            //
-            // NOTE: This is obviously only going to work with ZIP archives
-            //
-            
-            log.debug("Attempting to discover geronimoHome...");
-            try {
-                ZipFile zipFile = new ZipFile(installArchive);
-                Enumeration enum = zipFile.entries();
-                while (enum.hasMoreElements()) {
-                    ZipEntry entry = (ZipEntry)enum.nextElement();
-                    if (entry.getName().endsWith("bin/server.jar")) {
-                        File file = new File(installDirectory, entry.getName());
-                        geronimoHome = file.getParentFile().getParentFile();
-                        log.info("Discovered geronimoHome: " + geronimoHome);
-                        break;
-                    }
+            Enumeration enum = zipFile.entries();
+            while (enum.hasMoreElements()) {
+                ZipEntry entry = (ZipEntry)enum.nextElement();
+                if (entry.getName().endsWith("bin/server.jar")) {
+                    File file = new File(installDirectory, entry.getName());
+                    dir = file.getParentFile().getParentFile();
+                    break;
                 }
-                zipFile.close();
-            }
-            catch (IOException e) {
-                log.debug("Failed to scan archive for 'bin/server.jar'", e);
             }
 
-            if (geronimoHome == null) {
-                throw new MojoExecutionException("Failed to determine geronimoHome from archive: " + installArchive);
+            zipFile.close();
+        }
+        catch (IOException e) {
+            throw new MojoExecutionException("Failed to determine geronimoHome while scanning archive for 'bin/server.jar'", e);
+        }
+
+        if (dir == null) {
+            throw new MojoExecutionException("Archive does not contain a Geronimo assembly: " + archive);
+        }
+
+        return dir;
+    }
+
+    protected void init() throws MojoExecutionException, MojoFailureException {
+        super.init();
+
+        // First check if geronimoHome is set, if it is, then we can skip this
+        if (geronimoHome != null) {
+            // Quick sanity check
+            File file = new File(geronimoHome, "bin/server.jar");
+            if (!file.exists()) {
+                throw new MojoExecutionException("When geronimoHome is set, it must point to a directory that contains 'bin/server.jar'");
             }
+            log.info("Using pre-installed assembly: " + geronimoHome);
+
+            installType = INSTALL_ALREADY_EXISTS;
         }
         else {
-            Artifact artifact = getAssemblyArtifact();
+            if (assemblyArchive != null) {
+                log.info("Using non-artifact based assembly archive: " + assemblyArchive);
+
+                installType = INSTALL_FROM_FILE;
+            }
+            else {
+                Artifact artifact = getAssemblyArtifact();
+
+                if (!"zip".equals(artifact.getType())) {
+                    throw new MojoExecutionException("Assembly file does not look like a ZIP archive");
+                }
 
-            if (!"zip".equals(artifact.getType())) {
-                throw new MojoExecutionException("Assembly file does not look like a ZIP archive");
+                log.info("Using assembly artifact: " + artifact);
+
+                assemblyArchive = artifact.getFile();
+
+                installType = INSTALL_FROM_ARTIFACT;
             }
 
-            installArchive = artifact.getFile();
-            geronimoHome = new File(installDirectory, artifact.getArtifactId() + "-" + artifact.getVersion());
+            geronimoHome = discoverGeronimoHome(assemblyArchive);
+            log.info("Using geronimoHome: " + geronimoHome);
         }
     }
 
+    /**
+     * Selects the assembly artifact tp be used for installation.
+     *
+     * @return
+     * @throws MojoExecutionException
+     */
     protected Artifact getAssemblyArtifact() throws MojoExecutionException {
-        assert assemblies != null;
-
         AssemblyConfig config;
 
-        if (assemblies.length == 0) {
+        if (assemblies == null || assemblies.length == 0) {
             throw new MojoExecutionException("At least one assembly configuration must be specified");
         }
         else if (assemblies.length > 1 && assemblyId == null && defaultAssemblyId == null) {
@@ -239,7 +273,7 @@
             }
         }
 
-        log.info("Using assembly configuration: " + config);
+        log.info("Using assembly configuration: " + config.getId());
         Artifact artifact = getArtifact(config);
 
         if (artifact.getFile() == null) {
@@ -249,16 +283,25 @@
         return artifact;
     }
 
-    protected void doInstall() throws Exception {
+    /**
+     * Performs assembly installation unless the install type is pre-existing.
+     *
+     * @throws Exception
+     */
+    protected void installAssembly() throws Exception {
+        if (installType == INSTALL_ALREADY_EXISTS) {
+            log.info("Installation type is pre-existing; skipping installation");
+            return;
+        }
+
         // Check if there is a newer archive or missing marker to trigger assembly install
         File installMarker = new File(geronimoHome, ".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()) {
+            else if (assemblyArchive.lastModified() > installMarker.lastModified()) {
                 log.debug("Detected new assembly archive");
                 refresh = true;
             }
@@ -269,7 +312,7 @@
 
         if (refresh) {
             if (geronimoHome.exists()) {
-                log.debug("Removing: " + geronimoHome);
+                log.info("Uninstalling: " + geronimoHome);
                 FileUtils.forceDelete(geronimoHome);
             }
         }
@@ -279,13 +322,9 @@
             log.info("Installing assembly...");
 
             FileUtils.forceMkdir(geronimoHome);
-
-            //
-            // TODO: Maybe consider supporting untar + gz/bz ?
-            //
             
             Expand unzip = (Expand)createTask("unzip");
-            unzip.setSrc(installArchive);
+            unzip.setSrc(assemblyArchive);
             unzip.setDest(installDirectory);
             unzip.execute();
 
@@ -299,7 +338,7 @@
             installMarker.createNewFile();
         }
         else {
-            log.debug("Assembly already installed");
+            log.info("Re-using previously installed assembly");
         }
     }
 }

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?view=diff&rev=440064&r1=440063&r2=440064
==============================================================================
--- 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 Mon Sep  4 06:13:54 2006
@@ -111,14 +111,10 @@
     private Timer timer = new Timer(true);
 
     protected void doExecute() throws Exception {
-        log.info("Starting Geronimo server...");
-
-        //
-        // TODO: Support existing install (no assembly install logic), which needs geronimoHome to be set and exist
-        //
-
-        doInstall();
+        installAssembly();
 
+        log.info("Starting Geronimo server...");
+        
         // Setup the JVM to start the server with
         final Java java = (Java)createTask("java");
         java.setJar(new File(geronimoHome, "bin/server.jar"));