source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/main/org/apache/tools/ant/taskdefs/Deltree.java@ 14627

Last change on this file since 14627 was 14627, checked in by oranfry, 17 years ago

initial import of the gs3-release-maker

File size: 3.3 KB
Line 
1/*
2 * Copyright 2000,2002,2004 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18package org.apache.tools.ant.taskdefs;
19
20import java.io.File;
21import java.io.IOException;
22import org.apache.tools.ant.BuildException;
23import org.apache.tools.ant.Task;
24
25/**
26 *
27 *
28 *
29 * @since Ant 1.1
30 *
31 * @deprecated The deltree task is deprecated since Ant 1.2. Use
32 * delete instead.
33 */
34
35public class Deltree extends Task {
36
37 private File dir;
38
39 /**
40 * Set the directory to be deleted
41 *
42 * @param dir the root of the tree to be removed.
43 */
44 public void setDir(File dir) {
45 this.dir = dir;
46 }
47
48 /**
49 * Do the work.
50 *
51 * @exception BuildException if the task is not configured correctly or
52 * the tree cannot be removed.
53 */
54 public void execute() throws BuildException {
55 log("DEPRECATED - The deltree task is deprecated. "
56 + "Use delete instead.");
57
58 if (dir == null) {
59 throw new BuildException("dir attribute must be set!", getLocation());
60 }
61
62 if (dir.exists()) {
63 if (!dir.isDirectory()) {
64 if (!dir.delete()) {
65 throw new BuildException("Unable to delete directory "
66 + dir.getAbsolutePath(),
67 getLocation());
68 }
69 return;
70 }
71
72 log("Deleting: " + dir.getAbsolutePath());
73
74 try {
75 removeDir(dir);
76 } catch (IOException ioe) {
77 String msg = "Unable to delete " + dir.getAbsolutePath();
78 throw new BuildException(msg, getLocation());
79 }
80 }
81 }
82
83 private void removeDir(File dir) throws IOException {
84
85 // check to make sure that the given dir isn't a symlink
86 // the comparison of absolute path and canonical path
87 // catches this
88
89 // if (dir.getCanonicalPath().equals(dir.getAbsolutePath())) {
90 // (costin) It will not work if /home/costin is symlink to
91 // /da0/home/costin ( taz for example )
92 String[] list = dir.list();
93 for (int i = 0; i < list.length; i++) {
94 String s = list[i];
95 File f = new File(dir, s);
96 if (f.isDirectory()) {
97 removeDir(f);
98 } else {
99 if (!f.delete()) {
100 throw new BuildException("Unable to delete file "
101 + f.getAbsolutePath());
102 }
103 }
104 }
105 if (!dir.delete()) {
106 throw new BuildException("Unable to delete directory "
107 + dir.getAbsolutePath());
108 }
109 }
110}
111
Note: See TracBrowser for help on using the repository browser.