Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: cd7404d2bc125292046f92dfa710451ff97dd46d (plain) (blame)
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
/*******************************************************************************
 * Copyright (c) 2007, 2011 Intel Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 * Intel Corporation - Initial API and implementation
 *******************************************************************************/
package org.eclipse.cdt.managedbuilder.core.tests;

import java.io.File;
import java.io.FileFilter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.settings.model.CIncludePathEntry;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICFolderDescription;
import org.eclipse.cdt.core.settings.model.ICLanguageSetting;
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager;
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
import org.eclipse.cdt.core.testplugin.ResourceHelper;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IFolderInfo;
import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
import org.eclipse.cdt.managedbuilder.core.IOption;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.cdt.managedbuilder.core.OptionStringValue;
import org.eclipse.cdt.managedbuilder.internal.core.Tool;
import org.eclipse.cdt.managedbuilder.testplugin.BuildSystemTestHelper;
import org.eclipse.cdt.managedbuilder.testplugin.CTestPlugin;
import org.eclipse.cdt.managedbuilder.testplugin.ManagedBuildTestHelper;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;

public class BuildSystem40Tests extends TestCase {
	private IPath resourcesLocation = new Path(
			CTestPlugin.getFileInPlugin(new Path("resources/test40Projects/")).getAbsolutePath());

	public static Test suite() {
		TestSuite suite = new TestSuite(BuildSystem40Tests.class);

		return suite;
	}

	private String platformDependentPath(String cfgFolder, String winPath) {
		if (!Platform.getOS().equals(Platform.OS_WIN32)) {
			return cfgFolder + '/' + winPath;
		}
		return winPath;
	}

