ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/AntTasks/source/net/douglasthrift/anttasks/AAPTPackage.java
Revision: 1113
Committed: 2008-11-11T23:06:07-08:00 (16 years, 7 months ago) by douglas
File size: 4613 byte(s)
Log Message:
AAPT Package has upToDate.

File Contents

# User Rev Content
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     private File resource_;
49     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     public void setResource(File resource)
99     {
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     arguments("-S", resource_);
157    
158     if (file_ != null)
159     arguments("-F", file_);
160    
161     if (java_ != null)
162     arguments("-J", java_);
163    
164     for (DirSet dirSet : dirSets_)
165     for (Iterator iterator = dirSet.iterator(); iterator.hasNext();)
166     argument(iterator.next().toString());
167    
168     super.execute();
169 douglas 1108 }
170 douglas 1112
171     private boolean isUpToDate()
172     {
173 douglas 1113 Project project = getProject();
174     UpToDate upToDate = (UpToDate)project.createTask("uptodate");
175     Union union = upToDate.createSrcResources();
176    
177     if (manifest_ != null)
178     {
179     FileSet fileSet = (FileSet)project.createDataType("fileset");
180    
181     fileSet.setFile(manifest_);
182     union.add(fileSet);
183     }
184    
185     if (assets_ != null && assets_.exists())
186     {
187     FileSet fileSet = (FileSet)project.createDataType("fileset");
188    
189     fileSet.setDir(assets_);
190     union.add(fileSet);
191     }
192    
193     if (resource_ != null)
194     {
195     FileSet fileSet = (FileSet)project.createDataType("fileset");
196    
197     fileSet.setDir(resource_);
198     union.add(fileSet);
199     }
200    
201     union.addAll(dirSets_);
202    
203     // TODO: publicDefinitions_
204    
205     if (file_ != null)
206     {
207     upToDate.setTargetFile(file_);
208    
209     if (!upToDate.eval())
210     return false;
211     }
212    
213     if (java_ != null)
214     {
215     FileSet fileSet = (FileSet)project.createDataType("fileset");
216    
217     fileSet.setDir(java_);
218     fileSet.setIncludes("**/R.java");
219    
220     if (fileSet.size() == 0)
221     return false;
222    
223     for (Iterator iterator = fileSet.iterator(); iterator.hasNext();)
224     {
225     upToDate.setTargetFile(((FileResource)iterator.next()).getFile());
226    
227     if (!upToDate.eval())
228     return false;
229     }
230     }
231    
232     return upToDate.eval();
233 douglas 1112 }
234 douglas 1107 }

Properties

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