summaryrefslogtreecommitdiff
path: root/core/source/org/openoffice/ide/eclipse/core/internal/model/UnoidlProject.java
blob: 4e45a3cc10cb09dd7197fe75cf9faa201b3daf36 (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
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
/*************************************************************************
 *
 * $RCSfile: UnoidlProject.java,v $
 *
 * $Revision: 1.13 $
 *
 * last change: $Author: cedricbosdo $ $Date: 2008/12/13 13:42:48 $
 *
 * The Contents of this file are made available subject to the terms of
 * the GNU Lesser General Public License Version 2.1
 *
 * Sun Microsystems Inc., October, 2000
 *
 *
 * GNU Lesser General Public License Version 2.1
 * =============================================
 * Copyright 2000 by Sun Microsystems, Inc.
 * 901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License version 2.1, as published by the Free Software Foundation.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 * MA 02111-1307 USA
 * 
 * The Initial Developer of the Original Code is: Sun Microsystems, Inc..
 *
 * Copyright: 2002 by Sun Microsystems, Inc.
 *
 * All Rights Reserved.
 *
 * Contributor(s): Cedric Bosdonnat
 *
 *
 ************************************************************************/
package org.openoffice.ide.eclipse.core.internal.model;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.Properties;

import org.eclipse.core.resources.ICommand;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IProjectNature;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.openoffice.ide.eclipse.core.PluginLogger;
import org.openoffice.ide.eclipse.core.builders.TypesBuilder;
import org.openoffice.ide.eclipse.core.internal.helpers.UnoidlProjectHelper;
import org.openoffice.ide.eclipse.core.model.IUnoidlProject;
import org.openoffice.ide.eclipse.core.model.OOoContainer;
import org.openoffice.ide.eclipse.core.model.SDKContainer;
import org.openoffice.ide.eclipse.core.model.config.IConfigListener;
import org.openoffice.ide.eclipse.core.model.config.IOOo;
import org.openoffice.ide.eclipse.core.model.config.ISdk;
import org.openoffice.ide.eclipse.core.model.language.AbstractLanguage;
import org.openoffice.ide.eclipse.core.model.language.IProjectHandler;
import org.openoffice.ide.eclipse.core.model.language.LanguagesHelper;

/**
 * This class implements the UNO-IDL and project nature interface.
 * 
 * @author cedricbosdo
 * 
 */
public class UnoidlProject implements IUnoidlProject, IProjectNature {

    /**
     * Project property that stores the company prefix.
     */
    public static final String COMPANY_PREFIX = "project.prefix"; //$NON-NLS-1$

    /**
     * Project property that stores the output path extension.
     * 
     * <p>
     * If the company prefix is <code>org.openoffice.sample</code> and this property value is <code>impl</code>, the
     * root package of the implementations classes is <code>org.openoffice.sample.impl</code>.
     * </p>
     */
    public static final String OUTPUT_EXT = "project.implementation"; //$NON-NLS-1$

    /**
     * Project property that stores the sdk name to use for the project build.
     */
    public static final String SDK_NAME = "project.sdk"; //$NON-NLS-1$

    /**
     * Project property that stores the name of the OpenOffice.org instance used to run / deploy the project.
     */
    public static final String OOO_NAME = "project.ooo"; //$NON-NLS-1$

    /**
     * Project property that stores the language name.
     */
    public static final String LANGUAGE = "project.language"; //$NON-NLS-1$

    /**
     * Project property that stores the path to the folder containing the sources.
     */
    public static final String SRC_DIRECTORY = "project.srcdir"; //$NON-NLS-1$

    /**
     * Property name for the idl folder.
     */
    public static final String IDL_DIR = "project.idl"; //$NON-NLS-1$

    /**
     * Property name for the build directory.
     */
    public static final String BUILD_DIR = "project.build"; //$NON-NLS-1$

    /**
     * The name of the file containing the UNO project configuration.
     */
    private static final String CONFIG_FILE = ".unoproject"; //$NON-NLS-1$

    private IProject mProject;

    private String mCompanyPrefix;

    private String mOutputExtension;

    private ISdk mSdk;

    private IOOo mOOo;

    private AbstractLanguage mLanguage;

    private String mIdlDir;

    private String mSourcesDir;

    private IConfigListener mConfigListener;

    /**
     * Listener for the configuration to handle the changes on SDK and OOo instances.
     * 
     * @author cedricbosdo
     */
    private class configListener implements IConfigListener {

        /**
         * {@inheritDoc}
         */
        public void ConfigAdded(Object pElement) {
            // the selected SDK or OOo cannot be added again...
        }

        /**
         * {@inheritDoc}
         */
        public void ConfigRemoved(Object pElement) {
            if (pElement instanceof ISdk) {
                if (pElement == getSdk()) {

                    // Sets the selected SDK to null, it will tag the project as invalid
                    setSdk(null);
                }
            } else if (pElement instanceof IOOo) {
                if (pElement == getOOo()) {

                    // Removes OOo dependencies
                    getLanguage().getProjectHandler().removeOOoDependencies(getOOo(), getProject());

                    // Sets the selected OOo to null, it will tag the project as invalid
                    setOOo(null);
                }
            }
        }

        /**
         * {@inheritDoc}
         */
        public void ConfigUpdated(Object pElement) {
            if (pElement instanceof IOOo) {
                if (pElement == getOOo()) {
                    // the ooo is updated thanks to it's reference. Remove the old jar files
                    // from the classpath and the new ones

                    // Removes OOo dependencies
                    getLanguage().getProjectHandler().removeOOoDependencies(getOOo(), getProject());
                    getLanguage().getProjectHandler().addOOoDependencies(getOOo(), getProject());
                }
            }
        }
    }

    // ------------------------------------------------------------ Constructors

    /**
     * Default constructor initializing the configuration listener.
     */
    public UnoidlProject() {

        mConfigListener = new configListener();

        SDKContainer.addListener(mConfigListener);
        OOoContainer.addListener(mConfigListener);
    }

    /**
     * Removes the listeners needed by the UNO project.
     */
    public void dispose() {
        SDKContainer.removeListener(mConfigListener);
        OOoContainer.removeListener(mConfigListener);
    }

    /**
     * Return the path of the file in the idl folder. If the given file doesn't belong to the idl folder,
     * <code>null</code> is returned.
     * 
     * @param pResource
     *            resource of which the idl path is asked
     * @return idl relative path or <code>null</code>
     */
    public IPath getIdlRelativePath(IResource pResource) {
        IPath result = null;

        IPath projectRelative = pResource.getProjectRelativePath();

        if (projectRelative.toString().startsWith(getIdlPath().toString())) {
            result = projectRelative.removeFirstSegments(getIdlPath().segmentCount());
        }
        return result;
    }

    // *************************************************************************
    // IUnoidlModel Implementation
    // *************************************************************************

    /**
     * {@inheritDoc}
     */
    public AbstractLanguage getLanguage() {
        return mLanguage;
    }

    /**
     * {@inheritDoc}
     */
    public String getName() {
        return getProject().getName();
    }

    /**
     * {@inheritDoc}
     */
    public IOOo getOOo() {
        return mOOo;
    }

    /**
     * {@inheritDoc}
     */
    public ISdk getSdk() {
        return mSdk;
    }

    /**
     * {@inheritDoc}
     */
    public void setLanguage(AbstractLanguage pNewLanguage) {

        if (mLanguage == null && pNewLanguage != null) {
            mLanguage = pNewLanguage;
            mLanguage.getProjectHandler().addProjectNature(getProject());
            PluginLogger.debug("Language specific nature added"); //$NON-NLS-1$
        }
    }

    /**
     * {@inheritDoc}
     */
    public void setOOo(IOOo pOoo) {

        setErrorMarker(null == pOoo || null == getSdk());

        try {
            IProjectHandler langHandler = getLanguage().getProjectHandler();

            // Remove the old OOo libraries
            langHandler.removeOOoDependencies(mOOo, getProject());

            // Add the new ones
            langHandler.addOOoDependencies(pOoo, getProject());
        } catch (Exception e) {
            // This might happen at some stage of the project creation
        }

        this.mOOo = pOoo;
    }

    /**
     * {@inheritDoc}
     */
    public void setSdk(ISdk pSdk) {

        setErrorMarker(pSdk == null || null == getOOo());

        this.mSdk = pSdk;
    }

    /**
     * {@inheritDoc}
     */
    public void setIdlDir(String pIdlDir) {
        mIdlDir = pIdlDir;
    }

    /**
     * {@inheritDoc}
     */
    public void setSourcesDir(String pSourcesDir) {
        if (pSourcesDir == null || pSourcesDir.equals("")) { //$NON-NLS-1$
            pSourcesDir = UnoidlProjectHelper.SOURCE_BASIS;
        }

        // Add a / at the beginning of the path
        if (!pSourcesDir.startsWith("/")) { //$NON-NLS-1$
            pSourcesDir = "/" + pSourcesDir; //$NON-NLS-1$
        }

        mSourcesDir = pSourcesDir;
    }

    /**
     * {@inheritDoc}
     */
    public String getRootModule() {
        String result = ""; //$NON-NLS-1$

        if (null != mCompanyPrefix) {
            result = mCompanyPrefix.replaceAll("\\.", "::"); //$NON-NLS-1$ //$NON-NLS-2$
        }
        return result;
    }

    /**
     * {@inheritDoc}
     */
    public IPath getRootModulePath() {
        IPath result = null;

        if (null != mCompanyPrefix) {
            result = getIdlPath().append(mCompanyPrefix.replaceAll("\\.", "/")); //$NON-NLS-1$ //$NON-NLS-2$
        }
        return result;
    }

    /**
     * {@inheritDoc}
     */
    public void setCompanyPrefix(String pPrefix) {
        mCompanyPrefix = pPrefix;
    }

    /**
     * {@inheritDoc}
     */
    public String getCompanyPrefix() {
        return mCompanyPrefix;
    }

    /**
     * {@inheritDoc}
     */
    public void setOutputExtension(String pOutputExt) {
        mOutputExtension = pOutputExt;
    }

    /**
     * {@inheritDoc}
     */
    public String getOutputExtension() {
        return mOutputExtension;
    }

    /**
     * {@inheritDoc}
     */
    public IPath getBuildPath() {
        String buildDir = getProperty(BUILD_DIR);
        if (!buildDir.startsWith("/")) { //$NON-NLS-1$
            buildDir = "/" + buildDir; //$NON-NLS-1$
        }

        return getFolder(buildDir).getProjectRelativePath();
    }

    /**
     * {@inheritDoc}
     */
    public IPath getIdlPath() {
        String idlDir = getProperty(IDL_DIR);
        if (!idlDir.startsWith("/")) { //$NON-NLS-1$
            idlDir = "/" + idlDir; //$NON-NLS-1$
        }

        return getFolder(idlDir).getProjectRelativePath();
    }

    /**
     * {@inheritDoc}
     */
    public IPath getImplementationPath() {
        String path = new String(mCompanyPrefix + "." + mOutputExtension).replace('.', '/'); //$NON-NLS-1$
        return getSourcePath().append(path);
    }

    /**
     * {@inheritDoc}
     */
    public IPath getProjectPath() {
        return getProject().getLocation();
    }

    /**
     * {@inheritDoc}
     */
    public IPath getTypesPath() {
        return new Path("types.rdb"); //$NON-NLS-1$
    }

    /**
     * {@inheritDoc}
     */
    public IPath getServicesPath() {
        return new Path("services.rdb"); //$NON-NLS-1$
    }

    /**
     * {@inheritDoc}
     */
    public IPath getSourcePath() {
        if (mSourcesDir == null) {
            mSourcesDir = getProperty(SRC_DIRECTORY);
        }
        return getFolder(mSourcesDir).getProjectRelativePath();
    }

    /**
     * {@inheritDoc}
     */
    public IPath getUrdPath() {
        return getFolder(getBuildPath().append(UnoidlProjectHelper.URD_BASIS)).getProjectRelativePath();
    }

    /**
     * {@inheritDoc}
     */
    public IPath getDistPath() {
        return getFolder(UnoidlProjectHelper.DIST_BASIS).getProjectRelativePath();
    }

    /**
     * {@inheritDoc}
     */
    public IFolder getDistFolder() throws CoreException {
        IFolder folder = getFolder(getDistPath());
        if (!folder.exists()) {
            folder.getLocation().toFile().mkdirs();
        }
        return folder;
    }

    /**
     * {@inheritDoc}
     */
    public IPath getOpenOfficeUserProfilePath() {
        return getFolder(getDistPath().append(UnoidlProjectHelper.OO_PROFILE_BASIS)).getProjectRelativePath();
    }

    /**
     * {@inheritDoc}
     */
    public IFolder getOpenOfficeUserProfileFolder() throws CoreException {
        IFolder folder = getFolder(getOpenOfficeUserProfilePath());
        if (!folder.exists()) {
            folder.getLocation().toFile().mkdirs();
        }
        return folder;
    }

    /**
     * {@inheritDoc}
     */
    public IFile getFile(IPath pPath) {
        return getProject().getFile(pPath);
    }

    /**
     * {@inheritDoc}
     */
    public IFile getFile(String pPath) {
        return getProject().getFile(pPath);
    }

    /**
     * {@inheritDoc}
     */
    public IFolder getFolder(IPath pPath) {
        return getProject().getFolder(pPath);
    }

    /**
     * {@inheritDoc}
     */
    public IFolder getFolder(String pPath) {
        return getProject().getFolder(pPath);
    }

    /**
     * @return the UNO project configuration file
     * 
     * @see #CONFIG_FILE for the configuration file name
     */
    public File getConfigFile() {
        return new File(getProjectPath().append(CONFIG_FILE).toOSString());
    }

    /**
     * Reads a property from the UNO project configuration file.
     * 
     * <p>
     * Returns the property corresponding to the given name. If the configuration file doesn't exists, a default one
     * will be created.
     * </p>
     * 
     * @param pPropertyName
     *            the name of the property to get
     * @return the property value or <code>null</code> if not found.
     * 
     * @see #CONFIG_FILE for the configuration file name
     */
    public String getProperty(String pPropertyName) {

        Properties properties = new Properties();
        File configFile = getConfigFile();
        String property = null;

        FileInputStream in = null;
        try {
            // Create a default configuration file if needed
            if (!configFile.exists()) {
                UnoidlProjectHelper.createDefaultConfig(configFile);
            }

            in = new FileInputStream(configFile);
            properties.load(in);
            property = properties.getProperty(pPropertyName);
        } catch (Exception e) {
            String pattern = Messages.getString("UnoidlProject.UnreadableConfigFileWarning"); //$NON-NLS-1$
            String msg = MessageFormat.format(pattern, CONFIG_FILE);
            PluginLogger.warning(msg, e);
        } finally {
            try {
                in.close();
            } catch (IOException e) {
            }
        }

        return property;
    }

    /**
     * Define a property in the UNO project configuration file.
     * 
     * @param pName
     *            the property name
     * @param pValue
     *            the property value
     */
    public void setProperty(String pName, String pValue) {
        Properties properties = new Properties();
        File configFile = getConfigFile();

        FileInputStream in = null;
        FileOutputStream out = null;
        try {
            // Create a default configuration file if needed
            if (!configFile.exists()) {
                UnoidlProjectHelper.createDefaultConfig(configFile);
            }

            in = new FileInputStream(configFile);
            properties.load(in);

            properties.setProperty(pName, pValue);

            out = new FileOutputStream(configFile);
            properties.store(out, Messages.getString("UnoidlProject.ConfigFileComment")); //$NON-NLS-1$

            // Refresh the configuration file
            getFile(CONFIG_FILE).refreshLocal(IResource.DEPTH_ZERO, null);

        } catch (Exception e) {
            String pattern = Messages.getString("UnoidlProject.PropertyChangeError"); //$NON-NLS-1$
            String message = MessageFormat.format(pattern, pName, pValue);
            PluginLogger.warning(message, e);
        } finally {
            try {
                in.close();
            } catch (IOException e) {
            }
            try {
                out.close();
            } catch (IOException e) {
            }
        }
    }

    /**
     * {@inheritDoc}
     */
    public void saveAllProperties() {

        if( mLanguage == null || mOOo == null || mSdk == null){
            PluginLogger.warning(Messages.getString("UnoidlProject.InconsistentConfigurationError")); //$NON-NLS-1$
            return;
        }
        
        Properties properties = new Properties();
        File configFile = getConfigFile();

        // Create a default configuration file if needed
        if (!configFile.exists()) {
            UnoidlProjectHelper.createDefaultConfig(configFile);
        }

        FileInputStream in = null;
        FileOutputStream out = null;
        try {
            in = new FileInputStream(configFile);
            properties.load(in);
            
            properties.setProperty(LANGUAGE, mLanguage.getName());
            properties.setProperty(OOO_NAME, mOOo.getName());
            properties.setProperty(SDK_NAME, mSdk.getId());
            properties.setProperty(IDL_DIR, mIdlDir);
            properties.setProperty(SRC_DIRECTORY, mSourcesDir);
            properties.setProperty(COMPANY_PREFIX, mCompanyPrefix);
            properties.setProperty(OUTPUT_EXT, mOutputExtension);

            out = new FileOutputStream(configFile);
            properties.store(out, Messages.getString("UnoidlProject.ConfigFileComment")); //$NON-NLS-1$

            // Refresh the configuration file
            getFile(CONFIG_FILE).refreshLocal(IResource.DEPTH_ZERO, null);

        } catch (Exception e) {
            PluginLogger.warning(Messages.getString("UnoidlProject.ConfigFileSaveError"), e); //$NON-NLS-1$
        } finally {
            try {
                in.close();
            } catch (Exception e) {
            }
            try {
                out.close();
            } catch (Exception e) {
            }
        }
    }

    /**
     * {@inheritDoc}
     */
    public IFolder[] getBinFolders() {
        return getLanguage().getProjectHandler().getBinFolders(this);
    }

    // *************************************************************************
    // IProjectNature Implementation
    // *************************************************************************

    /**
     * {@inheritDoc}
     */
    public void configure() throws CoreException {

        // Load all the persistent properties into the members

        String sdkKey = getProperty(SDK_NAME);
        if (sdkKey != null) {
            setSdk(SDKContainer.getSDK(sdkKey));
        }

        String prefix = getProperty(COMPANY_PREFIX);
        if (prefix != null) {
            mCompanyPrefix = prefix;
        }

        String outputExt = getProperty(OUTPUT_EXT);
        if (outputExt != null) {
            mOutputExtension = outputExt;
        }

        String languageName = getProperty(LANGUAGE);
        if (languageName != null) {
            setLanguage(LanguagesHelper.getLanguageFromName(languageName));
        }

        String idlDir = getProperty(IDL_DIR);
        if (idlDir != null) {
            setIdlDir(idlDir);
        }

        String srcDir = getProperty(SRC_DIRECTORY);
        if (srcDir != null) {
            setSourcesDir(srcDir);
        }

        String oooKey = getProperty(OOO_NAME);
        if (oooKey != null) {
            IOOo someOOo = OOoContainer.getSomeOOo(oooKey);
            setOOo(someOOo);
        }

        // Save any change from the read project file
        saveAllProperties();
    }

    /**
     * {@inheritDoc}
     */
    public void deconfigure() throws CoreException {
        dispose();
    }

    /**
     * {@inheritDoc}
     */
    public IProject getProject() {
        return mProject;
    }

    /**
     * {@inheritDoc}
     */
    public void setProject(IProject pProject) {
        mProject = pProject;
    }

    // *************************************************************************
    // Useful methods for the nature implementation
    // *************************************************************************

    /**
     * Set the builders for the project.
     * 
     * <p>
     * This method configures the builders using the implementation language informations
     * </p>
     * 
     * @throws CoreException
     *             if the builders can't be set.
     */
    public void setBuilders() throws CoreException {
        if (!(null == mSdk || null == mOOo || null == mCompanyPrefix || null == mOutputExtension)) {

            // Set the types builder
            IProjectDescription descr = getProject().getDescription();
            ICommand[] builders = descr.getBuildSpec();
            ICommand[] newCommands = new ICommand[builders.length + 1];

            ICommand typesbuilderCommand = descr.newCommand();
            typesbuilderCommand.setBuilderName(TypesBuilder.BUILDER_ID);
            newCommands[0] = typesbuilderCommand;

            System.arraycopy(builders, 0, newCommands, 1, builders.length);

            descr.setBuildSpec(newCommands);
            getProject().setDescription(descr, null);
        }
    }

    /**
     * {@inheritDoc}
     */
    public String toString() {
        return "UNO Project " + getName(); //$NON-NLS-1$
    }

    /**
     * Toggle an error marker on the project indicating that the there is either no OpenOffice.org nor SDK set.
     * 
     * @param pSet
     *            <code>true</code> if the error marker should be set, <code>false</code> otherwise.
     */
    private void setErrorMarker(boolean pSet) {

        IProject prjRes = getProject();

        try {
            if (pSet) {
                IMarker marker = prjRes.createMarker(IMarker.PROBLEM);
                marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
                marker.setAttribute(IMarker.MESSAGE, Messages.getString("UnoidlProject.NoOOoSdkError")); //$NON-NLS-1$
            } else {
                prjRes.deleteMarkers(IMarker.PROBLEM, true, IResource.DEPTH_ZERO);
            }
        } catch (CoreException e) {
            if (pSet) {
                PluginLogger.error(Messages.getString("UnoidlProject.CreateMarkerError") + //$NON-NLS-1$
                                getProjectPath().toString(), e);
            } else {
                PluginLogger.error(Messages.getString("UnoidlProject.RemoveMarkerError"), e); //$NON-NLS-1$
            }
        }

    }
}