Created
February 14, 2011 20:27
-
-
Save millermedeiros/826481 to your computer and use it in GitHub Desktop.
Example Ant task to copy/delete folders
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<project name="example-purge-copy" default="" basedir="."> | |
<!-- properties --> | |
<!-- make sure you are pointing to the right folder since purgeDeploy can delete undesired files... --> | |
<property name="deploy.dir" value="../../deploy" /> | |
<!-- custom tasks --> | |
<!-- targets --> | |
<target name="-mkdirs" description="Make required dirs."> | |
<echo message="Creating required directories..."/> | |
<mkdir dir="${deploy.dir}"/> | |
</target> | |
<target name="purgeDeploy" description="Delete old deploy files."> | |
<echo message="Deleting old deploy files..."/> | |
<delete includeEmptyDirs="true"> | |
<fileset dir="${deploy.dir}"> | |
<include name="**" /> | |
<exclude name="**/.svn" /> <!-- skip .svn folders otherwise it will cause SVN conflicts --> | |
</fileset> | |
</delete> | |
<antcall target="-mkdirs"/> | |
</target> | |
<target name="copyToDeploy" description="Copy files to deploy folder."> | |
<copy todir="${deploy.dir}"> | |
<fileset dir="${basedir}"> | |
<include name="**" /> | |
<exclude name="**/_*/**" /> <!-- ignore files/folders starting with underscore --> | |
<exclude name="**/.svn" /> | |
<exclude name="**/.git" /> | |
<exclude name="**/.hg" /> | |
<exclude name="**/.DS_Store" /> | |
<exclude name="**/.tmp*" /> | |
<exclude name="**/.project" /> | |
<exclude name="**/.livereload" /> | |
<exclude name="**/.jshintrc" /> | |
<exclude name="**/.settings/**" /> | |
<exclude name="build.xml" /> | |
</fileset> | |
</copy> | |
</target> | |
</project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you want to delete all the old files before copying to deploy folder add
depends="purgeDeploy"
to thecopyToDeploy
target.. I've removed it from the example to avoid undesired side effects.PS: Ant is usually smart enough to copy only files that changed but in most of my build tasks I usually call
purgeDeploy
beforecopyToDeploy
since I'm usually generating files that have a unique name and/or that should be discarded or replaced at each build.