Return-Path: Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: (qmail 16952 invoked from network); 11 Jul 2006 23:38:12 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 11 Jul 2006 23:38:12 -0000 Received: (qmail 49081 invoked by uid 500); 11 Jul 2006 23:38:12 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 48999 invoked by uid 500); 11 Jul 2006 23:38:11 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org List-Id: Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 48988 invoked by uid 99); 11 Jul 2006 23:38:11 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 11 Jul 2006 16:38:11 -0700 X-ASF-Spam-Status: No, hits=-8.6 required=10.0 tests=ALL_TRUSTED,INFO_TLD,NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [140.211.166.113] (HELO eris.apache.org) (140.211.166.113) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 11 Jul 2006 16:38:09 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 861881A981A; Tue, 11 Jul 2006 16:37:49 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r421029 - in /geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin: ./ src/java/org/apache/geronimo/plugins/deployment/ src/java/org/apache/geronimo/plugins/util/ Date: Tue, 11 Jul 2006 23:37:47 -0000 To: scm@geronimo.apache.org From: jdillon@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20060711233749.861881A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: jdillon Date: Tue Jul 11 16:37:46 2006 New Revision: 421029 URL: http://svn.apache.org/viewvc?rev=421029&view=rev Log: Tidy up deployment plugin post application of GERONIMO-1738 Using plexus-utils CommandLine to handle launching Java Cleaned up logging, using MojoSupport to deal with exceptions Using more specific field types so that Maven will set File's instead of converting Strings to files Pending testing and resolution of custom logging bits which were mostly removed Modified: geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/pom.xml geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/AbstractModuleMojo.java geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/DistributeModuleMojo.java geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StartModuleMojo.java geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StartRemoteServerMojo.java geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StartServerMojo.java geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StopModuleMojo.java geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StopRemoteServerMojo.java geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StopServerMojo.java geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/UndeployModuleMojo.java geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/util/DeploymentClient.java geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/util/ServerBehavior.java Modified: 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=421029&r1=421028&r2=421029&view=diff ============================================================================== --- geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/pom.xml (original) +++ geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/pom.xml Tue Jul 11 16:37:46 2006 @@ -34,15 +34,31 @@ maven-plugin + + + org.apache.geronimo.modules geronimo-deploy-jsr88 ${pom.version} + + + + + commons-lang + commons-lang + + + + org.codehaus.plexus + plexus-utils + 1.2 + + - install maven-plugin-plugin Modified: 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=421029&r1=421028&r2=421029&view=diff ============================================================================== --- geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/AbstractModuleMojo.java (original) +++ geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/AbstractModuleMojo.java Tue Jul 11 16:37:46 2006 @@ -18,10 +18,7 @@ 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; @@ -29,14 +26,18 @@ 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; +import org.apache.geronimo.plugin.MojoSupport; + +// +// TODO: Rename to AbstractDeploymentMojo +// /** - * @version $Rev:$ $Date:$ + * Support for deployment Mojos. + * + * @version $Rev$ $Date$ */ -public abstract class AbstractModuleMojo extends AbstractMojo { +public abstract class AbstractModuleMojo extends MojoSupport { /** * The uri to look up the JMXConnector. @@ -45,12 +46,10 @@ */ private String uri; - /** * @parameter */ protected String id; - /** * The uri to connect to the jmx connector with. @@ -105,34 +104,6 @@ */ 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. */ @@ -178,80 +149,24 @@ 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); - } + protected DeploymentManager getDeploymentManager() throws IOException, DeploymentManagerCreationException { + // + // NOTE: username, password, and distributeURI will never be null + // + + // + // TODO: Document why this is here... seems very odd + // + new DeploymentFactoryImpl(); - /** - * @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); + ClassLoader oldcl = Thread.currentThread().getContextClassLoader(); + try { + Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); + DeploymentFactoryManager factoryManager = DeploymentFactoryManager.getInstance(); + return factoryManager.getDeploymentManager(getDistributeURI(), getUsername(), getPassword()); } - else { - try { - throw (MojoFailureException) new MojoFailureException(e, e.toString(), e.getMessage()); - } - catch (MojoFailureException e1) { - e1.printStackTrace(logStream); - logStream.println(lineSep); - } + finally { + Thread.currentThread().setContextClassLoader(oldcl); } } } Modified: 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=421029&r1=421028&r2=421029&view=diff ============================================================================== --- geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/DistributeModuleMojo.java (original) +++ geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/DistributeModuleMojo.java Tue Jul 11 16:37:46 2006 @@ -18,72 +18,41 @@ 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; + +// +// TODO: Rename to DistributeMojo +// /** - * + * ??? + * * @goal distribute * - * @version $Rev:$ $Date:$ + * @version $Rev$ $Date$ */ public class DistributeModuleMojo extends AbstractModuleMojo { /** * @parameter */ - private String module; + private File module; /** * @parameter */ - private String plan; + private File plan; + + protected void doExecute() throws Exception { + DeploymentManager manager = getDeploymentManager(); + Target[] targets = manager.getTargets(); - 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); - } + ProgressObject progress = manager.distribute(targets, module, plan); + DeploymentClient.waitFor(progress); } } Modified: 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=421029&r1=421028&r2=421029&view=diff ============================================================================== --- geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StartModuleMojo.java (original) +++ geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StartModuleMojo.java Tue Jul 11 16:37:46 2006 @@ -30,51 +30,38 @@ import org.apache.maven.plugin.MojoExecutionException; /** - * + * ??? + * * @goal start * - * @version $Rev:$ $Date:$ - * + * @version $Rev$ $Date$ */ public class StartModuleMojo extends AbstractModuleMojo { - private PrintStream logStream = System.out; + protected void doExecute() throws Exception { + RemoteDeploymentManager manager; - private PrintStream resultStream; + manager = (RemoteDeploymentManager) getDeploymentManager(); + manager.setLogConfiguration(true, true); - private final String goalName = "Start Module"; + Target[] targets = manager.getTargets(); + TargetModuleID moduleIds[] = manager.getNonRunningModules(null, targets); + List toStart = new ArrayList(moduleIds.length); - 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); - } + 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; + + if (toStart.size() == 0) { + throw new MojoExecutionException("Module is already running or may not be deployed: " + this.id); } - logResults(resultStream, goalName, "success"); + + moduleIds = (TargetModuleID[]) toStart.toArray(new TargetModuleID[toStart.size()]); + ProgressObject progress = manager.start(moduleIds); + DeploymentClient.waitFor(progress); } } Modified: 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=421029&r1=421028&r2=421029&view=diff ============================================================================== --- geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StartRemoteServerMojo.java (original) +++ geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StartRemoteServerMojo.java Tue Jul 11 16:37:46 2006 @@ -18,32 +18,46 @@ 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.io.FileNotFoundException; import java.util.StringTokenizer; import org.apache.geronimo.plugins.util.ServerBehavior; + +import org.apache.commons.lang.SystemUtils; import org.apache.maven.plugin.MojoExecutionException; +import org.codehaus.plexus.util.cli.Commandline; +import org.codehaus.plexus.util.cli.CommandLineUtils; +import org.codehaus.plexus.util.cli.DefaultConsumer; +import org.codehaus.plexus.util.cli.CommandLineException; + +// +// TODO: Rename to StartRemoteServerMojo +// + /** + * ??? + * * @goal startRemoteServer * - * @version $Rev:$ $Date:$ + * @version $Rev$ $Date$ */ public class StartRemoteServerMojo extends AbstractModuleMojo { /** * @parameter */ - private String geronimoTarget; + private File geronimoTarget; + + /** + * @parameter expression="${basedir}/target" + */ + private File workingDirectory; /** * @parameter default-value="" */ - private String vmArgs = ""; + private String vmArgs; /** * @parameter @@ -55,129 +69,91 @@ */ 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(); + /** + * Get the path of Java depending the OS. + * + * @return the path of the Java + */ + private String getJavaPath() { + String javaCommand = "java" + (SystemUtils.IS_OS_WINDOWS ? ".exe" : ""); + + File javaExe; + + // For IBM's JDK 1.2 + if (SystemUtils.IS_OS_AIX) { + javaExe = new File(SystemUtils.JAVA_HOME + "/../sh", javaCommand); } - catch (Exception e) { - logResults(resultStream, goalName, "fail"); - handleError(e, logStream); - return; + else if (SystemUtils.IS_OS_MAC_OSX ) { + javaExe = new File(SystemUtils.JAVA_HOME + "/bin", javaCommand); + } + else { + javaExe = new File(SystemUtils.JAVA_HOME + "/../bin", javaCommand); } - logResults(resultStream, goalName, "success"); + + log.debug("Java executable=[" + javaExe.getAbsolutePath() + "]"); + + return javaExe.getAbsolutePath(); } - - /** - * @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); + protected void doExecute() throws Exception { + Commandline cmd = new Commandline(); + + cmd.setWorkingDirectory(workingDirectory.getAbsolutePath()); + cmd.setExecutable(getJavaPath()); 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); + cmd.createArgument().setValue("-Xdebug"); + cmd.createArgument().setValue("-Xnoagent"); + cmd.createArgument().setValue("-Djava.compiler=NONE"); + cmd.createArgument().setValue("-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=" + debugPort); } for (StringTokenizer st = new StringTokenizer(this.vmArgs); st.hasMoreTokens();) { - cmd.add(st.nextToken()); + cmd.createArgument().setValue(st.nextToken()); } - cmd.add("-ea"); - cmd.add("-jar"); + cmd.createArgument().setValue("-ea"); + cmd.createArgument().setValue("-jar"); - if (systemFile.exists()) { - try { - cmd.add(systemFile.getCanonicalPath()); - } - catch (IOException e) { - } + File serverJar = new File(new File(geronimoTarget, "bin"), "server.jar"); + if (serverJar.exists()) { + cmd.createArgument().setFile(serverJar); } else { - throw new Exception(systemFile.getAbsolutePath() + " does not exist"); + throw new FileNotFoundException(serverJar.getAbsolutePath()); } - cmd.add("--quiet"); + cmd.createArgument().setValue("--quiet"); if (this.configs != null && this.configs.length > 0) { - cmd.add("--override"); + cmd.createArgument().setValue("--override"); + for (int i=0; i < this.configs.length; i++) { - cmd.add(this.configs[i]); + cmd.createArgument().setValue(this.configs[i]); } } - String[] command = (String[]) cmd.toArray(new String[0]); - Runtime runtime = Runtime.getRuntime(); - Process server; + if (log.isDebugEnabled()) { + log.debug(Commandline.toString(cmd.getCommandline())); + } + + CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer(); try { - server = runtime.exec(command); + int exitCode = CommandLineUtils.executeCommandLine(cmd, new DefaultConsumer(), err); - // 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"); + if (exitCode != 0) { + throw new MojoExecutionException("Exit code: " + exitCode + " - " + err.getOutput()); } } - catch (Exception e1) { - throw new Exception(e1); + catch (CommandLineException e) { + throw new MojoExecutionException("Unable to execute java command", e); } - } - public void destroy() { - logStream.close(); - } + ServerBehavior sb = new ServerBehavior(getUri(), getMaxTries(), getRetryIntervalMilliseconds()); + if (!sb.isFullyStarted()) { + CommandLineUtils.killProcess(cmd.getPid()); - 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(); - } + throw new MojoExecutionException("Server did not start"); } } } Modified: 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=421029&r1=421028&r2=421029&view=diff ============================================================================== --- geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StartServerMojo.java (original) +++ geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StartServerMojo.java Tue Jul 11 16:37:46 2006 @@ -46,8 +46,7 @@ * * @goal startServer * - * @version $Rev:$ $Date:$ - * + * @version $Rev$ $Date$ */ public class StartServerMojo extends AbstractModuleMojo { @@ -57,9 +56,9 @@ } /** - * @parameter expression=${basedir}/target default-value=${basedir}/target + * @parameter expression="${basedir}/target" */ - private String geronimoHome; + private File geronimoHome; /** * @parameter @@ -72,93 +71,41 @@ 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(); + protected void doExecute() throws Exception { + if (!geronimoHome.exists()) { + throw new RuntimeException("No such directory: " + geronimoHome); } - catch (Exception e) { - logResults(resultStream, goalName, "fail"); - handleError(e, logStream); - return; - } - logResults(resultStream, goalName, "success"); - } + System.setProperty("org.apache.geronimo.base.dir", this.geronimoHome.getAbsolutePath()); - /** - * @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; - } + configList.add(Artifact.create(this.configs[i])); } } - 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; - } + URL systemURL = new File(geronimoHome, "bin/server.jar").toURL(); + URL configURL = new URL("jar:" + systemURL.toString() + "!/META-INF/config.ser"); + 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; - } - } + ObjectInputStream ois = new ObjectInputStream(configURL.openStream()); + configuration.readExternal(ois); + 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 + // 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; - } + 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"); // load the rest of the configuration listed on the command line ConfigurationManager configurationManager = ConfigurationUtil.getConfigurationManager(kernel); @@ -167,11 +114,9 @@ Artifact configID = (Artifact) i.next(); configurationManager.loadConfiguration(configID); configurationManager.startConfiguration(configID); - logStream.println("started gbean: " + configID.toString()); + + log.info("Started GBean: " + configID); } - } - catch (Exception e) { - throw e; } finally { ConfigurationUtil.releaseConfigurationManager(kernel, configurationManager); Modified: 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=421029&r1=421028&r2=421029&view=diff ============================================================================== --- geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StopModuleMojo.java (original) +++ geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StopModuleMojo.java Tue Jul 11 16:37:46 2006 @@ -17,7 +17,6 @@ package org.apache.geronimo.plugins.deployment; -import java.io.PrintStream; import java.util.ArrayList; import java.util.List; @@ -29,50 +28,41 @@ import org.apache.geronimo.plugins.util.DeploymentClient; import org.apache.maven.plugin.MojoExecutionException; +// +// TODO: Rename to StopMojo +// + /** + * ??? + * * @goal stop * - * @version $Rev:$ $Date:$ + * @version $Rev$ $Date$ */ public class StopModuleMojo extends AbstractModuleMojo { - private PrintStream logStream = System.out; - - private PrintStream resultStream; + protected void doExecute() throws Exception { + RemoteDeploymentManager manager = (RemoteDeploymentManager) getDeploymentManager(); + manager.setLogConfiguration(true, true); + + Target[] targets = manager.getTargets(); + TargetModuleID moduleIds[] = manager.getRunningModules(null, targets); + List toStop = new ArrayList(moduleIds.length); - private final String goalName = "Stop Module"; + for (int i = 0; i < moduleIds.length; i++) { + TargetModuleID moduleId = moduleIds[i]; - 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; + if (this.id.equals(moduleId.getModuleID())) { + toStop.add(moduleId); } - 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; + + if (toStop.size() == 0) { + throw new MojoExecutionException("Module is not deployed: " + this.id); } - logResults(resultStream, goalName, "success"); + + moduleIds = (TargetModuleID[]) toStop.toArray(new TargetModuleID[toStop.size()]); + ProgressObject progress = manager.stop(moduleIds); + DeploymentClient.waitFor(progress); } } Modified: 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=421029&r1=421028&r2=421029&view=diff ============================================================================== --- geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StopRemoteServerMojo.java (original) +++ geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StopRemoteServerMojo.java Tue Jul 11 16:37:46 2006 @@ -17,7 +17,6 @@ package org.apache.geronimo.plugins.deployment; -import java.io.PrintStream; import java.util.HashMap; import java.util.Map; @@ -31,67 +30,40 @@ import org.apache.maven.plugin.MojoExecutionException; /** + * ??? + * * @goal stopRemoteServer * - * @version $Rev:$ $Date:$ + * @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"); + protected void doExecute() throws Exception { + stopRemoteServer(); } - /** - * - */ private void stopRemoteServer() throws Exception { String uri = getUri(); - if (!uri.startsWith("jmx")) { - throw new Exception("Bad JMX URI ("+uri+")"); + if (!uri.startsWith("jmx")) { + throw new MojoExecutionException("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; - } + JMXServiceURL address = new JMXServiceURL("service:" + uri); + ClassLoader oldcl = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); - jmxConnector = JMXConnectorFactory.connect(address, environment); - mbServerConnection = jmxConnector.getMBeanServerConnection(); - kernel = new KernelDelegate(mbServerConnection); + + JMXConnector jmxConnector = JMXConnectorFactory.connect(address, environment); + MBeanServerConnection mbServerConnection = jmxConnector.getMBeanServerConnection(); + Kernel kernel = new KernelDelegate(mbServerConnection); + kernel.shutdown(); } - catch (Exception e) { - throw e; - } finally { Thread.currentThread().setContextClassLoader(oldcl); } Modified: 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=421029&r1=421028&r2=421029&view=diff ============================================================================== --- geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StopServerMojo.java (original) +++ geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/StopServerMojo.java Tue Jul 11 16:37:46 2006 @@ -19,21 +19,19 @@ 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:$ + * @version $Rev$ $Date$ */ -public class StopServerMojo extends AbstractMojo { +public class StopServerMojo extends AbstractModuleMojo { private String kernelName; - public void execute() throws MojoExecutionException { + protected void doExecute() throws Exception { Kernel kernel = KernelRegistry.getKernel(this.kernelName); kernel.shutdown(); } Modified: 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=421029&r1=421028&r2=421029&view=diff ============================================================================== --- geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/UndeployModuleMojo.java (original) +++ geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/deployment/UndeployModuleMojo.java Tue Jul 11 16:37:46 2006 @@ -17,7 +17,6 @@ package org.apache.geronimo.plugins.deployment; -import java.io.PrintStream; import java.util.ArrayList; import java.util.List; @@ -29,50 +28,39 @@ import org.apache.geronimo.plugins.util.DeploymentClient; import org.apache.maven.plugin.MojoExecutionException; +// +// TODO: Rename to UndeployMojo +// + /** + * ??? + * * @goal undeploy * - * @version $Rev:$ $Date:$ + * @version $Rev$ $Date$ */ public class UndeployModuleMojo extends AbstractModuleMojo { - private PrintStream logStream = System.out; - - private PrintStream resultStream; - - private final String goalName = "Undeploy Module"; + protected void doExecute() throws Exception { + DeploymentManager manager = getDeploymentManager(); - 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); - } + 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; + + if (toUndeploy.size() == 0) { + throw new MojoExecutionException("Module is running or not deployed: " + this.id); } - logResults(resultStream, goalName, "success"); + + moduleIds = (TargetModuleID[]) toUndeploy.toArray(new TargetModuleID[toUndeploy.size()]); + ProgressObject progress = manager.undeploy(moduleIds); + DeploymentClient.waitFor(progress); } } Modified: 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=421029&r1=421028&r2=421029&view=diff ============================================================================== --- geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/util/DeploymentClient.java (original) +++ geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/util/DeploymentClient.java Tue Jul 11 16:37:46 2006 @@ -23,6 +23,7 @@ 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; @@ -31,7 +32,9 @@ import javax.enterprise.deploy.spi.status.DeploymentStatus; /** - * @version $Rev:$ $Date:$ + * ??? + * + * @version $Rev$ $Date$ */ public class DeploymentClient { private static final DeploymentFactoryManager FACTORY_MANAGER = DeploymentFactoryManager.getInstance(); @@ -54,6 +57,10 @@ if (parent == null) { parent = Thread.currentThread().getContextClassLoader(); } + + // + // FIXME: parent will never be null at this point... + // if (parent == null) { parent = DeploymentClient.class.getClassLoader(); } Modified: 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=421029&r1=421028&r2=421029&view=diff ============================================================================== --- geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/util/ServerBehavior.java (original) +++ geronimo/sandbox/svkmerge/m2migration/m2-plugins/geronimo-deployment-plugin/src/java/org/apache/geronimo/plugins/util/ServerBehavior.java Tue Jul 11 16:37:46 2006 @@ -33,11 +33,12 @@ 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:$ + * ??? + * + * @version $Rev$ $Date$ */ public class ServerBehavior { @@ -56,7 +57,7 @@ protected final String lineSep = "==========================================="; /** - * @param id + * @param uri * specify null for default * @param maxTries * specify -1 for default. default-value=40 @@ -72,16 +73,10 @@ this.retryIntervalMilliseconds = retryIntervalMilliseconds; } - /** - * - */ public ServerBehavior(String uri) { this(uri, -1, -1); } - /** - * - */ public ServerBehavior() { this(null, -1, -1); } @@ -170,10 +165,6 @@ return false; } - - /** - * @param logStream - */ public void setLogStream(PrintStream logStream) { if (logStream != null) this.logStream = logStream;