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 java.util.Iterator;
23
24 import org.apache.maven.plugin.MojoExecutionException;
25
26 /**
27 * Undeploys a directory or file from JBoss via JMX.
28 *
29 * @author <a href="mailto:jgenender@apache.org">Jeff Genender</a>
30 * @goal undeploy
31 */
32 public class UndeployMojo
33 extends AbstractJBossDeployerMojo
34 {
35
36 public static final String DEFAULT_UNDEPLOY_URL = "/jmx-console/HtmlAdaptor?action=invokeOpByName&name=jboss.system:service%3DMainDeployer&methodName=undeploy&argType=java.net.URL&arg0=";
37
38 /**
39 * The undeployment path relative to the base server URL.
40 *
41 * @parameter
42 */
43 protected String undeployUrlPath;
44
45 /**
46 * Main plugin execution.
47 *
48 * @throws MojoExecutionException
49 */
50 public void doExecute()
51 throws MojoExecutionException
52 {
53 // Note: the url path is set here instead of in the parameter default-value because of a parse error
54 // when generating the project site.
55 if ( undeployUrlPath == null )
56 {
57 undeployUrlPath = DEFAULT_UNDEPLOY_URL;
58 }
59
60 Iterator iter = fileNames.iterator();
61 while ( iter.hasNext() )
62 {
63 String fileName = (String) iter.next();
64 String fixedFile = null;
65 if ( fileName.toLowerCase().endsWith( "ejb" ) )
66 {
67 // Fix the ejb packaging to a jar
68 fixedFile = fileName.substring( 0, fileName.length() - 3 ) + "jar";
69 }
70 else
71 {
72 fixedFile = fileName;
73 }
74
75 getLog().info( "Undeploying " + fixedFile + " from JBoss." );
76 String url = "http://" + hostName + ":" + port + undeployUrlPath + fixedFile;
77 doURL( url );
78 }
79 }
80 }