ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/AntTasks/source/net/douglasthrift/anttasks/Dex.java
Revision: 1112
Committed: 2008-11-07T00:35:05-08:00 (16 years, 7 months ago) by douglas
File size: 5534 byte(s)
Log Message:
Progress on AAPT Package, needs upToDate still.

File Contents

# User Rev Content
1 douglas 1108 // Dex 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 1108 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.taskdefs.ExecTask;
31 douglas 1109 import org.apache.tools.ant.taskdefs.condition.Os;
32 douglas 1108 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 douglas 1107
37 douglas 1112 public class Dex extends CommandTask
38 douglas 1107 {
39 douglas 1108 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 douglas 1112 command(Os.isFamily(Os.FAMILY_WINDOWS) ? "dx.bat" : "dx");
162     argument("--dex");
163 douglas 1108
164     if (debug_)
165 douglas 1112 argument("--debug");
166 douglas 1108
167     if (verbose_)
168 douglas 1112 argument("--verbose");
169 douglas 1108
170     if (positions_ != null)
171 douglas 1112 argument("--positions=" + positions_);
172 douglas 1108
173     if (noLocals_)
174 douglas 1112 argument("--no-locals");
175 douglas 1108
176     if (noOptimize_)
177 douglas 1112 argument("--no-optimize");
178 douglas 1108
179     if (statistics_)
180 douglas 1112 argument("--statistics");
181 douglas 1108
182     if (noOptimizeList_ != null)
183 douglas 1112 argument("--no-optimize-list=" + noOptimizeList_);
184 douglas 1108
185     if (optimizeList_ != null)
186 douglas 1112 argument("--optimize-list=" + optimizeList_);
187 douglas 1108
188     if (noStrict_)
189 douglas 1112 argument("--no-strict");
190 douglas 1108
191     if (keepClasses_)
192 douglas 1112 argument("--keep-classes");
193 douglas 1108
194     if (output_ != null)
195 douglas 1112 argument("--output=" + output_);
196 douglas 1108
197     if (dumpTo_ != null)
198 douglas 1112 argument("--dump-to=" + dumpTo_);
199 douglas 1108
200     if (dumpWidth_ != null)
201 douglas 1112 argument("--dump-width=" + dumpWidth_);
202 douglas 1108
203     if (dumpMethod_ != null)
204 douglas 1112 argument("--dump-method=" + dumpMethod_);
205 douglas 1108
206     if (verboseDump_)
207 douglas 1112 argument("--verbose-dump");
208 douglas 1108
209     if (noFiles_)
210 douglas 1112 argument("--no-files");
211 douglas 1108
212     if (coreLibrary_)
213 douglas 1112 argument("--core-library");
214 douglas 1108
215     for (ResourceCollection fileSet : fileSets_)
216     for (Iterator iterator = fileSet.iterator(); iterator.hasNext();)
217 douglas 1112 argument(iterator.next().toString());
218 douglas 1108
219 douglas 1112 super.execute();
220 douglas 1108 }
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 douglas 1107 }

Properties

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