	public void test40() throws Exception {
		String[] makefiles = { "makefile", "objects.mk", "sources.mk", "d1/subdir.mk", "d1/d2/subdir.mk",
				"d1/d2/d3/subdir.mk", "d1_1/subdir.mk", "d1_1/d2_1/subdir.mk", "dir1/dd/excluded_c/subdir.mk",
				"dir1/dd/excluded_c/asd/subdir.mk", "dir1/dd/ff/subdir.mk", };
		IProject[] projects = createProjects("test_40", null, null, true);
		ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
		ICProjectDescription des = mngr.getProjectDescription(projects[0]);
		ICConfigurationDescription cfgDes = des.getConfigurationByName("dbg 2");
		assertNotNull(cfgDes);
		des.setActiveConfiguration(cfgDes);
		mngr.setProjectDescription(projects[0], des);
		buildProjects(projects, makefiles);

		des = mngr.getProjectDescription(projects[0]);
		cfgDes = des.getConfigurationByName("Test 4.0 ConfigName.Dbg");
		assertNotNull(cfgDes);
		des.setActiveConfiguration(cfgDes);
		mngr.setProjectDescription(projects[0], des);
		buildProjects(projects, makefiles);

		des = mngr.getProjectDescription(projects[0]);
		cfgDes = des.getConfigurationByName("dbg 3");
		IConfiguration cfg = ManagedBuildManager.getConfigurationForDescription(cfgDes);

		ICFolderDescription foDes = cfgDes.getRootFolderDescription();
		ICLanguageSetting ls = foDes.getLanguageSettingForFile("foo.cpp");
		IFolderInfo foInfo = cfg.getRootFolderInfo();
		Tool tool = (Tool) foInfo.getToolFromInputExtension("cpp");
		IOption option = tool.getOptionsOfType(IOption.INCLUDE_PATH)[0];
		OptionStringValue[] value = option.getBasicStringListValueElements();
		ICLanguageSettingEntry[] entries = ls.getSettingEntries(ICSettingEntry.INCLUDE_PATH);
		ICLanguageSettingEntry[] expectedEntries = new ICLanguageSettingEntry[] {
				new CIncludePathEntry("dbg 3/rel/path", 0), new CIncludePathEntry("proj/rel/path", 0),
				new CIncludePathEntry("/abs/path", 0),
				new CIncludePathEntry(platformDependentPath("dbg 3", "c:/abs/path"), 0),
				new CIncludePathEntry("/test_40/dir1/dir2/dir3",
						ICSettingEntry.VALUE_WORKSPACE_PATH/* | ICSettingEntry.RESOLVED*/),
				new CIncludePathEntry("/test_40", ICSettingEntry.VALUE_WORKSPACE_PATH/* | ICSettingEntry.RESOLVED*/),
				new CIncludePathEntry(platformDependentPath("dbg 3", "D:\\docs\\incs"), 0), };

		assertTrue(Arrays.equals(entries, expectedEntries));

		ls.setSettingEntries(ICSettingEntry.INCLUDE_PATH, entries);

		entries = ls.getSettingEntries(ICSettingEntry.INCLUDE_PATH);
		assertTrue(Arrays.equals(entries, expectedEntries));

		option = tool.getOptionsOfType(IOption.INCLUDE_PATH)[0];
		OptionStringValue[] modifiedValue = option.getBasicStringListValueElements();
		assertTrue(Arrays.equals(modifiedValue, value));

		{
			List<ICLanguageSettingEntry> list = new ArrayList<ICLanguageSettingEntry>();
			list.addAll(Arrays.asList(entries));
			list.add(new CIncludePathEntry(platformDependentPath("dbg 3", "E:\\tmp\\w"), 0));
			entries = list.toArray(new ICLanguageSettingEntry[0]);
			ls.setSettingEntries(ICLanguageSettingEntry.INCLUDE_PATH, entries);
			expectedEntries = entries;
			entries = ls.getSettingEntries(ICLanguageSettingEntry.INCLUDE_PATH);
			assertTrue(Arrays.equals(entries, expectedEntries));
		}

		{
			ArrayList<OptionStringValue> list = new ArrayList<OptionStringValue>();
			list.addAll(Arrays.asList(value));
			list.add(new OptionStringValue("\"E:\\tmp\\w\""));
			value = list.toArray(new OptionStringValue[0]);
		}

		option = tool.getOptionsOfType(IOption.INCLUDE_PATH)[0];
		modifiedValue = option.getBasicStringListValueElements();

		assertTrue(Arrays.equals(value, modifiedValue));

		foDes = (ICFolderDescription) cfgDes.getResourceDescription(new Path("d1/d2"), true);
		foInfo = (IFolderInfo) cfg.getResourceInfo(new Path("d1/d2"), true);

		ls = foDes.getLanguageSettingForFile("foo.cpp");
		tool = (Tool) foInfo.getToolFromInputExtension("cpp");
		option = tool.getOptionsOfType(IOption.INCLUDE_PATH)[0];

		expectedEntries = new ICLanguageSettingEntry[] { new CIncludePathEntry("dbg 3/d2_rel/path", 0),
				new CIncludePathEntry("d2_proj/rel/path", 0), new CIncludePathEntry("/d2_abs/path", 0),
				new CIncludePathEntry(platformDependentPath("dbg 3", "c:/d2_abs/path"), 0),
				new CIncludePathEntry("dbg 3/d1_rel/path", 0), new CIncludePathEntry("d1_proj/rel/path", 0),
				new CIncludePathEntry("/d1_abs/path", 0),
				new CIncludePathEntry(platformDependentPath("dbg 3", "c:/d1_abs/path"), 0),
				new CIncludePathEntry("dbg 3/rel/path", 0), new CIncludePathEntry("proj/rel/path", 0),
				new CIncludePathEntry("/abs/path", 0),
				new CIncludePathEntry(platformDependentPath("dbg 3", "c:/abs/path"), 0),
				new CIncludePathEntry("/test_40/dir1/dir2/dir3",
						ICSettingEntry.VALUE_WORKSPACE_PATH/* | ICSettingEntry.RESOLVED*/),
				new CIncludePathEntry("/test_40", ICSettingEntry.VALUE_WORKSPACE_PATH/* | ICSettingEntry.RESOLVED*/),
				new CIncludePathEntry(platformDependentPath("dbg 3", "D:\\docs\\incs"), 0),
				new CIncludePathEntry(platformDependentPath("dbg 3", "E:\\tmp\\w"), 0),
				new CIncludePathEntry(platformDependentPath("dbg 3", "D:\\d1_docs\\incs"), 0),
				new CIncludePathEntry(platformDependentPath("dbg 3", "D:\\d2_docs\\incs"), 0), };

		entries = ls.getSettingEntries(ICLanguageSettingEntry.INCLUDE_PATH);

		BuildSystemTestHelper.checkDiff(expectedEntries, entries);

		OptionStringValue[] expectedValue = new OptionStringValue[] { new OptionStringValue("d2_rel/path"),
				new OptionStringValue("../d2_proj/rel/path"), new OptionStringValue("/d2_abs/path"),
				new OptionStringValue("c:/d2_abs/path"), new OptionStringValue("${IncludeDefaults}"),
				new OptionStringValue("\"D:\\d2_docs\\incs\""), };

		value = option.getBasicStringListValueElements();
		BuildSystemTestHelper.checkDiff(expectedValue, value);

		ls.setSettingEntries(ICLanguageSettingEntry.INCLUDE_PATH, entries);
		value = option.getBasicStringListValueElements();
		entries = ls.getSettingEntries(ICLanguageSettingEntry.INCLUDE_PATH);
		BuildSystemTestHelper.checkDiff(expectedValue, value);
		BuildSystemTestHelper.checkDiff(expectedEntries, entries);

		{
			ArrayList<ICLanguageSettingEntry> list = new ArrayList<ICLanguageSettingEntry>(Arrays.asList(entries));
			list.remove(6); //new CIncludePathEntry("/d1_abs/path", 0),
			expectedEntries = list.toArray(new ICLanguageSettingEntry[0]);
			ls.setSettingEntries(ICLanguageSettingEntry.INCLUDE_PATH, list);
		}

		option = tool.getOptionsOfType(IOption.INCLUDE_PATH)[0];

		expectedValue = new OptionStringValue[] { new OptionStringValue("d2_rel/path"),
				new OptionStringValue("../d2_proj/rel/path"), new OptionStringValue("/d2_abs/path"),
				new OptionStringValue("c:/d2_abs/path"), new OptionStringValue("d1_rel/path"),
				new OptionStringValue("../d1_proj/rel/path"),
				//removed				new OptionStringValue("/d1_abs/path"),
				new OptionStringValue("c:/d1_abs/path"), new OptionStringValue("rel/path"),
				new OptionStringValue("../proj/rel/path"), new OptionStringValue("/abs/path"),
				new OptionStringValue("c:/abs/path"),
				new OptionStringValue("\"${workspace_loc:/test_40/dir1/dir2/dir3}\""),
				new OptionStringValue("\"${workspace_loc:/test_40}\""), new OptionStringValue("\"D:\\docs\\incs\""),
				new OptionStringValue("\"E:\\tmp\\w\""), new OptionStringValue("\"D:\\d1_docs\\incs\""),
				new OptionStringValue("\"D:\\d2_docs\\incs\""), };

		value = option.getBasicStringListValueElements();
		BuildSystemTestHelper.checkDiff(expectedValue, value);

		entries = ls.getSettingEntries(ICLanguageSettingEntry.INCLUDE_PATH);
		BuildSystemTestHelper.checkDiff(expectedEntries, entries);

		foDes = cfgDes.getRootFolderDescription();
		foInfo = cfg.getRootFolderInfo();
		ls = foDes.getLanguageSettingForFile("foo.cpp");
		tool = (Tool) foInfo.getToolFromInputExtension("cpp");
		option = tool.getOptionsOfType(IOption.INCLUDE_PATH)[0];

		{
			ArrayList<OptionStringValue> list = new ArrayList<OptionStringValue>(
					Arrays.asList(option.getBasicStringListValueElements()));
			assertTrue(list.remove(new OptionStringValue("${IncludeDefaults}")));
			list.add(0, new OptionStringValue("${IncludeDefaults}"));
			expectedValue = list.toArray(new OptionStringValue[0]);
			option = foInfo.setOption(tool, option, list.toArray(new OptionStringValue[0]));
			value = option.getBasicStringListValueElements();
		}

		expectedEntries = new ICLanguageSettingEntry[] { new CIncludePathEntry("dbg 3/rel/path", 0),
				new CIncludePathEntry("proj/rel/path", 0), new CIncludePathEntry("/abs/path", 0),
				new CIncludePathEntry(platformDependentPath("dbg 3", "c:/abs/path"), 0),
				new CIncludePathEntry("/test_40/dir1/dir2/dir3",
						ICSettingEntry.VALUE_WORKSPACE_PATH/* | ICSettingEntry.RESOLVED*/),
				new CIncludePathEntry("/test_40", ICSettingEntry.VALUE_WORKSPACE_PATH/* | ICSettingEntry.RESOLVED*/),
				new CIncludePathEntry(platformDependentPath("dbg 3", "D:\\docs\\incs"), 0),
				new CIncludePathEntry(platformDependentPath("dbg 3", "E:\\tmp\\w"), 0), };

		entries = ls.getSettingEntries(ICLanguageSettingEntry.INCLUDE_PATH);

		BuildSystemTestHelper.checkDiff(expectedValue, value);
		BuildSystemTestHelper.checkDiff(expectedEntries, entries);

		ls.setSettingEntries(ICLanguageSettingEntry.INCLUDE_PATH, entries);

		assertTrue(option == tool.getOptionsOfType(IOption.INCLUDE_PATH)[0]);
		value = option.getBasicStringListValueElements();

		entries = ls.getSettingEntries(ICLanguageSettingEntry.INCLUDE_PATH);

		BuildSystemTestHelper.checkDiff(expectedValue, value);
		BuildSystemTestHelper.checkDiff(expectedEntries, entries);

		{
			ArrayList<OptionStringValue> list = new ArrayList<OptionStringValue>(
					Arrays.asList(option.getBasicStringListValueElements()));
			assertTrue(list.remove(new OptionStringValue("${IncludeDefaults}")));
			list.add(list.size(), new OptionStringValue("${IncludeDefaults}"));
			expectedValue = list.toArray(new OptionStringValue[0]);
			option = foInfo.setOption(tool, option, list.toArray(new OptionStringValue[0]));
			value = option.getBasicStringListValueElements();
		}

		expectedEntries = new ICLanguageSettingEntry[] { new CIncludePathEntry("dbg 3/rel/path", 0),
				new CIncludePathEntry("proj/rel/path", 0), new CIncludePathEntry("/abs/path", 0),
				new CIncludePathEntry(platformDependentPath("dbg 3", "c:/abs/path"), 0),
				new CIncludePathEntry("/test_40/dir1/dir2/dir3",
						ICSettingEntry.VALUE_WORKSPACE_PATH/* | ICSettingEntry.RESOLVED*/),
				new CIncludePathEntry("/test_40", ICSettingEntry.VALUE_WORKSPACE_PATH/* | ICSettingEntry.RESOLVED*/),
				new CIncludePathEntry(platformDependentPath("dbg 3", "D:\\docs\\incs"), 0),
				new CIncludePathEntry(platformDependentPath("dbg 3", "E:\\tmp\\w"), 0), };

		entries = ls.getSettingEntries(ICLanguageSettingEntry.INCLUDE_PATH);

		BuildSystemTestHelper.checkDiff(expectedValue, value);
		BuildSystemTestHelper.checkDiff(expectedEntries, entries);

		ls.setSettingEntries(ICLanguageSettingEntry.INCLUDE_PATH, entries);

		assertTrue(option == tool.getOptionsOfType(IOption.INCLUDE_PATH)[0]);
		value = option.getBasicStringListValueElements();

		entries = ls.getSettingEntries(ICLanguageSettingEntry.INCLUDE_PATH);

		BuildSystemTestHelper.checkDiff(expectedValue, value);
		BuildSystemTestHelper.checkDiff(expectedEntries, entries);

		//deletion is performed in case if no fail occured
		for (int i = 0; i < projects.length; i++) {
			try {
				ResourceHelper.cleanUp(getName());
				projects[i].delete(true, null);
				assertNull(mngr.getProjectDescription(projects[i]));
				assertNull(mngr.getProjectDescription(projects[i], false));

				assertNull(ManagedBuildManager.getBuildInfo(projects[i]));
			} catch (Exception e) {
				System.err.println("Exception deleting a project " + projects[i].getName());
				System.err.println(e);
			}
		}
	}

