001    /**
002     *  Licensed to the Apache Software Foundation (ASF) under one
003     *  or more contributor license agreements.  See the NOTICE file
004     *  distributed with this work for additional information
005     *  regarding copyright ownership.  The ASF licenses this file
006     *  to you under the Apache License, Version 2.0 (the
007     *  "License"); you may not use this file except in compliance
008     *  with the License.  You may obtain a copy of the License at
009     *
010     *    http://www.apache.org/licenses/LICENSE-2.0
011     *
012     *  Unless required by applicable law or agreed to in writing,
013     *  software distributed under the License is distributed on an
014     *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015     *  KIND, either express or implied.  See the License for the
016     *  specific language governing permissions and limitations
017     *  under the License.
018     */
019    
020    package org.apache.geronimo.mavenplugins.geronimo.server;
021    
022    import org.apache.maven.plugin.MojoExecutionException;
023    
024    import org.apache.geronimo.mavenplugins.geronimo.ServerProxy;
025    import org.apache.geronimo.mavenplugins.geronimo.reporting.ReportingMojoSupport;
026    
027    /**
028     * Stop the Geronimo server.
029     *
030     * @goal stop-server
031     *
032     * @version $Rev: 495849 $ $Date: 2007-01-13 03:40:10 -0500 (Sat, 13 Jan 2007) $
033     */
034    public class StopServerMojo
035        extends ReportingMojoSupport
036    {
037        /**
038         * Fail the build if the server is not started.
039         *
040         * @parameter expression="${failIfNotStarted}" default-value="true"
041         */
042        private boolean failIfNotStarted = true;
043        
044        protected void doExecute() throws Exception {
045            ServerProxy server = new ServerProxy(hostname, port, username, password);
046    
047            //
048            // TODO: Maybe we just need isStarted() not need to be fully started?
049            //
050            
051            if (!server.isFullyStarted()) {
052                String msg = "Server does not appear to be started";
053                
054                if (failIfNotStarted) {
055                    throw new MojoExecutionException(msg);
056                }
057                else {
058                    log.warn(msg);
059                }
060            }
061            else {
062                log.info("Stopping Geronimo server...");
063                
064                server.shutdown();
065    
066                //
067                // TODO: Verify its down?
068                //
069            }
070        }
071    
072        protected String getFullClassName() {
073            return this.getClass().getName();
074        } 
075    }