View Javadoc

1   package org.codehaus.mojo.jboss;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file 
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   * 
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   * 
14   * Unless required by applicable law or agreed to in writing, 
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
17   * KIND, either express or implied.  See the License for the 
18   * specific language governing permissions and limitations 
19   * under the License.
20   */
21  
22  import org.apache.maven.plugin.MojoExecutionException;
23  
24  /**
25   * Stops JBoss. By default the plugin will return immediately after calling "shutdown" command. The @see #stopWait
26   * parameter can be used to force the plugin to wait for a specified time before returning control.
27   * 
28   * @author <a href="mailto:jgenender@apache.org">Jeff Genender</a>
29   * @goal stop
30   * @requiresProject false
31   */
32  public class StopMojo
33      extends AbstractJBossServerMojo
34  {
35  
36      /**
37       * The command to shutdown JBoss.
38       */
39      public static final String SHUTDOWN_COMMAND = "shutdown";
40  
41      /**
42       * The set of options to pass to the JBoss "run" command.
43       * 
44       * @parameter default-value="-S" expression="${jboss.stopOptions}"
45       * @since 1.5.0
46       */
47      protected String stopOptions;
48  
49      /**
50       * Wait in ms for server to shutdown before the plugin returns.
51       * 
52       * @since 1.4.1
53       * @parameter expression="${jboss.stopWait}"
54       */
55      protected int stopWait;
56  
57      /**
58       * The set of options to pass to the JBoss "run" command.
59       * 
60       * @parameter default-value="" expression="${jboss.options}"
61       * @deprecated use stopOptions instead
62       */
63      protected String options;
64  
65      /**
66       * Main plugin execution.
67       * 
68       * @throws MojoExecutionException
69       */
70      public void execute()
71          throws MojoExecutionException
72      {
73          if ( options != null && !options.equals("") )
74          {
75              stopOptions = options;
76          }
77          
78          String credentials = "";
79          
80          if ( getUsername() != null )
81          {
82              credentials = " -u " + getUsername() + " -p " + getPassword();
83          }
84          
85          stopOptions += credentials;
86          
87          launch( SHUTDOWN_COMMAND, stopOptions );
88  
89          if ( stopWait > 0 )
90          {
91              try
92              {
93                  Thread.sleep( stopWait );
94              }
95              catch ( InterruptedException e )
96              {
97                  getLog().warn( "Thread interrupted while waiting for JBoss to stop: " + e.getMessage() );
98                  if ( getLog().isDebugEnabled() )
99                  {
100                     getLog().debug( "Thread interrupted while waiting for JBoss to stop: ", e );
101                 }
102             }
103         }
104     }
105 
106 }