LUCENE-1405: Added support for Ant resource collections in contrib/ant <index> task.

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@786610 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Erik Hatcher 2009-06-19 18:24:19 +00:00
parent 19234f12bd
commit 65131ca7b9
4 changed files with 37 additions and 13 deletions

View File

@ -421,6 +421,9 @@ Bug fixes
structure of terms in the index that can be created by indexing structure of terms in the index that can be created by indexing
using the new NumericTokenStream class. (Uwe Schindler, using the new NumericTokenStream class. (Uwe Schindler,
Yonik Seeley, Mike McCandless) Yonik Seeley, Mike McCandless)
28. LUCENE-1405: Added support for Ant resource collections in contrib/ant
<index> task. (Przemyslaw Sztoch via Erik Hatcher)
Optimizations Optimizations

View File

@ -1,4 +1,8 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<!--
To use this example from a source checkout:
ant -f example.xml -lib ../../build/contrib/ant/ -lib ../../build/ -lib lib
-->
<project name="ant-example" default="index"> <project name="ant-example" default="index">
<description> <description>

View File

@ -38,15 +38,20 @@ import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task; import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.FileSet; import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.EnumeratedAttribute; import org.apache.tools.ant.types.EnumeratedAttribute;
import org.apache.tools.ant.types.Resource;
import org.apache.tools.ant.types.ResourceCollection;
import org.apache.tools.ant.types.resources.FileResource;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Date; import java.util.Date;
import java.util.Iterator;
import java.util.Properties; import java.util.Properties;
import java.util.Map; import java.util.Map;
import java.util.HashMap; import java.util.HashMap;
import java.util.Set; import java.util.Set;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Vector;
import java.text.ParseException; import java.text.ParseException;
/** /**
@ -55,9 +60,9 @@ import java.text.ParseException;
*/ */
public class IndexTask extends Task { public class IndexTask extends Task {
/** /**
* file list * resources
*/ */
private ArrayList filesets = new ArrayList(); protected Vector rcs = new Vector();
/** /**
* overwrite index? * overwrite index?
@ -173,9 +178,18 @@ public class IndexTask extends Task {
*@param set FileSet to be added *@param set FileSet to be added
*/ */
public void addFileset(FileSet set) { public void addFileset(FileSet set) {
filesets.add(set); add(set);
} }
/**
* Add a collection of files to copy.
* @param res a resource collection to copy.
* @since Ant 1.7
*/
public void add(ResourceCollection res) {
rcs.add(res);
}
/** /**
* Sets custom properties for a configurable document handler. * Sets custom properties for a configurable document handler.
*/ */
@ -267,18 +281,20 @@ public class IndexTask extends Task {
try { try {
writer.setMergeFactor(mergeFactor); writer.setMergeFactor(mergeFactor);
for (int i = 0; i < filesets.size(); i++) { for (int i = 0; i < rcs.size(); i++) {
FileSet fs = (FileSet) filesets.get(i); ResourceCollection rc = (ResourceCollection) rcs.elementAt(i);
if (fs != null) { if (rc.isFilesystemOnly()) {
DirectoryScanner ds = Iterator resources = rc.iterator();
fs.getDirectoryScanner(getProject()); while (resources.hasNext()) {
String[] dsfiles = ds.getIncludedFiles(); Resource r = (Resource) resources.next();
File baseDir = ds.getBasedir(); if (!r.isExists() || !(r instanceof FileResource)) {
continue;
for (int j = 0; j < dsfiles.length; j++) { }
File file = new File(baseDir, dsfiles[j]);
totalFiles++; totalFiles++;
File file = ((FileResource) r).getFile();
if (!file.exists() || !file.canRead()) { if (!file.exists() || !file.canRead()) {
throw new BuildException("File \"" + throw new BuildException("File \"" +
file.getAbsolutePath() file.getAbsolutePath()

View File

@ -59,6 +59,7 @@ public class IndexTaskTest extends TestCase {
IndexTask task = new IndexTask(); IndexTask task = new IndexTask();
FileSet fs = new FileSet(); FileSet fs = new FileSet();
fs.setProject(project);
fs.setDir(new File(docsDir)); fs.setDir(new File(docsDir));
task.addFileset(fs); task.addFileset(fs);
task.setOverwrite(true); task.setOverwrite(true);