diff --git a/WHATSNEW b/WHATSNEW index 02e7eae2f..f62683ff8 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -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. +* works on all files in parallel and supports multiple filesets. + Fixed bugs: ----------- diff --git a/build.xml b/build.xml index fdbb1d246..4e2b92be6 100644 --- a/build.xml +++ b/build.xml @@ -118,8 +118,14 @@ - - + + + + + + + + @@ -159,8 +165,11 @@ - - + + + + + @@ -195,19 +204,25 @@ - - + + + + + - + - - + + + + + diff --git a/src/main/org/apache/tools/ant/taskdefs/Chmod.java b/src/main/org/apache/tools/ant/taskdefs/Chmod.java index f4ce3920a..cde3cc76e 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Chmod.java +++ b/src/main/org/apache/tools/ant/taskdefs/Chmod.java @@ -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) mnowostawski@infoscience.otago.ac.nz + * @author Stefan Bodewig */ -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(); } } diff --git a/src/main/org/apache/tools/ant/taskdefs/ExecTask.java b/src/main/org/apache/tools/ant/taskdefs/ExecTask.java index 207b08068..87f3e7c9f 100644 --- a/src/main/org/apache/tools/ant/taskdefs/ExecTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/ExecTask.java @@ -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); diff --git a/src/main/org/apache/tools/ant/taskdefs/ExecuteOn.java b/src/main/org/apache/tools/ant/taskdefs/ExecuteOn.java index 48dd9f6af..19c90e923 100644 --- a/src/main/org/apache/tools/ant/taskdefs/ExecuteOn.java +++ b/src/main/org/apache/tools/ant/taskdefs/ExecuteOn.java @@ -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; /** diff --git a/src/main/org/apache/tools/ant/types/FileSet.java b/src/main/org/apache/tools/ant/types/FileSet.java index 9b82d14dd..4781007f4 100644 --- a/src/main/org/apache/tools/ant/types/FileSet.java +++ b/src/main/org/apache/tools/ant/types/FileSet.java @@ -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);