1 |
// Command Task |
2 |
// |
3 |
// Douglas Thrift |
4 |
// |
5 |
// $Id$ |
6 |
|
7 |
/* Copyright 2008 Douglas Thrift |
8 |
* |
9 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
10 |
* you may not use this file except in compliance with the License. |
11 |
* You may obtain a copy of the License at |
12 |
* |
13 |
* http://www.apache.org/licenses/LICENSE-2.0 |
14 |
* |
15 |
* Unless required by applicable law or agreed to in writing, software |
16 |
* distributed under the License is distributed on an "AS IS" BASIS, |
17 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
18 |
* See the License for the specific language governing permissions and |
19 |
* limitations under the License. |
20 |
*/ |
21 |
|
22 |
package net.douglasthrift.anttasks; |
23 |
|
24 |
import java.io.File; |
25 |
|
26 |
import org.apache.tools.ant.Task; |
27 |
import org.apache.tools.ant.taskdefs.ExecTask; |
28 |
import org.apache.tools.ant.types.Path; |
29 |
import org.apache.tools.ant.types.Reference; |
30 |
|
31 |
public abstract class CommandTask extends Task |
32 |
{ |
33 |
protected ExecTask command_; |
34 |
|
35 |
@Override |
36 |
public void execute() |
37 |
{ |
38 |
command_.execute(); |
39 |
} |
40 |
|
41 |
protected void command(String command) |
42 |
{ |
43 |
command_ = (ExecTask)getProject().createTask("exec"); |
44 |
|
45 |
command_.setTaskName(getTaskName()); |
46 |
command_.setExecutable(command); |
47 |
command_.setFailonerror(true); |
48 |
} |
49 |
|
50 |
protected void argument(File file) |
51 |
{ |
52 |
command_.createArg().setFile(file); |
53 |
} |
54 |
|
55 |
protected void argument(Path path) |
56 |
{ |
57 |
command_.createArg().setPath(path); |
58 |
} |
59 |
|
60 |
protected void argument(Reference reference) |
61 |
{ |
62 |
command_.createArg().setPathref(reference); |
63 |
} |
64 |
|
65 |
protected void argument(String value) |
66 |
{ |
67 |
command_.createArg().setValue(value); |
68 |
} |
69 |
|
70 |
protected void arguments(String line) |
71 |
{ |
72 |
command_.createArg().setLine(line); |
73 |
} |
74 |
|
75 |
protected void arguments(Object... objects) |
76 |
{ |
77 |
for (Object object : objects) |
78 |
if (object instanceof File) |
79 |
argument((File)object); |
80 |
else if (object instanceof Path) |
81 |
argument((Path)object); |
82 |
else if (object instanceof Reference) |
83 |
argument((Reference)object); |
84 |
else if (object instanceof String) |
85 |
argument((String)object); |
86 |
else |
87 |
assert (false); |
88 |
} |
89 |
} |