java/ant/src/org/apidesign/infra/ant/GrepCopy.java
changeset 268 fb9bf90251e3
child 271 a1c057f1f756
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/java/ant/src/org/apidesign/infra/ant/GrepCopy.java	Sun Jul 06 00:12:56 2008 +0200
     1.3 @@ -0,0 +1,51 @@
     1.4 +package org.apidesign.infra.ant;
     1.5 +
     1.6 +import java.io.File;
     1.7 +import java.io.FileWriter;
     1.8 +import java.io.IOException;
     1.9 +import java.util.Map;
    1.10 +import java.util.Map.Entry;
    1.11 +import org.apache.tools.ant.BuildException;
    1.12 +import org.apache.tools.ant.Task;
    1.13 +import org.apache.tools.ant.types.FileSet;
    1.14 +import org.apache.tools.ant.types.FilterSet;
    1.15 +import org.apache.tools.ant.util.FileUtils;
    1.16 +import org.openide.util.Exceptions;
    1.17 +
    1.18 +public class GrepCopy extends Task {
    1.19 +    private GrepFilter filter = new GrepFilter();
    1.20 +    private File dir;
    1.21 +    
    1.22 +    public GrepCopy() {
    1.23 +    }
    1.24 +
    1.25 +    public FileSet createFileSet() {
    1.26 +        return filter.createFileSet();
    1.27 +    }
    1.28 +
    1.29 +    public void setTarget(File dir) {
    1.30 +        this.dir = dir;
    1.31 +    }
    1.32 +
    1.33 +    @Override
    1.34 +    public void execute() throws BuildException {
    1.35 +        filter.setProject(getProject());
    1.36 +
    1.37 +        FilterSet set = filter.createFilterSet();
    1.38 +
    1.39 +        for (Object object : set.getFilterHash().entrySet()) {
    1.40 +
    1.41 +            FileWriter w = null;
    1.42 +            try {
    1.43 +                Entry en = (Entry) object;
    1.44 +                File to = new File(dir, (String) en.getKey());
    1.45 +                to.getParentFile().mkdirs();
    1.46 +                w = new FileWriter(to);
    1.47 +                w.write((String) en.getValue());
    1.48 +                w.close();
    1.49 +            } catch (IOException ex) {
    1.50 +                throw new BuildException(ex);
    1.51 +            }
    1.52 +        }
    1.53 +    }
    1.54 +}