I have found the need to change the behaviour of the javac task in
conjunction with the way that files are included/excluded before the
compiler is called.
Currently, what happens is that the Javac task creates a set of "candidate"
files. This is a list of files that match the include and exclude patterns
stated by the task's attributes/parameters. Next the Javac task goes
through that set of candidates, eliminating source files where the
associated class file is considered up to date with the source file. Thus,
the task only sends the files to the compile that it thinks are out of date.
My desire is to have a little bit of control over that second stage - the
elimination stage.
Why? On a ClearCase file system, file access is slightly slower then local
hard drive access (due to networks, NFS mounts, repository server loads,
etc). Therefore, accessing two different files in different directories for
time stamps can take a while.
What do I propose? I want to be able to tell the javac task to ignore the
elimination phase. I want the task to simply send all files to the
compiler.
How do I propose to do this? I have added an attribute to the MatchingTask
task called "includelevel". This is to indicate the level to which I want
to include files. MatchingTask is only the holder for the attribute -- it
actually does nothing with it. It is up to subclasses to react to the value
within the attribute. Therefore, I have also made changes to the javac task
such that if the includelevel attribute equals "all" then all files will be
included in the javac task. If the includelevel equals "outofdate" (or
anything other then "all" for that matter), then the default behaviour will
be used.
Why have I put the attribute in the MatchingTask class? I'm sure that there
are sub tasks that could more granularity of control over the include
results.
Does this work? I have found it to be quicker on slow file systems where
the code base is over 1700 files.
Well? What does the ant community think?
<<index.html.txt>> <<Javac.java.txt>> <<MatchingTask.java.txt>>
--
Jay Dickon Glanville
P068 - SiteManager Development, Nortel Networks
613-765-1144 (ESN 395-1144)
MS: 045/55/A05
E-Mail: [EMAIL PROTECTED]
--- index.html Mon Jan 29 21:06:32 2001
+++ index.html.new Mon Jan 29 21:02:46 2001
@@ -34,7 +34,7 @@
<center>
<p>Version: @VERSION@<br>
-$Id: index.html,v 1.197 2001/01/30 00:22:28 donaldp Exp $</p>
+$Id: index.html,v 1.196 2001/01/29 09:49:26 nico Exp $</p>
</center>
<hr>
@@ -207,8 +207,8 @@
to build a bootstrap version of Ant.</p>
<p>When finished, use:</p>
<blockquote>
- <p><code>build
-Ddist.dir=<<i>directory_to_contain_Ant_distribution</i>>
dist</code> (<i>Windows</i>)</p>
- <p><code>build.sh
-Ddist.dir=<<i>directory_to_contain_Ant_distribution</i>>
dist</code> (<i>Unix</i>)</p>
+ <p><code>build
-Dant.dist.dir=<<i>directory_to_contain_Ant_distribution</i>>
dist</code> (<i>Windows</i>)</p>
+ <p><code>build.sh
-Dant.dist.dir=<<i>directory_to_contain_Ant_distribution</i>>
dist</code> (<i>Unix</i>)</p>
</blockquote>
<p>to create a binary distribution of Ant. This distribution can be
found in the directory you specified.</p>
@@ -3273,6 +3273,19 @@
<td valign="top">indicates whether default excludes should be used
(<code>yes</code> | <code>no</code>); default excludes are used when
omitted.</td>
<td valign="top" align="center">No</td>
+ </tr>
+ <tr>
+ <td valign="top">includelevel</td>
+ <td valign="top">The level with which to include files in this task.
+ There are two possible values for this: <code>outofdate</code>
+ [default] and <code>all</code>. The <code>javac</code> task first uses
+ the includes/excludes patterns to determin a set of candidate files.
+ Next, if this attribute is to <code>outofdate</code>, then the set of
+ candidates is reduced to include only source files where the associated
+ class files are out of date. If this attribute is <code>all</code>,
+ then all cadidate files are passed to the compiler.
+ </td>
+ <td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">classpath</td>
--- Javac.java Mon Jan 29 21:06:22 2001
+++ Javac.java.new Mon Jan 29 20:14:58 2001
@@ -118,6 +118,11 @@
protected boolean failOnError = true;
protected File[] compileList = new File[0];
+ /** Whether or not to simply include all files or to perform time-stamp
+ * tests.
+ */
+ private boolean includeAllFiles = false;
+
/**
* Create a nested <src ...> element for multiple source path
* support.
@@ -418,6 +423,8 @@
throw new BuildException("destination directory \"" + destDir +
"\" does not exist or is not a directory", location);
}
+ setIncludeLevel();
+
// scan source directories and dest directory to build up
// compile lists
resetFileLists();
@@ -485,7 +492,14 @@
m.setFrom("*.java");
m.setTo("*.class");
SourceFileScanner sfs = new SourceFileScanner(this);
- File[] newFiles = sfs.restrictAsFiles(files, srcDir, destDir, m);
+ File[] newFiles = null;
+ if ( includeAllFiles ) {
+ newFiles = new File[files.length];
+ for (int i=0; i<files.length; i++)
+ newFiles[i] = new File(srcDir, files[i]);
+ } else {
+ newFiles = sfs.restrictAsFiles(files, srcDir, destDir, m);
+ }
if (newFiles.length > 0) {
File[] newCompileList = new File[compileList.length +
@@ -501,6 +515,29 @@
/** Gets the list of files to be compiled. */
public File[] getFileList() {
return compileList;
+ }
+
+ /**
+ * Determines if all files get included or if time-stamps should be
+ * evaluated. If the include level (defined in MatchingTask) is set to
+ * "all", then all files that match the include/exclude criteria are
+ * added. Whereas, if the include level is set to "outofdate" or
+ * anything other then "all", then the default criteria of matching is
+ * used (i.e.: all files that match include/exclude and who's classes
+ * are missing or out of date).
+ */
+ private void setIncludeLevel() {
+ String level = getIncludeLevel();
+ if ( level == null ) {
+ includeAllFiles = false;
+ return;
+ }
+ if ( level.equalsIgnoreCase( "all" ) ) {
+ includeAllFiles = true;
+ return;
+ }
+ if ( level.equalsIgnoreCase( "outofdate" ) )
+ includeAllFiles = false;
}
}
--- MatchingTask.java Mon Jan 29 21:06:22 2001
+++ MatchingTask.java.new Mon Jan 29 19:51:20 2001
@@ -75,6 +75,8 @@
protected boolean useDefaultExcludes = true;
protected FileSet fileset = new FileSet();
+ /** The level of which to include files. */
+ private String level = null;
/**
* add a name entry on the include list
@@ -199,6 +201,19 @@
*/
public void setExcludesfile(File excludesfile) {
fileset.setExcludesfile(excludesfile);
+ }
+
+ /**
+ * Sets the level to which this include/exclude set should work.
+ * It is up to sub-classes to determin what each level means. This
+ * level functionality is defined here for commonality purposes.
+ */
+ public void setIncludelevel( String level ) {
+ this.level = level;
+ }
+
+ protected String getIncludeLevel() {
+ return level;
}
}