1 /* 
2  * Copyright 2005 Paul Hinds
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.tp23.antinstaller.antmod.taskdefs;
17
18import java.io.File;
19import java.io.IOException;
20
21import org.apache.tools.ant.BuildException;
22import org.apache.tools.ant.Task;
23import org.tp23.antinstaller.selfextract.ResourceExtractor;
24/**
25 * Extracts a resource from the classpath into the filesystem
26 * @author teknopaul
27 *
28 */
29public class GetResourceTask extends Task{
30
31    String resource;
32    String dest;
33    String regex;
34    String replace;
35    
36    public void execute() throws BuildException{
37        try {
38            ResourceExtractor re = new ResourceExtractor();
39            if(regex != null){
40                re.copyResource(resource, new File(dest), regex, replace);
41            }
42            else{
43                re.copyResourceBinary(resource, new File(dest));
44            }
45        } catch (IOException e) {
46            throw new BuildException(e.getMessage());
47        }
48    }
49    public String getDest() {
50        return dest;
51    }
52    public void setDest(String file) {
53        this.dest = file;
54    }
55    public String getResource() {
56        return resource;
57    }
58    public void setResource(String resource) {
59        this.resource = resource;
60    }
61    public String getReplace() {
62        return replace;
63    }
64    public void setReplace(String replace) {
65        this.replace = replace;
66    }
67    public String getRegex() {
68        return regex;
69    }
70    public void setRegex(String token) {
71        this.regex = token;
72    }
73}
74