Menu

#53 wtkbuild re-compiles files every time

open
nobody
None
5
2005-10-31
2005-10-31
No

I'm having a problem with the wtkbuild task. I've found
that it re-compiles every source file every time the target
is executed.

This is because the files are compiled into a temporary
directory, and the temp. dir doesn't contain the previous
versions of the source files.

The Wtkbuild task uses super.execute() to compile the
source code, but the temporary directory is used as the
target directory, thus every file will be compiled. I submit
an alternative implementation of the execute() method -
one that only compiles source code newer than
the .class file:

public void execute() throws BuildException {
if (!isActive())
return;

//AB 31/10/05 Don't use super.execute() because we
need to check
//the destination directory, not the temp directory.
checkParameters();
resetFileLists();

File tmpDir = utility.getTempDir();
try {
if (getBootclasspath() == null) {
String bcp = utility.getMidpApi();
setBootclasspath(new Path(getProject(), bcp));
}
File origDest = getDestdir();
File tempDest = new File(tmpDir + "/tmpclasses");
if (preverify) {
setDestdir(tempDest);
tempDest.mkdir();
}

try {
//AB 31/10/05 Copied from Ant Javac task, instead of
calling super.execute();
// scan source directories and dest directory to build
up
// compile lists
String[] list = getSrcdir().list();
for (int i = 0; i < list.length; i++) {
File srcDir = getProject().resolveFile(list[i]);
if (!srcDir.exists()) {
throw new BuildException("srcdir \""
+ srcDir.getPath()
+ "\" does not exist!", getLocation());
}

DirectoryScanner ds = this.getDirectoryScanner
(srcDir);
String[] files = ds.getIncludedFiles();

//AB 31/10/05 NOTE: Use the original Destination
to check for modified files
scanDir(srcDir, origDest != null ? origDest : srcDir,
files);
}
compile();
}
finally {
setDestdir
(origDest);
}

if (preverify) {
String cp =
getBootclasspath() + File.pathSeparator + getClasspath
() + File.pathSeparator;

utility.preverify(tempDest, origDest, cp, cldc,
flags);
}
}
finally {
utility.delete(tmpDir);
}
}

Discussion