~ubuntu-branches/debian/sid/eclipse-cdt/sid

« back to all changes in this revision

Viewing changes to build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/dataprovider/ProjectConverter.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2011-10-06 21:15:04 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20111006211504-8dutmljjih0zikfv
Tags: 8.0.1-1
* New upstream release.
* Split the JNI packages into a separate architecture dependent
  package and made eclipse-cdt architecture independent.
* Install JNI libraries into multiarch aware location
* Bumped Standards-Version to 3.9.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*******************************************************************************
 
2
 * Copyright (c) 2007 Intel Corporation and others.
 
3
 * All rights reserved. This program and the accompanying materials
 
4
 * are made available under the terms of the Eclipse Public License v1.0
 
5
 * which accompanies this distribution, and is available at
 
6
 * http://www.eclipse.org/legal/epl-v10.html
 
7
 *
 
8
 * Contributors:
 
9
 * Intel Corporation - Initial API and implementation
 
10
 *******************************************************************************/
 
11
package org.eclipse.cdt.managedbuilder.internal.dataprovider;
 
12
 
 
13
import java.util.ArrayList;
 
14
import java.util.Arrays;
 
15
import java.util.HashMap;
 
16
import java.util.HashSet;
 
17
import java.util.Iterator;
 
18
import java.util.List;
 
19
import java.util.Map;
 
20
import java.util.Set;
 
21
 
 
22
import org.eclipse.cdt.core.CCorePlugin;
 
23
import org.eclipse.cdt.core.ICDescriptor;
 
24
import org.eclipse.cdt.core.ICDescriptorOperation;
 
25
import org.eclipse.cdt.core.cdtvariables.ICdtVariable;
 
26
import org.eclipse.cdt.core.model.CoreModel;
 
27
import org.eclipse.cdt.core.model.IPathEntry;
 
28
import org.eclipse.cdt.core.settings.model.ICConfigExtensionReference;
 
29
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
 
30
import org.eclipse.cdt.core.settings.model.ICExternalSetting;
 
31
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
 
32
import org.eclipse.cdt.core.settings.model.ICStorageElement;
 
33
import org.eclipse.cdt.core.settings.model.extension.CConfigurationData;
 
34
import org.eclipse.cdt.core.settings.model.extension.ICProjectConverter;
 
35
import org.eclipse.cdt.core.settings.model.util.PathEntryTranslator;
 
36
import org.eclipse.cdt.core.settings.model.util.PathEntryTranslator.ReferenceSettingsInfo;
 
37
import org.eclipse.cdt.internal.core.cdtvariables.ICoreVariableContextInfo;
 
38
import org.eclipse.cdt.internal.core.cdtvariables.StorableCdtVariables;
 
39
import org.eclipse.cdt.internal.core.cdtvariables.UserDefinedVariableSupplier;
 
40
import org.eclipse.cdt.make.core.IMakeTarget;
 
41
import org.eclipse.cdt.make.core.IMakeTargetManager;
 
42
import org.eclipse.cdt.make.core.MakeCorePlugin;
 
43
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
 
44
import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
 
45
import org.eclipse.cdt.managedbuilder.core.IManagedProject;
 
46
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
 
47
import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin;
 
48
import org.eclipse.cdt.managedbuilder.internal.core.Builder;
 
49
import org.eclipse.cdt.managedbuilder.internal.core.BuilderFactory;
 
50
import org.eclipse.cdt.managedbuilder.internal.core.Configuration;
 
51
import org.eclipse.cdt.managedbuilder.internal.core.ManagedProject;
 
52
import org.eclipse.cdt.managedbuilder.internal.core.ToolChain;
 
53
import org.eclipse.core.resources.ICommand;
 
54
import org.eclipse.core.resources.IContainer;
 
55
import org.eclipse.core.resources.IProject;
 
56
import org.eclipse.core.resources.IProjectDescription;
 
57
import org.eclipse.core.resources.IResource;
 
58
import org.eclipse.core.resources.IResourceVisitor;
 
59
import org.eclipse.core.resources.IWorkspace;
 
60
import org.eclipse.core.resources.IWorkspaceRunnable;
 
61
import org.eclipse.core.resources.ResourcesPlugin;
 
62
import org.eclipse.core.runtime.CoreException;
 
63
import org.eclipse.core.runtime.IPath;
 
64
import org.eclipse.core.runtime.IProgressMonitor;
 
65
import org.eclipse.core.runtime.IStatus;
 
66
import org.eclipse.core.runtime.NullProgressMonitor;
 
67
import org.eclipse.core.runtime.Status;
 
68
import org.eclipse.core.runtime.jobs.Job;
 
