mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 17:05:26 +02:00
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 <simeon.danailov.andreev@gmail.com>
This commit is contained in:
parent
b49930716f
commit
92bc379917
3 changed files with 89 additions and 2 deletions
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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());
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Add table
Reference in a new issue