01: /*
02: * Copyright 2005 Paul Hinds
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: */
16: package org.tp23.antinstaller.antmod.taskdefs;
17:
18: import java.io.File;
19: import java.io.IOException;
20:
21: import org.apache.tools.ant.BuildException;
22: import org.apache.tools.ant.Task;
23: import org.tp23.antinstaller.selfextract.ResourceExtractor;
24:
25: /**
26: * Extracts a resource from the classpath into the filesystem
27: * @author teknopaul
28: *
29: */
30: public class GetResourceTask extends Task {
31:
32: String resource;
33: String dest;
34: String regex;
35: String replace;
36:
37: public void execute() throws BuildException {
38: try {
39: ResourceExtractor re = new ResourceExtractor();
40: if (regex != null) {
41: re.copyResource(resource, new File(dest), regex,
42: replace);
43: } else {
44: re.copyResourceBinary(resource, new File(dest));
45: }
46: } catch (IOException e) {
47: throw new BuildException(e.getMessage());
48: }
49: }
50:
51: public String getDest() {
52: return dest;
53: }
54:
55: public void setDest(String file) {
56: this .dest = file;
57: }
58:
59: public String getResource() {
60: return resource;
61: }
62:
63: public void setResource(String resource) {
64: this .resource = resource;
65: }
66:
67: public String getReplace() {
68: return replace;
69: }
70:
71: public void setReplace(String replace) {
72: this .replace = replace;
73: }
74:
75: public String getRegex() {
76: return regex;
77: }
78:
79: public void setRegex(String token) {
80: this.regex = token;
81: }
82: }
|