001    /**
002     *
003     * Copyright 2003-2004 The Apache Software Foundation
004     *
005     *  Licensed under the Apache License, Version 2.0 (the "License");
006     *  you may not use this file except in compliance with the License.
007     *  You may obtain a copy of the License at
008     *
009     *     http://www.apache.org/licenses/LICENSE-2.0
010     *
011     *  Unless required by applicable law or agreed to in writing, software
012     *  distributed under the License is distributed on an "AS IS" BASIS,
013     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     *  See the License for the specific language governing permissions and
015     *  limitations under the License.
016     */
017    
018    package org.apache.geronimo.deployment.cli;
019    
020    import org.apache.geronimo.common.DeploymentException;
021    
022    import javax.enterprise.deploy.spi.DeploymentManager;
023    import javax.enterprise.deploy.spi.Target;
024    import javax.enterprise.deploy.spi.status.ProgressObject;
025    import java.io.File;
026    import java.io.PrintWriter;
027    
028    /**
029     * The CLI deployer logic to deploy (distribute plus start).
030     *
031     * @version $Rev: 398160 $ $Date: 2006-04-29 07:33:58 -0700 (Sat, 29 Apr 2006) $
032     */
033    public class CommandDeploy extends CommandDistribute {
034        public CommandDeploy() {
035            super("deploy", "1. Common Commands", "[--inPlace] [--targets target;target;...] [module] [plan]",
036                    "Normally both a module and plan are passed to the deployer.  " +
037                    "Sometimes the module contains a plan, or requires no plan, in which case " +
038                    "the plan may be omitted.  Sometimes the plan references a module already " +
039                    "deployed in the Geronimo server environment, in which case a module does " +
040                    "not need to be provided.\n" +
041                    "If no targets are provided, the module is deployed to all available " +
042                    "targets.  Geronimo only provides one target (ever), so this is primarily " +
043                    "useful when using a different driver.");
044        }
045    
046        protected String getAction() {
047            return "Deployed";
048        }
049    
050        protected ProgressObject runCommand(DeploymentManager mgr, PrintWriter out, boolean inPlace, Target[] tlist, File module, File plan) throws DeploymentException {
051            ProgressObject po = super.runCommand(mgr, out, inPlace, tlist, module, plan);
052            waitForProgress(out, po);
053            if(po.getDeploymentStatus().isFailed()) {
054                throw new DeploymentException("Unable to distribute "+(module == null ? plan.getName() : module.getName())+": "+po.getDeploymentStatus().getMessage());
055            }
056            return mgr.start(po.getResultTargetModuleIDs());
057        }
058    
059        public void execute(PrintWriter out, ServerConnection connection, String[] args) throws DeploymentException {
060            super.execute(out, connection, args);
061        }
062    }