ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/AntTasks/source/net/douglasthrift/anttasks/Preverify.java
Revision: 1107
Committed: 2008-11-04T12:53:49-08:00 (16 years, 8 months ago) by douglas
File size: 4783 byte(s)
Log Message:
Stub out some Ant tasks for Android!

File Contents

# User Rev Content
1 douglas 972 // Preverify Ant Task
2     //
3     // Douglas Thrift
4     //
5     // $Id$
6    
7 douglas 974 /* Copyright 2007 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 douglas 972 package net.douglasthrift.anttasks;
23    
24     import java.io.File;
25     import java.util.ArrayList;
26    
27     import org.apache.tools.ant.BuildException;
28     import org.apache.tools.ant.Task;
29     import org.apache.tools.ant.taskdefs.ExecTask;
30     import org.apache.tools.ant.types.EnumeratedAttribute;
31     import org.apache.tools.ant.types.Path;
32     import org.apache.tools.ant.types.Reference;
33     import org.apache.tools.ant.util.FileUtils;
34    
35     public class Preverify extends Task
36     {
37     public static class Target extends EnumeratedAttribute
38     {
39     public String[] getValues()
40     {
41     return new String[]{"CLDC1.1", "CLDC1.0"};
42     }
43     }
44    
45     private Path classpath;
46     private File directory;
47     private boolean cldc1_0;
48     private Target target;
49     private boolean nofinalize;
50     private boolean nonative;
51     private boolean nofp;
52 douglas 975 private ArrayList<String> classnames = new ArrayList<String>();
53 douglas 972 private Path dirnames;
54    
55     public void setClasspath(Path classpath)
56     {
57     if (this.classpath == null)
58     this.classpath = classpath;
59     else
60     this.classpath.add(classpath);
61     }
62    
63     public void setClasspathRef(Reference classpathRef)
64     {
65     this.setClasspath((Path)classpathRef.getReferencedObject(this.getProject()));
66     }
67    
68     public void setDirectory(File directory)
69     {
70     this.directory = directory;
71     }
72    
73     public void setCldc1_0(boolean cldc1_0)
74     {
75     this.cldc1_0 = cldc1_0;
76     }
77    
78     public void setCldc(boolean cldc)
79     {
80     this.setCldc1_0(cldc);
81     }
82    
83     public void setTarget(Target target)
84     {
85     this.target = target;
86     }
87    
88     public void setNofinalize(boolean nofinalize)
89     {
90     this.nofinalize = nofinalize;
91     }
92    
93     public void setNonative(boolean nonative)
94     {
95     this.nonative = nonative;
96     }
97    
98     public void setNofp(boolean nofp)
99     {
100     this.nofp = nofp;
101     }
102    
103     public void setClassnames(String classnames)
104     {
105     for (String classname: classnames.split("[ ,]"))
106     this.classnames.add(classname);
107     }
108    
109     public void setDirnames(Path dirnames)
110     {
111     if (this.dirnames == null)
112     this.dirnames = dirnames;
113     else
114     this.dirnames.add(dirnames);
115     }
116    
117     public void setDirnamesRef(Reference dirnamesRef)
118     {
119     this.setDirnames((Path)dirnamesRef.getReferencedObject(this.getProject()));
120     }
121    
122     public void addClasspath(Path classpath)
123     {
124     this.setClasspath(classpath);
125     }
126    
127     public void addDirnames(Path dirnames)
128     {
129     this.setDirnames(dirnames);
130     }
131    
132     public void execute()
133     {
134 douglas 975 if (classnames.isEmpty() && dirnames == null)
135 douglas 972 throw new BuildException("no classnames or dirnames");
136    
137     if (this.isUpToDate())
138     return;
139    
140     ExecTask exec = (ExecTask)this.getProject().createTask("exec");
141    
142     exec.setTaskName(this.getTaskName());
143     exec.setExecutable("preverify");
144     exec.setDir(new File(System.getProperty("java.io.tmpdir")));
145     exec.setFailonerror(true);
146    
147     if (this.classpath != null)
148     {
149     exec.createArg().setValue("-classpath");
150     exec.createArg().setPath(this.classpath);
151     }
152    
153     if (this.directory != null)
154     {
155     exec.createArg().setValue("-d");
156     exec.createArg().setFile(this.directory);
157     }
158    
159     if (this.cldc1_0)
160     exec.createArg().setValue("-cldc1.0");
161    
162     if (this.target != null)
163     exec.createArg().setLine("-target " + this.target);
164    
165     if (this.nofinalize)
166     exec.createArg().setValue("-nofinalize");
167    
168     if (this.nonative)
169     exec.createArg().setValue("-nonative");
170    
171     if (this.nofp)
172     exec.createArg().setValue("-nofp");
173    
174     ArrayList<String> files = new ArrayList<String>();
175    
176 douglas 975 for (String classname: this.classnames)
177     {
178     this.log("Preverifying " + classname);
179     exec.createArg().setValue(classname);
180     }
181 douglas 972
182     if (this.dirnames != null)
183     for (String dirname: this.dirnames.list())
184     {
185     this.log("Preverifying " + dirname);
186     exec.createArg().setValue(dirname);
187     }
188    
189     exec.execute();
190     }
191    
192     // XXX: this thing only really checks jar files right now
193     private boolean isUpToDate()
194     {
195     FileUtils utils = FileUtils.getFileUtils();
196    
197 douglas 975 if (!this.classnames.isEmpty())
198 douglas 972 return false;
199    
200     if (this.dirnames != null)
201     for (String dirname: this.dirnames.list())
202     {
203     File file = new File(dirname);
204    
205     if (file.isDirectory())
206     return false;
207    
208     if (!utils.isUpToDate(file, new File(this.directory != null ? this.directory : new File("output"), file.getName())))
209     return false;
210     }
211    
212     return true;
213     }
214     }

Properties

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