mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-10 17:55:39 +02:00
Bug 346365 - Codan ignores default preferences.
This commit is contained in:
parent
fe9af4f721
commit
63c5b6c950
2 changed files with 62 additions and 14 deletions
|
@ -7,6 +7,7 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Alena Laskavaia - initial API and implementation
|
* Alena Laskavaia - initial API and implementation
|
||||||
|
* Sergey Prigogin (Google)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.codan.internal.core;
|
package org.eclipse.cdt.codan.internal.core;
|
||||||
|
|
||||||
|
@ -39,6 +40,9 @@ import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IConfigurationElement;
|
import org.eclipse.core.runtime.IConfigurationElement;
|
||||||
import org.eclipse.core.runtime.IExtensionPoint;
|
import org.eclipse.core.runtime.IExtensionPoint;
|
||||||
import org.eclipse.core.runtime.Platform;
|
import org.eclipse.core.runtime.Platform;
|
||||||
|
import org.eclipse.core.runtime.preferences.ConfigurationScope;
|
||||||
|
import org.eclipse.core.runtime.preferences.DefaultScope;
|
||||||
|
import org.eclipse.core.runtime.preferences.InstanceScope;
|
||||||
import org.osgi.service.prefs.Preferences;
|
import org.osgi.service.prefs.Preferences;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -350,7 +354,12 @@ public class CheckersRegistry implements Iterable<IChecker>, ICheckersRegistry {
|
||||||
((ProblemProfile) wp).setResource(ResourcesPlugin.getWorkspace());
|
((ProblemProfile) wp).setResource(ResourcesPlugin.getWorkspace());
|
||||||
// load default values
|
// load default values
|
||||||
CodanPreferencesLoader loader = new CodanPreferencesLoader(wp);
|
CodanPreferencesLoader loader = new CodanPreferencesLoader(wp);
|
||||||
loader.load(CodanPreferencesLoader.getWorkspaceNode());
|
Preferences[] preferences = {
|
||||||
|
InstanceScope.INSTANCE.getNode(CodanCorePlugin.PLUGIN_ID),
|
||||||
|
ConfigurationScope.INSTANCE.getNode(CodanCorePlugin.PLUGIN_ID),
|
||||||
|
DefaultScope.INSTANCE.getNode(CodanCorePlugin.PLUGIN_ID),
|
||||||
|
};
|
||||||
|
loader.load(preferences);
|
||||||
profiles.put(ResourcesPlugin.getWorkspace(), wp);
|
profiles.put(ResourcesPlugin.getWorkspace(), wp);
|
||||||
}
|
}
|
||||||
return wp;
|
return wp;
|
||||||
|
@ -391,7 +400,6 @@ public class CheckersRegistry implements Iterable<IChecker>, ICheckersRegistry {
|
||||||
} else {
|
} else {
|
||||||
prof = getResourceProfile(element.getProject());
|
prof = getResourceProfile(element.getProject());
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
}
|
}
|
||||||
return prof;
|
return prof;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2009, 2010 Alena Laskavaia
|
* Copyright (c) 2009, 2011 Alena Laskavaia
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Alena Laskavaia - initial API and implementation
|
* Alena Laskavaia - initial API and implementation
|
||||||
|
* Sergey Prigogin (Google)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.codan.internal.core;
|
package org.eclipse.cdt.codan.internal.core;
|
||||||
|
|
||||||
|
@ -18,7 +19,10 @@ import org.eclipse.cdt.codan.core.model.IProblemWorkingCopy;
|
||||||
import org.eclipse.cdt.codan.core.param.IProblemPreference;
|
import org.eclipse.cdt.codan.core.param.IProblemPreference;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.resources.ProjectScope;
|
import org.eclipse.core.resources.ProjectScope;
|
||||||
|
import org.eclipse.core.runtime.Platform;
|
||||||
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
|
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
|
||||||
|
import org.eclipse.core.runtime.preferences.IPreferencesService;
|
||||||
|
import org.eclipse.core.runtime.preferences.InstanceScope;
|
||||||
import org.osgi.service.prefs.Preferences;
|
import org.osgi.service.prefs.Preferences;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -112,7 +116,7 @@ public class CodanPreferencesLoader {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Takes string values from storePreferences and applies them to the problem
|
* Takes string values from storePreferences and applies them to the problem
|
||||||
* profile
|
* profile.
|
||||||
*
|
*
|
||||||
* @param storePreferences
|
* @param storePreferences
|
||||||
*/
|
*/
|
||||||
|
@ -128,9 +132,28 @@ public class CodanPreferencesLoader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Takes string values from storePreferences and applies them to the problem
|
||||||
|
* profile
|
||||||
|
*
|
||||||
|
* @param storePreferences
|
||||||
|
*/
|
||||||
|
public void load(Preferences[] storePreferences) {
|
||||||
|
IPreferencesService prefService = Platform.getPreferencesService();
|
||||||
|
IProblem[] probs = getProblems();
|
||||||
|
for (int i = 0; i < probs.length; i++) {
|
||||||
|
String id = probs[i].getId();
|
||||||
|
String s = prefService.get(id, null, storePreferences);
|
||||||
|
if (s != null) {
|
||||||
|
setProperty(id, s);
|
||||||
|
setProblemPreferenceValues(id, storePreferences);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Takes string values of the problem preferences from storePreferences
|
* Takes string values of the problem preferences from storePreferences
|
||||||
* and applies them to the problem profile
|
* and applies them to the problem profile.
|
||||||
*
|
*
|
||||||
* @param problemId
|
* @param problemId
|
||||||
* @param storePreferences
|
* @param storePreferences
|
||||||
|
@ -151,6 +174,29 @@ public class CodanPreferencesLoader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Takes string values of the problem preferences from storePreferences
|
||||||
|
* and applies them to the problem profile.
|
||||||
|
*
|
||||||
|
* @param problemId
|
||||||
|
* @param storePreferences
|
||||||
|
*/
|
||||||
|
private void setProblemPreferenceValues(String problemId, Preferences[] storePreferences) {
|
||||||
|
IPreferencesService prefService = Platform.getPreferencesService();
|
||||||
|
IProblem prob = baseModel.findProblem(problemId);
|
||||||
|
String prefKey = getPreferencesKey(problemId);
|
||||||
|
if (prefKey == null)
|
||||||
|
return;
|
||||||
|
String exported = prefService.get(prefKey, null, storePreferences);
|
||||||
|
if (exported != null) {
|
||||||
|
try {
|
||||||
|
prob.getPreference().importValue(exported);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
CodanCorePlugin.log(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return preference node (osgi preferences) for the project
|
* Return preference node (osgi preferences) for the project
|
||||||
*
|
*
|
||||||
|
@ -160,10 +206,7 @@ public class CodanPreferencesLoader {
|
||||||
public static IEclipsePreferences getProjectNode(IProject project) {
|
public static IEclipsePreferences getProjectNode(IProject project) {
|
||||||
if (!project.exists())
|
if (!project.exists())
|
||||||
return null;
|
return null;
|
||||||
IEclipsePreferences prefNode = new ProjectScope(project).getNode(CodanCorePlugin.PLUGIN_ID);
|
return new ProjectScope(project).getNode(CodanCorePlugin.PLUGIN_ID);
|
||||||
if (prefNode == null)
|
|
||||||
return null;
|
|
||||||
return prefNode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -172,10 +215,7 @@ public class CodanPreferencesLoader {
|
||||||
* @return project preferences node
|
* @return project preferences node
|
||||||
*/
|
*/
|
||||||
public static IEclipsePreferences getWorkspaceNode() {
|
public static IEclipsePreferences getWorkspaceNode() {
|
||||||
IEclipsePreferences prefNode = CodanCorePlugin.getDefault().getStorePreferences();
|
return InstanceScope.INSTANCE.getNode(CodanCorePlugin.PLUGIN_ID);
|
||||||
if (prefNode == null)
|
|
||||||
return null;
|
|
||||||
return prefNode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue