1
/*******************************************************************************
2
* Copyright (c) 2007, 2010 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
9
* Intel Corporation - Initial API and implementation
10
*******************************************************************************/
11
package org.eclipse.cdt.projectmodel.tests;
13
import java.util.ArrayList;
14
import java.util.Arrays;
15
import java.util.List;
17
import junit.framework.Test;
18
import junit.framework.TestCase;
19
import junit.framework.TestSuite;
21
import org.eclipse.cdt.core.CCorePlugin;
22
import org.eclipse.cdt.core.model.CoreModel;
23
import org.eclipse.cdt.core.model.ElementChangedEvent;
24
import org.eclipse.cdt.core.model.ICElementDelta;
25
import org.eclipse.cdt.core.model.IElementChangedListener;
26
import org.eclipse.cdt.core.settings.model.CIncludePathEntry;
27
import org.eclipse.cdt.core.settings.model.CMacroEntry;
28
import org.eclipse.cdt.core.settings.model.CSourceEntry;
29
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
30
import org.eclipse.cdt.core.settings.model.ICFileDescription;
31
import org.eclipse.cdt.core.settings.model.ICFolderDescription;
32
import org.eclipse.cdt.core.settings.model.ICLanguageSetting;
33
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
34
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
35
import org.eclipse.cdt.core.settings.model.ICResourceDescription;
36
import org.eclipse.cdt.core.settings.model.ICSettingBase;
37
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
38
import org.eclipse.cdt.core.settings.model.ICSourceEntry;
39
import org.eclipse.cdt.core.settings.model.extension.CConfigurationData;
40
import org.eclipse.cdt.core.settings.model.extension.CLanguageData;
41
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
42
import org.eclipse.cdt.managedbuilder.core.IFileInfo;
43
import org.eclipse.cdt.managedbuilder.core.IFolderInfo;
44
import org.eclipse.cdt.managedbuilder.core.IProjectType;
45
import org.eclipse.cdt.managedbuilder.core.IResourceInfo;
46
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
47
import org.eclipse.cdt.managedbuilder.internal.core.Configuration;
48
import org.eclipse.cdt.managedbuilder.internal.core.ManagedBuildInfo;
49
import org.eclipse.cdt.managedbuilder.internal.core.ManagedProject;
50
import org.eclipse.cdt.managedbuilder.testplugin.BuildSystemTestHelper;
51
import org.eclipse.cdt.managedbuilder.testplugin.ManagedBuildTestHelper;
52
import org.eclipse.core.resources.IProject;
53
import org.eclipse.core.resources.IProjectDescription;
54
import org.eclipse.core.resources.IResource;
55
import org.eclipse.core.resources.IWorkspace;
56
import org.eclipse.core.resources.IWorkspaceDescription;
57
import org.eclipse.core.resources.IWorkspaceRoot;
58
import org.eclipse.core.resources.IWorkspaceRunnable;
59
import org.eclipse.core.resources.ResourcesPlugin;
60
import org.eclipse.core.runtime.CoreException;
61
import org.eclipse.core.runtime.IPath;
62
import org.eclipse.core.runtime.IProgressMonitor;
63
import org.eclipse.core.runtime.NullProgressMonitor;
64
import org.eclipse.core.runtime.Path;
66
public class ProjectModelTests extends TestCase implements IElementChangedListener{
67
private boolean isPrint = false;
68
private CDefaultModelEventChecker fEventChecker;
70
public void elementChanged(ElementChangedEvent event) {
71
if(fEventChecker != null)
72
fEventChecker.checkEvent(event);
75
private class CDefaultModelEventChecker {
77
void checkEvent(ElementChangedEvent event) {
78
assertEquals(ElementChangedEvent.POST_CHANGE, event.getType());
80
ICElementDelta delta = event.getDelta();
82
System.out.println(delta.toString());
89
public static Test suite() {
90
return new TestSuite(ProjectModelTests.class);
94
protected void setUp() throws Exception {
97
CoreModel.getDefault().addElementChangedListener(this);
101
protected void tearDown() throws Exception {
103
fEventChecker = null;
104
CoreModel.getDefault().removeElementChangedListener(this);
107
private void modify(ICFileDescription fiDes){
108
ICLanguageSetting ls = fiDes.getLanguageSetting();
112
private void modify(ICFolderDescription foDes){
113
ICLanguageSetting ls = foDes.getLanguageSettingForFile("a.c");
117
private void modify(ICLanguageSetting ls){
118
List<ICLanguageSettingEntry> list = ls.getSettingEntriesList(ICSourceEntry.INCLUDE_PATH);
119
list.add(new CIncludePathEntry("_modify_", 0));
120
ls.setSettingEntries(ICSettingEntry.INCLUDE_PATH, list);
123
private void modify(IFileInfo fiInfo){
124
CLanguageData lData = fiInfo.getCLanguageDatas()[0];
128
private void modify(CLanguageData lData){
129
ICLanguageSettingEntry[] entries = lData.getEntries(ICSourceEntry.INCLUDE_PATH);
130
ICLanguageSettingEntry[] updatedEntries = new ICLanguageSettingEntry[entries.length + 1];
131
System.arraycopy(entries, 0, updatedEntries, 0, entries.length);
132
updatedEntries[entries.length] = new CIncludePathEntry("_modify_", 0);
133
lData.setEntries(ICSettingEntry.INCLUDE_PATH, updatedEntries);
136
public void testDescription() throws Exception{
137
final String projectName = "test1";
138
IProject project = createProject(projectName);
139
CoreModel coreModel = CoreModel.getDefault();
140
ICProjectDescription des = coreModel.getProjectDescription(project);
141
assertNull("detDescription1 returned not null!", des);
143
des = coreModel.createProjectDescription(project, true);
144
assertNotNull("createDescription returned null!", des);
146
assertNull("detDescription2 returned not null!", coreModel.getProjectDescription(project));
148
assertFalse("new des should be not valid", des.isValid());
150
assertEquals(0, des.getConfigurations().length);
152
ManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project);
153
IProjectType type = ManagedBuildManager.getProjectType("cdt.managedbuild.target.gnu30.exe");
154
assertNotNull("project type not found", type);
156
ManagedProject mProj = new ManagedProject(project, type);
157
info.setManagedProject(mProj);
159
IConfiguration cfgs[] = type.getConfigurations();
162
for(int i = 0; i < cfgs.length; i++){
163
String id = ManagedBuildManager.calculateChildId(cfgs[i].getId(), null);
164
Configuration config = new Configuration(mProj, (Configuration)cfgs[i], id, false, true, false);
165
CConfigurationData data = config.getConfigurationData();
166
assertNotNull("data is null for created configuration", data);
167
des.createConfiguration("org.eclipse.cdt.managedbuilder.core.configurationDataProvider", data);
169
coreModel.setProjectDescription(project, des);
171
IWorkspace wsp = ResourcesPlugin.getWorkspace();
172
IWorkspaceRoot root = wsp.getRoot();
173
project.delete(false, true, new NullProgressMonitor());
175
project = root.getProject(projectName);
176
des = coreModel.getProjectDescription(project);
177
assertNull("project description is not null for removed project", des);
179
project = createProject(projectName);
180
des = coreModel.getProjectDescription(project);
181
assertNotNull("project description is null for re-created project", des);
182
assertTrue("des should be valid for re-created project", des.isValid());
184
ICConfigurationDescription cfgDess[] = des.getConfigurations();
186
assertEquals(2, cfgDess.length);
188
ICConfigurationDescription cfgDes = cfgDess[0];
189
ICResourceDescription rcDess[] = cfgDes.getResourceDescriptions();
190
assertEquals(1, rcDess.length);
191
assertEquals(cfgDes.getRootFolderDescription(), rcDess[0]);
192
assertFalse(cfgDes.isModified());
193
assertEquals(cfgDes.getRootFolderDescription(), cfgDes.getResourceDescription(new Path(""), true));
194
assertEquals(cfgDes.getRootFolderDescription(), cfgDes.getResourceDescription(new Path(""), false));
195
assertEquals(cfgDes.getRootFolderDescription(), cfgDes.getResourceDescription(new Path(""), false));
196
assertEquals(cfgDes.getRootFolderDescription(), cfgDes.getResourceDescription(new Path("ds/sd/sdf/"), false));
197
assertEquals(cfgDes.getRootFolderDescription(), cfgDes.getResourceDescription(new Path(""), true));
198
assertEquals(null, cfgDes.getResourceDescription(new Path("ds/sd/sdf/"), true));
200
ICFileDescription fd_abc = cfgDes.createFileDescription(new Path("a/b/c.c"), rcDess[0]);
202
assertTrue(cfgDes.isModified());
206
ICProjectDescription anotherDes = coreModel.getProjectDescription(project);
207
assertNotNull("project description is null for re-created project", des);
208
assertTrue("des should be valid for re-created project", des.isValid());
210
ICConfigurationDescription anotherCfgDess[] = anotherDes.getConfigurations();
212
assertEquals(2, anotherCfgDess.length);
214
ICConfigurationDescription anotherCfgDes = anotherCfgDess[0];
215
ICResourceDescription anotherRcDess[] = anotherCfgDes.getResourceDescriptions();
216
assertEquals(1, anotherRcDess.length);
217
assertEquals(anotherCfgDes.getRootFolderDescription(), anotherRcDess[0]);
218
assertFalse(anotherCfgDes.isModified());
220
CConfigurationData cfgData = cfgDes.getConfigurationData();
221
assertEquals(cfgData, cfgDes.getConfigurationData());
222
IConfiguration cfg = ManagedBuildManager.getConfigurationForDescription(cfgDes);
223
IResourceInfo infos[] = cfg.getResourceInfos();
224
assertEquals(2, infos.length);
226
ICFolderDescription rf = cfgDes.getRootFolderDescription();
227
ICResourceDescription nestedFis[] = rf.getNestedResourceDescriptions(ICSettingBase.SETTING_FILE);
228
ICResourceDescription nestedFos[] = rf.getNestedResourceDescriptions(ICSettingBase.SETTING_FOLDER);
229
assertEquals(2, cfgDes.getResourceDescriptions().length);
230
assertEquals(0, nestedFos.length);
231
assertEquals(1, nestedFis.length);
233
ICFileDescription fd_asd = cfgDes.createFileDescription(new Path("a/s/d.c"), cfgDes.getRootFolderDescription());
235
assertEquals(3, cfgDes.getResourceDescriptions().length);
236
nestedFis = rf.getNestedResourceDescriptions(ICSettingBase.SETTING_FILE);
237
nestedFos = rf.getNestedResourceDescriptions(ICSettingBase.SETTING_FOLDER);
238
assertEquals(0, nestedFos.length);
239
assertEquals(2, nestedFis.length);
241
IFileInfo fi = cfg.createFileInfo(new Path("z/x/c.c"));
243
nestedFis = rf.getNestedResourceDescriptions(ICSettingBase.SETTING_FILE);
244
nestedFos = rf.getNestedResourceDescriptions(ICSettingBase.SETTING_FOLDER);
245
assertEquals(0, nestedFos.length);
246
assertEquals(3, nestedFis.length);
247
assertEquals(4, cfgDes.getResourceDescriptions().length);
249
fi = cfg.createFileInfo(new Path("q/w/e.c"));
251
ICFileDescription fd_qwe = (ICFileDescription)cfgDes.getResourceDescription(new Path("q/w/e.c"), true);
252
assertNotNull(fd_qwe);
253
assertEquals(5, cfgDes.getResourceDescriptions().length);
254
nestedFis = rf.getNestedResourceDescriptions(ICSettingBase.SETTING_FILE);
255
nestedFos = rf.getNestedResourceDescriptions(ICSettingBase.SETTING_FOLDER);
256
assertEquals(0, nestedFos.length);
257
assertEquals(4, nestedFis.length);
259
cfgDes.removeResourceDescription(fd_abc);
260
nestedFis = rf.getNestedResourceDescriptions(ICSettingBase.SETTING_FILE);
261
nestedFos = rf.getNestedResourceDescriptions(ICSettingBase.SETTING_FOLDER);
262
assertEquals(0, nestedFos.length);
263
assertEquals(3, nestedFis.length);
264
assertEquals(4, cfgDes.getResourceDescriptions().length);
266
cfg.removeResourceInfo(new Path("a/s/d.c"));
267
assertEquals(3, cfgDes.getResourceDescriptions().length);
268
nestedFis = rf.getNestedResourceDescriptions(ICSettingBase.SETTING_FILE);
269
nestedFos = rf.getNestedResourceDescriptions(ICSettingBase.SETTING_FOLDER);
270
assertEquals(0, nestedFos.length);
271
assertEquals(2, nestedFis.length);
273
IFileInfo fi_qwe = (IFileInfo)cfg.getResourceInfo(new Path("q/w/e.c"), true);
274
assertNotNull(fi_qwe);
276
ICFileDescription fid_qwe = (ICFileDescription)cfgDes.getResourceDescription(new Path("q/w/e.c"), true);
277
assertNotNull(fid_qwe);
278
fi_qwe.setPath(new Path("r/t/y.c"));
279
assertEquals(fi_qwe, cfg.getResourceInfo(new Path("r/t/y.c"), true));
280
assertNull(cfgDes.getResourceDescription(new Path("q/w/e.c"), true));
281
ICFileDescription fid_rty = (ICFileDescription)cfgDes.getResourceDescription(new Path("r/t/y.c"), true);
282
assertEquals(fid_qwe, fid_rty);
284
fid_rty.setPath(new Path("f/g/h.c"));
285
assertNull(cfg.getResourceInfo(new Path("r/t/y.c"), true));
286
IFileInfo fi_fgh = (IFileInfo)cfg.getResourceInfo(new Path("f/g/h.c"), true);
287
assertEquals(fi_qwe, fi_fgh);
289
ICFolderDescription fod_fg1 = cfgDes.createFolderDescription(new Path("f/g/1"), cfgDes.getRootFolderDescription());
291
ICFolderDescription fod_fg12 = cfgDes.createFolderDescription(new Path("f/g/1/2"), fod_fg1);
293
assertEquals(fod_fg12, fod_fg1.getNestedResourceDescription(new Path("2"), true));
295
ICFileDescription fid_fg13 = cfgDes.createFileDescription(new Path("f/g/1/3.c"), fod_fg1);
297
assertEquals(fid_fg13, fod_fg1.getNestedResourceDescription(new Path("3.c"), true));
299
assertEquals(2, fod_fg1.getNestedResourceDescriptions().length);
300
assertEquals(1, fod_fg1.getNestedResourceDescriptions(ICSettingBase.SETTING_FILE).length);
301
assertEquals(1, fod_fg1.getNestedResourceDescriptions(ICSettingBase.SETTING_FOLDER).length);
303
IFolderInfo fo_fg1 = (IFolderInfo)cfg.getResourceInfo(new Path("f/g/1"), true);
304
assertNotNull(fo_fg1);
306
fo_fg1.setPath(new Path("t/y/u"));
308
assertEquals(2, fod_fg1.getNestedResourceDescriptions().length);
309
assertEquals(1, fod_fg1.getNestedResourceDescriptions(ICSettingBase.SETTING_FILE).length);
310
assertEquals(1, fod_fg1.getNestedResourceDescriptions(ICSettingBase.SETTING_FOLDER).length);
312
assertEquals(fod_fg12, cfgDes.getResourceDescription(new Path("t/y/u/2"), true));
313
assertEquals(fid_fg13, cfgDes.getResourceDescription(new Path("t/y/u/3.c"), true));
315
ICLanguageSetting settings[] = cfgDes.getRootFolderDescription().getLanguageSettings();
316
for(int i = 0; i < settings.length; i++){
317
ICLanguageSetting setting = settings[i];
318
ICLanguageSettingEntry[] entries = setting.getSettingEntries(ICLanguageSettingEntry.INCLUDE_PATH);
319
if (!setting.supportsEntryKind(ICSettingEntry.INCLUDE_PATH))
320
assertTrue(entries.length == 0);
322
for(int j = 0; j < entries.length; j++){
323
System.out.println(entries[j].getName());
325
System.out.println(entries.length);
328
coreModel.setProjectDescription(project, des);
330
project.delete(false, true, new NullProgressMonitor());
332
project = root.getProject(projectName);
333
assertFalse(project.exists());
334
assertFalse(project.isOpen());
335
des = coreModel.getProjectDescription(project);
336
assertFalse(project.exists());
337
assertFalse(project.isOpen());
338
assertNull("project description is not null for removed project", des);
340
project = createProject(projectName);
341
long time = System.currentTimeMillis();
342
des = coreModel.getProjectDescription(project);
343
time = System.currentTimeMillis() - time;
345
System.out.println("time to load = " + time);
347
assertNotNull("project description is null for re-created project", des);
348
assertTrue("des should be valid for re-created project", des.isValid());
350
cfgDess = des.getConfigurations();
352
rf = cfgDes.getRootFolderDescription();
353
settings = rf.getLanguageSettings();
354
ICLanguageSettingEntry updatedEntries[] = new ICLanguageSettingEntry[0];
355
for(int i = 0; i < settings.length; i++){
356
ICLanguageSetting setting = settings[i];
357
ICLanguageSettingEntry[] entries = setting.getSettingEntries(ICLanguageSettingEntry.INCLUDE_PATH);
358
if(entries.length > 0){
359
ICLanguageSettingEntry updated[] = new ICLanguageSettingEntry[entries.length + 1];
360
System.arraycopy(entries, 0, updated, 1, entries.length);
361
updated[0] = new CIncludePathEntry("a/b/c", 0);
362
setting.setSettingEntries(ICLanguageSettingEntry.INCLUDE_PATH, updated);
363
updatedEntries = setting.getSettingEntries(ICLanguageSettingEntry.INCLUDE_PATH);
364
assertEquals(updated.length, updatedEntries.length);
365
for(int k = 0; k < updated.length; k++){
366
assertEquals(updated[i].getValue(), updatedEntries[i].getValue());
371
fEventChecker = new CDefaultModelEventChecker();
372
coreModel.setProjectDescription(project, des);
373
fEventChecker = null;
375
project.delete(false, true, new NullProgressMonitor());
377
project = root.getProject(projectName);
378
assertFalse(project.exists());
379
assertFalse(project.isOpen());
380
des = coreModel.getProjectDescription(project);
381
assertNull("project description is not null for removed project", des);
383
project = createProject(projectName);
384
time = System.currentTimeMillis();
385
des = coreModel.getProjectDescription(project);
386
time = System.currentTimeMillis() - time;
388
System.out.println("time to load = " + time);
390
assertNotNull("project description is null for re-created project", des);
391
assertTrue("des should be valid for re-created project", des.isValid());
393
cfgDess = des.getConfigurations();
395
rf = cfgDes.getRootFolderDescription();
396
settings = rf.getLanguageSettings();
398
for(int i = 0; i < settings.length; i++){
399
ICLanguageSetting setting = settings[i];
400
ICLanguageSettingEntry[] entries = setting.getSettingEntries(ICLanguageSettingEntry.INCLUDE_PATH);
401
if (setting.supportsEntryKind(ICSettingEntry.INCLUDE_PATH)) {
402
BuildSystemTestHelper.checkDiff(entries, updatedEntries);
403
assertEquals(entries.length, updatedEntries.length);
404
for(int k = 0; k < entries.length; k++)
405
assertEquals(entries[i].getValue(), updatedEntries[i].getValue());
407
assertTrue(entries.length == 0);
410
assertEquals(2, cfgDess.length);
411
nestedFis = rf.getNestedResourceDescriptions(ICSettingBase.SETTING_FILE);
412
nestedFos = rf.getNestedResourceDescriptions(ICSettingBase.SETTING_FOLDER);
413
assertEquals(2, nestedFos.length);
414
assertEquals(3, nestedFis.length);
416
assertEquals(6, cfgDes.getResourceDescriptions().length);
418
ManagedBuildTestHelper.createFolder(project, "a/b");
419
ICFolderDescription base = (ICFolderDescription)cfgDes.getResourceDescription(new Path("a/b"), false);
420
ICFolderDescription abFoDes = cfgDes.createFolderDescription(new Path("a/b"), base);
421
ICLanguageSetting ls = abFoDes.getLanguageSettingForFile("a.c");
423
List<ICLanguageSettingEntry> list = ls.getSettingEntriesList(ICLanguageSettingEntry.INCLUDE_PATH);
424
list.add(0, new CIncludePathEntry("zzza/b/c", 0));
425
ls.setSettingEntries(ICLanguageSettingEntry.INCLUDE_PATH, list);
428
System.out.println("setting entries for non-root folder..\n");
429
fEventChecker = new CDefaultModelEventChecker();
430
coreModel.setProjectDescription(project, des);
431
fEventChecker = null;
433
time = System.currentTimeMillis();
434
des = coreModel.getProjectDescription(project);
435
time = System.currentTimeMillis() - time;
437
System.out.println("time to load = " + time);
439
assertNotNull("project description is null for re-created project", des);
440
assertTrue("des should be valid for re-created project", des.isValid());
442
cfgDess = des.getConfigurations();
444
rf = cfgDes.getRootFolderDescription();
446
ManagedBuildTestHelper.createFolder(project, "b/c");
447
base = (ICFolderDescription)cfgDes.getResourceDescription(new Path("b/c"), false);
448
ICFolderDescription bcFoDes = cfgDes.createFolderDescription(new Path("b/c"), base);
449
ls = bcFoDes.getLanguageSettingForFile("a.c");
451
ICLanguageSetting rLS = rf.getLanguageSettingForFile("a.c");
453
ls.getSettingEntriesList(ICLanguageSettingEntry.INCLUDE_PATH);
454
rLS.getSettingEntriesList(ICLanguageSettingEntry.INCLUDE_PATH);
457
System.out.println("default entries for non-root folder..\n");
458
fEventChecker = new CDefaultModelEventChecker();
459
coreModel.setProjectDescription(project, des);
460
fEventChecker = null;
462
project.delete(true, true, new NullProgressMonitor());
465
public void testSourceEntries() throws Exception {
466
final String projectName = "test2";
467
IProject project = createProject(projectName);
468
CoreModel coreModel = CoreModel.getDefault();
469
ICProjectDescription des = coreModel.getProjectDescription(project);
470
assertNull("detDescription1 returned not null!", des);
472
des = coreModel.createProjectDescription(project, true);
473
assertNotNull("createDescription returned null!", des);
475
assertNull("detDescription2 returned not null!", coreModel.getProjectDescription(project));
477
assertFalse("new des should be not valid", des.isValid());
479
assertEquals(0, des.getConfigurations().length);
481
ManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project);
482
IProjectType type = ManagedBuildManager.getProjectType("cdt.managedbuild.target.gnu30.exe");
483
assertNotNull("project type not found", type);
485
ManagedProject mProj = new ManagedProject(project, type);
486
info.setManagedProject(mProj);
488
IConfiguration cfgs[] = type.getConfigurations();
491
for(int i = 0; i < cfgs.length; i++){
492
String id = ManagedBuildManager.calculateChildId(cfgs[i].getId(), null);
493
Configuration config = new Configuration(mProj, (Configuration)cfgs[i], id, false, true);
494
CConfigurationData data = config.getConfigurationData();
495
assertNotNull("data is null for created configuration", data);
496
des.createConfiguration("org.eclipse.cdt.managedbuilder.core.configurationDataProvider", data);
498
coreModel.setProjectDescription(project, des);
500
IWorkspace wsp = ResourcesPlugin.getWorkspace();
501
IWorkspaceRoot root = wsp.getRoot();
502
project.delete(false, true, new NullProgressMonitor());
504
project = root.getProject(projectName);
505
des = coreModel.getProjectDescription(project);
506
assertNull("project description is not null for removed project", des);
508
project = createProject(projectName);
509
des = coreModel.getProjectDescription(project);
510
assertNotNull("project description is null for re-created project", des);
511
assertTrue("des should be valid for re-created project", des.isValid());
513
ICConfigurationDescription cfgDess[] = des.getConfigurations();
515
assertEquals(2, cfgDess.length);
517
ICConfigurationDescription cfgDes = cfgDess[0];
518
ICResourceDescription rcDess[] = cfgDes.getResourceDescriptions();
519
assertEquals(1, rcDess.length);
520
assertEquals(cfgDes.getRootFolderDescription(), rcDess[0]);
521
assertFalse(cfgDes.isModified());
522
assertEquals(cfgDes.getRootFolderDescription(), cfgDes.getResourceDescription(new Path(""), true));
523
assertEquals(cfgDes.getRootFolderDescription(), cfgDes.getResourceDescription(new Path(""), false));
524
assertEquals(cfgDes.getRootFolderDescription(), cfgDes.getResourceDescription(new Path(""), false));
525
assertEquals(cfgDes.getRootFolderDescription(), cfgDes.getResourceDescription(new Path("ds/sd/sdf/"), false));
526
assertEquals(cfgDes.getRootFolderDescription(), cfgDes.getResourceDescription(new Path(""), true));
527
assertEquals(null, cfgDes.getResourceDescription(new Path("ds/sd/sdf/"), true));
529
ICSourceEntry s[] = cfgDes.getSourceEntries();
530
IPath projPath = cfgDes.getProjectDescription().getProject().getFullPath();
531
assertEquals(1, s.length);
532
assertEquals(projPath, s[0].getFullPath());
533
assertEquals(0, s[0].getExclusionPatterns().length);
535
ManagedBuildTestHelper.createFolder(project, "a/b");
537
ICSourceEntry updatetSEs[] = new ICSourceEntry[2];
538
updatetSEs[0] = new CSourceEntry(projPath.append("a"), new Path[]{new Path("b")}, ICSourceEntry.VALUE_WORKSPACE_PATH);
539
updatetSEs[1] = s[0];
541
cfgDes.setSourceEntries(updatetSEs);
543
s = cfgDes.getSourceEntries();
544
updatetSEs[1] = new CSourceEntry(projPath, new Path[]{new Path("a")}, ICSourceEntry.VALUE_WORKSPACE_PATH | ICSourceEntry.RESOLVED);
545
checkArrays(updatetSEs, s);
546
//assertTrue(Arrays.equals(updatetSEs, s));
549
System.out.println("saving updated source entries..\n");
550
fEventChecker = new CDefaultModelEventChecker();
551
coreModel.setProjectDescription(project, des);
552
fEventChecker = null;
554
des = coreModel.getProjectDescription(project);
555
cfgDes = des.getConfigurations()[0];
556
checkArrays(cfgDes.getSourceEntries(), s);
558
project.delete(true, true, new NullProgressMonitor());
561
public void testMacroEntries() throws Exception {
562
final String projectName = "test3";
563
IProject project = createProject(projectName);
564
CoreModel coreModel = CoreModel.getDefault();
565
ICProjectDescription des = coreModel.getProjectDescription(project);
566
assertNull("detDescription1 returned not null!", des);
568
des = coreModel.createProjectDescription(project, true);
569
assertNotNull("createDescription returned null!", des);
571
assertNull("detDescription2 returned not null!", coreModel.getProjectDescription(project));
573
assertFalse("new des should be not valid", des.isValid());
575
assertEquals(0, des.getConfigurations().length);
577
ManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project);
578
IProjectType type = ManagedBuildManager.getProjectType("cdt.managedbuild.target.gnu30.exe");
579
assertNotNull("project type not found", type);
581
ManagedProject mProj = new ManagedProject(project, type);
582
info.setManagedProject(mProj);
584
IConfiguration cfgs[] = type.getConfigurations();
586
for(int i = 0; i < cfgs.length; i++){
587
String id = ManagedBuildManager.calculateChildId(cfgs[i].getId(), null);
588
Configuration config = new Configuration(mProj, (Configuration)cfgs[i], id, false, true);
589
CConfigurationData data = config.getConfigurationData();
590
assertNotNull("data is null for created configuration", data);
591
des.createConfiguration("org.eclipse.cdt.managedbuilder.core.configurationDataProvider", data);
593
coreModel.setProjectDescription(project, des);
595
des = coreModel.getProjectDescription(project);
596
assertNotNull("project description is null ", des);
597
assertTrue("des should be valid ", des.isValid());
599
ICConfigurationDescription cfgDess[] = des.getConfigurations();
601
assertEquals(2, cfgDess.length);
603
ICConfigurationDescription cfgDes = cfgDess[0];
604
ICResourceDescription rcDess[] = cfgDes.getResourceDescriptions();
605
assertEquals(1, rcDess.length);
606
assertEquals(cfgDes.getRootFolderDescription(), rcDess[0]);
607
assertFalse(cfgDes.isModified());
608
assertEquals(cfgDes.getRootFolderDescription(), cfgDes.getResourceDescription(new Path(""), true));
609
assertEquals(cfgDes.getRootFolderDescription(), cfgDes.getResourceDescription(new Path(""), false));
610
assertEquals(cfgDes.getRootFolderDescription(), cfgDes.getResourceDescription(new Path(""), false));
611
assertEquals(cfgDes.getRootFolderDescription(), cfgDes.getResourceDescription(new Path("ds/sd/sdf/"), false));
612
assertEquals(cfgDes.getRootFolderDescription(), cfgDes.getResourceDescription(new Path(""), true));
613
assertEquals(null, cfgDes.getResourceDescription(new Path("ds/sd/sdf/"), true));
615
ICFolderDescription rf = cfgDes.getRootFolderDescription();
616
ICLanguageSetting setting = rf.getLanguageSettingForFile("a.c");
617
ICLanguageSettingEntry entries[] = setting.getSettingEntries(ICLanguageSettingEntry.MACRO);
620
for(int i = 0; i < entries.length; i++){
621
System.out.println("name = \"" + entries[i].getName() + "\", value = \"" + entries[i].getValue() + "\"");
625
CMacroEntry entry = new CMacroEntry("a", "b", 0);
626
List<ICLanguageSettingEntry> list = new ArrayList<ICLanguageSettingEntry>();
628
list.addAll(Arrays.asList(entries));
630
setting.setSettingEntries(ICLanguageSettingEntry.MACRO, list);
632
ICLanguageSettingEntry updatedEntries[] = setting.getSettingEntries(ICLanguageSettingEntry.MACRO);
633
assertEquals(entries.length + 1, updatedEntries.length);
635
boolean found = false;
636
for(int i = 0; i < updatedEntries.length; i++){
637
if(updatedEntries[i].getName().equals("a")
638
&& updatedEntries[i].getValue().equals("b")){
647
public void testActiveCfg() throws Exception{
648
final String projectName = "test8";
650
IProject project = createProject(projectName, "cdt.managedbuild.target.gnu30.exe");
651
CoreModel coreModel = CoreModel.getDefault();
653
ICProjectDescription des = coreModel.getProjectDescription(project);
654
ICConfigurationDescription cfgs[] = des.getConfigurations();
655
String id1 = cfgs[0].getId();
659
assertEquals(cfgs[0], des.getActiveConfiguration());
661
coreModel.setProjectDescription(project, des);
663
des = coreModel.getProjectDescription(project);
664
cfgs = des.getConfigurations();
665
assertEquals(id1, des.getActiveConfiguration().getId());
667
ICConfigurationDescription newActive = null;
668
for(int i = 0; i < cfgs.length; i++){
669
if(!cfgs[i].getId().equals(id1)){
675
String newActiveId = newActive.getId();
676
newActive.setActive();
677
assertEquals(newActive, des.getActiveConfiguration());
679
coreModel.setProjectDescription(project, des);
681
des = coreModel.getProjectDescription(project);
682
assertEquals(newActiveId, des.getActiveConfiguration().getId());
687
private void checkArrays(Object[] a1, Object[] a2){
689
assertTrue(a2 == null);
692
assertTrue(a2 != null);
694
assertEquals(a1.length, a2.length);
696
for(int i = 0; i < a1.length; i++){
698
boolean found = false;
699
for(int j = 0; j < a2.length; j++){
700
if(o1.equals(a2[j])){
707
fail("a2 array does not contain the \"" + o1 + "\" element");
712
static public IProject createProject(String name, String projTypeId) throws CoreException{
713
IProject project = createProject(name);
715
CoreModel coreModel = CoreModel.getDefault();
716
ICProjectDescription des = coreModel.getProjectDescription(project);
717
assertNull("detDescription1 returned not null!", des);
719
des = coreModel.createProjectDescription(project, true);
720
assertNotNull("createDescription returned null!", des);
722
assertNull("detDescription2 returned not null!", coreModel.getProjectDescription(project));
724
assertFalse("new des should be not valid", des.isValid());
726
assertEquals(0, des.getConfigurations().length);
728
ManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project);
729
IProjectType type = ManagedBuildManager.getProjectType(projTypeId);
730
assertNotNull("project type not found", type);
732
ManagedProject mProj = new ManagedProject(project, type);
733
info.setManagedProject(mProj);
735
IConfiguration cfgs[] = type.getConfigurations();
738
for(int i = 0; i < cfgs.length; i++){
739
String id = ManagedBuildManager.calculateChildId(cfgs[i].getId(), null);
740
Configuration config = new Configuration(mProj, (Configuration)cfgs[i], id, false, true);
741
CConfigurationData data = config.getConfigurationData();
742
assertNotNull("data is null for created configuration", data);
743
des.createConfiguration("org.eclipse.cdt.managedbuilder.core.configurationDataProvider", data);
746
coreModel.setProjectDescription(project, des);
751
static public IProject createProject(String name) throws CoreException{
752
return createProject(name, (IPath)null);
755
static public IProject createProject(
757
final IPath location) throws CoreException{
758
IWorkspace workspace = ResourcesPlugin.getWorkspace();
759
IWorkspaceRoot root = workspace.getRoot();
760
final IProject newProjectHandle = root.getProject(name);
761
IProject project = null;
763
if (!newProjectHandle.exists()) {
764
IWorkspaceDescription workspaceDesc = workspace.getDescription();
765
workspaceDesc.setAutoBuilding(false);
766
workspace.setDescription(workspaceDesc);
767
IProjectDescription description = workspace.newProjectDescription(newProjectHandle.getName());
769
description.setLocation(location);
770
//description.setLocation(root.getLocation());
771
project = CCorePlugin.getDefault().createCDTProject(description, newProjectHandle, new NullProgressMonitor());
773
IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
774
public void run(IProgressMonitor monitor) throws CoreException {
775
newProjectHandle.refreshLocal(IResource.DEPTH_INFINITE, monitor);
778
NullProgressMonitor monitor = new NullProgressMonitor();
779
workspace.run(runnable, root, IWorkspace.AVOID_UPDATE, monitor);
780
project = newProjectHandle;
783
// Open the project if we have to
784
if (!project.isOpen()) {
785
project.open(new NullProgressMonitor());