geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r660581 - in /geronimo/server/trunk/buildsupport/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/module: InstallPluginMojo.java ModuleMojoSupport.java
Date Tue, 27 May 2008 16:20:25 GMT
Author: djencks
Date: Tue May 27 09:20:19 2008
New Revision: 660581

URL: http://svn.apache.org/viewvc?rev=660581&view=rev
Log:
GERONIMO-8043 add install plugin command to g-m-p

Added:
    geronimo/server/trunk/buildsupport/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/module/InstallPluginMojo.java
      - copied, changed from r658731, geronimo/server/trunk/buildsupport/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/module/DeployModuleMojo.java
Modified:
    geronimo/server/trunk/buildsupport/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/module/ModuleMojoSupport.java

Copied: geronimo/server/trunk/buildsupport/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/module/InstallPluginMojo.java
(from r658731, geronimo/server/trunk/buildsupport/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/module/DeployModuleMojo.java)
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/buildsupport/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/module/InstallPluginMojo.java?p2=geronimo/server/trunk/buildsupport/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/module/InstallPluginMojo.java&p1=geronimo/server/trunk/buildsupport/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/module/DeployModuleMojo.java&r1=658731&r2=660581&rev=660581&view=diff
==============================================================================
--- geronimo/server/trunk/buildsupport/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/module/DeployModuleMojo.java
(original)
+++ geronimo/server/trunk/buildsupport/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/module/InstallPluginMojo.java
Tue May 27 09:20:19 2008
@@ -20,164 +20,171 @@
 package org.apache.geronimo.mavenplugins.geronimo.module;
 
 import java.io.File;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.Iterator;
+import java.io.IOException;
 
-import javax.enterprise.deploy.spi.DeploymentManager;
 import javax.enterprise.deploy.spi.Target;
 import javax.enterprise.deploy.spi.TargetModuleID;
-import javax.enterprise.deploy.spi.status.ProgressObject;
+import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException;
+import javax.enterprise.deploy.spi.exceptions.TargetException;
 import javax.enterprise.deploy.spi.status.DeploymentStatus;
+import javax.enterprise.deploy.spi.status.ProgressObject;
 
+import org.apache.geronimo.deployment.plugin.GeronimoDeploymentManager;
+import org.apache.geronimo.system.plugin.DownloadResults;
+import org.apache.geronimo.system.plugin.PluginInstallerGBean;
+import org.apache.geronimo.system.plugin.model.ArtifactType;
+import org.apache.geronimo.system.plugin.model.PluginArtifactType;
+import org.apache.geronimo.system.plugin.model.PluginListType;
+import org.apache.geronimo.system.plugin.model.PluginType;
 import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.plugin.MojoExecutionException;
 
-import org.apache.geronimo.mavenplugins.geronimo.ModuleConfig;
-
 /**
  * Deploy modules (and optionally starting them) to a Geronimo server.
  *
- * @goal deploy-module
- * 
  * @version $Rev$ $Date$
+ * @goal install-plugin
  */
