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/07/12 00:03:00 UTC

svn commit: r421007 - in /geronimo/sandbox/svkmerge/m2migration/m2-plugins: ./ geronimo-deployment-plugin/ geronimo-deployment-plugin/src/ geronimo-deployment-plugin/src/java/ geronimo-deployment-plugin/src/java/org/ geronimo-deployment-plugin/src/java...

Author: jdillon
Date: Tue Jul 11 15:02:59 2006
New Revision: 421007

URL: http://svn.apache.org/viewvc?rev=421007&view=rev
Log:
Applied geronimo-deployment-plugin-RTC-VOTE.3.patch from GERONIMO-1738

Added:
    geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/
    geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/pom.xml   (with props)
    geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/
    geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/
    geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/
    geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/
    geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/
    geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/
    geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/
    geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/AbstractModuleMojo.java   (with props)
    geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/DistributeModuleMojo.java   (with props)
    geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StartModuleMojo.java   (with props)
    geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StartRemoteServerMojo.java   (with props)
    geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StartServerMojo.java   (with props)
    geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StopModuleMojo.java   (with props)
    geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StopRemoteServerMojo.java   (with props)
    geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StopServerMojo.java   (with props)
    geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/UndeployModuleMojo.java   (with props)
    geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/util/
    geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/util/DeploymentClient.java   (with props)
    geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/util/ServerBehavior.java   (with props)
Modified:
    geronimo/sandbox/svkmerge/m2migration/m2-plugins/pom.xml

Added: geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/pom.xml?rev=421007&view=auto
==============================================================================
--- geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/pom.xml (added)
+++ geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/pom.xml Tue Jul 11 15:02:59 2006
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+
+<!-- $Rev$ $Date$ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.geronimo.plugins</groupId>
+        <artifactId>plugins</artifactId>
+        <version>1.2-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+
+    <artifactId>geronimo-deployment-plugin</artifactId>
+    <name>Geronimo Plugins :: Deployment</name>
+    
+    <packaging>maven-plugin</packaging>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.geronimo.modules</groupId>
+            <artifactId>geronimo-deploy-jsr88</artifactId>
+            <version>${pom.version}</version>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <defaultGoal>install</defaultGoal>
+        <plugins>
+            <plugin>
+                <artifactId>maven-plugin-plugin</artifactId>
+                <configuration>
+                    <goalPrefix>deploy</goalPrefix>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+    
+</project>

