ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/AntTasks/source/net/douglasthrift/anttasks/APKBuilder.java
Revision: 1114
Committed: 2008-11-12T03:28:29-08:00 (16 years, 7 months ago) by douglas
File size: 3919 byte(s)
Log Message:
APK Builder!

File Contents

# User Rev Content
1 douglas 1107 // APKBuilder 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 douglas 1114 import java.io.File;
25 douglas 1107
26 douglas 1114 import java.util.Iterator;
27    
28     import org.apache.tools.ant.Project;
29     import org.apache.tools.ant.BuildException;
30     import org.apache.tools.ant.taskdefs.UpToDate;
31     import org.apache.tools.ant.taskdefs.condition.Os;
32     import org.apache.tools.ant.types.FileSet;
33     import org.apache.tools.ant.types.Path;
34     import org.apache.tools.ant.types.resources.FileResource;
35     import org.apache.tools.ant.types.resources.Union;
36    
37     public class APKBuilder extends CommandTask
38 douglas 1107 {
39 douglas 1114 private File output_;
40     private boolean verbose_;
41     private boolean unsigned_;
42     private String storeType_;
43     private Path zip_;
44     private Path file_;
45     private Path folder_;
46     private Path jar_;
47    
48     public void setOutput(File output)
49     {
50     output_ = output;
51     }
52    
53     public void setVerbose(boolean verbose)
54     {
55     verbose_ = verbose;
56     }
57    
58     public void setUnsigned(boolean unsigned)
59     {
60     unsigned_ = unsigned;
61     }
62    
63     public void setStoreType(String storeType)
64     {
65     storeType_ = storeType;
66     }
67    
68     public void setZip(Path zip)
69     {
70     zip_ = zip;
71     }
72    
73     public void setFile(Path file)
74     {
75     file_ = file;
76     }
77    
78     public void setFolder(Path folder)
79     {
80     folder_ = folder;
81     }
82    
83     public void setJar(Path jar)
84     {
85     jar_ = jar;
86     }
87    
88     @Override
89     public void execute()
90     {
91     if (output_ == null)
92     throw new BuildException("no output file specified");
93    
94     if (isUpToDate())
95     return;
96    
97     command(Os.isFamily(Os.FAMILY_WINDOWS) ? "apkbuilder.bat" : "apkbuilder");
98     argument(output_);
99    
100     if (verbose_)
101     argument("-v");
102    
103     if (unsigned_)
104     argument("-u");
105    
106     if (storeType_ != null)
107     arguments("-storetype", storeType_);
108    
109     if (zip_ != null)
110     for (Iterator iterator = zip_.iterator(); iterator.hasNext();)
111     arguments("-z", iterator.next().toString());
112    
113     if (file_ != null)
114     for (Iterator iterator = file_.iterator(); iterator.hasNext();)
115     arguments("-f", iterator.next().toString());
116    
117     if (folder_ != null)
118     for (Iterator iterator = folder_.iterator(); iterator.hasNext();)
119     arguments("-rf", iterator.next().toString());
120    
121     if (jar_ != null)
122     for (Iterator iterator = jar_.iterator(); iterator.hasNext();)
123     arguments("-rj", iterator.next().toString());
124    
125     super.execute();
126     }
127    
128     private boolean isUpToDate()
129     {
130     Project project = getProject();
131     UpToDate upToDate = (UpToDate)project.createTask("uptodate");
132    
133     upToDate.setTargetFile(output_);
134    
135     Union union = upToDate.createSrcResources();
136    
137     if (zip_ != null)
138     union.add(zip_);
139    
140     if (file_ != null)
141     union.add(file_);
142    
143     if (folder_ != null)
144     for (Iterator iterator = folder_.iterator(); iterator.hasNext();)
145     {
146     FileSet fileSet = (FileSet)project.createDataType("fileset");
147    
148     fileSet.setDir(((FileResource)iterator.next()).getFile());
149     fileSet.setExcludes("**/_*/** **/*.aidl **/*.class **/*.java **/META-INF/** **/overview.html **/package.html");
150     union.add(fileSet);
151     }
152    
153     if (jar_ != null)
154     for (Iterator iterator = jar_.iterator(); iterator.hasNext();)
155     {
156     FileSet fileSet = (FileSet)project.createDataType("fileset");
157     File file = ((FileResource)iterator.next()).getFile();
158    
159     if (file.isDirectory())
160     {
161     fileSet.setDir(file);
162     fileSet.setIncludes("*.jar");
163     }
164     else
165     fileSet.setFile(file);
166    
167     union.add(fileSet);
168     }
169    
170     return upToDate.eval();
171     }
172 douglas 1107 }

Properties

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