ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/AntTasks/source/net/douglasthrift/anttasks/Dex.java
(Generate patch)

Comparing:
AntTasks/source/net/douglasthrift/anttasks/DX.java (file contents), Revision 1107 by douglas, 2008-11-04T12:53:49-08:00 vs.
AntTasks/source/net/douglasthrift/anttasks/Dex.java (file contents), Revision 1112 by douglas, 2008-11-07T00:35:05-08:00

# Line 1 | Line 1
1 < // DX Ant Task
1 > // Dex Ant Task
2   //
3   // Douglas Thrift
4   //
# Line 21 | Line 21
21  
22   package net.douglasthrift.anttasks;
23  
24 < import org.apache.tools.ant.Task;
24 > import java.io.File;
25  
26 < public class DX extends Task
26 > import java.util.ArrayList;
27 > import java.util.Iterator;
28 >
29 > import org.apache.tools.ant.BuildException;
30 > import org.apache.tools.ant.taskdefs.ExecTask;
31 > import org.apache.tools.ant.taskdefs.condition.Os;
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 CommandTask
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 +                command(Os.isFamily(Os.FAMILY_WINDOWS) ? "dx.bat" : "dx");
162 +                argument("--dex");
163 +
164 +                if (debug_)
165 +                        argument("--debug");
166 +
167 +                if (verbose_)
168 +                        argument("--verbose");
169 +
170 +                if (positions_ != null)
171 +                        argument("--positions=" + positions_);
172 +
173 +                if (noLocals_)
174 +                        argument("--no-locals");
175 +
176 +                if (noOptimize_)
177 +                        argument("--no-optimize");
178 +
179 +                if (statistics_)
180 +                        argument("--statistics");
181 +
182 +                if (noOptimizeList_ != null)
183 +                        argument("--no-optimize-list=" + noOptimizeList_);
184 +
185 +                if (optimizeList_ != null)
186 +                        argument("--optimize-list=" + optimizeList_);
187 +
188 +                if (noStrict_)
189 +                        argument("--no-strict");
190 +
191 +                if (keepClasses_)
192 +                        argument("--keep-classes");
193 +
194 +                if (output_ != null)
195 +                        argument("--output=" + output_);
196 +
197 +                if (dumpTo_ != null)
198 +                        argument("--dump-to=" + dumpTo_);
199 +
200 +                if (dumpWidth_ != null)
201 +                        argument("--dump-width=" + dumpWidth_);
202 +
203 +                if (dumpMethod_ != null)
204 +                        argument("--dump-method=" + dumpMethod_);
205 +
206 +                if (verboseDump_)
207 +                        argument("--verbose-dump");
208 +
209 +                if (noFiles_)
210 +                        argument("--no-files");
211 +
212 +                if (coreLibrary_)
213 +                        argument("--core-library");
214 +
215 +                for (ResourceCollection fileSet : fileSets_)
216 +                        for (Iterator iterator = fileSet.iterator(); iterator.hasNext();)
217 +                                argument(iterator.next().toString());
218 +
219 +                super.execute();
220 +        }
221 +
222 +        private boolean isUpToDate()
223 +        {
224 +                if (output_ == null || !output_.exists())
225 +                        return false;
226 +
227 +                FileUtils utils = FileUtils.getFileUtils();
228 +
229 +                for (ResourceCollection fileSet_ : fileSets_)
230 +                        for (Iterator iterator_ = fileSet_.iterator(); iterator_.hasNext();)
231 +                        {
232 +                                FileResource resource = (FileResource)iterator_.next();
233 +
234 +                                if (!resource.isExists())
235 +                                        return false;
236 +
237 +                                if (resource.isDirectory())
238 +                                {
239 +                                        FileSet fileSet = (FileSet)getProject().createDataType("fileset");
240 +
241 +                                        fileSet.setDir(resource.getFile());
242 +                                        fileSet.setIncludes("**/*.apk **/*.class **/*.jar **/*.zip");
243 +
244 +                                        for (Iterator iterator = fileSet.iterator(); iterator.hasNext();)
245 +                                                if (!utils.isUpToDate(((FileResource)iterator.next()).getFile(), output_))
246 +                                                        return false;
247 +                                }
248 +                                else if (!utils.isUpToDate(resource.getFile(), output_))
249 +                                        return false;
250 +                        }
251 +
252 +                return true;
253 +        }
254   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines