ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/AntTasks/source/net/douglasthrift/anttasks/Preverify.java
Revision: 974
Committed: 2007-12-19T16:22:45-08:00 (17 years, 6 months ago) by douglas
File size: 4866 byte(s)
Log Message:
Add Apache License, stub out UnixZip.

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.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 private ArrayList<String> classnames;
53 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 if (this.classnames == null)
106 this.classnames = new ArrayList<String>();
107
108 for (String classname: classnames.split("[ ,]"))
109 this.classnames.add(classname);
110 }
111
112 public void setDirnames(Path dirnames)
113 {
114 if (this.dirnames == null)
115 this.dirnames = dirnames;
116 else
117 this.dirnames.add(dirnames);
118 }
119
120 public void setDirnamesRef(Reference dirnamesRef)
121 {
122 this.setDirnames((Path)dirnamesRef.getReferencedObject(this.getProject()));
123 }
124
125 public void addClasspath(Path classpath)
126 {
127 this.setClasspath(classpath);
128 }
129
130 public void addDirnames(Path dirnames)
131 {
132 this.setDirnames(dirnames);
133 }
134
135 public void execute()
136 {
137 if (classnames == null && dirnames == null)
138 throw new BuildException("no classnames or dirnames");
139
140 if (this.isUpToDate())
141 return;
142
143 ExecTask exec = (ExecTask)this.getProject().createTask("exec");
144
145 exec.setTaskName(this.getTaskName());
146 exec.setExecutable("preverify");
147 exec.setDir(new File(System.getProperty("java.io.tmpdir")));
148 exec.setFailonerror(true);
149
150 if (this.classpath != null)
151 {
152 exec.createArg().setValue("-classpath");
153 exec.createArg().setPath(this.classpath);
154 }
155
156 if (this.directory != null)
157 {
158 exec.createArg().setValue("-d");
159 exec.createArg().setFile(this.directory);
160 }
161
162 if (this.cldc1_0)
163 exec.createArg().setValue("-cldc1.0");
164
165 if (this.target != null)
166 exec.createArg().setLine("-target " + this.target);
167
168 if (this.nofinalize)
169 exec.createArg().setValue("-nofinalize");
170
171 if (this.nonative)
172 exec.createArg().setValue("-nonative");
173
174 if (this.nofp)
175 exec.createArg().setValue("-nofp");
176
177 ArrayList<String> files = new ArrayList<String>();
178
179 if (this.classnames != null)
180 for (String classname: this.classnames)
181 {
182 this.log("Preverifying " + classname);
183 exec.createArg().setValue(classname);
184 }
185
186 if (this.dirnames != null)
187 for (String dirname: this.dirnames.list())
188 {
189 this.log("Preverifying " + dirname);
190 exec.createArg().setValue(dirname);
191 }
192
193 exec.execute();
194 }
195
196 // XXX: this thing only really checks jar files right now
197 private boolean isUpToDate()
198 {
199 FileUtils utils = FileUtils.getFileUtils();
200
201 if (this.classnames != null)
202 return false;
203
204 if (this.dirnames != null)
205 for (String dirname: this.dirnames.list())
206 {
207 File file = new File(dirname);
208
209 if (file.isDirectory())
210 return false;
211
212 if (!utils.isUpToDate(file, new File(this.directory != null ? this.directory : new File("output"), file.getName())))
213 return false;
214 }
215
216 return true;
217 }
218 }

Properties

Name Value
svn:keywords Id