	public void test40_pathconverter() throws Exception {
		IProject[] projects = createProjects("test_40_pathconverter", null, null, true);
		ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();

		ICProjectDescription des = mngr.getProjectDescription(projects[0]);
		ICConfigurationDescription cfgDes = des.getConfigurationByName("Test 4.0 ConfigName.Dbg");
		IConfiguration cfg = ManagedBuildManager.getConfigurationForDescription(cfgDes);

		ICFolderDescription foDes = cfgDes.getRootFolderDescription();
		ICLanguageSetting ls = foDes.getLanguageSettingForFile("foo.cpp");
		IFolderInfo foInfo = cfg.getRootFolderInfo();
		Tool tool = (Tool) foInfo.getToolFromInputExtension("cpp");
		IOption option = tool.getOptionsOfType(IOption.INCLUDE_PATH)[0];
		OptionStringValue[] value = option.getBasicStringListValueElements();
		ICLanguageSettingEntry[] entries = ls.getSettingEntries(ICSettingEntry.INCLUDE_PATH);

		OptionStringValue[] expectedValue = new OptionStringValue[] { new OptionStringValue("../rel"),
				new OptionStringValue("/abs"), };

		ICLanguageSettingEntry[] expectedEntries = new ICLanguageSettingEntry[] { new CIncludePathEntry("rel", 0),
				new CIncludePathEntry("/test/abs", 0), };

		BuildSystemTestHelper.checkDiff(expectedValue, value);
		BuildSystemTestHelper.checkDiff(expectedEntries, entries);

		ls.setSettingEntries(ICLanguageSettingEntry.INCLUDE_PATH, entries);
		assertTrue(option == tool.getOptionsOfType(IOption.INCLUDE_PATH)[0]);
		value = option.getBasicStringListValueElements();
		entries = ls.getSettingEntries(ICSettingEntry.INCLUDE_PATH);

		BuildSystemTestHelper.checkDiff(expectedValue, value);
		BuildSystemTestHelper.checkDiff(expectedEntries, entries);

		ArrayList<ICLanguageSettingEntry> list = new ArrayList<ICLanguageSettingEntry>();
		list.addAll(Arrays.asList(entries));
		list.add(new CIncludePathEntry("/test/another/abs", 0));
		expectedEntries = list.toArray(new ICLanguageSettingEntry[0]);

		expectedValue = new OptionStringValue[] { new OptionStringValue("../rel"), new OptionStringValue("/abs"),
				new OptionStringValue("/another/abs"), };

		ls.setSettingEntries(ICLanguageSettingEntry.INCLUDE_PATH, list);

		assertTrue(option == tool.getOptionsOfType(IOption.INCLUDE_PATH)[0]);

		value = option.getBasicStringListValueElements();
		entries = ls.getSettingEntries(ICSettingEntry.INCLUDE_PATH);

		BuildSystemTestHelper.checkDiff(expectedValue, value);
		BuildSystemTestHelper.checkDiff(expectedEntries, entries);

		//testing one-way converter
		ls = foDes.getLanguageSettingForFile("foo.c");
		tool = (Tool) foInfo.getToolFromInputExtension("c");
		option = tool.getOptionsOfType(IOption.INCLUDE_PATH)[0];
		value = option.getBasicStringListValueElements();
		entries = ls.getSettingEntries(ICSettingEntry.INCLUDE_PATH);

		expectedValue = new OptionStringValue[] { new OptionStringValue("../rel"), new OptionStringValue("/abs"), };

		expectedEntries = new ICLanguageSettingEntry[] { new CIncludePathEntry("rel", 0),
				new CIncludePathEntry("/test/abs", 0), };

		BuildSystemTestHelper.checkDiff(expectedValue, value);
		BuildSystemTestHelper.checkDiff(expectedEntries, entries);

		ls.setSettingEntries(ICLanguageSettingEntry.INCLUDE_PATH, entries);
		assertTrue(option == tool.getOptionsOfType(IOption.INCLUDE_PATH)[0]);
		value = option.getBasicStringListValueElements();
		entries = ls.getSettingEntries(ICSettingEntry.INCLUDE_PATH);

		BuildSystemTestHelper.checkDiff(expectedValue, value);
		BuildSystemTestHelper.checkDiff(expectedEntries, entries);

		list = new ArrayList<ICLanguageSettingEntry>();
		list.addAll(Arrays.asList(entries));
		list.add(new CIncludePathEntry("/another/abs", 0));

		expectedEntries = new ICLanguageSettingEntry[] { new CIncludePathEntry("rel", 0),
				new CIncludePathEntry("/test/abs", 0), new CIncludePathEntry("/test/another/abs", 0), };

		expectedValue = new OptionStringValue[] { new OptionStringValue("../rel"), new OptionStringValue("/abs"),
				new OptionStringValue("/another/abs"), };

		ls.setSettingEntries(ICLanguageSettingEntry.INCLUDE_PATH, list);

		assertTrue(option == tool.getOptionsOfType(IOption.INCLUDE_PATH)[0]);

		value = option.getBasicStringListValueElements();
		entries = ls.getSettingEntries(ICSettingEntry.INCLUDE_PATH);

		BuildSystemTestHelper.checkDiff(expectedValue, value);
		BuildSystemTestHelper.checkDiff(expectedEntries, entries);

		//deletion is performed in case if no fail occured
		for (int i = 0; i < projects.length; i++) {
			ResourceHelper.cleanUp(getName());
			projects[i].delete(true, null);
			assertNull(mngr.getProjectDescription(projects[i]));
			assertNull(mngr.getProjectDescription(projects[i], false));

			assertNull(ManagedBuildManager.getBuildInfo(projects[i]));
		}
	}

