/** * Returns the set of containers (Project configurations) (project_name;config_id) for the project * descriptions reported as changed by the ICDescriptionDelta * * @param delta * @return String[] of Configuration Reference IDs */ private String[] getContainerIds(ICDescriptionDelta delta) { if (delta == null) return new String[0]; int deltaKind = delta.getDeltaKind(); Set<String> cfgIds = new HashSet<String>(); switch (deltaKind) { case ICDescriptionDelta.ADDED: case ICDescriptionDelta.REMOVED: ICProjectDescription des = (ICProjectDescription) delta.getSetting(); ICConfigurationDescription[] cfgs = des.getConfigurations(); if (cfgs.length != 0) { for (int i = 0; i < cfgs.length; i++) { cfgIds.add(cfgs[i].getId()); } cfgIds.add(ACTIVE_CONFIG_ID); } break; case ICDescriptionDelta.CHANGED: ICDescriptionDelta[] children = delta.getChildren(); collectCfgIds(children, cfgIds); if ((delta.getChangeFlags() & ICDescriptionDelta.ACTIVE_CFG) != 0) cfgIds.add(ACTIVE_CONFIG_ID); break; } String[] ids = new String[cfgIds.size()]; if (ids.length != 0) { String projName = ((ICProjectDescription) delta.getSetting()).getProject().getName(); int i = 0; for (String config : cfgIds) ids[i++] = createId(projName, config); } return ids; }
private void populateConfigurations() { IProject prj = getProject(); // Do nothing in case of Preferences page. if (prj == null) return; // Do not re-read if list already created by another page if (cfgDescs == null) { ICProjectDescription pDesc = CDTPropertyManager.getProjectDescription(this, prj); cfgDescs = (pDesc == null) ? null : pDesc.getConfigurations(); if (cfgDescs == null || cfgDescs.length == 0) return; Arrays.sort(cfgDescs, CDTListComparator.getInstance()); } else { if (cfgDescs.length == 0) return; // just register in CDTPropertyManager; CDTPropertyManager.getProjectDescription(this, prj); } // Do nothing if widget not created yet. if (configSelector == null) { lastSelectedCfg = cfgDescs[getActiveCfgIndex()]; cfgChanged(lastSelectedCfg); return; } // Clear and replace the contents of the selector widget configSelector.removeAll(); for (int i = 0; i < cfgDescs.length; ++i) { String name = cfgDescs[i].getName(); if (cfgDescs[i].isActive()) { name = name + " " + Messages.AbstractPage_16; // $NON-NLS-1$ } configSelector.add(name); } // Ensure that the last selected config is selected by default int cfgIndex = getCfgIndex(lastSelectedCfg); // "All cfgs" - shown if at least 2 cfgs available if (cfgDescs.length > 1) { configSelector.add(Messages.AbstractPage_4); if (multiCfgs == cfgDescs) { cfgIndex = cfgDescs.length; } } // "Multi cfgs" - shown if at least 3 cfgs available if (cfgDescs.length > 2) { configSelector.add(Messages.AbstractPage_5); if (multiCfgs != null && multiCfgs != cfgDescs) { cfgIndex = cfgDescs.length + 1; } } if (cfgIndex < 0) { cfgIndex = getActiveCfgIndex(); } configSelector.select(cfgIndex); handleConfigSelection(); }
@Override public CExternalSetting[] getExternalSettings() { IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(fProjName); if (project.isAccessible()) { ICProjectDescription des = CProjectDescriptionManager.getInstance().getProjectDescription(project, false); if (des != null) { ICConfigurationDescription cfg = fCfgId.length() != 0 ? des.getConfigurationById(fCfgId) : des.getActiveConfiguration(); if (cfg != null) { CExternalSetting[] es; ICExternalSetting[] ies = cfg.getExternalSettings(); if (ies instanceof CExternalSetting[]) es = (CExternalSetting[]) ies; else { es = new CExternalSetting[ies.length]; System.arraycopy(ies, 0, es, 0, es.length); } // Update the cache with the real settings this configuration is exporting cachedSettings.put(fId, es); return es; } } } // If project not yet accessible, just return the previous settings // for the moment. We'll update again when the referenced project reappears if (!cachedSettings.containsKey(fId) && prevSettings.length > 0) cachedSettings.putIfAbsent(fId, prevSettings); if (prevSettings.length == 0 && cachedSettings.containsKey(fId)) return cachedSettings.get(fId); return prevSettings; }
/** @see IncrementalProjectBuilder#build */ @Override protected IProject[] build( int kind, @SuppressWarnings("rawtypes") Map args, IProgressMonitor monitor) throws CoreException { if (DEBUG_EVENTS) { @SuppressWarnings("unchecked") Map<String, String> argsMap = args; printEvent(kind, argsMap); } // If auto discovery is disabled, do nothing // boolean autodiscoveryEnabled; // boolean autodiscoveryEnabled2; // IScannerConfigBuilderInfo2 buildInfo2 = null; // IConfiguration cfg = ScannerConfigUtil.getActiveConfiguration(getProject()); IManagedBuildInfo bInfo = ManagedBuildManager.getBuildInfo(getProject()); if (bInfo != null) { IConfiguration cfgs[] = bInfo.getManagedProject().getConfigurations(); if (cfgs.length != 0) { if (!needAllConfigBuild()) { ICProjectDescription des = CoreModel.getDefault().getProjectDescription(getProject(), false); IConfiguration cfg = null; if (des != null) { ICConfigurationDescription settingCfgDes = des.getDefaultSettingConfiguration(); if (settingCfgDes != null) { for (int i = 0; i < cfgs.length; i++) { if (settingCfgDes.getId().equals(cfgs[i].getId())) { cfg = cfgs[i]; break; } } } } if (cfg != null) { cfgs = new IConfiguration[] {cfg}; } else { cfgs = new IConfiguration[0]; } } int numWork = cfgs.length; if (numWork > 0) { monitor.beginTask( MakeMessages.getString("ScannerConfigBuilder.Invoking_Builder"), numWork); //$NON-NLS-1$ for (int i = 0; i < cfgs.length; i++) { build(cfgs[i], 0, new SubProgressMonitor(monitor, 1)); } } } CfgDiscoveredPathManager.getInstance().updateCoreSettings(getProject(), cfgs); } return getProject().getReferencedProjects(); }
@Override public void handleEvent(CProjectDescriptionEvent event) { // we are only interested in about to apply if (event.getEventType() != CProjectDescriptionEvent.ABOUT_TO_APPLY) return; ICProjectDescription projDesc = event.getNewCProjectDescription(); IEnvironmentVariableManager envManager = CCorePlugin.getDefault().getBuildEnvironmentManager(); IContributedEnvironment contribEnv = envManager.getContributedEnvironment(); if (projDesc.getActiveConfiguration() != null) { IEnvironmentVariable var = contribEnv.getVariable( ArduinoConst.ENV_KEY_JANTJE_PLATFORM_FILE, projDesc.getActiveConfiguration()); if (var != null) { IPath platformPath = new Path(var.getValue()); ArduinoHelpers.setProjectPathVariables( projDesc.getProject(), platformPath.removeLastSegments(1)); ArduinoHelpers.setTheEnvironmentVariables( projDesc.getProject(), projDesc.getActiveConfiguration(), false); try { ArduinoHelpers.addArduinoCodeToProject( projDesc.getProject(), projDesc.getActiveConfiguration()); } catch (CoreException e1) { Common.log( new Status( IStatus.ERROR, ArduinoConst.CORE_PLUGIN_ID, "Error adding the arduino code", e1)); } ArduinoLibraries.reAttachLibrariesToProject(projDesc.getActiveConfiguration()); } } }
private ICConfigurationDescription[] getCfgs(IProject prj) { ICProjectDescription prjd = CoreModel.getDefault().getProjectDescription(prj, false); if (prjd != null) { ICConfigurationDescription[] cfgs = prjd.getConfigurations(); if (cfgs != null) { return cfgs; } } return new ICConfigurationDescription[0]; }
/** * Gets the CDT environment from the CDT project's configuration referenced by the launch * * @since 3.0 */ public static String[] getLaunchEnvironment(ILaunchConfiguration config) throws CoreException { // Get the project String projectName = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, (String) null); if (projectName == null) { return null; } projectName = projectName.trim(); if (projectName.length() == 0) { return null; } IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); if (project == null || !project.isAccessible()) return null; ICProjectDescription projDesc = CoreModel.getDefault().getProjectDescription(project, false); // Not a CDT project? if (projDesc == null) return null; String buildConfigID = config.getAttribute( ICDTLaunchConfigurationConstants.ATTR_PROJECT_BUILD_CONFIG_ID, ""); // $NON-NLS-1$ ICConfigurationDescription cfg = null; if (buildConfigID.length() != 0) cfg = projDesc.getConfigurationById(buildConfigID); // if configuration is null fall-back to active if (cfg == null) cfg = projDesc.getActiveConfiguration(); // Environment variables and inherited vars HashMap<String, String> envMap = new HashMap<String, String>(); IEnvironmentVariable[] vars = CCorePlugin.getDefault().getBuildEnvironmentManager().getVariables(cfg, true); for (IEnvironmentVariable var : vars) envMap.put(var.getName(), var.getValue()); // Add variables from build info ICdtVariable[] build_vars = CCorePlugin.getDefault().getCdtVariableManager().getVariables(cfg); for (ICdtVariable var : build_vars) { try { envMap.put(var.getName(), var.getStringValue()); } catch (CdtVariableException e) { // Some Eclipse dynamic variables can't be resolved dynamically... we don't care. } } // Turn it into an envp format List<String> strings = new ArrayList<String>(envMap.size()); for (Entry<String, String> entry : envMap.entrySet()) { StringBuffer buffer = new StringBuffer(entry.getKey()); buffer.append('=').append(entry.getValue()); strings.add(buffer.toString()); } return strings.toArray(new String[strings.size()]); }
/** Set the program name attributes on the working copy based on the ICElement */ protected void initializeProgramName(ICElement cElement, ILaunchConfigurationWorkingCopy config) { boolean renamed = false; if (!(cElement instanceof IBinary)) { cElement = cElement.getCProject(); } if (cElement instanceof ICProject) { IProject project = cElement.getCProject().getProject(); String name = project.getName(); ICProjectDescription projDes = CCorePlugin.getDefault().getProjectDescription(project); if (projDes != null) { String buildConfigName = projDes.getActiveConfiguration().getName(); name = name + " " + buildConfigName; // $NON-NLS-1$ } name = getLaunchConfigurationDialog().generateName(name); config.rename(name); renamed = true; } IBinary binary = null; if (cElement instanceof ICProject) { IBinary[] bins = getBinaryFiles((ICProject) cElement); if (bins != null && bins.length == 1) { binary = bins[0]; } } else if (cElement instanceof IBinary) { binary = (IBinary) cElement; } if (binary != null) { String path; path = binary.getResource().getProjectRelativePath().toOSString(); config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, path); if (!renamed) { String name = binary.getElementName(); int index = name.lastIndexOf('.'); if (index > 0) { name = name.substring(0, index); } name = getLaunchConfigurationDialog().generateName(name); config.rename(name); renamed = true; } } if (!renamed) { String name = getLaunchConfigurationDialog().generateName(cElement.getCProject().getElementName()); config.rename(name); } }
public void storeMappings(IProject project, ProjectLanguageConfiguration config) throws CoreException { ICProjectDescription descriptor = getProjectDescription(project, true); ICStorageElement rootElement = descriptor.getStorage(LANGUAGE_MAPPING_ID, true); // clear all children and settings rootElement.clear(); ICStorageElement projectMappings = rootElement.createChild(PROJECT_MAPPINGS); addProjectContentTypeMappings(config.getContentTypeMappings(), projectMappings); addFileMappings(config.getFileMappings(), projectMappings); CCorePlugin.getDefault().setProjectDescription(project, descriptor); }
/** Get source entries for default setting configuration (i.e. configuration shown in UI). */ private static ICSourceEntry[] getSourceEntries(IProject project) { ICProjectDescriptionManager mgr = CCorePlugin.getDefault().getProjectDescriptionManager(); ICProjectDescription prjDescription = mgr.getProjectDescription(project, false); if (prjDescription != null) { ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); if (cfgDescription != null) { ICSourceEntry[] srcEntries = cfgDescription.getResolvedSourceEntries(); return srcEntries; } } return new ICSourceEntry[0]; }
/** * Synchronize the current set of configurations for the project with the Autotools saved * configuration data. This is required when configuration management occurs outside of the * Autotools Configure Settings page in the Property menu. * * @param project to synchronize configurations for */ public synchronized void syncConfigurations(IProject project) { setSyncing(true); clearTmpConfigurations(project); ICProjectDescription pd = CoreModel.getDefault().getProjectDescription(project); ICConfigurationDescription[] cfgs = pd.getConfigurations(); Map<String, IAConfiguration> newCfgList = new HashMap<>(); for (int i = 0; i < cfgs.length; ++i) { cfgs[i].getConfigurationData(); IAConfiguration acfg = getTmpConfiguration(project, cfgs[i]); newCfgList.put(cfgs[i].getId(), acfg); } setSyncing(false); clearTmpConfigurations(project); replaceProjectConfigurations(project, newCfgList); }
@Override public ICConfigurationDescription resolveSelectedConfiguration() { ICConfigurationDescription result = null; IProject project = resolveProject(); if (project != null) { ICProjectDescription desc = CoreModel.getDefault().getProjectDescription(project); if (desc != null) { result = desc.getConfigurationById(getSelectedConfigurationID()); } } return result; }
public ProjectLanguageConfiguration decodeMappings(IProject project) throws CoreException { ProjectLanguageConfiguration config = new ProjectLanguageConfiguration(); ICProjectDescription descriptor = getProjectDescription(project, false); if (descriptor != null) { ICStorageElement rootElement = descriptor.getStorage(LANGUAGE_MAPPING_ID, false); if (rootElement != null) { ICStorageElement[] mappingElements = rootElement.getChildrenByName(PROJECT_MAPPINGS); if (mappingElements.length > 0) { ICStorageElement element = mappingElements[0]; config.setContentTypeMappings(decodeProjectContentTypeMappings(element)); config.setFileMappings(decodeFileMappings(element)); } } } return config; }
@Override public Collection<ICConfigurationDescription> resolveConfigurations() { ICConfigurationDescription[] result = null; IProject project = resolveProject(); if (project != null) { ICProjectDescription desc = CoreModel.getDefault().getProjectDescription(project); if (desc != null) { result = desc.getConfigurations(); } } return (result == null) ? Collections.<ICConfigurationDescription>emptyList() : Arrays.asList(result); }
private boolean isIndexerAffected() { ICProjectDescription desc = CoreModel.getDefault().getProjectDescription(getProject(), false); if (desc == null || desc.isCdtProjectCreating()) return false; Iterator<InternalTab> it = itabs.iterator(); while (it.hasNext()) { InternalTab tab = it.next(); if (tab != null) { ICPropertyTab tabtab = tab.tab; if (tabtab instanceof AbstractCPropertyTab && ((AbstractCPropertyTab) tabtab).isIndexerAffected()) { return true; } } } return false; }
@Override public void activate() { ICConfigurationDescription config = resolveSelectedConfiguration(); if (config != null) { ICProjectDescription desc = config.getProjectDescription(); if (desc.getActiveConfiguration() != config) { try { IProject project = desc.getProject(); desc.setActiveConfiguration(config); CoreModel.getDefault().setProjectDescription(project, desc); } catch (CoreException e) { CUIPlugin.log(e); } } } }
private Preferences getProjectNode(ICProjectDescription projDes) { if (projDes == null) return null; IProject project = projDes.getProject(); if (!project.exists()) return null; Preferences prefNode = new ProjectScope(project).getNode(CCorePlugin.PLUGIN_ID); if (prefNode == null) return null; return prefNode.node(NODENAME); }
/** * Creates CDT project in a specific path in workspace adding specified configurations and opens * it. * * @param projectName - project name. * @param pathInWorkspace - path relative to workspace root. * @param configurationIds - array of configuration IDs. * @return - new {@link IProject}. * @throws CoreException - if the project can't be created. * @throws OperationCanceledException... */ public static IProject createCDTProject( String projectName, String pathInWorkspace, String[] configurationIds) throws OperationCanceledException, CoreException { CCorePlugin cdtCorePlugin = CCorePlugin.getDefault(); IWorkspace workspace = ResourcesPlugin.getWorkspace(); IWorkspaceRoot root = workspace.getRoot(); IProject project = root.getProject(projectName); IndexerPreferences.set(project, IndexerPreferences.KEY_INDEXER_ID, IPDOMManager.ID_NO_INDEXER); resourcesCreated.add(project); IProjectDescription prjDescription = workspace.newProjectDescription(projectName); if (pathInWorkspace != null) { IPath absoluteLocation = root.getLocation().append(pathInWorkspace); prjDescription.setLocation(absoluteLocation); } if (configurationIds != null && configurationIds.length > 0) { ICProjectDescriptionManager prjDescManager = cdtCorePlugin.getProjectDescriptionManager(); project.create(NULL_MONITOR); project.open(NULL_MONITOR); ICProjectDescription icPrjDescription = prjDescManager.createProjectDescription(project, false); ICConfigurationDescription baseConfiguration = cdtCorePlugin.getPreferenceConfiguration(TestCfgDataProvider.PROVIDER_ID); for (String cfgId : configurationIds) { icPrjDescription.createConfiguration(cfgId, cfgId + " Name", baseConfiguration); } prjDescManager.setProjectDescription(project, icPrjDescription); } project = cdtCorePlugin.createCDTProject(prjDescription, project, NULL_MONITOR); waitForProjectRefreshToFinish(); Assert.assertNotNull(project); project.open(null); Assert.assertTrue(project.isOpen()); return project; }
public void storeProjectEnvironment(ICProjectDescription des, boolean force) { ICConfigurationDescription cfgs[] = des.getConfigurations(); for (ICConfigurationDescription cfg : cfgs) { storeEnvironment(cfg, force, false); } Preferences node = getProjectNode(des); try { node.flush(); } catch (BackingStoreException e) { } }
/** @deprecated Not intended to be public - do not use */ @Deprecated public String getDefaultDebugger(final ILaunchConfiguration config) throws CoreException { // Mostly from CDebbuggerTab String defaultDebugger = null; String projectName = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""); if (projectName.length() > 0) { IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); ICProjectDescription projDesc = CoreModel.getDefault().getProjectDescription(project); if (projDesc != null) { ICConfigurationDescription configDesc = projDesc.getActiveConfiguration(); String configId = configDesc.getId(); ICDebugConfiguration[] debugConfigs = CDebugCorePlugin.getDefault().getActiveDebugConfigurations(); outer: for (int i = 0; i < debugConfigs.length; ++i) { ICDebugConfiguration debugConfig = debugConfigs[i]; String[] patterns = debugConfig.getSupportedBuildConfigPatterns(); if (patterns != null) { for (int j = 0; j < patterns.length; ++j) { if (configId.matches(patterns[j])) { defaultDebugger = debugConfig.getID(); break outer; } } } } } } if (defaultDebugger == null) { ICDebugConfiguration dc = CDebugCorePlugin.getDefault().getDefaultDebugConfiguration(); if (dc != null) { defaultDebugger = dc.getID(); } } return defaultDebugger; }
@Override public void handleEvent(ILanguageSettingsChangeEvent event) { IWorkspaceRoot wspRoot = ResourcesPlugin.getWorkspace().getRoot(); IProject project = wspRoot.getProject(event.getProjectName()); if (project != null) { ICProjectDescription prjDescription = CCorePlugin.getDefault().getProjectDescription(project, false); if (prjDescription != null) { // cfgDescription being indexed ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); String indexedId = cfgDescription.getId(); for (String id : event.getConfigurationDescriptionIds()) { if (id.equals(indexedId)) { reindex(id, event); return; } } } } }
private void initLanguageSettings(IProject project) throws CoreException { ICProjectDescription prjDesc = CoreModel.getDefault().getProjectDescription(project); if (prjDesc == null) throw new IllegalArgumentException("No valid CDT project given!"); ICConfigurationDescription activeConfig = prjDesc.getActiveConfiguration(); if (activeConfig == null) throw new IllegalArgumentException("No valid active configuration found!"); String[] extensionsToInclude = getExtensionsToInclude(project); ICFolderDescription folderDesc = activeConfig.getRootFolderDescription(); for (ICLanguageSetting ls : folderDesc.getLanguageSettings()) { String[] extensions = ls.getSourceExtensions(); Arrays.sort(extensions); if (Arrays.equals(extensionsToInclude, extensions)) { languageSettings.add(ls); } } }
/** * Searches in the prj for the config description with the same ID as for given cfg. If there's no * such cfgd, it will be created. * * @param prj - project description where we'll search (or create) config description * @param cfg - config description belonging to another project description, it is a sample for * search and base for possile creation of resulting configuration description. * @return the configuration description (found or created) or null in case of error */ private ICConfigurationDescription findCfg( ICProjectDescription prj, ICConfigurationDescription cfg) { String id = cfg.getId(); // find config with the same ID as original one ICConfigurationDescription c = prj.getConfigurationById(id); // if there's no cfg found, try to create it if (c == null) { try { c = prj.createConfiguration(id, cfg.getName(), cfg); c.setDescription(cfg.getDescription()); } catch (CoreException e) { /* do nothing: c is already null */ } } // if creation failed, report an error and return null if (c == null) { MessageBox mb = new MessageBox(getShell()); mb.setMessage(Messages.AbstractPage_3); mb.open(); } return c; }
public void checkInexistentConfigurations(ICProjectDescription projDes) { Preferences prefNode = getConfigurationNode(projDes); if (prefNode == null) return; try { String ids[] = prefNode.keys(); boolean found = false; for (String id : ids) { if (projDes.getConfigurationById(id) == null) { prefNode.remove(id); found = true; } } if (found) prefNode.flush(); } catch (BackingStoreException e) { } }
/** Returns configuration descriptions for given project */ @Override public ICConfigurationDescription[] getCfgsReadOnly(IProject p) { ICProjectDescription prjd = CoreModel.getDefault().getProjectDescription(p, false); if (prjd != null) return prjd.getConfigurations(); return null; }
/** * Checks whether project is new CDT project * * @param p - project to check * @returns true if it's new-style project. */ public static boolean isCDTPrj(IProject p) { ICProjectDescription prjd = CoreModel.getDefault().getProjectDescription(p, false); if (prjd == null) return false; ICConfigurationDescription[] cfgs = prjd.getConfigurations(); return (cfgs != null && cfgs.length > 0); }
public void testEnablement_Bug250686() throws Exception { final String testName = getName(); IProject project = ManagedBuildTestHelper.createProject(testName, PROJECT_TYPE); assertNotNull(project); IFolder folder = ManagedBuildTestHelper.createFolder(project, "Folder"); assertNotNull(folder); IFile file = ManagedBuildTestHelper.createFile(project, "Folder/file.c"); assertNotNull(file); ICProjectDescription prjDescription = CoreModel.getDefault().getProjectDescription(project); prjDescription.getConfigurationByName(CFG_NAME); IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project); IConfiguration cfg = info.getManagedProject().getConfigurations()[0]; assertNotNull(cfg); assertEquals(CFG_NAME, cfg.getName()); { // Round 1. Test root folder option IFolderInfo rootFolderInfo = cfg.getRootFolderInfo(); assertNotNull(rootFolderInfo); IOption option = getOptionForFolder(rootFolderInfo, TOOL_ID, OPTION_ID); assertNotNull(option); assertEquals(OPTION_VALUE_ENABLEMENT, option.getValue()); assertFalse(option.isExtensionElement()); } { // Round 1. Test subfolder option IResourceInfo folderInfo = cfg.getResourceInfo(folder.getFullPath(), false); assertNotNull(folderInfo); assertTrue(folderInfo instanceof IFolderInfo); IOption option = getOptionForFolder((IFolderInfo) folderInfo, TOOL_ID, OPTION_ID); assertNotNull(option); assertEquals(OPTION_VALUE_ENABLEMENT, option.getValue()); assertFalse(option.isExtensionElement()); } { // Round 1. Test file option IResourceInfo fileInfo = cfg.getResourceInfo(file.getFullPath(), false); assertNotNull(fileInfo); assertTrue(fileInfo instanceof IFolderInfo); // Option is taken from root folder here IOption option = getOptionForFolder((IFolderInfo) fileInfo, TOOL_ID, OPTION_ID); assertNotNull(option); assertEquals(OPTION_VALUE_ENABLEMENT, option.getValue()); assertFalse(option.isExtensionElement()); } { // Round 2. Override the value of the option for the root folder IFolderInfo rootFolderInfo = cfg.getRootFolderInfo(); ITool[] tools = rootFolderInfo.getToolsBySuperClassId(TOOL_ID); assertEquals(1, tools.length); IOption option = getOptionForFolder(rootFolderInfo, TOOL_ID, OPTION_ID); rootFolderInfo.setOption(tools[0], option, OPTION_VALUE_ROOT); } { // Round 2. Test root folder option IFolderInfo rootFolderInfo = cfg.getRootFolderInfo(); assertNotNull(rootFolderInfo); IOption option = getOptionForFolder(rootFolderInfo, TOOL_ID, OPTION_ID); assertNotNull(option); assertEquals(OPTION_VALUE_ROOT, option.getValue()); assertFalse(option.isExtensionElement()); } { // Round 2. Test subfolder option IResourceInfo folderInfo = cfg.getResourceInfo(folder.getFullPath(), false); assertNotNull(folderInfo); assertTrue(folderInfo instanceof IFolderInfo); IOption option = getOptionForFolder((IFolderInfo) folderInfo, TOOL_ID, OPTION_ID); assertNotNull(option); assertEquals(OPTION_VALUE_ROOT, option.getValue()); assertFalse(option.isExtensionElement()); } { // Round 2. Test file option IResourceInfo fileInfo = cfg.getResourceInfo(file.getFullPath(), false); assertNotNull(fileInfo); assertTrue(fileInfo instanceof IFolderInfo); // Option is taken from root folder here IOption option = getOptionForFolder((IFolderInfo) fileInfo, TOOL_ID, OPTION_ID); assertNotNull(option); assertEquals(OPTION_VALUE_ROOT, option.getValue()); assertFalse(option.isExtensionElement()); } { // Round 3. Override the value of the option for the subfolder IFolderInfo folderInfo = cfg.createFolderInfo(folder.getFullPath()); assertNotNull(folderInfo); ITool[] tools = folderInfo.getToolsBySuperClassId(TOOL_ID); assertEquals(1, tools.length); IOption option = getOptionForFolder(folderInfo, TOOL_ID, OPTION_ID); assertNotNull(option); assertEquals(OPTION_VALUE_ROOT, option.getValue()); assertFalse(option.isExtensionElement()); folderInfo.setOption(tools[0], option, OPTION_VALUE_FOLDER); } { // Round 3. Test root folder option IFolderInfo rootFolderInfo = cfg.getRootFolderInfo(); assertNotNull(rootFolderInfo); IOption option = getOptionForFolder(rootFolderInfo, TOOL_ID, OPTION_ID); assertNotNull(option); assertEquals(OPTION_VALUE_ROOT, option.getValue()); assertFalse(option.isExtensionElement()); } { // Round 3. Test subfolder option IResourceInfo folderInfo = cfg.getResourceInfo(folder.getFullPath(), false); assertNotNull(folderInfo); assertTrue(folderInfo instanceof IFolderInfo); IOption option = getOptionForFolder((IFolderInfo) folderInfo, TOOL_ID, OPTION_ID); assertNotNull(option); assertEquals(OPTION_VALUE_FOLDER, option.getValue()); assertFalse(option.isExtensionElement()); } { // Round 3. Test file option IResourceInfo fileInfo = cfg.getResourceInfo(file.getFullPath(), false); assertNotNull(fileInfo); assertTrue(fileInfo instanceof IFolderInfo); // Option is taken from parent folder here IOption option = getOptionForFolder((IFolderInfo) fileInfo, TOOL_ID, OPTION_ID); assertNotNull(option); assertEquals(OPTION_VALUE_FOLDER, option.getValue()); assertFalse(option.isExtensionElement()); } { // Round 4. Override the value of the option for the file IFileInfo fileInfo = cfg.createFileInfo(file.getFullPath()); assertNotNull(fileInfo); ITool[] tools = fileInfo.getTools(); assertEquals(1, tools.length); ITool tool = tools[0]; assertNotNull(tool); IOption option = getOptionForFile(fileInfo, OPTION_ID); assertNotNull(option); assertEquals(OPTION_VALUE_FOLDER, option.getValue()); assertFalse(option.isExtensionElement()); fileInfo.setOption(tool, option, OPTION_VALUE_FILE); } { // Round 4. Test root folder option IFolderInfo rootFolderInfo = cfg.getRootFolderInfo(); assertNotNull(rootFolderInfo); IOption option = getOptionForFolder(rootFolderInfo, TOOL_ID, OPTION_ID); assertNotNull(option); assertEquals(OPTION_VALUE_ROOT, option.getValue()); assertFalse(option.isExtensionElement()); } { // Round 4. Test subfolder option IResourceInfo folderInfo = cfg.getResourceInfo(folder.getFullPath(), false); assertNotNull(folderInfo); assertTrue(folderInfo instanceof IFolderInfo); IOption option = getOptionForFolder((IFolderInfo) folderInfo, TOOL_ID, OPTION_ID); assertNotNull(option); assertEquals(OPTION_VALUE_FOLDER, option.getValue()); assertFalse(option.isExtensionElement()); } { // Round 4. Test file option IResourceInfo fileInfo = cfg.getResourceInfo(file.getFullPath(), false); assertNotNull(fileInfo); assertTrue(fileInfo instanceof IFileInfo); IOption option = getOptionForFile((IFileInfo) fileInfo, OPTION_ID); assertNotNull(option); assertEquals(OPTION_VALUE_FILE, option.getValue()); assertFalse(option.isExtensionElement()); } ManagedBuildTestHelper.removeProject(testName); }
/** The same code used to perform OK and Apply */ private boolean performSave(int mode) { final int finalMode = mode; if (noContentOnPage || !displayedConfig) return true; if ((mode == SAVE_MODE_OK || mode == SAVE_MODE_APPLYOK) && CDTPropertyManager.isSaveDone()) return true; // do not duplicate final boolean needs = (mode != SAVE_MODE_OK); final ICProjectDescription local_prjd = needs ? CoreModel.getDefault().getProjectDescription(getProject()) : null; ICResourceDescription lc = null; if (needs) { if (isMultiCfg()) { ICResourceDescription[] rds = (ICResourceDescription[]) ((ICMultiItemsHolder) resd).getItems(); for (int i = 0; i < rds.length; i++) { ICConfigurationDescription c = local_prjd.getConfigurationById(rds[i].getConfiguration().getId()); rds[i] = getResDesc(c); } lc = MultiItemsHolder.createRDescription(rds); } else { ICConfigurationDescription c = findCfg(local_prjd, resd.getConfiguration()); if (c == null) return false; // cannot save: no cfg found lc = getResDesc(c); } } final ICResourceDescription local_cfgd = lc; final boolean rebuildIndex = isIndexerAffected(); IRunnableWithProgress runnable = new IRunnableWithProgress() { private void sendOK() { for (int j = 0; j < CDTPropertyManager.getPagesCount(); j++) { Object p = CDTPropertyManager.getPage(j); if (p != null && p instanceof AbstractPage) { AbstractPage ap = (AbstractPage) p; if (ap.displayedConfig) ap.forEach(ICPropertyTab.OK, null); } } } @Override public void run(IProgressMonitor monitor) { // ask all tabs to store changes in cfg switch (finalMode) { case SAVE_MODE_APPLYOK: sendOK(); ICConfigurationDescription[] olds = CDTPropertyManager.getProjectDescription(AbstractPage.this, getProject()) .getConfigurations(); for (ICConfigurationDescription old : olds) { resd = getResDesc(old); ICResourceDescription r = getResDesc(local_prjd.getConfigurationById(old.getId())); for (int j = 0; j < CDTPropertyManager.getPagesCount(); j++) { Object p = CDTPropertyManager.getPage(j); if (p != null && p instanceof AbstractPage) { AbstractPage ap = (AbstractPage) p; if (ap.displayedConfig) { ap.forEach(ICPropertyTab.UPDATE, resd); ap.forEach(ICPropertyTab.APPLY, r); } } } } break; case SAVE_MODE_APPLY: forEach(ICPropertyTab.APPLY, local_cfgd); break; case SAVE_MODE_OK: sendOK(); break; } // end switch try { if (needs) // CoreModel.getDefault().setProjectDescription(getProject(), local_prjd); else CDTPropertyManager.performOk(AbstractPage.this); } catch (CoreException e) { CUIPlugin.logError(Messages.AbstractPage_11 + e.getLocalizedMessage()); } updateViews(internalElement); } }; IRunnableWithProgress op = new WorkspaceModifyDelegatingOperation(runnable); try { PlatformUI.getWorkbench() .getProgressService() .runInUI( new ProgressMonitorDialog(getShell()), op, ResourcesPlugin.getWorkspace().getRoot()); } catch (InvocationTargetException e) { Throwable e1 = e.getTargetException(); CUIPlugin.errorDialog(getShell(), Messages.AbstractPage_8, Messages.AbstractPage_9, e1, true); return false; } catch (InterruptedException e) { // IProgressService.runInUI(...) misuses this exception to signal that the operation was // canceled. return false; } if (rebuildIndex) rebuildIndex(); return true; }