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.io.File;
23 import java.io.IOException;
24
25 import org.apache.maven.plugin.MojoExecutionException;
26 import org.codehaus.plexus.util.FileUtils;
27
28 /**
29 * Delete file form <code>$JBOSS_HOME/server/[serverName]/deploy</code> directory.
30 *
31 * @author <a href="mailto:bjkuczynski@gmial.com">Bartek 'Koziolek' Kuczynski</a>
32 * @goal hard-undeploy
33 * @since 1.4
34 */
35 public class HardUnDeployMojo
36 extends AbstractJBossServerMojo
37 {
38 /**
39 * The names of the files or directories to undeploy. If this is set, the fileName parameter will be ignored.
40 *
41 * @parameter
42 * @since 1.4.1
43 */
44 protected File[] fileNames;
45
46 /**
47 * The name of the file or directory to undeploy.
48 *
49 * @parameter default-value="${project.build.directory}/${project.build.finalName}.${project.packaging}"
50 */
51 protected File fileName;
52
53 /**
54 * Main plugin execution.
55 *
56 * @throws MojoExecutionException
57 */
58 public void execute()
59 throws MojoExecutionException
60 {
61 checkConfig();
62
63 if ( fileNames == null || fileNames.length == 0 )
64 {
65 fileNames = new File[1];
66 fileNames[0] = fileName;
67 }
68
69 for ( int i = 0; i < fileNames.length; ++i )
70 {
71 File nextFile = new File( jbossHome + "/server/" + serverName + "/deploy/" + fileNames[i].getName() );
72 getLog().debug( "Undeploy file: " + nextFile.getName() );
73 if ( !nextFile.exists() )
74 {
75 getLog().info( "File " + nextFile.getAbsolutePath() + " doesn't exist!" );
76 return;
77 }
78 if ( nextFile.isFile() )
79 {
80 if ( nextFile.delete() )
81 {
82 getLog().info( "File " + nextFile.getName() + " undeployed." );
83 }
84 else
85 {
86 getLog().warn( "Unable to delete file: " + nextFile );
87 }
88 }
89 else if ( nextFile.isDirectory() )
90 {
91 try
92 {
93 FileUtils.deleteDirectory( nextFile );
94 getLog().info( "Directory " + nextFile.getName() + " undeployed." );
95 }
96 catch ( IOException e )
97 {
98 getLog().warn( "Unable to delete directory: " + nextFile );
99 getLog().warn( e.getMessage() );
100 }
101 }
102 }
103 }
104 }