From 0f82f86fa935910c8bd5feeca0afb9566ceb39da Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Thu, 3 Sep 2009 17:50:32 +0000 Subject: [PATCH] bug 226419: [Scanner Discovery] "Other toolchain" projects attempt scanner config discovery --- .../ScannerConfigDiscoveryTests.java | 12 ++--- .../ScannerConfigProfileTests.java | 2 +- .../DiscoveredPathInitializer.java | 6 ++- .../ScannerConfigProfileManager.java | 7 ++- .../CfgScannerConfigProfileManager.java | 3 +- .../ui/properties/DiscoveryTab.java | 52 ++++++++++++------- 6 files changed, 51 insertions(+), 31 deletions(-) diff --git a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/ScannerConfigDiscoveryTests.java b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/ScannerConfigDiscoveryTests.java index 25910b580fa..caf6852f8c5 100644 --- a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/ScannerConfigDiscoveryTests.java +++ b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/ScannerConfigDiscoveryTests.java @@ -71,9 +71,9 @@ public class ScannerConfigDiscoveryTests extends BaseTestCase { getScannerInformation(fCFile); assertNotNull(scInfo); String[] includes = scInfo.getIncludePaths(); - assertTrue(includes.length > 0); - Map symbols = scInfo.getDefinedSymbols(); - assertFalse(symbols.isEmpty()); + assertTrue(includes.length == 0); + Map symbols = scInfo.getDefinedSymbols(); + assertTrue(symbols.isEmpty()); } public void testGetCCCompilerBuiltins() throws CoreException { @@ -86,9 +86,9 @@ public class ScannerConfigDiscoveryTests extends BaseTestCase { getScannerInformation(fCFile); assertNotNull(scInfo); String[] includes = scInfo.getIncludePaths(); - assertTrue(includes.length > 0); - Map symbols = scInfo.getDefinedSymbols(); - assertFalse(symbols.isEmpty()); + assertTrue(includes.length == 0); + Map symbols = scInfo.getDefinedSymbols(); + assertTrue(symbols.isEmpty()); } } diff --git a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/ScannerConfigProfileTests.java b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/ScannerConfigProfileTests.java index acde3fc9888..cea4e8a06aa 100644 --- a/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/ScannerConfigProfileTests.java +++ b/build/org.eclipse.cdt.make.core.tests/src/org/eclipse/cdt/make/scannerdiscovery/ScannerConfigProfileTests.java @@ -50,7 +50,7 @@ public class ScannerConfigProfileTests extends BaseTestCase { */ public void testBasicScannerConfigProfile() throws CoreException { // Add a scanner config profile to the project - IScannerConfigBuilderInfo2 scProjInfo = ScannerConfigProfileManager.createScannerConfigBuildInfo2(fCProject, ScannerConfigProfileManager.DEFAULT_SI_PROFILE_ID); + IScannerConfigBuilderInfo2 scProjInfo = ScannerConfigProfileManager.createScannerConfigBuildInfo2(fCProject, ScannerConfigProfileManager.PER_PROJECT_PROFILE_ID); // Save scProjInfo.save(); diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/DiscoveredPathInitializer.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/DiscoveredPathInitializer.java index a640408c788..4b67a08bd57 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/DiscoveredPathInitializer.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/DiscoveredPathInitializer.java @@ -30,8 +30,12 @@ public class DiscoveredPathInitializer extends PathEntryContainerInitializer { public void initialize(IPath containerPath, ICProject cProject) throws CoreException { IProject project = cProject.getProject(); IScannerConfigBuilderInfo2 buildInfo = ScannerConfigProfileManager.createScannerConfigBuildInfo2(project); + String selectedProfileId = buildInfo.getSelectedProfileId(); + if (ScannerConfigProfileManager.NULL_PROFILE_ID.equals(selectedProfileId)) + return; + ScannerConfigScope profileScope = ScannerConfigProfileManager.getInstance(). - getSCProfileConfiguration(buildInfo.getSelectedProfileId()).getProfileScope(); + getSCProfileConfiguration(selectedProfileId).getProfileScope(); if (ScannerConfigScope.PROJECT_SCOPE.equals(profileScope)) { CoreModel.setPathEntryContainer(new ICProject[]{cProject}, new DiscoveredPathContainer(project), null); } diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig2/ScannerConfigProfileManager.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig2/ScannerConfigProfileManager.java index 8ccb4c7eee7..9f7036eb2fd 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig2/ScannerConfigProfileManager.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig2/ScannerConfigProfileManager.java @@ -35,8 +35,8 @@ import org.eclipse.core.runtime.Preferences; public final class ScannerConfigProfileManager { public static final String SI_PROFILE_SIMPLE_ID = "ScannerConfigurationDiscoveryProfile"; //$NON-NLS-1$ public static final String PER_PROJECT_PROFILE_ID = MakeCorePlugin.getUniqueIdentifier() + ".GCCStandardMakePerProjectProfile"; //$NON-NLS-1$ - public static final String DEFAULT_SI_PROFILE_ID = PER_PROJECT_PROFILE_ID; - public static final String NULL_PROFILE_ID = "";//$NON-NLS-1$ + public static final String NULL_PROFILE_ID = "";//$NON-NLS-1$ + public static final String DEFAULT_SI_PROFILE_ID = NULL_PROFILE_ID; private final Map> projectToProfileInstanceMap; private List profileIds; @@ -171,9 +171,8 @@ public final class ScannerConfigProfileManager { } /** - * returns the list of profile IDs supported for this context * @param context - * @return + * @return the list of profile IDs supported for this context */ public List getProfileIds(InfoContext context){ if(context.isDefaultContext() || context.getProject() == null) diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/build/internal/core/scannerconfig2/CfgScannerConfigProfileManager.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/build/internal/core/scannerconfig2/CfgScannerConfigProfileManager.java index 6061b6d12ea..5b8bf3996e6 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/build/internal/core/scannerconfig2/CfgScannerConfigProfileManager.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/build/internal/core/scannerconfig2/CfgScannerConfigProfileManager.java @@ -29,7 +29,8 @@ public class CfgScannerConfigProfileManager { public static boolean isPerFileProfile(String profileId){ ScannerConfigProfile profile = ScannerConfigProfileManager.getInstance().getSCProfileConfiguration(profileId); - return profile.getProfileScope().equals(ScannerConfigScope.FILE_SCOPE); + ScannerConfigScope scope = profile.getProfileScope(); + return scope!=null && scope.equals(ScannerConfigScope.FILE_SCOPE); } public static InfoContext createDefaultContext(IProject project){ diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/DiscoveryTab.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/DiscoveryTab.java index b019f46ab67..ee22002ccd1 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/DiscoveryTab.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/DiscoveryTab.java @@ -33,6 +33,7 @@ import org.eclipse.cdt.managedbuilder.core.IConfiguration; import org.eclipse.cdt.managedbuilder.core.IInputType; import org.eclipse.cdt.managedbuilder.core.IResourceInfo; import org.eclipse.cdt.managedbuilder.core.ITool; +import org.eclipse.cdt.managedbuilder.core.IToolChain; import org.eclipse.cdt.managedbuilder.internal.core.InputType; import org.eclipse.cdt.managedbuilder.internal.core.Tool; import org.eclipse.cdt.ui.CUIPlugin; @@ -67,6 +68,7 @@ public class DiscoveryTab extends AbstractCBuildPropertyTab implements IBuildInf @Deprecated protected static final String PREFIX = "ScannerConfigOptionsDialog"; //$NON-NLS-1$ + private static final String MAKEFILE_PROJECT_TOOLCHAIN_ID = "org.eclipse.cdt.build.core.prefbase.toolchain"; //$NON-NLS-1$ private static final String NAMESPACE = "org.eclipse.cdt.make.ui"; //$NON-NLS-1$ private static final String POINT = "DiscoveryProfilePage"; //$NON-NLS-1$ private static final String PROFILE_PAGE = "profilePage"; //$NON-NLS-1$ @@ -175,10 +177,14 @@ public class DiscoveryTab extends AbstractCBuildPropertyTab implements IBuildInf autoDiscoveryCheckBox.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - buildInfo.setAutoDiscoveryEnabled(autoDiscoveryCheckBox.getSelection()); enableAllControls(); - if (autoDiscoveryCheckBox.getSelection()) + boolean isSCDEnabled = autoDiscoveryCheckBox.getSelection(); + buildInfo.setAutoDiscoveryEnabled(isSCDEnabled); + if (isSCDEnabled) { + String id = visibleProfilesList.get(profileComboBox.getSelectionIndex()); + buildInfo.setSelectedProfileId(id); handleDiscoveryProfileChanged(); + } } }); reportProblemsCheckBox = setupCheck(autoDiscoveryGroup, @@ -319,6 +325,16 @@ public class DiscoveryTab extends AbstractCBuildPropertyTab implements IBuildInf return false; } + /** + * @param toolchain to check + * @return if this toolchain is a toolchain created by Makefile project "Other Toolchain". + * Note that name of this toolchain set to "No ToolChain" in plugin.xml. + */ + private boolean isMakefileProjectToolChain(IToolChain toolchain) { + return toolchain!=null + && (toolchain.getId().equals(MAKEFILE_PROJECT_TOOLCHAIN_ID) || isMakefileProjectToolChain(toolchain.getSuperClass())); + } + private void handleToolSelected() { if (resTable.getSelectionCount() == 0) return; @@ -327,8 +343,10 @@ public class DiscoveryTab extends AbstractCBuildPropertyTab implements IBuildInf TableItem ti = resTable.getSelection()[0]; buildInfo = (IScannerConfigBuilderInfo2) ti.getData("info"); //$NON-NLS-1$ + String selectedProfileId = buildInfo.getSelectedProfileId(); iContext = (CfgInfoContext) ti.getData("cont"); //$NON-NLS-1$ - autoDiscoveryCheckBox.setSelection(buildInfo.isAutoDiscoveryEnabled()); + autoDiscoveryCheckBox.setSelection(buildInfo.isAutoDiscoveryEnabled() + && !selectedProfileId.equals(ScannerConfigProfileManager.NULL_PROFILE_ID)); reportProblemsCheckBox.setSelection(buildInfo.isProblemReportingEnabled()); profileComboBox.removeAll(); @@ -350,28 +368,26 @@ public class DiscoveryTab extends AbstractCBuildPropertyTab implements IBuildInf String[] profiles = new String[profilesList.size()]; int counter = 0; int pos = 0; - String selectedProfileId = buildInfo.getSelectedProfileId(); ITool[] tools = null; + IConfiguration conf = iContext.getConfiguration(); + IToolChain toolchain = conf!=null ? conf.getToolChain() : null; boolean needPerRcProfile = cbi.isPerRcTypeDiscovery(); if (!page.isForPrefs()) { Tool tool = (Tool) iContext.getTool(); - if (null == tool) { - IConfiguration conf = iContext.getConfiguration(); - if (null != conf) { - tools = conf.getToolChain().getTools(); - } - if (null == tools) - return; - } else { + if (tool != null) { tools = new ITool[] { tool }; + } else { + if (toolchain != null) { + tools = toolchain.getTools(); + } + if (tools == null) + return; } } for (String profileId : profilesList) { - // do not check selected profile id in tool-chain because - // for Makefile project tool-chain does not contain profile, - // instead default one is loaded from preferences to selectedProfileId - if (!profileId.equals(selectedProfileId)) { + // for Makefile project with default tool-chain any profiles can be selected + if (!isMakefileProjectToolChain(toolchain) || needPerRcProfile) { if (tools != null) { boolean foundProfile = false; for (ITool tool : tools) { @@ -382,9 +398,9 @@ public class DiscoveryTab extends AbstractCBuildPropertyTab implements IBuildInf if (!foundProfile) continue; } + if (needPerRcProfile && !CfgScannerConfigProfileManager.isPerFileProfile(profileId)) + continue; } - if (needPerRcProfile && !CfgScannerConfigProfileManager.isPerFileProfile(profileId)) - continue; visibleProfilesList.add(profileId); labels[counter] = profiles[counter] = getProfileName(profileId);