Add the ability for network resource bundles to have an index file which tells them which files they should expect to find. This turns out to be pretty useful since resources try to grab a locale-specific version first, which often fails, and then they have to grab their generic version. This allows us to bypass some of this latency when we're able to know ahead of time which resources we will have.
git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@500 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
package com.threerings.media.tools;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
import org.apache.tools.ant.DirectoryScanner;
|
||||
import org.apache.tools.ant.Task;
|
||||
import org.apache.tools.ant.types.FileSet;
|
||||
|
||||
/**
|
||||
* Creates a file that lists all the resources in a fileset out to an index file.
|
||||
*/
|
||||
public class ResourceIndexerTask extends Task
|
||||
{
|
||||
/**
|
||||
* Adds a nested <fileset> element.
|
||||
*/
|
||||
public void addFileset (FileSet set)
|
||||
{
|
||||
_filesets.add(set);
|
||||
}
|
||||
|
||||
public void setIndexFile (String file)
|
||||
{
|
||||
_indexFile = file;
|
||||
}
|
||||
|
||||
@Override // documentation inherited
|
||||
public void execute () throws BuildException
|
||||
{
|
||||
PrintWriter fout = null;
|
||||
try {
|
||||
fout = new PrintWriter(new FileWriter(_indexFile));
|
||||
|
||||
for (FileSet fs : _filesets) {
|
||||
DirectoryScanner ds = fs.getDirectoryScanner(getProject());
|
||||
String[] srcFiles = ds.getIncludedFiles();
|
||||
for (String filename : srcFiles) {
|
||||
fout.println(filename);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (IOException ioe) {
|
||||
throw new BuildException(ioe);
|
||||
} finally {
|
||||
if (fout != null) {
|
||||
fout.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** A list of filesets that contain files to include in the index. */
|
||||
protected ArrayList<FileSet> _filesets = new ArrayList<FileSet>();
|
||||
|
||||
/** The name of the file to which we should write the index. */
|
||||
protected String _indexFile;
|
||||
}
|
||||
Reference in New Issue
Block a user