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

File Contents

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

Properties

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