1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.util.ant;
16  
17  import java.io.File;
18  
19  import org.apache.tools.ant.taskdefs.Delete;
20  import org.apache.tools.ant.types.FileSet;
21  
22  /**
23   * <a href="DeleteTask.java.html"><b><i>View Source</i></b></a>
24   *
25   * @author Brian Wing Shun Chan
26   */
27  public class DeleteTask {
28  
29      public static void deleteDirectory(File dir) {
30          Delete delete = new Delete();
31  
32          delete.setProject(AntUtil.getProject());
33          delete.setDir(dir);
34          delete.setFailOnError(false);
35  
36          delete.execute();
37      }
38  
39      public static void deleteDirectory(String dir) {
40          deleteDirectory(new File(dir));
41      }
42  
43      public static void deleteFile(File file) {
44          Delete delete = new Delete();
45  
46          delete.setProject(AntUtil.getProject());
47          delete.setFile(file);
48          delete.setFailOnError(false);
49  
50          delete.execute();
51      }
52  
53      public static void deleteFile(String file) {
54          deleteFile(new File(file));
55      }
56  
57      public static void deleteFiles(File dir, String includes, String excludes) {
58          Delete delete = new Delete();
59  
60          delete.setProject(AntUtil.getProject());
61          delete.setFailOnError(false);
62  
63          FileSet fileSet = new FileSet();
64  
65          fileSet.setDir(dir);
66          fileSet.setIncludes(includes);
67          fileSet.setExcludes(excludes);
68  
69          delete.addFileset(fileSet);
70  
71          delete.execute();
72      }
73  
74      public static void deleteFiles(
75          String dir, String includes, String excludes) {
76  
77          deleteFiles(new File(dir), includes, excludes);
78      }
79  
80  }