1 |
douglas |
1112 |
// AAPT Package Ant Task |
2 |
douglas |
1107 |
// |
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 |
douglas |
1112 |
import java.io.File; |
25 |
douglas |
1107 |
|
26 |
douglas |
1112 |
import java.util.ArrayList; |
27 |
|
|
import java.util.Iterator; |
28 |
|
|
|
29 |
douglas |
1113 |
import org.apache.tools.ant.Project; |
30 |
|
|
import org.apache.tools.ant.taskdefs.UpToDate; |
31 |
douglas |
1112 |
import org.apache.tools.ant.types.DirSet; |
32 |
douglas |
1113 |
import org.apache.tools.ant.types.FileSet; |
33 |
douglas |
1112 |
import org.apache.tools.ant.types.Path; |
34 |
douglas |
1113 |
import org.apache.tools.ant.types.resources.FileResource; |
35 |
|
|
import org.apache.tools.ant.types.resources.Union; |
36 |
douglas |
1112 |
|
37 |
|
|
public class AAPTPackage extends CommandTask |
38 |
douglas |
1107 |
{ |
39 |
douglas |
1112 |
private boolean force_; |
40 |
|
|
private boolean update_; |
41 |
|
|
private boolean make_; |
42 |
|
|
private boolean verbose_; |
43 |
|
|
private boolean extending_; |
44 |
|
|
private File manifest_; |
45 |
|
|
private Path include_; |
46 |
douglas |
1113 |
private File assets_; |
47 |
douglas |
1112 |
private File publicDefinitions_; |
48 |
douglas |
1183 |
private Path resource_; |
49 |
douglas |
1112 |
private File file_; |
50 |
|
|
private File java_; |
51 |
|
|
private ArrayList<DirSet> dirSets_ = new ArrayList<DirSet>(); |
52 |
|
|
|
53 |
|
|
public void setForce(boolean force) |
54 |
|
|
{ |
55 |
|
|
force_ = force; |
56 |
|
|
} |
57 |
|
|
|
58 |
|
|
public void setUpdate(boolean update) |
59 |
|
|
{ |
60 |
|
|
update_ = update; |
61 |
|
|
} |
62 |
|
|
|
63 |
|
|
public void setMake(boolean make) |
64 |
|
|
{ |
65 |
|
|
make_ = make; |
66 |
|
|
} |
67 |
|
|
|
68 |
|
|
public void setVerbose(boolean verbose) |
69 |
|
|
{ |
70 |
|
|
verbose_ = verbose; |
71 |
|
|
} |
72 |
|
|
|
73 |
|
|
public void setExtending(boolean extending) |
74 |
|
|
{ |
75 |
|
|
extending_ = extending; |
76 |
|
|
} |
77 |
|
|
|
78 |
|
|
public void setManifest(File manifest) |
79 |
|
|
{ |
80 |
|
|
manifest_ = manifest; |
81 |
|
|
} |
82 |
|
|
|
83 |
|
|
public void setInclude(Path include) |
84 |
|
|
{ |
85 |
|
|
include_ = include; |
86 |
|
|
} |
87 |
|
|
|
88 |
douglas |
1113 |
public void setAssets(File assets) |
89 |
douglas |
1112 |
{ |
90 |
douglas |
1113 |
assets_ = assets; |
91 |
douglas |
1112 |
} |
92 |
|
|
|
93 |
|
|
public void setPublicDefinitions(File publicDefinitions) |
94 |
|
|
{ |
95 |
|
|
publicDefinitions_ = publicDefinitions; |
96 |
|
|
} |
97 |
|
|
|
98 |
douglas |
1183 |
public void setResource(Path resource) |
99 |
douglas |
1112 |
{ |
100 |
|
|
resource_ = resource; |
101 |
|
|
} |
102 |
|
|
|
103 |
|
|
public void setFile(File file) |
104 |
|
|
{ |
105 |
|
|
file_ = file; |
106 |
|
|
} |
107 |
|
|
|
108 |
|
|
public void setJava(File java) |
109 |
|
|
{ |
110 |
|
|
java_ = java; |
111 |
|
|
} |
112 |
|
|
|
113 |
|
|
public void add(DirSet dirSet) |
114 |
|
|
{ |
115 |
|
|
dirSets_.add(dirSet); |
116 |
|
|
} |
117 |
|
|
|
118 |
|
|
@Override |
119 |
douglas |
1108 |
public void execute() |
120 |
|
|
{ |
121 |
douglas |
1112 |
if (isUpToDate()) |
122 |
|
|
return; |
123 |
|
|
|
124 |
|
|
command("aapt"); |
125 |
|
|
argument("package"); |
126 |
|
|
|
127 |
|
|
if (force_) |
128 |
|
|
argument("-f"); |
129 |
|
|
|
130 |
|
|
if (update_) |
131 |
|
|
argument("-u"); |
132 |
|
|
|
133 |
|
|
if (make_) |
134 |
|
|
argument("-m"); |
135 |
|
|
|
136 |
|
|
if (verbose_) |
137 |
|
|
argument("-v"); |
138 |
|
|
|
139 |
|
|
if (extending_) |
140 |
|
|
argument("-x"); |
141 |
|
|
|
142 |
|
|
if (manifest_ != null) |
143 |
|
|
arguments("-M", manifest_); |
144 |
|
|
|
145 |
|
|
if (include_ != null) |
146 |
|
|
for (Iterator iterator = include_.iterator(); iterator.hasNext();) |
147 |
|
|
arguments("-I", iterator.next().toString()); |
148 |
|
|
|
149 |
douglas |
1113 |
if (assets_ != null && assets_.exists()) |
150 |
|
|
arguments("-A", assets_); |
151 |
douglas |
1112 |
|
152 |
|
|
if (publicDefinitions_ != null) |
153 |
|
|
arguments("-P", publicDefinitions_); |
154 |
|
|
|
155 |
|
|
if (resource_ != null) |
156 |
douglas |
1183 |
for (String resource : resource_.list()) |
157 |
|
|
arguments("-S", resource); |
158 |
douglas |
1112 |
|
159 |
|
|
if (file_ != null) |
160 |
|
|
arguments("-F", file_); |
161 |
|
|
|
162 |
|
|
if (java_ != null) |
163 |
|
|
arguments("-J", java_); |
164 |
|
|
|
165 |
|
|
for (DirSet dirSet : dirSets_) |
166 |
|
|
for (Iterator iterator = dirSet.iterator(); iterator.hasNext();) |
167 |
|
|
argument(iterator.next().toString()); |
168 |
|
|
|
169 |
|
|
super.execute(); |
170 |
douglas |
1108 |
} |
171 |
douglas |
1112 |
|
172 |
|
|
private boolean isUpToDate() |
173 |
|
|
{ |
174 |
douglas |
1113 |
Project project = getProject(); |
175 |
|
|
UpToDate upToDate = (UpToDate)project.createTask("uptodate"); |
176 |
|
|
Union union = upToDate.createSrcResources(); |
177 |
|
|
|
178 |
|
|
if (manifest_ != null) |
179 |
|
|
{ |
180 |
|
|
FileSet fileSet = (FileSet)project.createDataType("fileset"); |
181 |
|
|
|
182 |
|
|
fileSet.setFile(manifest_); |
183 |
|
|
union.add(fileSet); |
184 |
|
|
} |
185 |
|
|
|
186 |
|
|
if (assets_ != null && assets_.exists()) |
187 |
|
|
{ |
188 |
|
|
FileSet fileSet = (FileSet)project.createDataType("fileset"); |
189 |
|
|
|
190 |
|
|
fileSet.setDir(assets_); |
191 |
|
|
union.add(fileSet); |
192 |
|
|
} |
193 |
|
|
|
194 |
|
|
if (resource_ != null) |
195 |
douglas |
1183 |
union.add(resource_); |
196 |
douglas |
1113 |
|
197 |
|
|
union.addAll(dirSets_); |
198 |
|
|
|
199 |
|
|
// TODO: publicDefinitions_ |
200 |
|
|
|
201 |
|
|
if (file_ != null) |
202 |
|
|
{ |
203 |
|
|
upToDate.setTargetFile(file_); |
204 |
|
|
|
205 |
|
|
if (!upToDate.eval()) |
206 |
|
|
return false; |
207 |
|
|
} |
208 |
|
|
|
209 |
|
|
if (java_ != null) |
210 |
|
|
{ |
211 |
|
|
FileSet fileSet = (FileSet)project.createDataType("fileset"); |
212 |
|
|
|
213 |
|
|
fileSet.setDir(java_); |
214 |
|
|
fileSet.setIncludes("**/R.java"); |
215 |
|
|
|
216 |
|
|
if (fileSet.size() == 0) |
217 |
|
|
return false; |
218 |
|
|
|
219 |
|
|
for (Iterator iterator = fileSet.iterator(); iterator.hasNext();) |
220 |
|
|
{ |
221 |
|
|
upToDate.setTargetFile(((FileResource)iterator.next()).getFile()); |
222 |
|
|
|
223 |
|
|
if (!upToDate.eval()) |
224 |
|
|
return false; |
225 |
|
|
} |
226 |
|
|
} |
227 |
|
|
|
228 |
|
|
return upToDate.eval(); |
229 |
douglas |
1112 |
} |
230 |
douglas |
1107 |
} |