The old way I had the Directory-based bundlers checking for out-of-dateness was prone to error in the face of new files or unfortunate subdirectory situations. Now check on an entry-by-entry basis instead, which is much happier.

git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@351 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
Mike Thomas
2007-11-15 21:56:34 +00:00
parent c68df0bab2
commit c73ec397e0
4 changed files with 92 additions and 66 deletions
@@ -58,17 +58,9 @@ public class DirectoryTileSetBundler extends TileSetBundler
super(configPath);
}
/**
* Finish the creation of a tileset bundle jar file.
*
* @param target the tileset bundle file that will be created.
* @param bundle contains the tilesets we'd like to save out to the bundle.
* @param improv the image provider.
* @param imageBase the base directory for getting images for non
* ObjectTileSet tilesets.
*/
@Override // documentation inherited
public boolean createBundle (
File target, TileSetBundle bundle, ImageProvider improv, String imageBase)
File target, TileSetBundle bundle, ImageProvider improv, String imageBase, long newestMod)
throws IOException
{
try {
@@ -101,6 +93,10 @@ public class DirectoryTileSetBundler extends TileSetBundler
// write the trimmed tileset image to the destination
// output stream
File outFile = new File(target, imagePath);
if (outFile.lastModified() > newestMod) {
// Our file's newer than the newest bundle mod - up to date.
continue;
}
outFile.getParentFile().mkdirs();
FileOutputStream fout = new FileOutputStream(outFile);
TrimmedObjectTileSet tset =
@@ -123,9 +119,18 @@ public class DirectoryTileSetBundler extends TileSetBundler
// read the image file and convert it to our custom
// format in the bundle
File ifile = new File(imageBase, imagePath);
if (ifile.lastModified() > newestMod) {
// Our file's newer than the newest bundle mod - up to date.
continue;
}
try {
BufferedImage image = ImageIO.read(ifile);
File outFile = new File(target, imagePath);
if (outFile.lastModified() > newestMod) {
// Our file's newer than the newest bundle mod - up to date.
continue;
}
outFile.getParentFile().mkdirs();
FileOutputStream fout = new FileOutputStream(outFile);
FileInputStream imgin = new FileInputStream(ifile);
@@ -141,6 +146,7 @@ public class DirectoryTileSetBundler extends TileSetBundler
// now write a serialized representation of the tileset bundle
// object to the bundle jar file
File outFile = new File(target, BundleUtil.METADATA_PATH);
outFile.getParentFile().mkdirs();
FileOutputStream fout = new FileOutputStream(outFile);
ObjectOutputStream oout = new ObjectOutputStream(fout);
@@ -156,9 +162,9 @@ public class DirectoryTileSetBundler extends TileSetBundler
}
@Override // documentation inherited
protected long getTgtModificationDate (File target)
protected boolean skipIfTargetNewer ()
{
// Return the oldest modification date of anything within the directory.
return FileUtil.getOldestLastModified(target);
// We have to check modification later on a file-by-file basis, so cannot skip.
return false;
}
}
@@ -310,7 +310,7 @@ public class TileSetBundler
}
// see if our newest file is newer than the tileset bundle
if (newest < getTgtModificationDate(target)) {
if (skipIfTargetNewer() && newest < target.lastModified()) {
return false;
}
@@ -322,7 +322,7 @@ public class TileSetBundler
}
};
return createBundle(target, bundle, improv, bundleDesc.getParent());
return createBundle(target, bundle, improv, bundleDesc.getParent(), newest);
}
/**
@@ -332,10 +332,12 @@ public class TileSetBundler
* @param bundle contains the tilesets we'd like to save out to the bundle.
* @param improv the image provider.
* @param imageBase the base directory for getting images for non
* @param newestMod the most recent modification to any part of the bundle. By default we
* ignore this since we normally duck out if we're up to date.
* ObjectTileSet tilesets.
*/
public boolean createBundle (
File target, TileSetBundle bundle, ImageProvider improv, String imageBase)
File target, TileSetBundle bundle, ImageProvider improv, String imageBase, long newestMod)
throws IOException
{
return createBundleJar(target, bundle, improv, imageBase);
@@ -455,11 +457,11 @@ public class TileSetBundler
}
/**
* Returns the last modified date of <code>target</code> to be compared for out-of-dateness.
* Returns whether we should skip updating the bundle if the target is newer than any component.
*/
protected long getTgtModificationDate (File target)
protected boolean skipIfTargetNewer ()
{
return target.lastModified();
return true;
}
/** Replaces the image suffix with <code>.raw</code>. */