From 92bc379917ecf365261385dc98c70e618fa1fe58 Mon Sep 17 00:00:00 2001 From: Simeon Andreev Date: Thu, 21 Dec 2017 09:15:21 +0100 Subject: [PATCH] Bug 529023 - Cannot set build.proj.ref.configs.enabled via customization The setting build.proj.ref.configs.enabled=true ensures CDT projects are not rebuilt if non-related projects are changed. This setting cannot be changed with product or command line customization, hindering products which require this behavior. The reason for this is that ACBuilder, which is asked for the value of the preference, communicates with the instance scope of preferences. Product and command line customization, however, are on default scope level. With this change, ACBuilder will also ask the default scope when retrieving the value of the preference. Change-Id: I09e895ea2a05b677e36fac9eb28f24f1f3bc2877 Signed-off-by: Simeon Andreev --- ...fBuildConfigResourceChangesPreference.java | 74 +++++++++++++++++++ .../core/suite/AutomatedIntegrationSuite.java | 2 + .../eclipse/cdt/core/resources/ACBuilder.java | 15 +++- 3 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/core/preferences/tests/TestScopeOfBuildConfigResourceChangesPreference.java 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"