Propchange: geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/AbstractModuleMojo.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/AbstractModuleMojo.java?rev=421007&view=auto
==============================================================================
--- geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/AbstractModuleMojo.java (added)
+++ geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/AbstractModuleMojo.java Tue Jul 11 15:02:59 2006
@@ -0,0 +1,257 @@
+/**
+ *
+ * Copyright 2004-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.plugins.deployment;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+
+import javax.enterprise.deploy.shared.factories.DeploymentFactoryManager;
+
+import javax.enterprise.deploy.spi.DeploymentManager;
+import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException;
+
+import org.apache.geronimo.deployment.plugin.factories.DeploymentFactoryImpl;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+/**
+ * @version $Rev:$ $Date:$
+ */
+public abstract class AbstractModuleMojo extends AbstractMojo {
+    
+    /**
+     * The uri to look up the JMXConnector.
+     * 
+     * @parameter default-value="jmx:rmi://localhost/jndi/rmi:/JMXConnector"
+     */
+    private String uri;
+
+
+    /**
+     * @parameter
+     */
+    protected String id;
+    
+
+    /**
+     * The uri to connect to the jmx connector with.
+     * 
+     * @parameter default-value="deployer:geronimo:jmx"
+     */
+    private String distributeURI;
+
+    /**
+     * The authentication user name.
+     * 
+     * @parameter default-value="system"
+     */
+    private String username;
+
+    /**
+     * The authentication password.
+     * 
+     * @parameter default-value="manager"
+     */
+    private String password;
+
+    /**
+     * The time between connect attempts.
+     * 
+     * @parameter default-value=0
+     */
+    private long sleepTimer;
+
+    /**
+     * @parameter default-value=100
+     */
+    private int maxTries;
+
+    /**
+     * @parameter default-value=2000
+     */
+    private int retryIntervalMilliseconds;
+
+    /**
+     * @parameter default-value=true
+     */
+    private boolean failOnError;
+
+    /**
+     * @parameter
+     */
+    private File outputDirectory;
+
+    /**
+     * @parameter default-value=null
+     */
+    private File resultsLog;
+
+    protected final String lineSep = "===========================================";
+
+    public abstract void execute() throws MojoExecutionException;
+
+    protected DeploymentManager getDeploymentManager() throws IOException, DeploymentManagerCreationException {
+        if (getUsername() == null) {
+            throw new IllegalStateException("No user specified");
+        }
+        if (getPassword() == null) {
+            throw new IllegalStateException("No password specified");
+        }
+        if (getDistributeURI() == null) {
+            throw new IllegalStateException("No uri specified");
+        }
+        new DeploymentFactoryImpl();
+
+        ClassLoader oldcl = Thread.currentThread().getContextClassLoader();
+        try {
+            Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
+            DeploymentFactoryManager factoryManager = DeploymentFactoryManager.getInstance();
+            DeploymentManager manager = factoryManager.getDeploymentManager(getDistributeURI(), getUsername(), getPassword());
+            return manager;
+        }
+        finally {
+            Thread.currentThread().setContextClassLoader(oldcl);
+        }
+    }
+
+    /**
+     * @return Returns the maxTries.
+     */
+    public int getMaxTries() {
+        return maxTries;
+    }
+
+    /**
+     * @return Returns the retryIntervalMilliseconds.
+     */
+    public int getRetryIntervalMilliseconds() {
+        return retryIntervalMilliseconds;
+    }
+
+    /**
+     * @return Returns the sleepTimer.
+     */
+    public long getSleepTimer() {
+        return sleepTimer;
+    }
+
+    public String getUri() {
+        return uri;
+    }
+
+    public String getDistributeURI() {
+        return distributeURI;
+    }
+
+    public String getUsername() {
+        return username;
+    }
+
+    public String getPassword() {
+        return password;
+    }
+
+    public boolean isFailOnError() {
+        return failOnError;
+    }
+
+    public File getOutputDirectory() {
+        return outputDirectory;
+    }
+
+    public PrintStream getResultsStream() {
+        PrintStream resultStream = null;
+        if (this.resultsLog != null) {
+            try {
+                resultStream = new PrintStream(new FileOutputStream(this.resultsLog, true), true);
+            }
+            catch (FileNotFoundException e) {
+                //e.printStackTrace();
+                getLog().warn(e.toString());
+                getLog().warn("Results cannot be logged");
+            }
+        }
+        return resultStream;
+    }
+
+    public PrintStream getLogStream(String goalName) {
+        PrintStream stream = System.out;
+    
+        if (this.outputDirectory != null) {
+            if (!this.outputDirectory.exists())
+                this.outputDirectory.mkdirs();
+    
+            String fileName = this.outputDirectory.getAbsolutePath() + File.separator + goalName + ".log";
+    
+            try {
+                stream = new PrintStream(new FileOutputStream(fileName, true), true);
+            }
+            catch (FileNotFoundException e) {
+                //e.printStackTrace();
+                getLog().warn(e.toString());
+                getLog().warn("No logs will be available");
+            }
+        }
+        return stream;
+    }
+
+    public void logResults(PrintStream resultStream, String goalName, String result) {
+        if (resultStream != null)
+            getResultsStream().println(goalName + ":" + result);
+    }
+
+    /**
+     * Method is used to point to the log location for more errors.
+     */
+    protected void seeLog() {
+        if (this.outputDirectory != null)
+            getLog().error("See log at " + getOutputDirectory().getAbsolutePath() + " for more details");
+    }
+
+    public void debug(String debugString) {
+        System.out.println(debugString);
+    }
+
+    /**
+     * @param e
+     * @param logStream
+     * @throws MojoExecutionException
+     * @throws MojoFailureException
+     */
+    protected void handleError(Exception e, PrintStream logStream) throws MojoExecutionException {
+        seeLog();
+        e.printStackTrace(logStream);
+        logStream.println(lineSep);
+        if (isFailOnError()) {            
+            throw (MojoExecutionException) new MojoExecutionException(e.toString(), e);
+        }
+        else {            
+             try {
+                throw (MojoFailureException) new MojoFailureException(e, e.toString(), e.getMessage());
+            }
+            catch (MojoFailureException e1) {
+                e1.printStackTrace(logStream);
+                logStream.println(lineSep);
+            }
+        }
+    }
+}

Propchange: geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/AbstractModuleMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/AbstractModuleMojo.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/AbstractModuleMojo.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/DistributeModuleMojo.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/DistributeModuleMojo.java?rev=421007&view=auto
==============================================================================
--- geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/DistributeModuleMojo.java (added)
+++ geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/DistributeModuleMojo.java Tue Jul 11 15:02:59 2006
@@ -0,0 +1,89 @@
+/**
+ *
+ * Copyright 2004-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.plugins.deployment;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.net.MalformedURLException;
+
+import javax.enterprise.deploy.spi.DeploymentManager;
+import javax.enterprise.deploy.spi.Target;
+import javax.enterprise.deploy.spi.status.ProgressObject;
+
+import org.apache.geronimo.plugins.util.DeploymentClient;
+import org.apache.maven.plugin.MojoExecutionException;
+
+/**
+ * 
+ * @goal distribute
+ * 
+ * @version $Rev:$ $Date:$
+ */
+public class DistributeModuleMojo extends AbstractModuleMojo {
+
+    /**
+     * @parameter
+     */
+    private String module;
+
+    /**
+     * @parameter
+     */
+    private String plan;
+
+    private PrintStream logStream = System.out;
+    private PrintStream resultStream;
+    
+    private final String goalName = "Deploy Module";
+
+    public void execute() throws MojoExecutionException {
+        resultStream = getResultsStream();
+        logStream = getLogStream(goalName);
+        
+        DeploymentManager manager;
+        try {
+            manager = getDeploymentManager();
+
+            Target[] targets = manager.getTargets();
+            File moduleFile = (this.module == null) ? null : getFile(this.module);
+            File planFile = (this.plan == null) ? null : getFile((this.plan));
+            ProgressObject progress = manager.distribute(targets, moduleFile, planFile);
+            DeploymentClient.waitFor(progress);
+        }
+        catch (Exception e) {
+            logResults(resultStream, goalName, "fail");
+            handleError(e, logStream);
+            return;
+        }
+        logResults(resultStream, goalName, "success");  
+    }
+
+    private File getFile(String location) throws MalformedURLException {
+        try {
+            File f = new File(location).getCanonicalFile();
+            if (!f.exists() || !f.canRead()) {
+                throw new MalformedURLException("Invalid location: " + location);
+            }
+            return f;
+        }
+        catch (IOException e) {
+            throw (MalformedURLException) new MalformedURLException("Invalid location: " + location).initCause(e);
+        }
+    }
+}

