001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.util.ant;
016    
017    import java.io.File;
018    
019    import org.apache.tools.ant.taskdefs.Delete;
020    import org.apache.tools.ant.types.FileSet;
021    
022    /**
023     * @author Brian Wing Shun Chan
024     */
025    public class DeleteTask {
026    
027            public static void deleteDirectory(File dir) {
028                    Delete delete = new Delete();
029    
030                    delete.setProject(AntUtil.getProject());
031                    delete.setDir(dir);
032                    delete.setFailOnError(false);
033    
034                    delete.execute();
035            }
036    
037            public static void deleteDirectory(String dir) {
038                    deleteDirectory(new File(dir));
039            }
040    
041            public static void deleteFile(File file) {
042                    Delete delete = new Delete();
043    
044                    delete.setProject(AntUtil.getProject());
045                    delete.setFile(file);
046                    delete.setFailOnError(false);
047    
048                    delete.execute();
049            }
050    
051            public static void deleteFile(String file) {
052                    deleteFile(new File(file));
053            }
054    
055            public static void deleteFiles(File dir, String includes, String excludes) {
056                    Delete delete = new Delete();
057    
058                    delete.setProject(AntUtil.getProject());
059                    delete.setFailOnError(false);
060    
061                    FileSet fileSet = new FileSet();
062    
063                    fileSet.setDir(dir);
064                    fileSet.setIncludes(includes);
065                    fileSet.setExcludes(excludes);
066    
067                    delete.addFileset(fileSet);
068    
069                    delete.execute();
070            }
071    
072            public static void deleteFiles(
073                    String dir, String includes, String excludes) {
074    
075                    deleteFiles(new File(dir), includes, excludes);
076            }
077    
078    }