-public class DeployModuleMojo
-    extends ModuleMojoSupport
-{
+public class InstallPluginMojo
+        extends ModuleMojoSupport {
     /**
-     * A file which points to a specific module's jar | war | ear | rar archive.
-     * If this parameter is set, then it will be used instead of from the
-     * modules configuration.
+     * Flag to indicate if modules should be started after they have been distributed to
the server.
      *
-     * @parameter expression="${moduleArchive}"
+     * @parameter default-value="true"
      * @optional
      */
-    protected File moduleArchive = null;
+    private boolean startModules = false;
 
     /**
-     * The fully qualified path of the external plan file (geronimo-web.xml).
-     * The application module may already have included in the package a deployment plan
or the
-     * application is so simple that may not require any deployment plan.
-     * 
-     * @parameter expression="${modulePlan}"
-     * @optional
+     * Artifact file
+     *
+     * @parameter expression="${project.build.directory}/${project.build.finalName}.car"
+     * @readonly
+     * @required
      */
-    private File modulePlan = null;
+    private File artifactFile;
 
     /**
-     * Flag to indicate if modules should be started after they have been distributed to
the server.
+     * maven artifact
      *
-     * @parameter default-value="true"
-     * @optional
+     * @parameter expression="${project.artifact}"
+     * @readonly
+     * @required
      */
-    private boolean startModules = false;
+    private Artifact artifact;
 
-    protected void doExecute() throws Exception {
-        List completed = new ArrayList();
-
-        if (moduleArchive != null || modulePlan != null) {
-            log.info("Using non-artifact based module archive: " + moduleArchive);
-            if (modulePlan != null) {
-                log.info("Using non-artifact based plan: " + modulePlan);
-            }
+    /**
+     * local repository location
+     *
+     * @parameter expression="${localRepository}"
+     * @readonly
+     * @required
+     */
+    private ArtifactRepository artifactRepository;
 
-            TargetModuleID[] ids = distribute(moduleArchive, modulePlan);
-            completed.add(ids);
-        }
-        else if (modules == null || modules.length == 0) {
-            throw new MojoExecutionException("At least one module configuration (or moduleArchive)
must be specified");
-        }
+    /**
+     * Default geronimo repository matching the geronimo version to install to
+     *
+     * @parameter
+     */
+    private String defaultGeronimoRepository;
 
-        if (modules != null && modules.length != 0) {
-            log.info("Using artifact based module archive(s)...");
-
-            for (int i=0; i<modules.length; i++) {
-                TargetModuleID[] ids = distribute(getModuleArchive(modules[i]), modules[i].getPlan());
-                completed.add(ids);
-            }
-        }
+    @Override
+    public void execute() throws MojoExecutionException {
+        getLog().info("artifactFile: " + artifactFile);
+        getLog().info("artifact: " + artifact);
+        getLog().info("artifactRepository: " + artifactRepository);
+
+        String moduleId = artifact.getGroupId() + "/" + artifact.getArtifactId() + "/" +
artifact.getVersion() + "/" + artifact.getType();
+        org.apache.geronimo.kernel.repository.Artifact geronimoArtifact = org.apache.geronimo.kernel.repository.Artifact.create(moduleId);
+
+        PluginListType pluginListType = new PluginListType();
+        String defaultRepository = artifactRepository.getBasedir();
+        if (defaultGeronimoRepository != null) {
+            pluginListType.getDefaultRepository().add(defaultGeronimoRepository);
+            defaultRepository = defaultGeronimoRepository;
+        }
+        pluginListType.getDefaultRepository().add(artifactRepository.getBasedir());
+        PluginType pluginType = new PluginType();
+        pluginListType.getPlugin().add(pluginType);
+        PluginArtifactType instance = new PluginArtifactType();
+        pluginType.getPluginArtifact().add(instance);
+        ArtifactType artifactType = PluginInstallerGBean.toArtifactType(geronimoArtifact);
+        instance.setModuleId(artifactType);
+
+        GeronimoDeploymentManager mgr = getDeploymentManager2();
+        Object key = mgr.startInstall(pluginListType, defaultRepository, false, null, null);
+//        Object key = mgr.startInstall(artifactFile, defaultRepository, false, null, null);
+        waitTillDone(mgr, key);
 
         if (startModules) {
-            log.info("Starting modules...");
-
-            Iterator iter = completed.iterator();
-            while (iter.hasNext()) {
-                TargetModuleID[] moduleIds = (TargetModuleID[])iter.next();
-                for (int i=0; i < moduleIds.length; i++) {
-                    String url = moduleIds[i].getWebURL();
-                    log.info("Starting module: " + moduleIds[i].getModuleID() + (url == null
? "" : ("; URL: " + url)));
-                }
-
-                ProgressObject progress = getDeploymentManager().start(moduleIds);
-                DeploymentStatus status = waitFor(progress);
-
-                if (status.isFailed()) {
-                    throw new MojoExecutionException("Failed to start modules: " + status.getMessage());
+            getLog().info("Starting modules...");
+            Target[] allTargets = mgr.getTargets();
+            TargetModuleID[] allModules;
+            try {
+                allModules = mgr.getAvailableModules(null, allTargets);
+            } catch (TargetException e) {
+                throw new MojoExecutionException("Unable to load module list from server",
e);
+            }
+            TargetModuleID id = null;
+            for (TargetModuleID test : allModules) {
+                if (geronimoArtifact.matches(org.apache.geronimo.kernel.repository.Artifact.create(test.getModuleID())))
{
+                    id = test;
+                    break;
                 }
+            }
+            if (id == null) {
+                throw new MojoExecutionException("Just installed plugin cannot be located");
+            }
+            TargetModuleID[] ids = new TargetModuleID[]{id};
 
-                log.info("Started module(s):");
-                logModules(moduleIds, "    ");
+            ProgressObject progress = getDeploymentManager2().start(ids);
+            DeploymentStatus status = null;
+            try {
+                status = waitFor(progress);
+            } catch (InterruptedException e) {
+                throw new MojoExecutionException("Interrupted waiting for start completion",
e);
             }
-        }
-    }
 
-    private File getModuleArchive(final ModuleConfig module) throws MojoExecutionException
{
-        Artifact artifact = getArtifact(module);
+            if (status.isFailed()) {
+                throw new MojoExecutionException("Failed to start modules: " + status.getMessage());
+            }
 
-        File file = artifact.getFile();
-        if (file == null) {
-            throw new MojoExecutionException("Module artifact does not have an attached file:
" + module);
+            getLog().info("Started module(s):");
+            logModules(ids, "    ");
         }
+    }
 
-        String type = artifact.getType();
-        log.debug("Artifact file is: " + file + " (" + type + ")");
-
-        if ((!"war".equals(type)) &&
-            (!"ear".equals(type)) &&
-            (!"rar".equals(type)) &&
-            (!"jar".equals(type)))
-        {
-            throw new MojoExecutionException("Module does not look like a JavaEE archive:
" + module);
+    private GeronimoDeploymentManager getDeploymentManager2() throws MojoExecutionException
{
+        try {
+            return (GeronimoDeploymentManager) getDeploymentManager();
+        } catch (IOException e) {
+            throw new MojoExecutionException("could not communicate with server", e);
+        } catch (DeploymentManagerCreationException e) {
+            throw new MojoExecutionException("Could not create deployment manager", e);
         }
-
-        return file;
     }
 
-    private TargetModuleID[] distribute(final File file, final File plan) throws Exception
{
-        if (log.isInfoEnabled()) {
-            String msg = "Distributing module artifact: " + file;
-            if (plan != null) {
-                msg += " with plan " + plan;
+    static DownloadResults waitTillDone(GeronimoDeploymentManager mgr, Object key) throws
MojoExecutionException {
+        while (true) {
+            DownloadResults results = mgr.checkOnInstall(key);
+            if (results.isFinished()) {
+                if (results.isFailed()) {
+                    throw new MojoExecutionException("Failed to install plugin");
+                }
+                return results;
             }
-            log.info(msg);
-        }
-
-        DeploymentManager manager = getDeploymentManager();
-        Target[] targets = manager.getTargets();
-        if (null == targets) {
-            throw new IllegalStateException("No target to distribute to");
-        }
-        targets = new Target[] {targets[0]};
-        
-        ProgressObject progress = manager.distribute(targets, file, plan);
-        DeploymentStatus status = waitFor(progress);
-
-        if (status.isFailed()) {
-            //
-            // FIXME: There must be a better way to handle this.
-            //
-            if (status.getMessage().indexOf("already exists") < 0 ) {
-                throw new MojoExecutionException("Distribution failed: " + status.getMessage());
+            try {
+                Thread.sleep(1000);
+            } catch (InterruptedException e) {
+                throw new MojoExecutionException("Failed to install plugin, interrupted");
             }
-            log.info("Module already exists");
         }
-        
-
-        return (progress != null) ? progress.getResultTargetModuleIDs() : null;
     }
 
+
     protected String getFullClassName() {
         return this.getClass().getName();
-    } 
-}
+    }
+}
\ No newline at end of file

Modified: geronimo/server/trunk/buildsupport/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/module/ModuleMojoSupport.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/buildsupport/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/module/ModuleMojoSupport.java?rev=660581&r1=660580&r2=660581&view=diff
==============================================================================
--- geronimo/server/trunk/buildsupport/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/module/ModuleMojoSupport.java
(original)
+++ geronimo/server/trunk/buildsupport/geronimo-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/geronimo/module/ModuleMojoSupport.java
Tue May 27 09:20:19 2008
@@ -346,7 +346,7 @@
 
         for (int i=0; i<targetIds.length; i++) {
             String url = targetIds[i].getWebURL();
-            log.info(pad + "[" + i + "] " + targetIds[i].getModuleID() + (url == null ? ""
: ("; URL: " + url)));
+            getLog().info(pad + "[" + i + "] " + targetIds[i].getModuleID() + (url == null
? "" : ("; URL: " + url)));
 
             TargetModuleID[] children = targetIds[i].getChildTargetModuleID();
             if (children != null) {



Mime
View raw message