ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/AntTasks/source/net/douglasthrift/anttasks/Dex.java
Revision: 1108
Committed: 2008-11-05T21:07:38-08:00 (16 years, 7 months ago) by douglas
File size: 5925 byte(s)
Log Message:
Dex task.

File Contents

# Content
1 // Dex Ant 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 java.util.ArrayList;
27 import java.util.Iterator;
28
29 import org.apache.tools.ant.BuildException;
30 import org.apache.tools.ant.Task;
31 import org.apache.tools.ant.taskdefs.ExecTask;
32 import org.apache.tools.ant.types.FileSet;
33 import org.apache.tools.ant.types.ResourceCollection;
34 import org.apache.tools.ant.types.resources.FileResource;
35 import org.apache.tools.ant.util.FileUtils;
36
37 public class Dex extends Task
38 {
39 private boolean debug_;
40 private boolean verbose_;
41 private String positions_;
42 private boolean noLocals_;
43 private boolean noOptimize_;
44 private boolean statistics_;
45 private File noOptimizeList_;
46 private File optimizeList_;
47 private boolean noStrict_;
48 private boolean keepClasses_;
49 private File output_;
50 private File dumpTo_;
51 private Integer dumpWidth_;
52 private String dumpMethod_;
53 private boolean verboseDump_;
54 private boolean noFiles_;
55 private boolean coreLibrary_;
56 private ArrayList<ResourceCollection> fileSets_ = new ArrayList<ResourceCollection>();
57
58 public void setDebug(boolean debug)
59 {
60 debug_ = debug;
61 }
62
63 public void setVerbose(boolean verbose)
64 {
65 verbose_ = verbose;
66 }
67
68 public void setPositions(String positions)
69 {
70 positions_ = positions;
71 }
72
73 public void setNoLocals(boolean noLocals)
74 {
75 noLocals_ = noLocals;
76 }
77
78 public void setNoOptimize(boolean noOptimize)
79 {
80 noOptimize_ = noOptimize;
81 }
82
83 public void setStatistics(boolean statistics)
84 {
85 statistics_ = statistics;
86 }
87
88 public void setNoOptimizeList(File noOptimizeList)
89 {
90 noOptimizeList_ = noOptimizeList;
91 }
92
93 public void setOptimizeList(File optimizeList)
94 {
95 optimizeList_ = optimizeList;
96 }
97
98 public void setNoStrict(boolean noStrict)
99 {
100 noStrict_ = noStrict;
101 }
102
103 public void setKeepClasses(boolean keepClasses)
104 {
105 keepClasses_ = keepClasses;
106 }
107
108 public void setOutput(File output)
109 {
110 output_ = output;
111 }
112
113 public void setDumpTo(File dumpTo)
114 {
115 dumpTo_ = dumpTo;
116 }
117
118 public void setDumpWidth(int dumpWidth)
119 {
120 dumpWidth_ = new Integer(dumpWidth);
121 }
122
123 public void setDumpMethod(String dumpMethod)
124 {
125 dumpMethod_ = dumpMethod;
126 }
127
128 public void setVerboseDump(boolean verboseDump)
129 {
130 verboseDump_ = verboseDump;
131 }
132
133 public void setNoFiles(boolean noFiles)
134 {
135 noFiles_ = noFiles;
136 }
137
138 public void setCoreLibrary(boolean coreLibrary)
139 {
140 coreLibrary_ = coreLibrary;
141 }
142
143 public void add(ResourceCollection fileSet)
144 {
145 fileSets_.add(fileSet);
146 }
147
148 @Override
149 public void execute()
150 {
151 if (fileSets_.isEmpty())
152 throw new BuildException("no input files specified");
153
154 for (ResourceCollection fileSet : fileSets_)
155 if (!fileSet.isFilesystemOnly())
156 throw new BuildException("not file system only");
157
158 if (isUpToDate())
159 return;
160
161 ExecTask exec = (ExecTask)getProject().createTask("exec");
162
163 exec.setTaskName(getTaskName());
164 exec.setExecutable("dx");
165 exec.setFailonerror(true);
166 exec.createArg().setValue("--dex");
167
168 if (debug_)
169 exec.createArg().setValue("--debug");
170
171 if (verbose_)
172 exec.createArg().setValue("--verbose");
173
174 if (positions_ != null)
175 exec.createArg().setValue("--positions=" + positions_);
176
177 if (noLocals_)
178 exec.createArg().setValue("--no-locals");
179
180 if (noOptimize_)
181 exec.createArg().setValue("--no-optimize");
182
183 if (statistics_)
184 exec.createArg().setValue("--statistics");
185
186 if (noOptimizeList_ != null)
187 exec.createArg().setValue("--no-optimize-list=" + noOptimizeList_);
188
189 if (optimizeList_ != null)
190 exec.createArg().setValue("--optimize-list=" + optimizeList_);
191
192 if (noStrict_)
193 exec.createArg().setValue("--no-strict");
194
195 if (keepClasses_)
196 exec.createArg().setValue("--keep-classes");
197
198 if (output_ != null)
199 exec.createArg().setValue("--output=" + output_);
200
201 if (dumpTo_ != null)
202 exec.createArg().setValue("--dump-to=" + dumpTo_);
203
204 if (dumpWidth_ != null)
205 exec.createArg().setValue("--dump-width=" + dumpWidth_);
206
207 if (dumpMethod_ != null)
208 exec.createArg().setValue("--dump-method=" + dumpMethod_);
209
210 if (verboseDump_)
211 exec.createArg().setValue("--verbose-dump");
212
213 if (noFiles_)
214 exec.createArg().setValue("--no-files");
215
216 if (coreLibrary_)
217 exec.createArg().setValue("--core-library");
218
219 for (ResourceCollection fileSet : fileSets_)
220 for (Iterator iterator = fileSet.iterator(); iterator.hasNext();)
221 exec.createArg().setValue(iterator.next().toString());
222
223 exec.execute();
224 }
225
226 private boolean isUpToDate()
227 {
228 if (output_ == null || !output_.exists())
229 return false;
230
231 FileUtils utils = FileUtils.getFileUtils();
232
233 for (ResourceCollection fileSet_ : fileSets_)
234 for (Iterator iterator_ = fileSet_.iterator(); iterator_.hasNext();)
235 {
236 FileResource resource = (FileResource)iterator_.next();
237
238 if (!resource.isExists())
239 return false;
240
241 if (resource.isDirectory())
242 {
243 FileSet fileSet = (FileSet)getProject().createDataType("fileset");
244
245 fileSet.setDir(resource.getFile());
246 fileSet.setIncludes("**/*.apk **/*.class **/*.jar **/*.zip");
247
248 for (Iterator iterator = fileSet.iterator(); iterator.hasNext();)
249 if (!utils.isUpToDate(((FileResource)iterator.next()).getFile(), output_))
250 return false;
251 }
252 else if (!utils.isUpToDate(resource.getFile(), output_))
253 return false;
254 }
255
256 return true;
257 }
258 }

Properties

Name Value
svn:eol-style native
svn:keywords Id
svn:mergeinfo