69
import org.eclipse.jface.dialogs.MessageDialog;
 
70
import org.eclipse.swt.widgets.Shell;
 
71
import org.eclipse.ui.IWorkbenchWindow;
 
72
import org.eclipse.ui.PlatformUI;
 
73
import org.eclipse.ui.dialogs.IOverwriteQuery;
 
74
 
 
75
public class ProjectConverter implements ICProjectConverter {
 
76
        private final static String OLD_MAKE_BUILDER_ID = "org.eclipse.cdt.make.core.makeBuilder";      //$NON-NLS-1$
 
77
        private final static String OLD_MAKE_NATURE_ID = "org.eclipse.cdt.make.core.makeNature";        //$NON-NLS-1$
 
78
        private final static String OLD_MNG_BUILDER_ID = "org.eclipse.cdt.managedbuilder.core.genmakebuilder";  //$NON-NLS-1$
 
79
        private final static String OLD_MNG_NATURE_ID = "org.eclipse.cdt.managedbuilder.core.managedBuildNature";       //$NON-NLS-1$
 
80
        private final static String OLD_DISCOVERY_MODULE_ID = "scannerConfiguration";   //$NON-NLS-1$
 
81
        private final static String OLD_BINARY_PARSER_ID = "org.eclipse.cdt.core.BinaryParser"; //$NON-NLS-1$
 
82
        private final static String OLD_ERROR_PARSER_ID = "org.eclipse.cdt.core.ErrorParser";   //$NON-NLS-1$
 
83
        private final static String OLD_PATH_ENTRY_ID = "org.eclipse.cdt.core.pathentry"; //$NON-NLS-1$
 
84
        private final static String OLD_DISCOVERY_NATURE_ID = "org.eclipse.cdt.make.core.ScannerConfigNature"; //$NON-NLS-1$
 
85
        private final static String OLD_DISCOVERY_BUILDER_ID = "org.eclipse.cdt.make.core.ScannerConfigBuilder"; //$NON-NLS-1$
 
86
        private final static String OLD_MAKE_TARGET_BUIDER_ID = "org.eclipse.cdt.make.MakeTargetBuilder"; //$NON-NLS-1$
 
87
        private final static String NEW_MAKE_TARGET_BUIDER_ID = "org.eclipse.cdt.build.MakeTargetBuilder"; //$NON-NLS-1$
 
88
 
 
89
        private static ResourcePropertyHolder PROPS = new ResourcePropertyHolder(true);
 
90
        
 
91
        private static String CONVERSION_FAILED_MSG_ID = "conversionFailed"; //$NON-NLS-1$
 
92
        
 
93
        public boolean canConvertProject(IProject project, String oldOwnerId, ICProjectDescription oldDes) {
 
94
                try {
 
95
                        if(oldOwnerId == null || oldDes == null)
 
96
                                return false;
 
97
                
 
98
                        IProjectDescription eDes = project.getDescription();
 
99
                        Set<String> natureSet = new HashSet<String>(Arrays.asList(eDes.getNatureIds()));
 
100
                        if(natureSet.contains(OLD_MAKE_NATURE_ID))
 
101
                                return true;
 
102
                        
 
103
                        if(natureSet.contains(OLD_MNG_NATURE_ID))
 
104
                                return true;
 
105
                        
 
106
                } catch (CoreException e) {
 
107
                }
 
108
                
 
109
                return false;
 
110
//              return ManagedBuildManager.canGetBuildInfo(project);
 
111
        }
 
112
 
 
113
        public ICProjectDescription convertProject(IProject project, IProjectDescription eDes, String oldOwnerId, ICProjectDescription oldDes)
 
114
                        throws CoreException {
 
115
                Set<String> natureSet = new HashSet<String>(Arrays.asList(eDes.getNatureIds()));
 
116
                CoreModel model = CoreModel.getDefault();
 
117
                ICProjectDescription newDes = null;
 
118
                IManagedBuildInfo info = null;
 
119
                String[] binErrParserIds = null;
 
120
//              boolean convertMakeTargetInfo = false;
 
121
 
 
122
                if(natureSet.contains(OLD_MAKE_NATURE_ID)){
 
123
                        newDes = oldDes;
 
124
                        ICConfigurationDescription des = newDes.getConfigurations()[0];
 
125
                        ICConfigExtensionReference refs[] = des.get(OLD_BINARY_PARSER_ID);
 
126
                        if(refs.length != 0){
 
127
                                binErrParserIds = new String[refs.length];
 
128
                                for(int i = 0; i < refs.length; i++){
 
129
                                        binErrParserIds[i] = refs[i].getID();
 
130
                                }
 
131
                        }
 
132
                        info = ManagedBuildManager.createBuildInfo(project);
 
133
                        ManagedProject mProj = new ManagedProject(newDes);
 
134
                        info.setManagedProject(mProj);
 
135
 
 
136
                        Configuration cfg = ConfigurationDataProvider.getClearPreference(des.getId());
 
137
                        cfg.applyToManagedProject(mProj);
 
138
                        cfg.setConfigurationDescription(des);
 
139
 
 
140
                        des.setConfigurationData(ManagedBuildManager.CFG_DATA_PROVIDER_ID, cfg.getConfigurationData());
 
141
                } else if(natureSet.contains(OLD_MNG_NATURE_ID)){
 
142
                        try {
 
143
                                if(PROPS.getProperty(project, CONVERSION_FAILED_MSG_ID) != null)
 
144
                                        throw new CoreException(new Status(IStatus.ERROR, ManagedBuilderCorePlugin.getUniqueIdentifier(), DataProviderMessages.getString("ProjectConverter.0"))); //$NON-NLS-1$
 
145
 
 
146
                                newDes = model.createProjectDescription(project, false);
 
147
                                info = convertManagedBuildInfo(project, newDes);
 
148
                        } catch (CoreException e) {
 
149
                                displayInfo(project, CONVERSION_FAILED_MSG_ID, DataProviderMessages.getString("ProjectConverter.10"), DataProviderMessages.getFormattedString("ProjectConverter.11", new String[]{project.getName(), e.getLocalizedMessage()})); //$NON-NLS-1$ //$NON-NLS-2$
 
150
                                throw e;
 
151
                        }
 
152
                } 
 
153
 
 
154
                if(newDes == null || !newDes.isValid() || newDes.getConfigurations().length == 0){
 
155
                        newDes = null;
 
156
                } else {
 
157
                        boolean changeEDes = false;
 
158
                        if(natureSet.remove(OLD_MAKE_NATURE_ID))
 
159
                                changeEDes = true;
 
160
                        if(natureSet.remove(OLD_DISCOVERY_NATURE_ID))
 
161
                                changeEDes = true;
 
162
                                
 
163
                        if(changeEDes)
 
164
                                eDes.setNatureIds(natureSet.toArray(new String[natureSet.size()]));
 
165
                        
 
166
                        changeEDes = false;
 
167
                        ICommand[] cmds = eDes.getBuildSpec();
 
168
                        List<ICommand> list = new ArrayList<ICommand>(Arrays.asList(cmds));
 
169
                        ICommand makeBuilderCmd = null;
 
170
                        for(Iterator<ICommand> iter = list.iterator(); iter.hasNext();){
 
171
                                ICommand cmd = iter.next();
 
172
                                if(OLD_MAKE_BUILDER_ID.equals(cmd.getBuilderName())){
 
173
                                        makeBuilderCmd = cmd;
 
174
                                        iter.remove();
 
175
                                        changeEDes = true;
 
176
//                                      convertMakeTargetInfo = true;
 
177
                                } else if(OLD_DISCOVERY_BUILDER_ID.equals(cmd.getBuilderName())){
 
178
                                        iter.remove();
 
179
                                        changeEDes = true;
 
180
                                }
 
181
                        }
 
182
                        
 
183
                        ICConfigurationDescription cfgDess[] = newDes.getConfigurations();
 
184
                        for(int i = 0; i < cfgDess.length; i++){
 
185
                                ICConfigurationDescription cfgDes = cfgDess[i];
 
186
                                BuildConfigurationData data = (BuildConfigurationData)cfgDes.getConfigurationData();
 
187
                                IConfiguration cfg = ManagedBuildManager.getConfigurationForDescription(cfgDes);
 
188
 
 
189
                                if(makeBuilderCmd != null)
 
190
                                        loadBuilderSettings(cfg, makeBuilderCmd);
 
191
                                
 
192
//                              loadDiscoveryOptions(cfgDes, cfg);
 
193
                                
 
194
                                loadPathEntryInfo(project, cfgDes, data);
 
195
                                
 
196
                                if(binErrParserIds != null){
 
197
                                        data.getTargetPlatformData().setBinaryParserIds(binErrParserIds);
 
198
                                        cfgDes.get(OLD_BINARY_PARSER_ID);
 
199
//                                      ICConfigExtensionReference refs[] = cfgDes.get(OLD_BINARY_PARSER_ID);
 
200
//                                      String ids[] = idsFromRefs(refs);
 
201
//                                      data.getTargetPlatformData().setBinaryParserIds(ids);
 
202
//                                      
 
203
//                                      refs = cfgDes.get(OLD_ERROR_PARSER_ID);
 
204
//                                      ids = idsFromRefs(refs);
 
205
//                                      data.getBuildData().setErrorParserIDs(ids);
 
206
                                }
 
207
                                
 
208
                                try {
 
209
                                        ConfigurationDataProvider.writeConfiguration(cfgDes, data);
 
210
                                } catch (CoreException e){
 
211
                                }
 
212
                        }
 
213
                        
 
214
//                      if(convertMakeTargetInfo){
 
215
//                              try {
 
216
//                                      convertMakeTargetInfo(project, newDes, null);
 
217
//                              } catch (CoreException e){
 
218
//                                      ManagedBuilderCorePlugin.log(e);
 
219
//                              }
 
220
//                      }
 
221
                        
 
222
                        if(changeEDes){
 
223
                                cmds = list.toArray(new ICommand[list.size()]);
 
224
                                eDes.setBuildSpec(cmds);
 
225
                        }
 
226
                        
 
227
                        info.setValid(true);
 
228
                        
 
229
                        
 
230
                        try {
 
231
                                ManagedBuildManager.setLoaddedBuildInfo(project, info);
 
232
                        } catch (Exception e) {
 
233
                        }
 
234
                }
 
235
 
 
236
                return newDes;
 
237
        }
 
238
        
 
239
        static void displayInfo(IProject proj, String id, String title, String message){
 
240
                if(PROPS.getProperty(proj, id) == null){
 
241
                        openInformation(proj, id, title, message, false);
 
242
                        PROPS.setProperty(proj, id, Boolean.TRUE);
 
243
                }
 
244
        }
 
245
        
 
246
        public static boolean getBooleanFromQueryAnswer(String answer){
 
247
                if(IOverwriteQuery.ALL.equalsIgnoreCase(answer) ||
 
248
                                IOverwriteQuery.YES.equalsIgnoreCase(answer))
 
249
                        return true;
 
250
                return false;
 
251
        }
 
252
        
 
253
        static public boolean openQuestion(final IResource rc, final String id, final String title, final String message, IOverwriteQuery query, final boolean multiple){
 
254
                if(query != null)
 
255
                        return getBooleanFromQueryAnswer(query.queryOverwrite(message));
 
256
 
 
257
                IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
 
258
                if(window == null){
 
259
                        IWorkbenchWindow windows[] = PlatformUI.getWorkbench().getWorkbenchWindows();
 
260
                        window = windows[0];
 
261
                }
 
262
 
 
263
                final Shell shell = window.getShell();
 
264
                final boolean [] answer = new boolean[1];
 
265
                shell.getDisplay().syncExec(new Runnable() {
 
266
                        public void run() {
 
267
                                Object ob = PROPS.getProperty(rc, id);
 
268
                                if(multiple || ob == null){
 
269
                                        PROPS.setProperty(rc, id, Boolean.TRUE);
 
270
                                        answer[0] = MessageDialog.openQuestion(shell,title,message);
 
271
                                        PROPS.setProperty(rc, id, answer[0] ? Boolean.TRUE : Boolean.FALSE);
 
272
                                } else {
 
273
                                        answer[0] = ((Boolean)ob).booleanValue();
 
274
                                }
 
275
                        }
 
276
                });     
 
277
                return answer[0];
 
278
        }
 
279
        
 
280
        static private void openInformation(final IResource rc, final String id, final String title, final String message, final boolean multiple){
 
281
                IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
 
282
                if(window == null){
 
283
                        IWorkbenchWindow windows[] = PlatformUI.getWorkbench().getWorkbenchWindows();
 
284
                        window = windows[0];
 
285
                }
 
286
 
 
287
                final Shell shell = window.getShell();
 
288
                shell.getDisplay().syncExec(new Runnable() {
 
289
                        public void run() {
 
290
                                if(multiple || PROPS.getProperty(rc, id) == null){
 
291
                                        PROPS.setProperty(rc, id, Boolean.TRUE);
 
292
                                        MessageDialog.openInformation(shell,title,message);
 
293
                                }
 
294
                        }
 
295
                });     
 
296
        }
 
297
        
 
298
        private static void convertMakeTargetInfo(final IProject project, ICProjectDescription des, IProgressMonitor monitor) throws CoreException{
 
299
                if(monitor == null)
 
300
                        monitor = new NullProgressMonitor();
 
301
                
 
302
                CCorePlugin.getDefault().getCDescriptorManager().runDescriptorOperation(project, des, new ICDescriptorOperation(){
 
303
 
 
304
                        public void execute(ICDescriptor descriptor,
 
305
                                        IProgressMonitor monitor) throws CoreException {
 
306
                                final IMakeTargetManager mngr = MakeCorePlugin.getDefault().getTargetManager();
 
307
                                
 
308
                                project.accept(new IResourceVisitor(){
 
309
 
 
310
                                        public boolean visit(IResource resource)
 
311
                                                        throws CoreException {
 
312
                                                if(resource.getType() == IResource.FILE)
 
313
                                                        return false;
 
314
                                                
 
315
                                                try {
 
316
                                                        IContainer cr = (IContainer)resource;
 
317
                                                        IMakeTarget targets[] = mngr.getTargets(cr);
 
318
                                                        for(int i = 0; i < targets.length; i++){
 
319
                                                                IMakeTarget t = targets[i];
 
320
                                                                if(!OLD_MAKE_TARGET_BUIDER_ID.equals(t.getTargetBuilderID()))
 
321
                                                                        continue;
 
322
                                                                
 
323
                                                                IMakeTarget newT = mngr.createTarget(project, t.getName(), NEW_MAKE_TARGET_BUIDER_ID);
 
324
                                                                copySettings(t, newT);
 
325
                                                                mngr.removeTarget(t);
 
326
                                                                mngr.addTarget(cr, newT);
 
327
                                                        }
 
328
                                                } catch ( CoreException e){
 
329
                                                        ManagedBuilderCorePlugin.log(e);
 
330
                                                }
 
331
                                                return true;
 
332
                                        }
 
333
                                        
 
334
                                });
 
335
                        }
 
336
                        
 
337
                }, monitor);
 
338
        }
 
339
        
 
340
        private static void copySettings(IMakeTarget fromTarget, IMakeTarget toTarget) throws CoreException{
 
341
                        toTarget.setAppendEnvironment(fromTarget.appendEnvironment());
 
342
                        toTarget.setAppendProjectEnvironment(fromTarget.appendProjectEnvironment());
 
343
 
 
344
                        toTarget.setBuildAttribute(IMakeTarget.BUILD_LOCATION, fromTarget.getBuildAttribute(IMakeTarget.BUILD_LOCATION, null));
 
345
                        toTarget.setBuildAttribute(IMakeTarget.BUILD_COMMAND, fromTarget.getBuildAttribute(IMakeTarget.BUILD_COMMAND, null));
 
346
                        toTarget.setBuildAttribute(IMakeTarget.BUILD_ARGUMENTS, fromTarget.getBuildAttribute(IMakeTarget.BUILD_ARGUMENTS, null));
 
347
                        toTarget.setBuildAttribute(IMakeTarget.BUILD_TARGET, fromTarget.getBuildAttribute(IMakeTarget.BUILD_TARGET, null));
 
348
                        
 
349
                        Map<String, String> fromMap = fromTarget.getEnvironment();
 
350
                        if(fromMap != null)
 
351
                                toTarget.setEnvironment(new HashMap<String, String>(fromMap));
 
352
                        
 
353
//                      toTarget.setErrorParsers(fromTarget.getErrorParsers());
 
354
                        
 
355
                        toTarget.setRunAllBuilders(fromTarget.runAllBuilders());
 
356
                        
 
357
                        toTarget.setStopOnError(fromTarget.isStopOnError());
 
358
                        
 
359
                        toTarget.setUseDefaultBuildCmd(fromTarget.isDefaultBuildCmd());
 
360
                        
 
361
                        toTarget.setContainer(fromTarget.getContainer());
 
362
 
 
363
        }
 
364
        
 
365
        private void loadPathEntryInfo(IProject project, ICConfigurationDescription des, CConfigurationData data){
 
366
                try {
 
367
                        ICStorageElement el = des.getStorage(OLD_PATH_ENTRY_ID, false);
 
368
                        if(el != null){
 
369
                                IPathEntry[] entries = PathEntryTranslator.decodePathEntries(project, el);
 
370
                                if(entries.length != 0){
 
371
                                        List<IPathEntry> list = new ArrayList<IPathEntry>(Arrays.asList(entries));
 
372
                                        for(Iterator<IPathEntry> iter = list.iterator(); iter.hasNext();){
 
373
                                                IPathEntry entry = iter.next();
 
374
                                                if(entry.getEntryKind() == IPathEntry.CDT_CONTAINER){
 
375
                                                        iter.remove();
 
376
                                                        continue;
 
377
                                                }
 
378
                                        }
 
379
                                        
 
380
                                        if(list.size() != 0){
 
381
                                                PathEntryTranslator tr = new PathEntryTranslator(project, data);
 
382
                                                entries = list.toArray(new IPathEntry[list.size()]);
 
383
                                                ReferenceSettingsInfo refInfo = tr.applyPathEntries(entries, null, PathEntryTranslator.OP_REPLACE);
 
384
                                                ICExternalSetting extSettings[] = refInfo.getExternalSettings();
 
385
                                                des.removeExternalSettings();
 
386
                                                if(extSettings.length != 0){
 
387
                                                        ICExternalSetting setting;
 
388
                                                        for(int i = 0; i < extSettings.length; i++){
 
389
                                                                setting = extSettings[i];
 
390
                                                                des.createExternalSetting(setting.getCompatibleLanguageIds(), 
 
391
                                                                                setting.getCompatibleContentTypeIds(), 
 
392
                                                                                setting.getCompatibleExtensions(), 
 
393
                                                                                setting.getEntries());
 
394
                                                        }
 
395
                                                }
 
396
 
 
397
                                                IPath projPaths[] = refInfo.getReferencedProjectsPaths();
 
398
                                                if(projPaths.length != 0){
 
399
                                                        Map<String, String> map = new HashMap<String, String>(projPaths.length);
 
400
                                                        for(int i = 0; i < projPaths.length; i++){
 
401
                                                                map.put(projPaths[i].segment(0), "");   //$NON-NLS-1$
 
402
                                                        }
 
403
                                                        des.setReferenceInfo(map);
 
404
                                                }
 
405
                                        }
 
406
                                }
 
407
                                des.removeStorage(OLD_PATH_ENTRY_ID);
 
408
                        }
 
409
                } catch (CoreException e) {
 
410
                        ManagedBuilderCorePlugin.log(e);
 
411
                }
 
412
        }
 
413
        
 
414
//      private String[] idsFromRefs(ICConfigExtensionReference refs[]){
 
415
//              String ids[] = new String[refs.length];
 
416
//              for(int i = 0; i < ids.length; i++){
 
417
//                      ids[i] = refs[i].getID();
 
418
//              }
 
419
//              return ids;
 
420
//      }
 
421
        
 
422
//      private void loadDiscoveryOptions(ICConfigurationDescription des, IConfiguration cfg){
 
423
//              try {
 
424
//                      ICStorageElement discoveryStorage = des.getStorage(OLD_DISCOVERY_MODULE_ID, false);
 
425
//                      if(discoveryStorage != null){
 
426
//                              Configuration config = (Configuration)cfg;
 
427
//                              IScannerConfigBuilderInfo2 scannerConfigInfo = ScannerConfigInfoFactory2.create(new CfgInfoContext(cfg), discoveryStorage, ScannerConfigProfileManager.NULL_PROFILE_ID);
 
428
//                              config.setPerRcTypeDiscovery(false);
 
429
//                              config.setScannerConfigInfo(scannerConfigInfo);
 
430
//                              des.removeStorage(OLD_DISCOVERY_MODULE_ID);
 
431
//                      }
 
432
//              } catch (CoreException e) {
 
433
//                      ManagedBuilderCorePlugin.log(e);
 
434
//              }
 
435
//              
 
436
//              
 
437
//      }
 
438
        
 
439
        private void loadBuilderSettings(IConfiguration cfg, ICommand cmd){
 
440
                Builder builder = (Builder)BuilderFactory.createBuilderFromCommand(cfg, cmd);
 
441
                if(builder.getCommand() != null && builder.getCommand().length() != 0){
 
442
                        String[] errParserIds = builder.getCustomizedErrorParserIds();
 
443
                        builder.setCustomizedErrorParserIds(null);
 
444
                        ((ToolChain)cfg.getToolChain()).setBuilder(builder);
 
445
                        if(errParserIds != null && errParserIds.length != 0){
 
446
                                cfg.setErrorParserList(errParserIds);
 
447
                        }
 
448
                }
 
449
        }
 
450
        
 
451
        private static boolean convertOldStdMakeToNewStyle(final IProject project, boolean checkOnly, IProgressMonitor monitor, boolean throwExceptions) throws CoreException {
 
452
                try {
 
453
//                      ICDescriptor dr = CCorePlugin.getDefault().getCProjectDescription(project, false);
 
454
//                      if(dr == null){
 
455
//                              if(throwExceptions)
 
456
//                                      throw new CoreException(new Status(IStatus.ERROR,
 
457
//                                                      ManagedBuilderCorePlugin.getUniqueIdentifier(),
 
458
//                                                      DataProviderMessages.getString("ProjectConverter.0"))); //$NON-NLS-1$
 
459
//                              return false;
 
460
//                      }
 
461
//
 
462
//                      if(!MakeCorePlugin.MAKE_PROJECT_ID.equals(dr.getProjectOwner().getID())){
 
463
//                              if(throwExceptions)
 
464
//                                      throw new CoreException(new Status(IStatus.ERROR,
 
465
//                                                      ManagedBuilderCorePlugin.getUniqueIdentifier(),
 
466
//                                                      DataProviderMessages.getString("ProjectConverter.1") + dr.getProjectOwner().getID())); //$NON-NLS-1$
 
467
//                              return false;
 
468
//                      }
 
469
                        
 
470
                        ICProjectDescription des = CCorePlugin.getDefault().getProjectDescription(project, false);
 
471
                        
 
472
                        if(des == null){
 
473
                                if(throwExceptions)
 
474
                                        throw new CoreException(new Status(IStatus.ERROR,
 
475
                                                        ManagedBuilderCorePlugin.getUniqueIdentifier(),
 
476
                                                        DataProviderMessages.getString("ProjectConverter.9")));  //$NON-NLS-1$
 
477
                                return false;
 
478
                        }
 
479
 
 
480
                        ICConfigurationDescription cfgs[] = des.getConfigurations();
 
481
                        if(cfgs.length != 1){
 
482
                                if(throwExceptions)
 
483
                                        throw new CoreException(new Status(IStatus.ERROR,
 
484
                                                        ManagedBuilderCorePlugin.getUniqueIdentifier(),
 
485
                                                        DataProviderMessages.getString("ProjectConverter.2") + cfgs.length)); //$NON-NLS-1$
 
486
                                return false;
 
487
                        }
 
488
                        
 
489
                        if(!CCorePlugin.DEFAULT_PROVIDER_ID.equals(cfgs[0].getBuildSystemId())){
 
490
                                if(throwExceptions)
 
491
                                        throw new CoreException(new Status(IStatus.ERROR,
 
492
                                                        ManagedBuilderCorePlugin.getUniqueIdentifier(),
 
493
                                                        DataProviderMessages.getString("ProjectConverter.3") + cfgs.length)); //$NON-NLS-1$
 
494
                                return false;
 
495
                        }
 
496
                        
 
497
                        final IProjectDescription eDes = project.getDescription();
 
498
                        String natureIds[] = eDes.getNatureIds();
 
499
                        Set<String> set = new HashSet<String>(Arrays.asList(natureIds));
 
500
                        if(!set.contains(OLD_MAKE_NATURE_ID)){
 
501
                                if(throwExceptions)
 
502
                                        throw new CoreException(new Status(IStatus.ERROR,
 
503
                                                        ManagedBuilderCorePlugin.getUniqueIdentifier(),
 
504
                                                        DataProviderMessages.getString("ProjectConverter.4") + natureIds.toString())); //$NON-NLS-1$
 
505
                                return false;
 
506
                        }
 
507
                        
 
508
                        if(!checkOnly){
 
509
                                ProjectConverter instance = new ProjectConverter();
 
510
                                ICProjectDescription oldDes = CCorePlugin.getDefault().getProjectDescription(project);
 
511
                                if(!instance.canConvertProject(project, MakeCorePlugin.MAKE_PROJECT_ID, oldDes)){
 
512
                                        if(throwExceptions)
 
513
                                                throw new CoreException(new Status(IStatus.ERROR,
 
514
                                                                ManagedBuilderCorePlugin.getUniqueIdentifier(),
 
515
                                                                DataProviderMessages.getString("ProjectConverter.5"))); //$NON-NLS-1$
 
516
                                        return false;
 
517
                                }
 
518
                                
 
519
                                final ICProjectDescription newDes = instance.convertProject(project, eDes, MakeCorePlugin.MAKE_PROJECT_ID, oldDes);
 
520
                                if(newDes == null){
 
521
                                        if(throwExceptions)
 
522
                                                throw new CoreException(new Status(IStatus.ERROR,
 
523
                                                                ManagedBuilderCorePlugin.getUniqueIdentifier(),
 
524
                                                                DataProviderMessages.getString("ProjectConverter.6"))); //$NON-NLS-1$
 
525
                                        return false;
 
526
                                }
 
527
                                
 
528
                                final IWorkspace wsp = ResourcesPlugin.getWorkspace();
 
529
                                wsp.run(new IWorkspaceRunnable(){
 
530
 
 
531
                                        public void run(IProgressMonitor monitor)
 
532
                                                        throws CoreException {
 
533
                                                project.setDescription(eDes, monitor);
 
534
                                                CCorePlugin.getDefault().setProjectDescription(project, newDes);
 
535
                                                Job job = new Job(DataProviderMessages.getString("ProjectConverter.7")){ //$NON-NLS-1$
 
536
 
 
537
                                                        @Override
 
538
                                                        protected IStatus run(IProgressMonitor monitor) {
 
539
                                                                try {
 
540
                                                                        ICProjectDescription des = CCorePlugin.getDefault().getProjectDescription(project);
 
541
                                                                        convertMakeTargetInfo(project, des, monitor);
 
542
                                                                        CCorePlugin.getDefault().setProjectDescription(project, des);
 
543
                                                                } catch (CoreException e) {
 
544
                                                                        return e.getStatus();
 
545
                                                                }
 
546
                                                                return Status.OK_STATUS;
 
547
                                                        }
 
548
                                                        
 
549
                                                };
 
550
                                                
 
551
                                                job.setRule(wsp.getRoot());
 
552
                                                job.schedule();
 
553
                                        }
 
554
                                        
 
555
                                }, wsp.getRoot(), IWorkspace.AVOID_UPDATE, monitor);
 
556
                        }
 
557
                        return true;
 
558
                } catch (CoreException e) {
 
559
                        if(throwExceptions)
 
560
                                throw e;
 
561
                        ManagedBuilderCorePlugin.log(e);
 
562
                }
 
563
                if(throwExceptions)
 
564
                        throw new CoreException(new Status(IStatus.ERROR,
 
565
                                        ManagedBuilderCorePlugin.getUniqueIdentifier(),
 
566
                                        DataProviderMessages.getString("ProjectConverter.8"))); //$NON-NLS-1$
 
567
                return false;
 
568
        }
 
569
        
 
570
        public static boolean isOldStyleMakeProject(IProject project){
 
571
                try {
 
572
                        return convertOldStdMakeToNewStyle(project, true, null, false);
 
573
                } catch (CoreException e) {
 
574
                        ManagedBuilderCorePlugin.log(e);
 
575
                }
 
576
                return false;
 
577
        }
 
578
 
 
579
        public static void convertOldStdMakeToNewStyle(IProject project, IProgressMonitor monitor) throws CoreException{
 
580
                convertOldStdMakeToNewStyle(project, false, monitor, true);
 
581
        }
 
582
 
 
583
        private IManagedBuildInfo convertManagedBuildInfo(IProject project, ICProjectDescription newDes) throws CoreException {
 
584
                IManagedBuildInfo info = ManagedBuildManager.getOldStyleBuildInfo(project);
 
585
                
 
586
                synchronized(PROPS){
 
587
                        if(info != null && info.isValid()){
 
588
                                IManagedProject mProj = info.getManagedProject();
 
589
                                IConfiguration cfgs[] = mProj.getConfigurations();
 
590
                                if(cfgs.length != 0){
 
591
                                        Configuration cfg;
 
592
                                        CConfigurationData data;
 
593
 
 
594
                                        UserDefinedVariableSupplier usrSupplier = UserDefinedVariableSupplier.getInstance();
 
595
 
 
596
                                        for(int i = 0; i < cfgs.length; i++){
 
597
                                                cfg = (Configuration)cfgs[i];
 
598
                                                data = cfg.getConfigurationData();
 
599
//                                              try {
 
600
                                                        ICConfigurationDescription cfgDes = newDes.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDER_ID, data);
 
601
                                                        if(cfg.getConfigurationDescription() != null) {
 
602
                                                                //copy cfg to avoid raise conditions
 
603
                                                                cfg = ConfigurationDataProvider.copyCfg(cfg, cfgDes);
 
604
                                                                cfgDes.setConfigurationData(ManagedBuildManager.CFG_DATA_PROVIDER_ID, cfg.getConfigurationData());
 
605
                                                        }
 
606
                                                        cfg.setConfigurationDescription(cfgDes);
 
607
                                                        
 
608
                                                        StorableCdtVariables vars = ((ToolChain)cfg.getToolChain()).getResetOldStyleProjectVariables();
 
609
                                                        if(vars != null){
 
610
                                                                ICdtVariable vs[] = vars.getMacros();
 
611
                                                                for(int k = 0; k < vs.length; k++){
 
612
                                                                        usrSupplier.createMacro(vs[k], ICoreVariableContextInfo.CONTEXT_CONFIGURATION, cfgDes);
 
613
                                                                }
 
614
                                                        }
 
615
//                                              } catch (WriteAccessException e) {
 
616
//                                                      ManagedBuilderCorePlugin.log(e);
 
617
//                                              } catch (CoreException e) {
 
618
//                                                      ManagedBuilderCorePlugin.log(e);
 
619
//                                              }
 
620
                                                cfg.exportArtifactInfo();
 
621
                                        }
 
622
                                }
 
623
                        } else {
 
624
                                throw new CoreException(new Status(IStatus.ERROR, ManagedBuilderCorePlugin.getUniqueIdentifier(), DataProviderMessages.getString("ProjectConverter.13"))); //$NON-NLS-1$
 
625
                        }
 
626
                }
 
627
                return info;
 
628
        }
 
629
 
 
630
}