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

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

Properties

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