Propchange: geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/DistributeModuleMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/DistributeModuleMojo.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/DistributeModuleMojo.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StartModuleMojo.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StartModuleMojo.java?rev=421007&view=auto
==============================================================================
--- geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StartModuleMojo.java (added)
+++ geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StartModuleMojo.java Tue Jul 11 15:02:59 2006
@@ -0,0 +1,80 @@
+/**
+ *
+ * Copyright 2004-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.plugins.deployment;
+
+import java.io.PrintStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.enterprise.deploy.spi.Target;
+import javax.enterprise.deploy.spi.TargetModuleID;
+import javax.enterprise.deploy.spi.status.ProgressObject;
+
+import org.apache.geronimo.deployment.plugin.jmx.RemoteDeploymentManager;
+import org.apache.geronimo.plugins.util.DeploymentClient;
+import org.apache.maven.plugin.MojoExecutionException;
+
+/**
+ * 
+ * @goal start
+ * 
+ * @version $Rev:$ $Date:$
+ *  
+ */
+public class StartModuleMojo extends AbstractModuleMojo {
+
+    private PrintStream logStream = System.out;
+
+    private PrintStream resultStream;
+
+    private final String goalName = "Start Module";
+
+    public void execute() throws MojoExecutionException {
+        resultStream = getResultsStream();
+        logStream = getLogStream(goalName);
+        RemoteDeploymentManager manager;
+        try {
+            manager = (RemoteDeploymentManager) getDeploymentManager();
+            manager.setLogConfiguration(true, true);
+
+            Target[] targets = manager.getTargets();
+            TargetModuleID moduleIds[] = manager.getNonRunningModules(null, targets);
+            List toStart = new ArrayList(moduleIds.length);
+            for (int i = 0; i < moduleIds.length; i++) {
+                TargetModuleID moduleId = moduleIds[i];
+                if (this.id.equals(moduleId.getModuleID())) {
+                    toStart.add(moduleId);
+                }
+            }
+            if (toStart.size() == 0) {
+                logResults(resultStream, goalName, "fail");
+                handleError(new Exception("Module is already running or may not be deployed: " + this.id), logStream);
+                return;
+            }
+            moduleIds = (TargetModuleID[]) toStart.toArray(new TargetModuleID[toStart.size()]);
+            ProgressObject progress = manager.start(moduleIds);            
+            DeploymentClient.waitFor(progress);            
+        }
+        catch (Exception e) {
+            logResults(resultStream, goalName, "fail");
+            handleError(e, logStream);
+            return;
+        }
+        logResults(resultStream, goalName, "success");
+    }
+}

