bodewig 00/08/01 02:18:41
Modified: . WHATSNEW build.xml
src/main/org/apache/tools/ant/taskdefs Chmod.java
ExecTask.java ExecuteOn.java
src/main/org/apache/tools/ant/types FileSet.java
Log:
Make Chmod extend ExecuteOn instead of MatchingTask.
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.
Revision Changes Path
1.8 +2 -0 jakarta-ant/WHATSNEW
Index: WHATSNEW
===================================================================
RCS file: /home/cvs/jakarta-ant/WHATSNEW,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- WHATSNEW 2000/07/31 16:21:44 1.7
+++ WHATSNEW 2000/08/01 09:18:38 1.8
@@ -43,6 +43,8 @@
* 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:
-----------
1.52 +24 -9 jakarta-ant/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-ant/build.xml,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -r1.51 -r1.52
--- build.xml 2000/07/31 12:09:25 1.51
+++ build.xml 2000/08/01 09:18:38 1.52
@@ -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>
<!-- ===================================================================
-->
1.6 +96 -32
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Chmod.java
Index: Chmod.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Chmod.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Chmod.java 2000/07/24 14:01:26 1.5
+++ Chmod.java 2000/08/01 09:18:39 1.6
@@ -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 @@
*
* @author [EMAIL PROTECTED]
* @author Mariusz Nowostawski (Marni) <a href="mailto:[EMAIL
PROTECTED]">[EMAIL PROTECTED]</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">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 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();
}
}
1.5 +1 -1
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/ExecTask.java
Index: ExecTask.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/ExecTask.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ExecTask.java 2000/07/25 12:03:26 1.4
+++ ExecTask.java 2000/08/01 09:18:39 1.5
@@ -164,7 +164,7 @@
/**
* 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);
1.4 +1 -1
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/ExecuteOn.java
Index: ExecuteOn.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/ExecuteOn.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ExecuteOn.java 2000/07/31 13:30:20 1.3
+++ ExecuteOn.java 2000/08/01 09:18:40 1.4
@@ -69,7 +69,7 @@
*/
public class ExecuteOn extends ExecTask {
- private Vector filesets = new Vector();
+ protected Vector filesets = new Vector();
private boolean parallel = false;
/**
1.5 +23 -6
jakarta-ant/src/main/org/apache/tools/ant/types/FileSet.java
Index: FileSet.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/types/FileSet.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- FileSet.java 2000/07/23 14:20:26 1.4
+++ FileSet.java 2000/08/01 09:18:40 1.5
@@ -84,12 +84,18 @@
}
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 @@
* 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);