summaryrefslogtreecommitdiffstats
path: root/src/main/java/net/sf/antcontrib/cpptasks/apple/XcodeProjectWriter.java
blob: 49c1b532990dbacd75f1008a6395a17ca651bb96 (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
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
/*
 *
 * Copyright 2004-2005 The Ant-Contrib project
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package net.sf.antcontrib.cpptasks.apple;

import net.sf.antcontrib.cpptasks.CCTask;
import net.sf.antcontrib.cpptasks.TargetInfo;
import net.sf.antcontrib.cpptasks.CUtil;
import net.sf.antcontrib.cpptasks.compiler.CommandLineCompilerConfiguration;
import net.sf.antcontrib.cpptasks.compiler.ProcessorConfiguration;
import net.sf.antcontrib.cpptasks.gcc.GccCCompiler;
import net.sf.antcontrib.cpptasks.ide.ProjectDef;
import net.sf.antcontrib.cpptasks.ide.ProjectWriter;
import org.apache.tools.ant.BuildException;
import org.xml.sax.SAXException;

import javax.xml.transform.Result;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.stream.StreamResult;
import java.io.File;
import java.io.IOException;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;


/**
 * Writes a Apple Xcode 2.1+ project directory.  XCode stores project
 * configuration as a PropertyList.  Though it will always write the project
 * as a Cocoa Old-Style ASCII property list, it will read projects
 * stored using Cocoa's XML Property List format.
 */
public final class XcodeProjectWriter
        implements ProjectWriter {

    /**
     * Constructor.
     */
    public XcodeProjectWriter() {
    }

    /**
     * Writes a project definition file.
     *
     * @param fileName   File name base, writer may append appropriate extension
     * @param task       cc task for which to write project
     * @param projectDef project element
     * @param targets    compilation targets
     * @param linkTarget link target
     * @throws IOException if error writing project file
     */
    public void writeProject(final File fileName,
                             final CCTask task,
                             final ProjectDef projectDef,
                             final List sources,
                             final Hashtable targets,
                             final TargetInfo linkTarget) throws IOException {

        File xcodeDir = new File(fileName + ".xcodeproj");
        if (!projectDef.getOverwrite() && xcodeDir.exists()) {
            throw new BuildException("Not allowed to overwrite project file "
                    + xcodeDir.toString());
        }

        CommandLineCompilerConfiguration compilerConfig =
                getBaseCompilerConfiguration(targets);
        if (compilerConfig == null) {
            throw new BuildException(
                    "Unable to find compilation target using GNU C++ compiler");
        }

        String projectName = projectDef.getName();
        if (projectName == null) {
            projectName = fileName.getName();
        }
        final String basePath = fileName.getAbsoluteFile().getParent();

        xcodeDir.mkdir();

        File xcodeProj = new File(xcodeDir, "project.pbxproj");

        //
        //   create property list
        //
        Map propertyList = new HashMap();
        propertyList.put("archiveVersion", "1");
        propertyList.put("classes", new HashMap());
        propertyList.put("objectVersion", "42");
        Map objects = new HashMap();

        final String sourceTree = "<source>";

        //
        //   add source files and source group to property list
        //
        List sourceGroupChildren =
                addSources(objects, "SOURCE_ROOT", basePath, targets);
        PBXObjectRef sourceGroup =
                createPBXGroup("Source", sourceTree, sourceGroupChildren);
        objects.put(sourceGroup.getID(), sourceGroup.getProperties());

        //
        //    add product to property list
        //
        PBXObjectRef product = addProduct(objects, linkTarget);
        List productsList = new ArrayList();
        productsList.add(product);
        PBXObjectRef productsGroup =
                createPBXGroup("Products", sourceTree, productsList);
        objects.put(productsGroup.getID(), productsGroup.getProperties());

        //
        //    add documentation group to property list
        //
        PBXObjectRef documentationGroup = addDocumentationGroup(objects, sourceTree);

        //
        //    add main group containing source, products and documentation group
        //
        ArrayList groups = new ArrayList(3);
        groups.add(sourceGroup);
        groups.add(documentationGroup);
        groups.add(productsGroup);
        PBXObjectRef mainGroup = createPBXGroup(projectName, sourceTree, groups);
        objects.put(mainGroup.getID(), mainGroup.getProperties());

        //
        //   add project configurations
        //
        PBXObjectRef projectConfigurations = addProjectConfigurationList(objects);

        String projectDirPath = "";
        List projectTargets = new ArrayList();

        //
        //   add description of native target (that is the executable or
        //      shared library)
        //
        PBXObjectRef nativeTarget =
                addNativeTarget(objects, linkTarget, product, sourceGroupChildren);
        projectTargets.add(nativeTarget);


        //
        //    add project to property list
        //
        PBXObjectRef project = createPBXProject(projectConfigurations, mainGroup,
                projectDirPath, projectTargets);
        objects.put(project.getID(), project.getProperties());


        //
        //    finish up overall property list
        //
        propertyList.put("objects", objects);
        propertyList.put("rootObject", project.getID());


        //
        //    write property list out to XML file
        //
        Result result = new StreamResult(xcodeProj);

        try {
            PropertyListSerialization.serialize(propertyList, result);
        } catch (TransformerConfigurationException ex) {
            throw new IOException(ex.toString());
        } catch (SAXException ex) {
            if (ex.getException() instanceof IOException) {
                throw (IOException) ex.getException();
            }
            throw new IOException(ex.toString());
        }
    }


    /**
     * Add documentation group to map of objects.
     * @param objects object map.
     * @param sourceTree source tree description.
     * @return documentation group.
     */
    private PBXObjectRef addDocumentationGroup(final Map objects,
                                            final String sourceTree) {
        List productsList = new ArrayList();
        PBXObjectRef products =
                createPBXGroup("Documentation", sourceTree, productsList);
        objects.put(products.getID(), products.getProperties());
        return products;
    }

    /**
     * Add file reference of product to map of objects.
     * @param objects object map.
     * @param linkTarget build description for executable or shared library.
     * @return file reference to generated executable or shared library.
     */
    private PBXObjectRef addProduct(final Map objects,
                                 final TargetInfo linkTarget) {

        //
        //   create file reference for executable file
        //     forget Ant's location, just place in XCode's default location
        PBXObjectRef executable = createPBXFileReference("BUILD_PRODUCTS_DIR",
                linkTarget.getOutput().getParent(),
                linkTarget.getOutput());
        Map executableProperties = executable.getProperties();
        executableProperties.put("explicitFileType", "compiled.mach-o.executable");
        executableProperties.put("includeInIndex", "0");
        objects.put(executable.getID(), executableProperties);

        return executable;
    }


    /**
     * Add file references for all source files to map of objects.
     * @param objects map of objects.
     * @param sourceTree source tree.
     * @param basePath parent of XCode project dir
     * @param targets build targets.
     * @return list containing file references of source files.
     */
    private List addSources(final Map objects,
                            final String sourceTree,
                            final String basePath,
                            final Hashtable targets) {
        List sourceGroupChildren = new ArrayList();

        ArrayList sourceList = new ArrayList(targets.size());
        Iterator targetIter = targets.values().iterator();
        while (targetIter.hasNext()) {
            TargetInfo info = (TargetInfo) targetIter.next();
            File[] targetsources = info.getSources();
            for (int i = 0; i < targetsources.length; i++) {
                sourceList.add(targetsources[i]);
            }
        }
        Object[] sortedSources = sourceList.toArray();
        Arrays.sort(sortedSources, new Comparator() {
            public int compare(final Object o1, final Object o2) {
                return (((File) o1).getName().compareTo(
                        ((File) o2).getName()));
            }
        });
        for (int i = 0; i < sortedSources.length; i++) {
            PBXObjectRef fileRef = createPBXFileReference(sourceTree,
                    basePath, (File) sortedSources[i]);
            sourceGroupChildren.add(fileRef);
            objects.put(fileRef.getID(), fileRef.getProperties());
        }

        return sourceGroupChildren;
    }

    /**
     * Add native target configuration list.
     * @param objects map of objects.
     * @param projectName project name.
     * @return build configurations for native target.
     */
    private PBXObjectRef addNativeTargetConfigurationList(final Map objects,
                                                       final String projectName) {
        //
        //   Create a configuration list with
        //     two stock configurations: Debug and Release
        //
        List configurations = new ArrayList();
        Map debugSettings = new HashMap();
        debugSettings.put("COPY_PHASE_STRIP", "NO");
        debugSettings.put("GCC_DYNAMIC_NO_PIC", "NO");
        debugSettings.put("GCC_ENABLE_FIX_AND_CONTINUE", "YES");
        debugSettings.put("GCC_MODEL_TUNING", "G5");
        debugSettings.put("GCC_OPTIMIZATION_LEVEL", "0");
        debugSettings.put("INSTALL_PATH", "$(HOME)/bin");
        debugSettings.put("PRODUCT_NAME", projectName);
        debugSettings.put("ZERO_LINK", "YES");
        PBXObjectRef debugConfig = createXCBuildConfiguration("Debug",
                debugSettings);
        objects.put(debugConfig.getID(), debugConfig.getProperties());
        configurations.add(debugConfig);

        Map releaseSettings = new HashMap();
        List archs = new ArrayList();
        archs.add("ppc");
        archs.add("i386");
        releaseSettings.put("ARCHS", archs);
        releaseSettings.put("GCC_GENERATE_DEBUGGING_SYMBOLS", "NO");
        releaseSettings.put("GCC_MODEL_TUNING", "G5");
        releaseSettings.put("INSTALL_PATH", "$(HOME)/bin");
        releaseSettings.put("PRODUCT_NAME", projectName);
        PBXObjectRef releaseConfig = createXCBuildConfiguration("Release",
                releaseSettings);
        objects.put(releaseConfig.getID(), releaseConfig.getProperties());
        configurations.add(releaseConfig);

        PBXObjectRef configurationList = createXCConfigurationList(configurations);
        objects.put(configurationList.getID(), configurationList.getProperties());
        return configurationList;
    }

    /**
     * Add project configuration list.
     * @param objects map of objects.
     * @return project configuration object.
     */
    private PBXObjectRef addProjectConfigurationList(final Map objects) {
        //
        //   Create a configuration list with
        //     two stock configurations: Debug and Release
        //
        List configurations = new ArrayList();
        Map debugSettings = new HashMap();
        debugSettings.put("GCC_WARN_ABOUT_RETURN_TYPE", "YES");
        debugSettings.put("GCC_WARN_UNUSED_VARIABLE", "YES");
        debugSettings.put("PREBINDING", "NO");
        debugSettings.put("SDKROOT", "/Developer/SDKs/MacOSX10.4u.sdk");
        PBXObjectRef debugConfig = createXCBuildConfiguration("Debug", debugSettings);
        objects.put(debugConfig.getID(), debugConfig.getProperties());
        configurations.add(debugConfig);

        Map releaseSettings = new HashMap();
        releaseSettings.put("GCC_WARN_ABOUT_RETURN_TYPE", "YES");
        releaseSettings.put("GCC_WARN_UNUSED_VARIABLE", "YES");
        releaseSettings.put("PREBINDING", "NO");
        releaseSettings.put("SDKROOT", "/Developer/SDKs/MacOSX10.4u.sdk");
        PBXObjectRef releaseConfig =
                createXCBuildConfiguration("Release", releaseSettings);
        objects.put(releaseConfig.getID(), releaseConfig.getProperties());
        configurations.add(releaseConfig);
        PBXObjectRef configurationList = createXCConfigurationList(configurations);
        Map projectConfigurationListProperties = configurationList.getProperties();
        projectConfigurationListProperties.put("defaultConfigurationIsVisible", "0");
        projectConfigurationListProperties.put("defaultConfigurationName", "Release");
        objects.put(configurationList.getID(), configurationList.getProperties());
        return configurationList;
    }

    /**
     * Add native target to map of objects.
     * @param objects map of objects.
     * @param linkTarget description of executable or shared library.
     * @param product product.
     * @param sourceGroupChildren source files needed to build product.
     * @return native target.
     */
    private PBXObjectRef addNativeTarget(final Map objects,
                                      final TargetInfo linkTarget,
                                      final PBXObjectRef product,
                                      final List sourceGroupChildren) {

        PBXObjectRef buildConfigurations = this.addNativeTargetConfigurationList(objects,
                linkTarget.getOutput().getName());

        int buildActionMask = 2147483647;
        List buildPhases = new ArrayList();

        Map settings = new HashMap();
        settings.put("ATTRIBUTES", new ArrayList());
        List buildFiles = new ArrayList();
        for (Iterator iter = sourceGroupChildren.iterator();
             iter.hasNext();) {
            PBXObjectRef sourceFile = (PBXObjectRef) iter.next();
            PBXObjectRef buildFile = createPBXBuildFile(sourceFile, settings);
            buildFiles.add(buildFile);
            objects.put(buildFile.getID(), buildFile.getProperties());
        }


        PBXObjectRef sourcesBuildPhase = createPBXSourcesBuildPhase(buildActionMask,
                buildFiles, false);
        objects.put(sourcesBuildPhase.getID(), sourcesBuildPhase.getProperties());
        buildPhases.add(sourcesBuildPhase);


        PBXObjectRef frameworksBuildPhase =
                createPBXFrameworksBuildPhase(buildActionMask,
                new ArrayList(), false);
        objects.put(frameworksBuildPhase.getID(), frameworksBuildPhase.getProperties());
        buildPhases.add(frameworksBuildPhase);

        PBXObjectRef copyFilesBuildPhase = createPBXCopyFilesBuildPhase(8,
                "/usr/share/man/man1", "0", new ArrayList(), true);
        objects.put(copyFilesBuildPhase.getID(), copyFilesBuildPhase.getProperties());
        buildPhases.add(copyFilesBuildPhase);

        List buildRules = new ArrayList();

        List dependencies = new ArrayList();

        String productInstallPath = "$(HOME)/bin";

        String productType = "com.apple.product-type.tool";

        PBXObjectRef nativeTarget = createPBXNativeTarget("hello",
                buildConfigurations, buildPhases, buildRules, dependencies,
                productInstallPath, "hello", product, productType);
        objects.put(nativeTarget.getID(), nativeTarget.getProperties());

        return nativeTarget;
    }


    /**
     * Create PBXFileReference.
     * @param sourceTree source tree.
     * @param baseDir base directory.
     * @param file file.
     * @return PBXFileReference object.
     */
    private static PBXObjectRef createPBXFileReference(final String sourceTree,
                                             final String baseDir,
                                             final File file) {
        Map map = new HashMap();
        map.put("isa", "PBXFileReference");

        String relPath = CUtil.getRelativePath(baseDir, file);
        String name = file.getName();

        if (!name.equals(relPath)) {
            map.put("name", name);
        }
        map.put("path", relPath);
        map.put("sourceTree", sourceTree);
        return new PBXObjectRef(map);
    }

    /**
     * Create PBXGroup.
     * @param name group name.
     * @param sourceTree source tree.
     * @param children list of PBXFileReferences.
     * @return group.
     */
    private static PBXObjectRef createPBXGroup(final String name,
                                     final String sourceTree,
                                     final List children) {
        Map map = new HashMap();
        map.put("isa", "PBXGroup");
        map.put("name", name);
        map.put("sourceTree", sourceTree);
        map.put("children", children);
        return new PBXObjectRef(map);
    }

    /**
     * Create PBXProject.
     * @param buildConfigurationList build configuration list.
     * @param mainGroup main group.
     * @param projectDirPath project directory path.
     * @param targets targets.
     * @return project.
     */
    private static PBXObjectRef createPBXProject(final PBXObjectRef buildConfigurationList,
                                       final PBXObjectRef mainGroup,
                                       final String projectDirPath,
                                       final List targets) {
        Map map = new HashMap();
        map.put("isa", "PBXProject");
        map.put("buildConfigurationList", buildConfigurationList.getID());
        map.put("hasScannedForEncodings", "0");
        map.put("mainGroup", mainGroup.getID());
        map.put("projectDirPath", projectDirPath);
        map.put("targets", targets);
        return new PBXObjectRef(map);
    }

    /**
     * Create XCConfigurationList.
     * @param buildConfigurations build configurations.
     * @return configuration list.
     */
    private static PBXObjectRef createXCConfigurationList(final List buildConfigurations) {
        Map map = new HashMap();
        map.put("isa", "XCConfigurationList");
        map.put("buildConfigurations", buildConfigurations);
        return new PBXObjectRef(map);
    }


    /**
     * Create XCBuildConfiguration.
     * @param name name.
     * @param buildSettings build settings.
     * @return build configuration.
     */
    private static PBXObjectRef createXCBuildConfiguration(final String name,
                                                 final Map buildSettings) {
        Map map = new HashMap();
        map.put("isa", "XCBuildConfiguration");
        map.put("buildSettings", buildSettings);
        map.put("name", name);
        return new PBXObjectRef(map);
    }

    /**
     * Create PBXNativeTarget.
     * @param name name.
     * @param buildConfigurationList build configuration list.
     * @param buildPhases build phases.
     * @param buildRules build rules.
     * @param dependencies dependencies.
     * @param productInstallPath product install path.
     * @param productName product name.
     * @param productReference file reference for product.
     * @param productType product type.
     * @return native target.
     */
    private static PBXObjectRef createPBXNativeTarget(final String name,
                                            final PBXObjectRef buildConfigurationList,
                                            final List buildPhases,
                                            final List buildRules,
                                            final List dependencies,
                                            final String productInstallPath,
                                            final String productName,
                                            final PBXObjectRef productReference,
                                            final String productType) {
        Map map = new HashMap();
        map.put("isa", "PBXNativeTarget");
        map.put("buildConfigurationList", buildConfigurationList);
        map.put("buildPhases", buildPhases);
        map.put("buildRules", buildRules);
        map.put("dependencies", dependencies);
        map.put("name", name);
        map.put("productInstallPath", productInstallPath);
        map.put("productName", productName);
        map.put("productReference", productReference);
        map.put("productType", productType);
        return new PBXObjectRef(map);
    }

    /**
     * Create PBXSourcesBuildPhase.
     * @param buildActionMask build action mask.
     * @param files source files.
     * @param runOnly if true, phase should only be run on deployment.
     * @return PBXSourcesBuildPhase.
     */
    private static PBXObjectRef createPBXSourcesBuildPhase(int buildActionMask,
                                                 List files,
                                                 boolean runOnly) {
        Map map = new HashMap();
        map.put("buildActionMask",
                String.valueOf(buildActionMask));
        map.put("files", files);
        map.put("isa", "PBXSourcesBuildPhase");
        map.put("runOnlyForDeploymentPostprocessing", toString(runOnly));
        return new PBXObjectRef(map);
    }

    /**
     * Create PBXBuildFile.
     * @param fileRef source file.
     * @param settings build settings.
     * @return PBXBuildFile.
     */
    private static PBXObjectRef createPBXBuildFile(PBXObjectRef fileRef,
                                         Map settings) {
        Map map = new HashMap();
        map.put("fileRef", fileRef);
        map.put("isa", "PBXBuildFile");
        if (settings != null) {
            map.put("settings", settings);
        }
        return new PBXObjectRef(map);
    }

    /**
     * Create PBXFrameworksBuildPhase.
     * @param buildActionMask build action mask.
     * @param files files.
     * @param runOnly if true, phase should only be run on deployment.
     * @return PBXFrameworkBuildPhase.
     */
    private static PBXObjectRef createPBXFrameworksBuildPhase(
            final int buildActionMask,
            final List files,
            final boolean runOnly) {
        Map map = new HashMap();
        map.put("isa", "PBXFrameworksBuildPhase");
        map.put("buildActionMask", NumberFormat.getIntegerInstance(Locale.US).format(buildActionMask));
        map.put("files", files);
        map.put("runOnlyForDeploymentPostprocessing", toString(runOnly));
        return new PBXObjectRef(map);
    }

    /**
     * Create a build phase that copies files to a destination.
     * @param buildActionMask build action mask.
     * @param dstPath destination path.
     * @param dstSubfolderSpec subfolder spec.
     * @param files files.
     * @param runOnly if true, phase should only be run on deployment.
     * @return PBXCopyFileBuildPhase.
     */
    private static PBXObjectRef createPBXCopyFilesBuildPhase(
            final int buildActionMask,
            final String dstPath,
            final String dstSubfolderSpec,
            final List files,
            final boolean runOnly) {
        Map map = new HashMap();
        map.put("isa", "PBXCopyFilesBuildPhase");
        map.put("buildActionMask", NumberFormat.getIntegerInstance(Locale.US).format(buildActionMask));
        map.put("dstPath", dstPath);
        map.put("dstSubfolderSpec", dstSubfolderSpec);
        map.put("files", files);
        map.put("runOnlyForDeploymentPostprocessing", toString(runOnly));
        return new PBXObjectRef(map);
    }

    /**
     * Method returns "1" for true, "0" for false.
     * @param b boolean value.
     * @return "1" for true, "0" for false.
     */
    private static String toString(boolean b) {
        if (b) {
            return "1";
        } else {
            return "0";
        }
    }

    /**
     * Represents a property map with an 96 bit identity.
     * When placed in a property list, this object will
     * output the string representation of the identity
     * which XCode uses to find the corresponding property
     * bag in the "objects" property of the top-level property list.
     */
    private static final class PBXObjectRef {
        /**
         * Identifier.
         */
        private final String id;
        /**
         * Properties.
         */
        private final Map properties;
        /**
         * Next available identifier.
         */
        private static int nextID = 0;

        /**
         * Create reference.
         * @param props properties.
         */
        public PBXObjectRef(final Map props) {
            if (props == null) {
                throw new NullPointerException("props");
            }
            StringBuffer buf = new StringBuffer("000000000000000000000000");
            String idStr = Integer.toHexString(nextID++);
            buf.replace(buf.length() - idStr.length(), buf.length(), idStr);
            id = buf.toString();
            properties = props;
        }

        /**
         * Get object identifier.
         * @return identifier.
         */
        public String toString() {
            return id;
        }

        /**
         * Get object identifier.
         * @return object identifier.
         */
        public String getID() {
            return id;
        }

        /**
         * Get properties.
         * @return properties.
         */
        public Map getProperties() {
            return properties;
        }
    }

    /**
     * Gets the first recognized compiler from the
     * compilation targets.
     *
     * @param targets compilation targets
     * @return representative (hopefully) compiler configuration
     */
    private CommandLineCompilerConfiguration
    getBaseCompilerConfiguration(Hashtable targets) {
        //
        //   find first target with an GNU C++ compilation
        //
        CommandLineCompilerConfiguration compilerConfig;
        //
        //   get the first target and assume that it is representative
        //
        Iterator targetIter = targets.values().iterator();
        while (targetIter.hasNext()) {
            TargetInfo targetInfo = (TargetInfo) targetIter.next();
            ProcessorConfiguration config = targetInfo.getConfiguration();
            //
            //   for the first cl compiler
            //
            if (config instanceof CommandLineCompilerConfiguration) {
                compilerConfig = (CommandLineCompilerConfiguration) config;
                if (compilerConfig.getCompiler() instanceof GccCCompiler) {
                    return compilerConfig;
                }
            }
        }
        return null;
    }

}