01: /*
02: * CacheWriterTask.java
03: *
04: * Created on February 19, 2004, 12:07 AM
05: */
06:
07: package org.netbeans.imagecache;
08:
09: import java.io.File;
10: import java.io.IOException;
11: import java.util.ArrayList;
12: import java.util.Iterator;
13: import java.util.List;
14: import org.apache.tools.ant.*;
15: import org.apache.tools.ant.types.FileSet;
16: import org.apache.tools.ant.types.Path;
17:
18: /**
19: *
20: * @author tim
21: */
22: public class CacheWriterTask extends Task {
23: private File outDir = null;
24: private List paths = new ArrayList();
25: private boolean clean = true;
26:
27: /** Creates a new instance of CacheWriterTask */
28: public CacheWriterTask() {
29: }
30:
31: public void setDir(File dir) {
32: paths.add(new Path(getProject(), dir.toString()));
33: }
34:
35: public void setOutdir(File dir) {
36: this .outDir = dir;
37: }
38:
39: public void addPath(Path fs) {
40: paths.add(fs);
41: }
42:
43: public void setClean(boolean clean) {
44: this .clean = clean;
45: }
46:
47: public void execute() throws BuildException {
48: if (paths.isEmpty()) {
49: throw new BuildException(
50: "Source dir or fileset required to scan for images");
51: }
52: if (outDir == null) {
53: throw new BuildException(
54: "Output directory for cache file must be specified");
55: }
56:
57: try {
58: CacheWriter writer = new CacheWriter();
59: writer.setDir(outDir.toString(), clean);
60:
61: Iterator it = paths.iterator();
62: while (it.hasNext()) {
63: Path curr = (Path) it.next();
64: String[] dirs = curr.list();
65: for (int i = 0; i < dirs.length; i++) {
66: System.err.println("WriteDir " + dirs[i]);
67: writer.writeDir(dirs[i], true);
68: }
69: }
70: } catch (IOException ioe) {
71: ioe.printStackTrace();
72: throw new BuildException(ioe.getMessage());
73: }
74: }
75: }
|