diff --git a/src/java/com/threerings/cast/bundle/tools/ComponentBundlerTask.java b/src/java/com/threerings/cast/bundle/tools/ComponentBundlerTask.java index fa79e055..92b092d1 100644 --- a/src/java/com/threerings/cast/bundle/tools/ComponentBundlerTask.java +++ b/src/java/com/threerings/cast/bundle/tools/ComponentBundlerTask.java @@ -302,16 +302,17 @@ public class ComponentBundlerTask extends Task DirectoryScanner ds = fs.getDirectoryScanner(getProject()); File fromDir = fs.getDir(getProject()); String[] srcFiles = ds.getIncludedFiles(); + long tgtModificationDate = getTgtModificationDate(target); for (int f = 0; f < srcFiles.length; f++) { File cfile = new File(fromDir, srcFiles[f]); - if (newer(cfile, target)) { + if (newer(cfile, tgtModificationDate)) { return true; } } return false; } else if (source instanceof File) { - return newer((File)source, target); + return newer((File)source, getTgtModificationDate(target)); } else { System.err.println("Can't compare " + source + @@ -324,9 +325,17 @@ public class ComponentBundlerTask extends Task * Returns true if source is newer than * target. */ - protected boolean newer (File source, File target) + protected boolean newer (File source, long tgtModificationDate) { - return source.lastModified() > target.lastModified(); + return source.lastModified() > tgtModificationDate; + } + + /** + * Returns the last modified date of target to be compared for out-of-dateness. + */ + protected long getTgtModificationDate (File target) + { + return target.lastModified(); } /** diff --git a/src/java/com/threerings/cast/bundle/tools/DirectoryComponentBundlerTask.java b/src/java/com/threerings/cast/bundle/tools/DirectoryComponentBundlerTask.java index d3ab04e4..6318b09f 100644 --- a/src/java/com/threerings/cast/bundle/tools/DirectoryComponentBundlerTask.java +++ b/src/java/com/threerings/cast/bundle/tools/DirectoryComponentBundlerTask.java @@ -27,8 +27,9 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; -import com.threerings.media.tile.TileSet; +import com.threerings.util.FileUtil; +import com.threerings.media.tile.TileSet; import com.threerings.media.tile.TrimmedTileSet; /** @@ -62,9 +63,9 @@ public class DirectoryComponentBundlerTask extends ComponentBundlerTask } @Override // documentation inherited - protected boolean outOfDate (Object source, File target) + protected long getTgtModificationDate (File target) { - // Since we're updating individual files, assume always out of date and rebuild. - return true; + // Return the oldest modification date of anything within the directory. + return FileUtil.getOldestLastModified(target); } } diff --git a/src/java/com/threerings/media/tile/bundle/tools/DirectoryTileSetBundler.java b/src/java/com/threerings/media/tile/bundle/tools/DirectoryTileSetBundler.java index 507281b9..23c6f299 100644 --- a/src/java/com/threerings/media/tile/bundle/tools/DirectoryTileSetBundler.java +++ b/src/java/com/threerings/media/tile/bundle/tools/DirectoryTileSetBundler.java @@ -36,6 +36,7 @@ import javax.imageio.ImageIO; import org.apache.commons.io.IOUtils; import com.threerings.media.Log; +import com.threerings.util.FileUtil; import com.threerings.media.tile.ImageProvider; import com.threerings.media.tile.ObjectTileSet; import com.threerings.media.tile.TileSet; @@ -155,9 +156,9 @@ public class DirectoryTileSetBundler extends TileSetBundler } @Override // documentation inherited - protected boolean maySkipIfNewer () + protected long getTgtModificationDate (File target) { - // Can't skip since we're copying individual files. - return false; + // Return the oldest modification date of anything within the directory. + return FileUtil.getOldestLastModified(target); } } diff --git a/src/java/com/threerings/media/tile/bundle/tools/TileSetBundler.java b/src/java/com/threerings/media/tile/bundle/tools/TileSetBundler.java index 2143c113..fe0ddaa2 100644 --- a/src/java/com/threerings/media/tile/bundle/tools/TileSetBundler.java +++ b/src/java/com/threerings/media/tile/bundle/tools/TileSetBundler.java @@ -310,7 +310,7 @@ public class TileSetBundler } // see if our newest file is newer than the tileset bundle - if (newest < target.lastModified() && maySkipIfNewer()) { + if (newest < getTgtModificationDate(target)) { return false; } @@ -325,14 +325,6 @@ public class TileSetBundler return createBundle(target, bundle, improv, bundleDesc.getParent()); } - /** - * Whether we're allowed to skip creation of the bundle if we're not out of date. - */ - protected boolean maySkipIfNewer () - { - return true; - } - /** * Finish the creation of a tileset bundle jar file. * @@ -462,6 +454,14 @@ public class TileSetBundler } } + /** + * Returns the last modified date of target to be compared for out-of-dateness. + */ + protected long getTgtModificationDate (File target) + { + return target.lastModified(); + } + /** Replaces the image suffix with .raw. */ protected static String adjustImagePath (String imagePath) { diff --git a/src/java/com/threerings/util/FileUtil.java b/src/java/com/threerings/util/FileUtil.java new file mode 100644 index 00000000..5db6e773 --- /dev/null +++ b/src/java/com/threerings/util/FileUtil.java @@ -0,0 +1,43 @@ +// +// $Id$ +// +// Nenya library - tools for developing networked games +// Copyright (C) 2002-2007 Three Rings Design, Inc., All Rights Reserved +// http://www.threerings.net/code/nenya/ +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published +// by the Free Software Foundation; either version 2.1 of the License, or +// (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +package com.threerings.util; + +import java.io.File; + +public class FileUtil +{ + /** + * Returns the timestamp of the oldest modification date of any file within the directory. + */ + public static long getOldestLastModified (File dir) + { + long oldest = dir.lastModified(); + for (File file : dir.listFiles()) { + if (file.isDirectory()) { + oldest = Math.min(oldest, getOldestLastModified(file)); + } else { + oldest = Math.min(oldest, file.lastModified()); + } + } + return oldest; + } +}