Propchange: geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StartModuleMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StartModuleMojo.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StartModuleMojo.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StartRemoteServerMojo.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StartRemoteServerMojo.java?rev=421007&view=auto
==============================================================================
--- geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StartRemoteServerMojo.java (added)
+++ geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StartRemoteServerMojo.java Tue Jul 11 15:02:59 2006
@@ -0,0 +1,183 @@
+/**
+ *
+ * Copyright 2004-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.plugins.deployment;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.util.ArrayList;
+import java.util.StringTokenizer;
+
+import org.apache.geronimo.plugins.util.ServerBehavior;
+import org.apache.maven.plugin.MojoExecutionException;
+
+/**
+ * @goal startRemoteServer
+ * 
+ * @version $Rev:$ $Date:$
+ */
+public class StartRemoteServerMojo extends AbstractModuleMojo {
+
+    /**
+     * @parameter
+     */
+    private String geronimoTarget;
+
+    /**
+     * @parameter default-value=""
+     */
+    private String vmArgs = "";
+
+    /**
+     * @parameter
+     */
+    private String[] configs;
+
+    /**
+     * @parameter
+     */
+    private String debugPort;
+
+    private PrintStream logStream = System.out;
+    private PrintStream resultStream;
+    
+    private final String goalName = "Start Remote Server";
+
+    public void execute() throws MojoExecutionException {
+        resultStream = getResultsStream();        
+        logStream = getLogStream(goalName);
+        
+        try {
+            startRemoteServer();
+        }
+        catch (Exception e) {
+            logResults(resultStream, goalName, "fail");
+            handleError(e, logStream);
+            return;
+        }
+        logResults(resultStream, goalName, "success");
+    }
+    
+    /**
+     * @throws MojoExecutionException
+     */
+    private void startRemoteServer() throws Exception {
+        ArrayList cmd = new ArrayList();
+        File root = new File(this.geronimoTarget);
+        File systemFile = new File(root, "bin/server.jar");
+        String s = java.io.File.separator;
+        String java = System.getProperty("java.home") + s + "bin" + s + "java";
+
+        cmd.add(java);
+
+        if (debugPort != null) {
+            cmd.add("-Xdebug");
+            cmd.add("-Xnoagent");
+            cmd.add("-Djava.compiler=NONE");
+            cmd.add("-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=" + debugPort);
+        }
+
+        for (StringTokenizer st = new StringTokenizer(this.vmArgs); st.hasMoreTokens();) {
+            cmd.add(st.nextToken());
+        }
+
+        cmd.add("-ea");
+        cmd.add("-jar");
+
+        if (systemFile.exists()) {
+            try {
+                cmd.add(systemFile.getCanonicalPath());
+            }
+            catch (IOException e) {
+            }
+        }
+        else {
+            throw new Exception(systemFile.getAbsolutePath() + " does not exist");                                 
+        }
+
+        cmd.add("--quiet");
+
+        if (this.configs != null && this.configs.length > 0) {
+            cmd.add("--override");
+            for (int i=0; i < this.configs.length; i++) {
+                cmd.add(this.configs[i]);
+            }
+        }
+        String[] command = (String[]) cmd.toArray(new String[0]);
+
+        Runtime runtime = Runtime.getRuntime();
+        Process server;
+        try {
+            server = runtime.exec(command);
+
+            // Pipe the processes STDOUT to ours
+            InputStream outStream = server.getInputStream();
+            Thread serverOut = new Thread(new Pipe(outStream, logStream));
+            serverOut.setDaemon(true);
+            serverOut.start();
+
+            // Pipe the processes STDERR to ours
+            InputStream errStream = server.getErrorStream();
+            Thread serverErr = new Thread(new Pipe(errStream, logStream));
+            serverErr.setDaemon(true);
+            serverErr.start();
+
+            ServerBehavior sb = new ServerBehavior(getUri(), getMaxTries(), getRetryIntervalMilliseconds());
+            sb.setLogStream(logStream);
+            if (!sb.isFullyStarted()) {
+                server.destroy();
+                throw new Exception("Server did not start");
+            }
+        }
+        catch (Exception e1) {
+            throw new Exception(e1);
+        }
+    }
+
+    public void destroy() {
+        logStream.close();
+    }
+
+    private final class Pipe implements Runnable {
+
+        private final InputStream in;
+
+        private final OutputStream out;
+
+        public Pipe(InputStream in, OutputStream out) {
+            this.in = in;
+            this.out = out;
+        }
+
+        public void run() {
+            int i;
+            try {
+                do {
+                    i = in.read();
+                    out.write(i);
+                }
+                while (i != -1);
+            }
+            catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+    }
+}

Propchange: geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StartRemoteServerMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StartRemoteServerMojo.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StartRemoteServerMojo.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StartServerMojo.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StartServerMojo.java?rev=421007&view=auto
==============================================================================
--- geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StartServerMojo.java (added)
+++ geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StartServerMojo.java Tue Jul 11 15:02:59 2006
@@ -0,0 +1,180 @@
+/**
+ *
+ * Copyright 2004-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.plugins.deployment;
+
+import java.io.File;
+import java.io.ObjectInputStream;
+import java.io.PrintStream;
+import java.net.URI;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import javax.management.ObjectName;
+
+import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.gbean.GBeanData;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.KernelFactory;
+import org.apache.geronimo.kernel.config.Configuration;
+import org.apache.geronimo.kernel.config.ConfigurationManager;
+import org.apache.geronimo.kernel.config.ConfigurationUtil;
+import org.apache.geronimo.kernel.config.ManageableAttributeStore;
+import org.apache.geronimo.kernel.log.GeronimoLogging;
+import org.apache.geronimo.kernel.repository.Artifact;
+import org.apache.maven.plugin.MojoExecutionException;
+
+/**
+ * This starts a geronimo server in vm.  It might not have ever been used.
+ *
+ * @goal startServer
+ * 
+ * @version $Rev:$ $Date:$
+ *  
+ */
+public class StartServerMojo extends AbstractModuleMojo {
+
+    static {
+        // This MUST be done before the first log is acquired
+        GeronimoLogging.initialize(GeronimoLogging.INFO);
+    }
+
+    /**
+     * @parameter expression=${basedir}/target default-value=${basedir}/target
+     */
+    private String geronimoHome;
+
+    /**
+     * @parameter
+     */
+    private String domainName;
+
+    /**
+     * @parameter
+     */
+    private String[] configs;
+
+    private String kernelName;
+    private PrintStream logStream = System.out;
+
+    private PrintStream resultStream;
+
+    private final String goalName = "Start Server";
+
+    public void execute() throws MojoExecutionException {
+        resultStream = getResultsStream();
+        logStream = getLogStream(goalName);
+
+        try {
+            startServer();
+        }
+        catch (Exception e) {
+            logResults(resultStream, goalName, "fail");
+            handleError(e, logStream);
+            return;
+        }
+        logResults(resultStream, goalName, "success");
+    }
+
+    /**
+     * @throws MojoExecutionException
+     */
+    private void startServer() throws Exception {
+        System.setProperty("org.apache.geronimo.base.dir", this.geronimoHome);
+        List configList = new ArrayList();
+        if (this.configs != null && this.configs.length > 0) {
+            for (int i=0; i < this.configs.length; i++) {
+                try {
+                    configList.add(Artifact.create(this.configs[i]));
+                }
+                catch (Exception e) {
+                    throw e;
+                }
+            }
+        }
+        File root = new File(this.geronimoHome);
+        if (!root.exists())
+            throw new Exception(root.getAbsolutePath() + " does not exist");
+
+        URL systemURL = null;
+        URL configURL = null;
+        try {
+            systemURL = new File(root, "bin/server.jar").toURL();
+            configURL = new URL("jar:" + systemURL.toString() + "!/META-INF/config.ser");
+        }
+        catch (Exception e) {
+            throw e;
+        }
+        GBeanData configuration = new GBeanData();
+        ObjectInputStream ois = null;
+        try {
+            ois = new ObjectInputStream(configURL.openStream());
+            configuration.readExternal(ois);
+        }
+        catch (Exception e) {
+            throw e;
+        }
+        finally {
+            try {
+                ois.close();
+            }
+            catch (Exception e1) {
+                throw e1;
+            }
+        }
+        URI configurationId = (URI) configuration.getAttribute("id");
+        AbstractName abstractName = new AbstractName(configurationId);
+
+
+        configuration.setAbstractName(abstractName);
+        configuration.setAttribute("baseURL", systemURL);
+
+        // build a basic kernel without a configuration-store, our configuration
+        // store is
+        Kernel kernel = KernelFactory.newInstance().createKernel(this.kernelName);
+        try {
+            kernel.boot();
+            kernel.loadGBean(configuration, this.getClass().getClassLoader());
+            kernel.startGBean(abstractName);
+            kernel.invoke(abstractName, "loadGBeans", new Object[] { null}, new String[] { ManageableAttributeStore.class.getName()});
+            kernel.invoke(abstractName, "startRecursiveGBeans");
+        }
+        catch (Exception e) {
+            throw e;
+        }
+
+        // load the rest of the configuration listed on the command line
+        ConfigurationManager configurationManager = ConfigurationUtil.getConfigurationManager(kernel);
+        try {
+            for (Iterator i = configList.iterator(); i.hasNext();) {
+                Artifact configID = (Artifact) i.next();
+                configurationManager.loadConfiguration(configID);
+                configurationManager.startConfiguration(configID);
+                logStream.println("started gbean: " + configID.toString());
+            }
+        }
+        catch (Exception e) {
+            throw e;
+        }
+        finally {
+            ConfigurationUtil.releaseConfigurationManager(kernel, configurationManager);
+        }
+    }
+}

Propchange: geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StartServerMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StartServerMojo.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StartServerMojo.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StopModuleMojo.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StopModuleMojo.java?rev=421007&view=auto
==============================================================================
--- geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StopModuleMojo.java (added)
+++ geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StopModuleMojo.java Tue Jul 11 15:02:59 2006
@@ -0,0 +1,78 @@
+/**
+ *
+ * Copyright 2004-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.plugins.deployment;
+
+import java.io.PrintStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.enterprise.deploy.spi.Target;
+import javax.enterprise.deploy.spi.TargetModuleID;
+import javax.enterprise.deploy.spi.status.ProgressObject;
+
+import org.apache.geronimo.deployment.plugin.jmx.RemoteDeploymentManager;
+import org.apache.geronimo.plugins.util.DeploymentClient;
+import org.apache.maven.plugin.MojoExecutionException;
+
+/**
+ * @goal stop
+ * 
+ * @version $Rev:$ $Date:$
+ */
+public class StopModuleMojo extends AbstractModuleMojo {
+
+    private PrintStream logStream = System.out;
+
+    private PrintStream resultStream;
+
+    private final String goalName = "Stop Module";
+
+    public void execute() throws MojoExecutionException {
+        resultStream = getResultsStream();
+        logStream = getLogStream(goalName);
+        RemoteDeploymentManager manager;
+        try {
+            manager = (RemoteDeploymentManager) getDeploymentManager();
+            manager.setLogConfiguration(true, true);
+
+            Target[] targets = manager.getTargets();
+            TargetModuleID moduleIds[] = manager.getRunningModules(null, targets);
+            List toStop = new ArrayList(moduleIds.length);
+            for (int i = 0; i < moduleIds.length; i++) {
+                TargetModuleID moduleId = moduleIds[i];
+                if (this.id.equals(moduleId.getModuleID())) {
+                    toStop.add(moduleId);
+                }
+            }
+            if (toStop.size() == 0) {
+                logResults(resultStream, goalName, "fail");
+                handleError(new Exception("Module is not deployed: " + this.id), logStream);
+                return;
+            }
+            moduleIds = (TargetModuleID[]) toStop.toArray(new TargetModuleID[toStop.size()]);
+            ProgressObject progress = manager.stop(moduleIds);
+            DeploymentClient.waitFor(progress);
+        }
+        catch (Exception e) {
+            logResults(resultStream, goalName, "fail");
+            handleError(e, logStream);
+            return;
+        }
+        logResults(resultStream, goalName, "success");
+    }
+}

Propchange: geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StopModuleMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StopModuleMojo.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StopModuleMojo.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StopRemoteServerMojo.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StopRemoteServerMojo.java?rev=421007&view=auto
==============================================================================
--- geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StopRemoteServerMojo.java (added)
+++ geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StopRemoteServerMojo.java Tue Jul 11 15:02:59 2006
@@ -0,0 +1,99 @@
+/**
+ *
+ * Copyright 2004-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.plugins.deployment;
+
+import java.io.PrintStream;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.MBeanServerConnection;
+import javax.management.remote.JMXConnector;
+import javax.management.remote.JMXConnectorFactory;
+import javax.management.remote.JMXServiceURL;
+
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.system.jmx.KernelDelegate;
+import org.apache.maven.plugin.MojoExecutionException;
+
+/**
+ * @goal stopRemoteServer
+ *
+ * @version $Rev:$ $Date:$
+ */
+public class StopRemoteServerMojo extends AbstractModuleMojo {
+    private MBeanServerConnection mbServerConnection;
+    private Kernel kernel;
+
+    private PrintStream logStream = System.out;
+    
+    private PrintStream resultStream;
+    
+    private final String goalName = "Stop Remote Server";
+
+    public void execute() throws MojoExecutionException {
+        resultStream = getResultsStream();
+        logStream = getLogStream(goalName);
+        
+        try {
+            stopRemoteServer();
+        }
+        catch (Exception e) {
+            logResults(resultStream, goalName, "fail");
+            handleError(e, logStream);
+            return;
+        }
+        logResults(resultStream, goalName, "success"); 
+    }
+
+    /**
+     * 
+     */
+    private void stopRemoteServer() throws Exception {
+        String uri = getUri();
+        if (!uri.startsWith("jmx")) {            
+                throw new Exception("Bad JMX URI ("+uri+")");
+        }
+
+        Map environment = new HashMap();
+        String[] credentials = new String[]{getUsername(), getPassword()};
+        environment.put(JMXConnector.CREDENTIALS, credentials);
+
+        JMXServiceURL address = null;
+        JMXConnector jmxConnector;
+        try {
+            address = new JMXServiceURL("service:" + uri);
+        }
+        catch (Exception e) {
+            throw e;
+        }
+        ClassLoader oldcl = Thread.currentThread().getContextClassLoader();
+        try {
+            Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
+            jmxConnector = JMXConnectorFactory.connect(address, environment);
+            mbServerConnection = jmxConnector.getMBeanServerConnection();
+            kernel = new KernelDelegate(mbServerConnection);
+            kernel.shutdown();
+        }
+        catch (Exception e) {
+            throw e;
+        } 
+        finally {
+            Thread.currentThread().setContextClassLoader(oldcl);
+        }
+    }
+}

Propchange: geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StopRemoteServerMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StopRemoteServerMojo.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StopRemoteServerMojo.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StopServerMojo.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StopServerMojo.java?rev=421007&view=auto
==============================================================================
--- geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StopServerMojo.java (added)
+++ geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StopServerMojo.java Tue Jul 11 15:02:59 2006
@@ -0,0 +1,40 @@
+/**
+ *
+ * Copyright 2004-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.plugins.deployment;
+
+import org.apache.geronimo.kernel.KernelRegistry;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+
+/**
+ * In vm server stop.  May not have been tested.
+
+ * @goal stopServer
+ *
+ * @version $Rev:$ $Date:$
+ */
+public class StopServerMojo extends AbstractMojo {
+
+    private String kernelName;
+
+    public void execute() throws MojoExecutionException {
+        Kernel kernel = KernelRegistry.getKernel(this.kernelName);
+        kernel.shutdown();
+    }
+}

Propchange: geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StopServerMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StopServerMojo.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StopServerMojo.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/UndeployModuleMojo.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/UndeployModuleMojo.java?rev=421007&view=auto
==============================================================================
--- geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/UndeployModuleMojo.java (added)
+++ geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/UndeployModuleMojo.java Tue Jul 11 15:02:59 2006
@@ -0,0 +1,78 @@
+/**
+ *
+ * Copyright 2004-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.plugins.deployment;
+
+import java.io.PrintStream;
+import java.util.ArrayList;
+import java.util.List;
+
+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 org.apache.geronimo.plugins.util.DeploymentClient;
+import org.apache.maven.plugin.MojoExecutionException;
+
+/**
+ * @goal undeploy
+ *
+ * @version $Rev:$ $Date:$
+ */
+public class UndeployModuleMojo extends AbstractModuleMojo {
+
+    private PrintStream logStream = System.out;
+
+    private PrintStream resultStream;
+
+    private final String goalName = "Undeploy Module";
+
+    public void execute() throws MojoExecutionException {
+        resultStream = getResultsStream();
+        logStream = getLogStream(goalName);
+
+        DeploymentManager manager;
+        try {
+            manager = getDeploymentManager();
+
+            Target[] targets = manager.getTargets();
+            TargetModuleID moduleIds[] = manager.getNonRunningModules(null, targets);
+            List toUndeploy = new ArrayList(moduleIds.length);
+            for (int i = 0; i < moduleIds.length; i++) {
+                TargetModuleID moduleId = moduleIds[i];
+                if (this.id.equals(moduleId.getModuleID())) {
+                    toUndeploy.add(moduleId);
+                }
+            }
+            if (toUndeploy.size() == 0) {   
+                logResults(resultStream, goalName, "fail");
+                handleError(new Exception("Module is running or not deployed: " + this.id), logStream);
+                return;
+            }
+            moduleIds = (TargetModuleID[]) toUndeploy.toArray(new TargetModuleID[toUndeploy.size()]);
+            ProgressObject progress = manager.undeploy(moduleIds);
+            DeploymentClient.waitFor(progress);
+        }
+        catch (Exception e) {
+            logResults(resultStream, goalName, "fail");
+            handleError(e, logStream);
+            return;
+        }
+        logResults(resultStream, goalName, "success");
+    }
+}

Propchange: geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/UndeployModuleMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/UndeployModuleMojo.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/UndeployModuleMojo.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/util/DeploymentClient.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/util/DeploymentClient.java?rev=421007&view=auto
==============================================================================
--- geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/util/DeploymentClient.java (added)
+++ geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/util/DeploymentClient.java Tue Jul 11 15:02:59 2006
@@ -0,0 +1,104 @@
+/**
+ *
+ * Copyright 2004-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.plugins.util;
+
+import java.io.IOException;
+import java.net.JarURLConnection;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.StringTokenizer;
+import java.util.jar.Attributes;
+import javax.enterprise.deploy.shared.factories.DeploymentFactoryManager;
+import javax.enterprise.deploy.spi.factories.DeploymentFactory;
+import javax.enterprise.deploy.spi.status.ProgressObject;
+import javax.enterprise.deploy.spi.status.ProgressListener;
+import javax.enterprise.deploy.spi.status.ProgressEvent;
+import javax.enterprise.deploy.spi.status.DeploymentStatus;
+
+/**
+ * @version $Rev:$ $Date:$
+ */
+public class DeploymentClient {
+    private static final DeploymentFactoryManager FACTORY_MANAGER = DeploymentFactoryManager.getInstance();
+
+    private URL provider;
+
+    public URL getProvider() {
+        return provider;
+    }
+
+    public void setProvider(URL provider) {
+        this.provider = provider;
+    }
+
+    public void doIt() throws IOException {
+        registerProvider(provider, null);
+    }
+
+    public static void registerProvider(URL provider, ClassLoader parent) throws IOException {
+        if (parent == null) {
+            parent = Thread.currentThread().getContextClassLoader();
+        }
+        if (parent == null) {
+            parent = DeploymentClient.class.getClassLoader();
+        }
+
+        // read manifest entry from provider
+        URL url = new URL("jar:" + provider.toString() + "!/");
+        JarURLConnection jarConnection = (JarURLConnection) url.openConnection();
+        Attributes attrs = jarConnection.getMainAttributes();
+        String factoryNames = attrs.getValue("J2EE-DeploymentFactory-Implementation-Class");
+        if (factoryNames == null) {
+            throw new IOException("No DeploymentFactory found in jar");
+        }
+
+        // register listed DeploymentFactories
+        ClassLoader cl = new URLClassLoader(new URL[]{provider}, parent);
+        for (StringTokenizer tokenizer = new StringTokenizer(factoryNames); tokenizer.hasMoreTokens();) {
+            String className = tokenizer.nextToken();
+            try {
+                DeploymentFactory factory = (DeploymentFactory) cl.loadClass(className).newInstance();
+                FACTORY_MANAGER.registerDeploymentFactory(factory);
+            } catch (Exception e) {
+                throw (IOException) new IOException("Unable to instantiate DeploymentFactory: " + className).initCause(e);
+            }
+        }
+    }
+
+    public static void waitFor(final ProgressObject progress) throws InterruptedException {
+        ProgressListener listener = new ProgressListener() {
+            public void handleProgressEvent(ProgressEvent event) {
+                DeploymentStatus status = event.getDeploymentStatus();
+                if (status.getMessage() != null) {
+                    System.out.println(status.getMessage());
+                }
+                if (!status.isRunning()) {
+                    synchronized (progress) {
+                        progress.notify();
+                    }
+                }
+            }
+        };
+        progress.addProgressListener(listener);
+        synchronized (progress) {
+            while (progress.getDeploymentStatus().isRunning()) {
+                progress.wait();
+            }
+        }
+    }
+}

Propchange: geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/util/DeploymentClient.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/util/DeploymentClient.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/util/DeploymentClient.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/util/ServerBehavior.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/util/ServerBehavior.java?rev=421007&view=auto
==============================================================================
--- geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/util/ServerBehavior.java (added)
+++ geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/util/ServerBehavior.java Tue Jul 11 15:02:59 2006
@@ -0,0 +1,185 @@
+/**
+ *
+ * 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.plugins.util;
+
+import java.io.PrintStream;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.List;
+
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+import javax.management.remote.JMXConnector;
+import javax.management.remote.JMXConnectorFactory;
+import javax.management.remote.JMXServiceURL;
+
+import org.apache.geronimo.kernel.config.ConfigurationUtil;
+import org.apache.geronimo.kernel.config.ConfigurationManager;
+import org.apache.geronimo.kernel.GBeanNotFoundException;
+import org.apache.geronimo.kernel.InternalKernelException;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.NoSuchAttributeException;
+import org.apache.geronimo.kernel.config.PersistentConfigurationList;
+import org.apache.geronimo.system.jmx.KernelDelegate;
+
+/**
+ * @version $Rev:$ $Date:$
+ */
+public class ServerBehavior {
+
+    private int maxTries = 100;
+
+    private int retryIntervalMilliseconds = 1000;
+
+    private String uri = "jmx:rmi://localhost/jndi/rmi:/JMXConnector";
+
+    private String username = "system";
+
+    private String password = "manager";
+
+    private PrintStream logStream = System.out;
+
+    protected final String lineSep = "===========================================";
+
+    /**
+     * @param id
+     *            specify null for default
+     * @param maxTries
+     *            specify -1 for default. default-value=40
+     * @param retryIntervalMilliseconds
+     *            specify -1 for default. default-value=1000
+     */
+    public ServerBehavior(String uri, int maxTries, int retryIntervalMilliseconds) {
+        if (uri != null)
+            this.uri = uri;
+        if (maxTries > -1)
+            this.maxTries = maxTries;
+        if (retryIntervalMilliseconds > -1)
+            this.retryIntervalMilliseconds = retryIntervalMilliseconds;
+    }
+
+    /**
+     *  
+     */
+    public ServerBehavior(String uri) {
+        this(uri, -1, -1);
+    }
+
+    /**
+     *  
+     */
+    public ServerBehavior() {
+        this(null, -1, -1);
+    }
+
+    public boolean isFullyStarted() {
+        Kernel kernel = null;
+
+        if (!uri.startsWith("jmx")) {
+            logStream.println("Bad JMX URI (" + uri + ")");
+            logStream.println(lineSep);
+            return false;
+        }
+
+        // Get the kernel first
+        Map environment = new HashMap();
+        String[] credentials = new String[] { username, password };
+        environment.put(JMXConnector.CREDENTIALS, credentials);
+        ClassLoader oldcl = Thread.currentThread().getContextClassLoader();
+        try {
+            JMXServiceURL address = new JMXServiceURL("service:" + uri);
+            Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
+            for (int tries = maxTries; true; tries--) {
+                try {
+                    JMXConnector jmxConnector = JMXConnectorFactory.connect(address, environment);
+                    MBeanServerConnection mbServerConnection = jmxConnector.getMBeanServerConnection();
+                    kernel = new KernelDelegate(mbServerConnection);
+                    break;
+                }
+                catch (Exception e) {
+                    if (tries == 0) {
+                        e.printStackTrace(logStream);
+                        logStream.println("Could not connect");
+                        logStream.println(lineSep);
+                        return false;
+                    }
+                    Thread.sleep(retryIntervalMilliseconds);
+                }
+            }
+        }
+        catch (Exception e1) {
+            e1.printStackTrace(logStream);
+            logStream.println(lineSep);
+            return false;
+        }
+        finally {
+            Thread.currentThread().setContextClassLoader(oldcl);
+        }
+
+        // Now check to see if all configurations have started
+        ConfigurationManager mgr = ConfigurationUtil.getConfigurationManager(kernel);
+        List configLists = mgr.listConfigurations();
+        ObjectName on = null;
+        if (!configLists.isEmpty())
+            on = (ObjectName) configLists.toArray()[0];
+
+        for (int tries = maxTries; tries > 0; tries--) {
+            try {
+                Thread.sleep(retryIntervalMilliseconds);
+                Boolean b = (Boolean) kernel.getAttribute(on, "kernelFullyStarted");
+                //System.out.println("attempt.. " + (maxTries - tries));
+                if (b.booleanValue())
+                    return true;
+            }
+            catch (InternalKernelException e) {
+                //hasn't been loaded yet, keep trying
+            }
+            catch (GBeanNotFoundException e) {
+                //hasn't been loaded yet, keep trying
+            }
+            catch (InterruptedException e) {
+                e.printStackTrace(logStream);
+                logStream.println(lineSep);
+                return false;
+            }
+            catch (NoSuchAttributeException e) {
+                e.printStackTrace(logStream);
+                logStream.println(lineSep);
+                return false;
+            }
+            catch (Exception e) {
+                e.printStackTrace(logStream);
+                logStream.println(lineSep);
+                return false;
+            }
+        }
+        return false;
+    }  
+    
+
+    /**
+     * @param logStream
+     */
+    public void setLogStream(PrintStream logStream) {
+        if (logStream != null)
+            this.logStream = logStream;
+    }
+    
+    public void destroy() {
+        logStream.close();
+    }
+}

Propchange: geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/util/ServerBehavior.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/util/ServerBehavior.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/util/ServerBehavior.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/svkmerge/m2migration/m2-plugins/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/svkmerge/m2migration/m2-plugins/pom.xml?rev=421007&r1=421006&r2=421007&view=diff
==============================================================================
--- geronimo/sandbox/svkmerge/m2migration/m2-plugins/pom.xml (original)
+++ geronimo/sandbox/svkmerge/m2migration/m2-plugins/pom.xml Tue Jul 11 15:02:59 2006
@@ -70,7 +70,26 @@
     <modules>
         <module>geronimo-packaging-plugin</module>
         <module>geronimo-assembly-plugin</module>
+        <module>geronimo-deployment-plugin</module>
     </modules>
+    
+    <!--
+    
+    TODO: Finish the site config for plugins
+    
+    <reporting>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-project-info-reports-plugin</artifactId>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-plugin-plugin</artifactId>
+            </plugin>
+        </plugins>
+    </reporting>
+    -->
     
 </project>