It now processes all files in parallel and can take multiple filesets as well as references to patternsets and filesets. See build.xml for an example. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@267859 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -43,6 +43,8 @@ specified on the command line. | |||
| * Added a -emacs option to tell the logger to leave out taskname adornments | |||
| on log output. | |||
| * <chmod> works on all files in parallel and supports multiple filesets. | |||
| Fixed bugs: | |||
| ----------- | |||
| @@ -118,8 +118,14 @@ | |||
| <target name="main" depends="jar"> | |||
| <mkdir dir="${bin.dir}"/> | |||
| <copydir src="${src.bin.dir}" dest="${bin.dir}"/> | |||
| <chmod perm="+x" file="${bin.dir}/ant"/> | |||
| <chmod perm="+x" file="${bin.dir}/antRun"/> | |||
| <chmod perm="+x"> | |||
| <fileset dir="${bin.dir}"> | |||
| <patternset id="chmod.patterns"> | |||
| <include name="**/ant" /> | |||
| <include name="**/antRun" /> | |||
| </patternset> | |||
| </fileset> | |||
| </chmod> | |||
| <fixcrlf srcdir="${bin.dir}" includes="ant,antRun" cr="remove"/> | |||
| <fixcrlf srcdir="${bin.dir}" includes="*.bat" cr="add"/> | |||
| </target> | |||
| @@ -159,8 +165,11 @@ | |||
| <copydir src="${docs.dir}" dest="${ant.dist.dir}/docs"/> | |||
| <copydir src="${build.javadocs}" dest="${ant.dist.dir}/docs/api"/> | |||
| <chmod perm="+x" file="${ant.dist.dir}/bin/ant"/> | |||
| <chmod perm="+x" file="${ant.dist.dir}/bin/antRun"/> | |||
| <chmod perm="+x"> | |||
| <fileset dir="${ant.dist.dir}/bin"> | |||
| <patternsetref refid="chmod.patterns"/> | |||
| </fileset> | |||
| </chmod> | |||
| <copyfile src="README" dest="${ant.dist.dir}/README"/> | |||
| <copyfile src="TODO" dest="${ant.dist.dir}/TODO"/> | |||
| @@ -195,19 +204,25 @@ | |||
| <echo message="installing full copy of ant into ${ant.install}"/> | |||
| <mkdir dir="${ant.install}"/> | |||
| <copydir src="${ant.dist.dir}" dest="${ant.install}"/> | |||
| <chmod perm="+x" file="${ant.install}/bin/ant"/> | |||
| <chmod perm="+x" file="${ant.install}/bin/antRun"/> | |||
| <chmod perm="+x"> | |||
| <fileset dir="${ant.install}/bin"> | |||
| <patternsetref refid="chmod.patterns"/> | |||
| </fileset> | |||
| </chmod> | |||
| </target> | |||
| <target name="fullinstall" depends="install"/> | |||
| <target name="mininstall" depends="main" if="ant.install"> | |||
| <echo message="copy minimal ant installtion into ${ant.install}"/> | |||
| <echo message="copy minimal ant installation into ${ant.install}"/> | |||
| <mkdir dir="${ant.install}"/> | |||
| <copydir src="${lib.dir}" dest="${ant.install}/lib"/> | |||
| <copydir src="${bin.dir}" dest="${ant.install}/bin"/> | |||
| <chmod perm="+x" file="${ant.install}/bin/ant"/> | |||
| <chmod perm="+x" file="${ant.install}/bin/antRun"/> | |||
| <chmod perm="+x"> | |||
| <fileset dir="${ant.install}/bin"> | |||
| <patternsetref refid="chmod.patterns"/> | |||
| </fileset> | |||
| </chmod> | |||
| </target> | |||
| <!-- =================================================================== --> | |||
| @@ -55,6 +55,7 @@ | |||
| package org.apache.tools.ant.taskdefs; | |||
| import org.apache.tools.ant.*; | |||
| import org.apache.tools.ant.types.*; | |||
| import java.io.*; | |||
| import java.util.*; | |||
| @@ -64,20 +65,28 @@ import java.util.*; | |||
| * | |||
| * @author costin@eng.sun.com | |||
| * @author Mariusz Nowostawski (Marni) <a href="mailto:mnowostawski@infoscience.otago.ac.nz">mnowostawski@infoscience.otago.ac.nz</a> | |||
| * @author <a href="mailto:stefan.bodewig@megabit.net">Stefan Bodewig</a> | |||
| */ | |||
| public class Chmod extends MatchingTask { | |||
| public class Chmod extends ExecuteOn { | |||
| private File srcFile; //if we want to chmod a single file or dir | |||
| private File srcDir; //if we want to chmod a list of files | |||
| private String mod; | |||
| private FileSet defaultSet = new FileSet(); | |||
| private boolean havePerm = false; | |||
| public Chmod() { | |||
| super.setExecutable("chmod"); | |||
| super.setParallel(true); | |||
| } | |||
| public void setFile(File src) { | |||
| srcFile = src; | |||
| FileSet fs = new FileSet(); | |||
| fs.setDir(new File(src.getParent())); | |||
| fs.createInclude().setName(src.getName()); | |||
| addFileset(fs); | |||
| } | |||
| public void setDir(File src) { | |||
| srcDir = src; | |||
| defaultSet.setDir(src); | |||
| } | |||
| public void setSrc(File src) { | |||
| @@ -88,38 +97,93 @@ public class Chmod extends MatchingTask { | |||
| } | |||
| public void setPerm(String perm) { | |||
| mod=perm; | |||
| createArg().setValue(perm); | |||
| havePerm = true; | |||
| } | |||
| /** | |||
| * add a name entry on the include list | |||
| */ | |||
| public PatternSet.NameEntry createInclude() { | |||
| return defaultSet.createInclude(); | |||
| } | |||
| /** | |||
| * add a name entry on the exclude list | |||
| */ | |||
| public PatternSet.NameEntry createExclude() { | |||
| return defaultSet.createExclude(); | |||
| } | |||
| /** | |||
| * add a set of patterns | |||
| */ | |||
| public PatternSet createPatternSet() { | |||
| return defaultSet.createPatternSet(); | |||
| } | |||
| /** | |||
| * add a reference to a set of patterns | |||
| */ | |||
| public Reference createPatternSetRef() { | |||
| return defaultSet.createPatternSetRef(); | |||
| } | |||
| public void execute() throws BuildException { | |||
| try { | |||
| // XXX if OS=unix | |||
| if (System.getProperty("path.separator").equals(":") && | |||
| !System.getProperty("os.name").startsWith("Mac")) { | |||
| /** | |||
| * Sets the set of include patterns. Patterns may be separated by a comma | |||
| * or a space. | |||
| * | |||
| * @param includes the string containing the include patterns | |||
| */ | |||
| public void setIncludes(String includes) { | |||
| defaultSet.setIncludes(includes); | |||
| } | |||
| /** | |||
| * Sets the set of exclude patterns. Patterns may be separated by a comma | |||
| * or a space. | |||
| * | |||
| * @param excludes the string containing the exclude patterns | |||
| */ | |||
| public void setExcludes(String excludes) { | |||
| defaultSet.setExcludes(excludes); | |||
| } | |||
| /** | |||
| * Sets whether default exclusions should be used or not. | |||
| * | |||
| * @param useDefaultExcludes "true"|"on"|"yes" when default exclusions | |||
| * should be used, "false"|"off"|"no" when they | |||
| * shouldn't be used. | |||
| */ | |||
| public void setDefaultexcludes(boolean useDefaultExcludes) { | |||
| defaultSet.setDefaultexcludes(useDefaultExcludes); | |||
| } | |||
| protected void checkConfiguration() { | |||
| if (!havePerm) { | |||
| throw new BuildException("Required attribute perm not set in chmod", | |||
| location); | |||
| } | |||
| if (srcFile != null && srcDir == null) { | |||
| chmod(srcFile.toString()); | |||
| } else if(srcFile == null && srcDir == null) { | |||
| log("The attribute 'file' or 'dir' needs to be set.", Project.MSG_WARN); | |||
| throw new BuildException("Required attribute not set in Chmod", location); | |||
| } else if(srcFile == null && srcDir != null) { | |||
| DirectoryScanner ds = getDirectoryScanner(srcDir); | |||
| String[] files = ds.getIncludedFiles(); | |||
| for (int i = 0; i < files.length; i++) { | |||
| chmod((new File(srcDir, files[i])).getAbsolutePath()); | |||
| } | |||
| } | |||
| } | |||
| } catch (IOException ioe) { | |||
| // ignore, but warn | |||
| log("Error in Chmod " + ioe.toString() , Project.MSG_WARN); | |||
| if (defaultSet.getDir() != null) { | |||
| addFileset(defaultSet); | |||
| } | |||
| super.checkConfiguration(); | |||
| } | |||
| public void setExecutable(String e) { | |||
| throw new BuildException(taskType+" doesn\'t support the executable attribute", location); | |||
| } | |||
| public void setCommand(String e) { | |||
| throw new BuildException(taskType+" doesn\'t support the command attribute", location); | |||
| } | |||
| private void chmod(String file) throws BuildException, IOException { | |||
| Runtime.getRuntime().exec("chmod " + mod + " " + file); | |||
| protected boolean isValidOs() { | |||
| // XXX if OS=unix | |||
| return System.getProperty("path.separator").equals(":") && | |||
| !System.getProperty("os.name").startsWith("Mac") && | |||
| super.isValidOs(); | |||
| } | |||
| } | |||
| @@ -164,7 +164,7 @@ public class ExecTask extends Task { | |||
| /** | |||
| * Is this the OS the user wanted? | |||
| */ | |||
| private boolean isValidOs() { | |||
| protected boolean isValidOs() { | |||
| // test if os match | |||
| String myos = System.getProperty("os.name"); | |||
| log("Myos = " + myos, Project.MSG_VERBOSE); | |||
| @@ -69,7 +69,7 @@ import java.io.IOException; | |||
| */ | |||
| public class ExecuteOn extends ExecTask { | |||
| private Vector filesets = new Vector(); | |||
| protected Vector filesets = new Vector(); | |||
| private boolean parallel = false; | |||
| /** | |||
| @@ -84,12 +84,18 @@ public class FileSet { | |||
| } | |||
| public void setDir(File dir) throws BuildException { | |||
| if (!dir.exists()) { | |||
| throw new BuildException(dir.getAbsolutePath()+" not found."); | |||
| } | |||
| if (!dir.isDirectory()) { | |||
| throw new BuildException(dir.getAbsolutePath()+" is not a directory."); | |||
| } | |||
| /* | |||
| * XXX cannot check as long as tasks get configured at parse time. | |||
| * | |||
| * the build process might create the directory. | |||
| */ | |||
| // if (!dir.exists()) { | |||
| // throw new BuildException(dir.getAbsolutePath()+" not found."); | |||
| // } | |||
| // if (!dir.isDirectory()) { | |||
| // throw new BuildException(dir.getAbsolutePath()+" is not a directory."); | |||
| // } | |||
| this.dir = dir; | |||
| } | |||
| @@ -176,6 +182,17 @@ public class FileSet { | |||
| * Returns the directory scanner needed to access the files to process. | |||
| */ | |||
| public DirectoryScanner getDirectoryScanner(Project p) { | |||
| /* | |||
| * XXX remove the check here and enable the one in setDir as soon | |||
| * as we configure tasks at execution time. | |||
| */ | |||
| if (!dir.exists()) { | |||
| throw new BuildException(dir.getAbsolutePath()+" not found."); | |||
| } | |||
| if (!dir.isDirectory()) { | |||
| throw new BuildException(dir.getAbsolutePath()+" is not a directory."); | |||
| } | |||
| DirectoryScanner ds = new DirectoryScanner(); | |||
| ds.setBasedir(dir); | |||