	private void buildProjects(IProject projects[], String[] files) {
		buildProjectsWorker(projects, files, true);
	}

	private void buildProjectsWorker(IProject projects[], String[] files, boolean compareBenchmark) {
		if (projects == null || projects.length == 0)
			return;

		for (int i = 0; i < projects.length; i++) {
			IProject curProject = projects[i];

			IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(curProject);

			//check whether the managed build info is converted
			boolean isCompatible = true;//UpdateManagedProjectManager.isCompatibleProject(info);
			//assertTrue(isCompatible);

			if (isCompatible) {
				// Build the project in order to generate the makefiles
				try {
					curProject.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
				} catch (CoreException e) {
					fail(e.getStatus().getMessage());
				} catch (OperationCanceledException e) {
					fail("the project \"" + curProject.getName() + "\" build was cancelled, exception message: "
							+ e.getMessage());
				}

				//compare the generated makefiles to their benchmarks
				if (files != null && files.length > 0) {
					if (i == 0) {
						String configName = info.getDefaultConfiguration().getName();
						IPath buildDir = Path.fromOSString(configName);
						if (compareBenchmark) {
							IPath benchmarkLocationBase = resourcesLocation.append(curProject.getName());
							IPath buildLocationBase = curProject.getLocation();
							IPath[] paths = new IPath[files.length];
							for (int ii = 0; ii < files.length; ii++) {
								paths[ii] = buildDir.append(files[ii]);
							}
							ManagedBuildTestHelper.compareBenchmarks(curProject, buildLocationBase, paths,
									benchmarkLocationBase);
						}
					}
				}
			}
		}
	}

