author | Jaroslav Tulach <jtulach@netbeans.org> |
Sun, 06 Jul 2008 00:31:01 +0200 | |
changeset 271 | a1c057f1f756 |
parent 268 | fb9bf90251e3 |
child 274 | e1a7420cea38 |
permissions | -rw-r--r-- |
jtulach@268 | 1 |
package org.apidesign.infra.ant; |
jtulach@268 | 2 |
|
jtulach@268 | 3 |
import java.io.File; |
jtulach@268 | 4 |
import java.io.FileWriter; |
jtulach@268 | 5 |
import java.io.IOException; |
jtulach@268 | 6 |
import java.util.Map.Entry; |
jtulach@268 | 7 |
import org.apache.tools.ant.BuildException; |
jtulach@268 | 8 |
import org.apache.tools.ant.Task; |
jtulach@268 | 9 |
import org.apache.tools.ant.types.FileSet; |
jtulach@268 | 10 |
import org.apache.tools.ant.types.FilterSet; |
jtulach@268 | 11 |
|
jtulach@268 | 12 |
public class GrepCopy extends Task { |
jtulach@268 | 13 |
private GrepFilter filter = new GrepFilter(); |
jtulach@268 | 14 |
private File dir; |
jtulach@268 | 15 |
|
jtulach@268 | 16 |
public GrepCopy() { |
jtulach@268 | 17 |
} |
jtulach@268 | 18 |
|
jtulach@268 | 19 |
public FileSet createFileSet() { |
jtulach@268 | 20 |
return filter.createFileSet(); |
jtulach@268 | 21 |
} |
jtulach@268 | 22 |
|
jtulach@268 | 23 |
public void setTarget(File dir) { |
jtulach@268 | 24 |
this.dir = dir; |
jtulach@268 | 25 |
} |
jtulach@268 | 26 |
|
jtulach@268 | 27 |
@Override |
jtulach@268 | 28 |
public void execute() throws BuildException { |
jtulach@268 | 29 |
filter.setProject(getProject()); |
jtulach@268 | 30 |
|
jtulach@268 | 31 |
FilterSet set = filter.createFilterSet(); |
jtulach@268 | 32 |
|
jtulach@268 | 33 |
for (Object object : set.getFilterHash().entrySet()) { |
jtulach@268 | 34 |
|
jtulach@268 | 35 |
FileWriter w = null; |
jtulach@268 | 36 |
try { |
jtulach@268 | 37 |
Entry en = (Entry) object; |
jtulach@268 | 38 |
File to = new File(dir, (String) en.getKey()); |
jtulach@268 | 39 |
to.getParentFile().mkdirs(); |
jtulach@268 | 40 |
w = new FileWriter(to); |
jtulach@268 | 41 |
w.write((String) en.getValue()); |
jtulach@268 | 42 |
w.close(); |
jtulach@268 | 43 |
} catch (IOException ex) { |
jtulach@268 | 44 |
throw new BuildException(ex); |
jtulach@268 | 45 |
} |
jtulach@268 | 46 |
} |
jtulach@268 | 47 |
} |
jtulach@268 | 48 |
} |