diff --git a/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/preferences/tests/TestScopeOfBuildConfigResourceChangesPreference.java b/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/preferences/tests/TestScopeOfBuildConfigResourceChangesPreference.java new file mode 100644 index 00000000000..0527eeb0c32 --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/preferences/tests/TestScopeOfBuildConfigResourceChangesPreference.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * Copyright (c) 2017 Simeon Andreev and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Simeon Andreev - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.core.preferences.tests; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.CCorePreferenceConstants; +import org.eclipse.cdt.core.resources.ACBuilder; +import org.eclipse.core.runtime.preferences.DefaultScope; +import org.eclipse.core.runtime.preferences.IEclipsePreferences; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Test case for Bug 529023: Cannot set build.proj.ref.configs.enabled via + * plugin_customization.ini. + * + * @author Simeon Andreev + */ +public class TestScopeOfBuildConfigResourceChangesPreference extends TestCase { + + private static final String PREFERENCE_NAME = CCorePreferenceConstants.PREF_BUILD_CONFIGS_RESOURCE_CHANGES; + + private boolean oldInstanceScopeValue; + private boolean oldDefaultScopeValue; + + public static Test suite() { + return new TestSuite(TestScopeOfBuildConfigResourceChangesPreference.class); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + + oldInstanceScopeValue = ACBuilder.buildConfigResourceChanges(); + IEclipsePreferences defaultScopePreferences = defaultScopePreferences(); + oldDefaultScopeValue = defaultScopePreferences.getBoolean(PREFERENCE_NAME, oldInstanceScopeValue); + } + + @Override + protected void tearDown() throws Exception { + ACBuilder.setBuildConfigResourceChanges(oldInstanceScopeValue); + IEclipsePreferences defaultScopePreferences = defaultScopePreferences(); + defaultScopePreferences.putBoolean(PREFERENCE_NAME, oldDefaultScopeValue); + + super.tearDown(); + } + + private static IEclipsePreferences defaultScopePreferences() { + return DefaultScope.INSTANCE.getNode(CCorePlugin.PLUGIN_ID); + } + + /** + * Validates that {@link ACBuilder#buildConfigResourceChanges()} also takes + * {@link DefaultScope} into account. + */ + public void testSettingPreferenceViaDefaultScope() throws Exception { + IEclipsePreferences defaultScopePreferences = defaultScopePreferences(); + defaultScopePreferences.putBoolean(PREFERENCE_NAME, true); + + boolean buildConfigResourceChanges = ACBuilder.buildConfigResourceChanges(); + assertTrue("unable to set preference \"" + PREFERENCE_NAME + "\" via default scope", + buildConfigResourceChanges); + } +} diff --git a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java index d0697ef1898..74dd12243a2 100644 --- a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java +++ b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java @@ -27,6 +27,7 @@ import org.eclipse.cdt.core.model.tests.WorkingCopyTests; import org.eclipse.cdt.core.parser.tests.ParserTestSuite; import org.eclipse.cdt.core.parser.tests.ast2.cxx14.constexpr.AllConstexprEvalTests; import org.eclipse.cdt.core.parser.tests.rewrite.RewriteTests; +import org.eclipse.cdt.core.preferences.tests.TestScopeOfBuildConfigResourceChangesPreference; import org.eclipse.cdt.core.resources.tests.RefreshScopeTests; import org.eclipse.cdt.internal.index.tests.IndexTests; import org.eclipse.cdt.internal.pdom.tests.PDOMTests; @@ -90,6 +91,7 @@ public class AutomatedIntegrationSuite extends TestSuite { suite.addTest(EFSExtensionTests.suite()); suite.addTest(ByteUtilsTest.suite()); suite.addTest(UNCPathConverterTest.suite()); + suite.addTest(TestScopeOfBuildConfigResourceChangesPreference.suite()); // Add in PDOM tests suite.addTest(PDOMTests.suite()); diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/ACBuilder.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/ACBuilder.java index 92eb57e4522..968100e592e 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/ACBuilder.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/resources/ACBuilder.java @@ -38,8 +38,11 @@ import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IncrementalProjectBuilder; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.jobs.ISchedulingRule; +import org.eclipse.core.runtime.preferences.DefaultScope; import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.core.runtime.preferences.IScopeContext; import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.osgi.util.NLS; @@ -258,7 +261,7 @@ public abstract class ACBuilder extends IncrementalProjectBuilder implements IMa } public static boolean needAllConfigBuild() { - return prefs.getBoolean(CCorePreferenceConstants.PREF_BUILD_ALL_CONFIGS, false); + return getPreference(CCorePreferenceConstants.PREF_BUILD_ALL_CONFIGS, false); } public static void setAllConfigBuild(boolean enable) { @@ -274,7 +277,7 @@ public abstract class ACBuilder extends IncrementalProjectBuilder implements IMa */ public static boolean buildConfigResourceChanges() { //bug 219337 - return prefs.getBoolean(CCorePreferenceConstants.PREF_BUILD_CONFIGS_RESOURCE_CHANGES, false); + return getPreference(CCorePreferenceConstants.PREF_BUILD_CONFIGS_RESOURCE_CHANGES, false); } /** @@ -287,6 +290,14 @@ public abstract class ACBuilder extends IncrementalProjectBuilder implements IMa prefs.putBoolean(CCorePreferenceConstants.PREF_BUILD_CONFIGS_RESOURCE_CHANGES, enable); } + private static boolean getPreference(String preferenceName, boolean defaultValue) { + IScopeContext[] contexts = { + InstanceScope.INSTANCE, // for preference page + DefaultScope.INSTANCE // for product customization + }; + return Platform.getPreferencesService().getBoolean(CCorePlugin.PLUGIN_ID, preferenceName, defaultValue, contexts); + } + @SuppressWarnings("nls") private static String kindToString(int kind) { return (kind==IncrementalProjectBuilder.AUTO_BUILD ? "AUTO_BUILD"