1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.github.maven_nar.cpptasks.trolltech;
21
22 import java.io.File;
23 import java.util.Vector;
24
25 import org.apache.tools.ant.BuildException;
26 import org.apache.tools.ant.types.Environment;
27
28 import com.github.maven_nar.cpptasks.CCTask;
29 import com.github.maven_nar.cpptasks.OptimizationEnum;
30 import com.github.maven_nar.cpptasks.VersionInfo;
31 import com.github.maven_nar.cpptasks.compiler.CommandLineCompiler;
32 import com.github.maven_nar.cpptasks.compiler.CommandLineCompilerConfiguration;
33 import com.github.maven_nar.cpptasks.compiler.LinkType;
34 import com.github.maven_nar.cpptasks.compiler.Linker;
35 import com.github.maven_nar.cpptasks.compiler.Processor;
36 import com.github.maven_nar.cpptasks.compiler.ProgressMonitor;
37 import com.github.maven_nar.cpptasks.gcc.LdLinker;
38 import com.github.maven_nar.cpptasks.parser.Parser;
39
40
41
42
43
44
45 public final class UserInterfaceCompiler extends CommandLineCompiler {
46
47
48
49 private static final UserInterfaceCompiler INSTANCE = new UserInterfaceCompiler(false, null);
50
51
52
53
54
55
56 public static UserInterfaceCompiler getInstance() {
57 return INSTANCE;
58 }
59
60
61
62
63
64
65
66
67
68 private UserInterfaceCompiler(final boolean newEnvironment, final Environment env) {
69 super("uic", "-version", new String[] {
70 ".ui"
71 }, new String[0], ".h", false, null, newEnvironment, env);
72 }
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92 @Override
93 protected void addImpliedArgs(final Vector<String> args, final boolean debug, final boolean multithreaded,
94 final boolean exceptions, final LinkType linkType, final Boolean rtti, final OptimizationEnum optimization) {
95 }
96
97
98
99
100
101
102
103
104
105 @Override
106 protected void addWarningSwitch(final Vector<String> args, final int level) {
107 }
108
109
110
111
112
113
114
115
116
117
118 @Override
119 public Processor changeEnvironment(final boolean newEnvironment, final Environment env) {
120 return this;
121 }
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143 @Override
144 public void compile(final CCTask task, final File outputDir, final String[] sourceFiles, final String[] args,
145 final String[] endArgs, final boolean relentless, final CommandLineCompilerConfiguration config,
146 final ProgressMonitor monitor) {
147
148 BuildException exc = null;
149 final String[] thisSource = new String[1];
150 final String[] uicCommand = new String[args.length + endArgs.length + 4];
151 uicCommand[0] = "uic";
152 final String[] uicImplCommand = new String[args.length + endArgs.length + 6];
153 uicImplCommand[0] = "uic";
154 final String[] mocCommand = new String[args.length + endArgs.length + 4];
155 mocCommand[0] = "moc";
156 for (int i = 0; i < args.length; i++) {
157 uicCommand[i + 1] = args[i];
158 uicImplCommand[i + 1] = args[i];
159 mocCommand[i + i] = args[i];
160 }
161 uicCommand[args.length + 1] = "-o";
162 uicImplCommand[args.length + 1] = "-o";
163 mocCommand[args.length + 1] = "-o";
164
165 int uicIndex = args.length + 4;
166 int uicImplIndex = args.length + 6;
167 int mocIndex = args.length + 4;
168 for (final String endArg : endArgs) {
169 uicCommand[uicIndex++] = endArg;
170 uicImplCommand[uicImplIndex++] = endArg;
171 mocCommand[mocIndex++] = endArg;
172 }
173 for (final String sourceFile : sourceFiles) {
174 uicIndex = args.length + 2;
175 uicImplIndex = args.length + 2;
176 mocIndex = args.length + 2;
177 final String[] outputFileNames = getOutputFileNames(sourceFile, null);
178
179 uicCommand[uicIndex++] = outputFileNames[0];
180 uicCommand[uicIndex++] = sourceFile;
181
182 uicImplCommand[uicImplIndex++] = outputFileNames[1];
183 uicImplCommand[uicImplIndex++] = "-impl";
184 uicImplCommand[uicImplIndex++] = outputFileNames[0];
185 uicImplCommand[uicImplIndex++] = sourceFile;
186
187 mocCommand[mocIndex++] = outputFileNames[2];
188 mocCommand[mocIndex++] = outputFileNames[0];
189
190 int retval = runCommand(task, outputDir, uicCommand);
191 if (retval == 0) {
192 retval = runCommand(task, outputDir, uicImplCommand);
193 if (retval == 0) {
194 retval = runCommand(task, outputDir, mocCommand);
195 }
196 }
197 if (monitor != null) {
198 thisSource[0] = sourceFile;
199 monitor.progress(thisSource);
200 }
201
202
203
204
205 if (retval != 0 && exc == null) {
206
207
208
209 exc = new BuildException(this.getCommand() + " failed with return code " + retval, task.getLocation());
210
211
212
213 if (!relentless) {
214 throw exc;
215 }
216 }
217 }
218
219
220
221 if (exc != null) {
222 throw exc;
223 }
224 }
225
226
227
228
229
230
231
232
233
234 @Override
235 protected Parser createParser(final File source) {
236 return new UserInterfaceParser();
237 }
238
239
240
241
242
243
244 @Override
245 protected int getArgumentCountPerInputFile() {
246 return 3;
247 }
248
249
250
251
252
253
254
255
256
257
258
259 @Override
260 protected void getDefineSwitch(final StringBuffer buffer, final String define, final String value) {
261 }
262
263
264
265
266
267
268 @Override
269 protected File[] getEnvironmentIncludePath() {
270 return new File[0];
271 }
272
273
274
275
276
277
278
279
280 @Override
281 protected String getIncludeDirSwitch(final String includeDir) {
282 return "";
283 }
284
285
286
287
288
289
290
291
292
293
294
295
296
297 @Override
298 protected String getInputFileArgument(final File outputDir, final String filename, final int index) {
299 switch (index) {
300 case 0:
301 return "-o";
302
303 case 1:
304 final String outputFileName = getOutputFileNames(filename, null)[0];
305 return new File(outputDir, outputFileName).toString();
306
307 case 2:
308 return filename;
309
310 default:
311 return null;
312 }
313 }
314
315
316
317
318
319
320
321
322 @Override
323 public Linker getLinker(final LinkType type) {
324 return LdLinker.getInstance();
325 }
326
327
328
329
330
331
332 @Override
333 public int getMaximumCommandLength() {
334 return 1024;
335 }
336
337
338
339
340
341
342 @Override
343 protected int getMaximumInputFilesPerCommand() {
344 return 1;
345 }
346
347
348
349
350
351
352
353
354
355
356 @Override
357 public String[] getOutputFileNames(final String inputFile, final VersionInfo versionInfo) {
358
359
360
361 final String baseName = getBaseOutputName(inputFile);
362 return new String[] {
363 baseName + ".h", baseName + ".cpp", "moc_" + baseName + ".cpp"
364 };
365 }
366
367
368
369
370
371
372
373
374
375 @Override
376 protected void getUndefineSwitch(final StringBuffer buffer, final String define) {
377 }
378 }