	private IProject[] createProjects(String projName, IPath location, String projectTypeId, boolean containsZip) {
		IProject projects[] = createProject(projName, location, projectTypeId, containsZip);
		return projects;
	}

	private IProject[] createProject(String projName, IPath location, String projectTypeId, boolean containsZip) {
		ArrayList<IProject> projectList = null;
		if (containsZip) {
			File testDir = CTestPlugin.getFileInPlugin(new Path("resources/test40Projects/" + projName));
			if (testDir == null) {
				fail("Test project directory " + projName + " is missing.");
				return null;
			}

			File projectZips[] = testDir.listFiles(new FileFilter() {
				@Override
				public boolean accept(File pathname) {
					if (pathname.isDirectory())
						return false;
					return true;
				}
			});

			projectList = new ArrayList<IProject>(projectZips.length);
			for (int i = 0; i < projectZips.length; i++) {
				try {
					String projectName = projectZips[i].getName();
					if (!projectName.endsWith(".zip"))
						continue;

					projectName = projectName.substring(0, projectName.length() - ".zip".length());
					if (projectName.length() == 0)
						continue;
					IProject project = ManagedBuildTestHelper.createProject(projectName, projectZips[i], location,
							projectTypeId);
					if (project != null)
						projectList.add(project);
				} catch (Exception e) {
				}
			}
			if (projectList.size() == 0) {
				fail("No projects found in test project directory " + testDir.getName()
						+ ".  The .zip file may be missing or corrupt.");
				return null;
			}
		} else {
			try {
				IProject project = ManagedBuildTestHelper.createProject(projName, null, location, projectTypeId);
				if (project != null)
					projectList = new ArrayList<IProject>(1);
				projectList.add(project);
			} catch (Exception e) {
			}
		}

		return projectList.toArray(new IProject[projectList.size()]);
	}

}

Back to the top