blob: be53914910950575fa6b2b310f202b9cd2cf0a35 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
|
// **********************************************************************
//
// Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************
//package Ice.Ant;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.taskdefs.ExecTask;
import org.apache.tools.ant.taskdefs.Execute;
import org.apache.tools.ant.taskdefs.PumpStreamHandler;
import org.apache.tools.ant.types.Commandline;
import org.apache.tools.ant.types.Commandline.Argument;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.Reference;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.StringReader;
import java.io.BufferedReader;
import java.io.BufferedWriter;
/**
* An ant task for slice2java. This task extends the abstract
* SliceTask class which takes care of attributes common to all slice
* translators (see SliceTask.java for details on these attributes).
*
* Attributes specific to slice2java:
*
* translator - The pathname of the translator (default: "slice2java").
* tie - The value for the --tie translator option.
* checksum - The value for the --checksum translator option.
* stream - The value for the --stream translator option.
*
* Example:
*
* <project ...>
* <taskdef name="slice2java" classname="Slice2JavaTask" />
* <property name="slice.dir" value="../include/slice"/>
* <target name="generate">
* <mkdir dir="tags" />
* <slice2java tagdir="tags" outputdir="out">
* <define name="SYMBOL" value="VALUE"/>
* <includepath>
* <pathelement path="${slice.dir}" />
* </includepath>
* <fileset dir="${slice.dir}">
* <include name="*.ice" />
* </fileset>
* </slice2java>
* </target>
* </project>
*
* The <taskdef> element installs the slice2java task.
*/
public class Slice2JavaTask extends SliceTask
{
public
Slice2JavaTask()
{
_translator = null;
_tie = false;
_checksum = null;
}
public void
setTranslator(File prog)
{
_translator = prog;
}
public void
setTie(boolean tie)
{
_tie = tie;
}
public void
setChecksum(String checksum)
{
_checksum = checksum;
}
public void
setStream(boolean stream)
{
_stream = stream;
}
public void
execute()
throws BuildException
{
if(_fileSets.isEmpty())
{
throw new BuildException("No fileset specified");
}
//
// Read the set of dependencies for this task.
//
java.util.HashMap<String, SliceDependency> dependencies = readDependencies();
//
// Compose a list of the files that need to be translated. A
// file needs to translated if we can't find a dependency in
// the dependency table or if its dependency is not up-to-date
// anymore (the slice file changed since the dependency was
// last updated or a slice file it depends on changed).
//
java.util.HashSet<File> buildList = new java.util.HashSet<File>();
java.util.HashSet<File> skipList = new java.util.HashSet<File>();
for(FileSet fileset : _fileSets)
{
DirectoryScanner scanner = fileset.getDirectoryScanner(getProject());
scanner.scan();
String[] files = scanner.getIncludedFiles();
for(String file : files)
{
File slice = new File(fileset.getDir(getProject()), file);
SliceDependency depend = dependencies.get(getTargetKey(slice.toString()));
if(depend == null || !depend.isUpToDate())
{
buildList.add(slice);
}
else
{
skipList.add(slice);
}
}
}
if(_checksum != null && _checksum.length() > 0 && !buildList.isEmpty())
{
//
// Recompile all Slice files when checksums are used.
//
buildList.addAll(skipList);
}
else
{
for(File file : skipList)
{
log("skipping " + file.getName());
}
}
//
// Run the translator
//
if(!buildList.isEmpty())
{
String translator;
if(_translator == null)
{
translator = getDefaultTranslator("slice2java");
}
else
{
translator = _translator.toString();
}
StringBuilder cmd = new StringBuilder(256);
//
// Add --output-dir
//
if(_outputDir != null)
{
cmd.append(" --output-dir ");
cmd.append(_outputDirString);
}
//
// Add include directives
//
if(_includePath != null)
{
String[] dirs = _includePath.list();
for(String dir : dirs)
{
cmd.append(" -I");
if(dir.indexOf(' ') != -1)
{
cmd.append('"');
cmd.append(dir);
cmd.append('"');
}
else
{
cmd.append(dir);
}
}
}
//
// Add defines
//
if(!_defines.isEmpty())
{
for(SliceDefine define : _defines)
{
cmd.append(" -D");
cmd.append(define.getName());
String value = define.getValue();
if(value != null)
{
cmd.append("=");
cmd.append(value);
}
}
}
//
// Add --tie
//
if(_tie)
{
cmd.append(" --tie");
}
//
// Add --checksum
//
if(_checksum != null && _checksum.length() > 0)
{
cmd.append(" --checksum ");
cmd.append(_checksum);
}
//
// Add --stream
//
if(_stream)
{
cmd.append(" --stream");
}
//
// Add --meta
//
if(!_meta.isEmpty())
{
for(SliceMeta m : _meta)
{
cmd.append(" --meta ");
cmd.append(m.getValue());
}
}
//
// Add --ice
//
if(_ice)
{
cmd.append(" --ice");
}
//
// Add --underscore
//
if(_underscore)
{
cmd.append(" --underscore");
}
//
// Add files to be translated
//
for(File f : buildList)
{
cmd.append(" ");
String s = f.toString();
if(s.indexOf(' ') != -1)
{
cmd.append('"');
cmd.append(s);
cmd.append('"');
}
else
{
cmd.append(s);
}
}
//
// Execute
//
log(translator + " " + cmd);
ExecTask task = (ExecTask)getProject().createTask("exec");
addLdLibraryPath(task);
task.setFailonerror(true);
Argument arg = task.createArg();
arg.setLine(cmd.toString());
task.setExecutable(translator);
task.execute();
//
// Update the dependencies.
//
cmd = new StringBuilder(256);
cmd.append("--depend-xml");
//
// Add --ice
//
if(_ice)
{
cmd.append(" --ice");
}
//
// Add --underscore
//
if(_underscore)
{
cmd.append(" --underscore");
}
//
// Add include directives
//
if(_includePath != null)
{
String[] dirs = _includePath.list();
for(String dir : dirs)
{
cmd.append(" -I");
if(dir.indexOf(' ') != -1)
{
cmd.append('"');
cmd.append(dir);
cmd.append('"');
}
else
{
cmd.append(dir);
}
}
}
//
// Add files for which we need to check dependencies.
//
for(File f : buildList)
{
cmd.append(" ");
String s = f.toString();
if(s.indexOf(' ') != -1)
{
cmd.append('"');
cmd.append(s);
cmd.append('"');
}
else
{
cmd.append(s);
}
}
//
// It's not possible anymore to re-use the same output property since Ant 1.5.x. so we use a
// unique property name here. Perhaps we should output the dependencies to a file instead.
//
final String outputProperty = "slice2java.depend." + System.currentTimeMillis();
final String errorProperty = "slice2java.error." + System.currentTimeMillis();
task = (ExecTask)getProject().createTask("exec");
addLdLibraryPath(task);
task.setFailonerror(true);
arg = task.createArg();
arg.setLine(cmd.toString());
task.setExecutable(translator);
task.setOutputproperty(outputProperty);
task.setErrorProperty(errorProperty);
task.execute();
//
// Update dependency file.
//
java.util.List<SliceDependency> newDependencies =
parseDependencies(getProject().getProperty(outputProperty));
for(SliceDependency dep : newDependencies)
{
dependencies.put(getTargetKey(dep._dependencies[0]), dep);
}
writeDependencies(dependencies);
}
}
private String
getTargetKey(String slice)
{
//
// Since the dependency file can be shared by several slice
// tasks we need to make sure that each dependency has a
// unique key. We use the name of the task, the output
// directory and the name of the slice file to be compiled.
//
// If there's two slice2java tasks using the same dependency
// file, with the same output dir and which compiles the same
// slice file they'll use the same dependency.
//
return "slice2java " + _outputDir.toString() + " " + slice;
}
private File _translator;
private boolean _tie;
private String _checksum;
private boolean _stream;
}
|