Rather than forcing a rebuild of our tileset and component bundles every time when we're deploying to a directory bundle, decide based on the oldest modification time stamp of any file within the directory. Otherwise, these builds get crazy long.

git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@347 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
Mike Thomas
2007-11-13 18:29:49 +00:00
parent a0b5874d5f
commit f57e973987
5 changed files with 74 additions and 20 deletions
@@ -302,16 +302,17 @@ public class ComponentBundlerTask extends Task
DirectoryScanner ds = fs.getDirectoryScanner(getProject()); DirectoryScanner ds = fs.getDirectoryScanner(getProject());
File fromDir = fs.getDir(getProject()); File fromDir = fs.getDir(getProject());
String[] srcFiles = ds.getIncludedFiles(); String[] srcFiles = ds.getIncludedFiles();
long tgtModificationDate = getTgtModificationDate(target);
for (int f = 0; f < srcFiles.length; f++) { for (int f = 0; f < srcFiles.length; f++) {
File cfile = new File(fromDir, srcFiles[f]); File cfile = new File(fromDir, srcFiles[f]);
if (newer(cfile, target)) { if (newer(cfile, tgtModificationDate)) {
return true; return true;
} }
} }
return false; return false;
} else if (source instanceof File) { } else if (source instanceof File) {
return newer((File)source, target); return newer((File)source, getTgtModificationDate(target));
} else { } else {
System.err.println("Can't compare " + source + System.err.println("Can't compare " + source +
@@ -324,9 +325,17 @@ public class ComponentBundlerTask extends Task
* Returns true if <code>source</code> is newer than * Returns true if <code>source</code> is newer than
* <code>target</code>. * <code>target</code>.
*/ */
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 <code>target</code> to be compared for out-of-dateness.
*/
protected long getTgtModificationDate (File target)
{
return target.lastModified();
} }
/** /**
@@ -27,8 +27,9 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; 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; import com.threerings.media.tile.TrimmedTileSet;
/** /**
@@ -62,9 +63,9 @@ public class DirectoryComponentBundlerTask extends ComponentBundlerTask
} }
@Override // documentation inherited @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 the oldest modification date of anything within the directory.
return true; return FileUtil.getOldestLastModified(target);
} }
} }
@@ -36,6 +36,7 @@ import javax.imageio.ImageIO;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import com.threerings.media.Log; import com.threerings.media.Log;
import com.threerings.util.FileUtil;
import com.threerings.media.tile.ImageProvider; import com.threerings.media.tile.ImageProvider;
import com.threerings.media.tile.ObjectTileSet; import com.threerings.media.tile.ObjectTileSet;
import com.threerings.media.tile.TileSet; import com.threerings.media.tile.TileSet;
@@ -155,9 +156,9 @@ public class DirectoryTileSetBundler extends TileSetBundler
} }
@Override // documentation inherited @Override // documentation inherited
protected boolean maySkipIfNewer () protected long getTgtModificationDate (File target)
{ {
// Can't skip since we're copying individual files. // Return the oldest modification date of anything within the directory.
return false; return FileUtil.getOldestLastModified(target);
} }
} }
@@ -310,7 +310,7 @@ public class TileSetBundler
} }
// see if our newest file is newer than the tileset bundle // see if our newest file is newer than the tileset bundle
if (newest < target.lastModified() && maySkipIfNewer()) { if (newest < getTgtModificationDate(target)) {
return false; return false;
} }
@@ -325,14 +325,6 @@ public class TileSetBundler
return createBundle(target, bundle, improv, bundleDesc.getParent()); 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. * Finish the creation of a tileset bundle jar file.
* *
@@ -462,6 +454,14 @@ public class TileSetBundler
} }
} }
/**
* Returns the last modified date of <code>target</code> to be compared for out-of-dateness.
*/
protected long getTgtModificationDate (File target)
{
return target.lastModified();
}
/** Replaces the image suffix with <code>.raw</code>. */ /** Replaces the image suffix with <code>.raw</code>. */
protected static String adjustImagePath (String imagePath) protected static String adjustImagePath (String imagePath)
{ {
@@ -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;
}
}