Bug 582220 - [Designer] JDT and CDT project creation require UI

- Fix multiple issues:
  - Only look for "supported" project types (pt.isSupported)
  - Check whether toolchain is for current platform (ManagedBuildManager.isPlatformOk)
  - Set artifact name

Change-Id: I976a778c47d7bc5bc23d29c545145abc266bc674
Signed-off-by: aradermache <ansgar.radermacher@cea.fr>
diff --git a/plugins/languages/cpp/org.eclipse.papyrus.designer.languages.cpp.cdt.project/src/org/eclipse/papyrus/designer/languages/cpp/cdt/project/C_CppProjectSupportNoUI.java b/plugins/languages/cpp/org.eclipse.papyrus.designer.languages.cpp.cdt.project/src/org/eclipse/papyrus/designer/languages/cpp/cdt/project/C_CppProjectSupportNoUI.java
index 5a1e4ce..32de063 100644
--- a/plugins/languages/cpp/org.eclipse.papyrus.designer.languages.cpp.cdt.project/src/org/eclipse/papyrus/designer/languages/cpp/cdt/project/C_CppProjectSupportNoUI.java
+++ b/plugins/languages/cpp/org.eclipse.papyrus.designer.languages.cpp.cdt.project/src/org/eclipse/papyrus/designer/languages/cpp/cdt/project/C_CppProjectSupportNoUI.java
@@ -16,7 +16,6 @@
 import org.eclipse.cdt.core.model.CoreModel;
 import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager;
 import org.eclipse.cdt.managedbuilder.buildproperties.IBuildPropertyValue;
-import org.eclipse.cdt.managedbuilder.core.IConfiguration;
 import org.eclipse.cdt.managedbuilder.core.IProjectType;
 import org.eclipse.cdt.managedbuilder.core.IToolChain;
 import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
@@ -86,8 +85,9 @@
 	}
 
 	/**
-	 * Basic configuration of a CDT project with managed builds created from type
-	 * map
+	 * Basic configuration of a CDT project with managed builds created from type map.
+	 * The function uses the first (supported) tool-chain for the current platform that
+	 * produces an executable.
 	 * 
 	 * @throws CoreException
 	 */
@@ -98,29 +98,40 @@
 		if (cdesc == null) {
 			cdesc = mngr.createProjectDescription(project, true);
 		}
+
 		SortedMap<String, IProjectType> typeMap = ManagedBuildManager.getExtensionProjectTypeMap();
 		for (Map.Entry<String, IProjectType> e : typeMap.entrySet()) {
 			IProjectType pt = e.getValue();
 			IBuildPropertyValue type = pt.getBuildArtefactType();
-			if (!type.getName().equals(EXECUTABLE)) {
-				// only look for executable builds
-				break;
+			// always only check supported toolchains (might change, if running in docker?)
+			boolean isValid = type.getName().equals(EXECUTABLE) && pt.isSupported()
+					&& !pt.isAbstract() && !pt.isSystemObject();
+			if (!isValid) {
+				continue;
 			}
 			IToolChain[] tcs = ManagedBuildManager.getExtensionToolChains(pt);
 
-			if (tcs.length > 0) {
-				var cfgs = ManagedBuildManager.getExtensionConfigurations(tcs[0], pt);
-				if (cfgs.length > 0) {
-					IConfiguration firstCF = cfgs[0];
+			for (IToolChain tc : tcs) {
+				if (ManagedBuildManager.isPlatformOk(tc)) {
+					var cfgs = ManagedBuildManager.getExtensionConfigurations(tc, pt);
 					ManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project);
-					ManagedProject mProj = new ManagedProject(project, firstCF.getProjectType());
+					ManagedProject mProj = new ManagedProject(project, pt);
 					info.setManagedProject(mProj);
-					info.setDefaultConfiguration(firstCF);
+					// typically debug and release configurations
+					boolean firstCF = true;
 					for (var cf : cfgs) {
-						// typically debug and release configurations
+						if (firstCF) {
+							firstCF = false;
+							info.setDefaultConfiguration(cf);
+						}
+						// set artifact name (otherwise build does not run)
+						cf.setArtifactName(mProj.getDefaultArtifactName());
 						ManagedBuildManager.createConfigurationForProject(cdesc, mProj, cf, ManagedBuildManager.CFG_DATA_PROVIDER_ID);
 					}
+					// a tool-chain for the current platform has been added, don't check further
+					break;
 				}
+
 			}
 		}
 		mngr.setProjectDescription(project, cdesc, true, null);