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.BufferedReader;
23 import java.io.File;
24 import java.io.FileReader;
25 import java.io.IOException;
26 import java.io.Reader;
27 import java.util.Vector;
28
29 import org.apache.tools.ant.types.Environment;
30
31 import com.github.maven_nar.cpptasks.OptimizationEnum;
32 import com.github.maven_nar.cpptasks.VersionInfo;
33 import com.github.maven_nar.cpptasks.compiler.CommandLineCompiler;
34 import com.github.maven_nar.cpptasks.compiler.LinkType;
35 import com.github.maven_nar.cpptasks.compiler.Linker;
36 import com.github.maven_nar.cpptasks.compiler.Processor;
37 import com.github.maven_nar.cpptasks.gcc.LdLinker;
38 import com.github.maven_nar.cpptasks.parser.CParser;
39 import com.github.maven_nar.cpptasks.parser.Parser;
40
41
42
43
44
45
46 public final class MetaObjectCompiler extends CommandLineCompiler {
47
48
49
50 private static final MetaObjectCompiler INSTANCE = new MetaObjectCompiler(false, null);
51
52
53
54
55
56
57 public static MetaObjectCompiler getInstance() {
58 return INSTANCE;
59 }
60
61
62
63
64
65
66
67
68
69 private MetaObjectCompiler(final boolean newEnvironment, final Environment env) {
70 super("moc", "-version", new String[] {
71 ".h", ".cpp"
72 }, new String[0], ".moc", false, null, newEnvironment, env);
73 }
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93 @Override
94 protected void addImpliedArgs(final Vector<String> args, final boolean debug, final boolean multithreaded,
95 final boolean exceptions, final LinkType linkType, final Boolean rtti, final OptimizationEnum optimization) {
96 }
97
98
99
100
101
102
103
104
105
106 @Override
107 protected void addWarningSwitch(final Vector<String> args, final int level) {
108 }
109
110
111
112
113
114
115
116
117
118
119 @Override
120 public int bid(final String inputFile) {
121
122
123 final int baseBid = super.bid(inputFile);
124
125
126
127 if (baseBid > 0) {
128
129
130
131
132 try {
133 final Reader reader = new BufferedReader(new FileReader(inputFile));
134 final boolean hasQObject = MetaObjectParser.hasQObject(reader);
135 reader.close();
136 if (hasQObject) {
137 return baseBid;
138 }
139 } catch (final IOException ex) {
140 return 0;
141 }
142 }
143 return 0;
144 }
145
146
147
148
149
150
151
152
153
154
155 @Override
156 public Processor changeEnvironment(final boolean newEnvironment, final Environment env) {
157 return this;
158 }
159
160
161
162
163
164
165
166
167 @Override
168 protected Parser createParser(final File source) {
169 return new CParser();
170 }
171
172
173
174
175
176
177 @Override
178 protected int getArgumentCountPerInputFile() {
179 return 3;
180 }
181
182
183
184
185
186
187
188
189
190
191
192 @Override
193 protected void getDefineSwitch(final StringBuffer buffer, final String define, final String value) {
194 }
195
196
197
198
199
200
201 @Override
202 protected File[] getEnvironmentIncludePath() {
203 return new File[0];
204 }
205
206
207
208
209
210
211
212
213 @Override
214 protected String getIncludeDirSwitch(final String includeDir) {
215 return "";
216 }
217
218
219
220
221
222
223
224
225
226
227
228
229
230 @Override
231 protected String getInputFileArgument(final File outputDir, final String filename, final int index) {
232 switch (index) {
233 case 0:
234 return "-o";
235 case 1:
236 final String outputFileName = getOutputFileNames(filename, null)[0];
237 return new File(outputDir, outputFileName).toString();
238
239 case 2:
240 return filename;
241
242 default:
243 return null;
244 }
245 }
246
247
248
249
250
251
252
253
254 @Override
255 public Linker getLinker(final LinkType type) {
256 return LdLinker.getInstance();
257 }
258
259
260
261
262
263
264 @Override
265 public int getMaximumCommandLength() {
266 return 1024;
267 }
268
269
270
271
272
273
274 @Override
275 protected int getMaximumInputFilesPerCommand() {
276 return 1;
277 }
278
279
280
281
282
283
284
285
286
287
288 @Override
289 public String[] getOutputFileNames(final String inputFile, final VersionInfo versionInfo) {
290 if (inputFile.endsWith(".cpp")) {
291 return super.getOutputFileNames(inputFile, versionInfo);
292 }
293
294
295
296 final String baseName = getBaseOutputName(inputFile);
297 return new String[] {
298 "moc_" + baseName + ".cpp"
299 };
300 }
301
302
303
304
305
306
307
308
309
310 @Override
311 protected void getUndefineSwitch(final StringBuffer buffer, final String define) {
312 }
313 }