Skip to content

Commit c5cf13b

Browse files
author
Anton Krug
committed
VariablesPlugin implementation for the path macro substitution
1 parent ebad04b commit c5cf13b

File tree

6 files changed

+38
-9
lines changed

6 files changed

+38
-9
lines changed

com.googlecode.cppcheclipse.core/META-INF/MANIFEST.MF

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.5.0",
1111
com.google.guava;bundle-version="12.0.0",
1212
org.apache.commons.codec;bundle-version="1.4.0",
1313
org.apache.commons.io;bundle-version="2.0.1",
14-
org.apache.commons.exec;bundle-version="1.1.0"
14+
org.apache.commons.exec;bundle-version="1.1.0",
15+
org.eclipse.core.variables
1516
Bundle-ActivationPolicy: lazy
1617
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
1718
Export-Package: com.googlecode.cppcheclipse.core,

com.googlecode.cppcheclipse.core/src/com/googlecode/cppcheclipse/core/Checker.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public Checker(IConsole console, IPreferenceStore projectPreferences,
7474
symbols = new Symbols();
7575
}
7676

77-
String binaryPath = PathMacroReplacer.process(CppcheclipsePlugin.getConfigurationPreferenceStore()
77+
String binaryPath = PathMacroReplacer.performMacroSubstitution(CppcheclipsePlugin.getConfigurationPreferenceStore()
7878
.getString(IPreferenceConstants.P_BINARY_PATH));
7979

8080
command = new CppcheckCommand(console, binaryPath, settingsPreferences,

com.googlecode.cppcheclipse.core/src/com/googlecode/cppcheclipse/core/CppcheclipsePlugin.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public boolean removeChangeListener(IPropertyChangeListener listener) {
157157

158158
private synchronized ProblemProfile getInternalNewProblemProfile(IConsole console, IPreferenceStore store) throws CloneNotSupportedException, XPathExpressionException, IOException, InterruptedException, ParserConfigurationException, SAXException, ProcessExecutionException {
159159
if (profile == null) {
160-
String binaryPath = PathMacroReplacer.process(CppcheclipsePlugin.getConfigurationPreferenceStore()
160+
String binaryPath = PathMacroReplacer.performMacroSubstitution(CppcheclipsePlugin.getConfigurationPreferenceStore()
161161
.getString(IPreferenceConstants.P_BINARY_PATH));
162162
profile = new ProblemProfile(console, binaryPath);
163163
registerChangeListener();
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,39 @@
11
package com.googlecode.cppcheclipse.core.utils;
22

3+
import org.eclipse.core.runtime.CoreException;
4+
import org.eclipse.core.variables.IStringVariableManager;
5+
import org.eclipse.core.variables.VariablesPlugin;
6+
7+
import com.googlecode.cppcheclipse.core.CppcheclipsePlugin;
8+
9+
/**
10+
* This util class is helping replace path containing macros into real path.
11+
*
12+
* Following macros will resolve to:
13+
* ${eclipse_home} to a Eclipse's installation folder.
14+
* ${project_loc} to the folder of a active project.
15+
* ${workspace_loc} to the current open workspace.
16+
*
17+
* https://help.eclipse.org/luna/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2Fconcepts%2Fcpathvars.htm
18+
*
19+
* @author Anton Krug
20+
*
21+
*/
22+
323
public class PathMacroReplacer {
424

5-
// TODO implement the VariablesPlugin
6-
7-
public static String process(String input) {
8-
return input.replace("${eclipse_home}", System.getProperty("eclipse.home.location").replace("file:/", ""));
25+
public static String performMacroSubstitution(String input) {
26+
String ret = input;
27+
28+
IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager();
29+
try {
30+
ret = manager.performStringSubstitution(ret, false);
31+
} catch (CoreException e) {
32+
// in case of a issue, keep the path as it is and log error
33+
CppcheclipsePlugin.logError("Path macro subsitution failed", e); //$NON-NLS-1$
34+
}
35+
36+
return ret;
937
}
1038

1139
}

com.googlecode.cppcheclipse.ui/src/com/googlecode/cppcheclipse/ui/UpdateCheck.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ private static boolean needUpdateCheck() {
9494
public static boolean startUpdateCheck() {
9595
// do not start another update check, if one is already running
9696
if (UpdateCheck.needUpdateCheck()) {
97-
String binaryPath = PathMacroReplacer.process(CppcheclipsePlugin.getConfigurationPreferenceStore()
97+
String binaryPath = PathMacroReplacer.performMacroSubstitution(CppcheclipsePlugin.getConfigurationPreferenceStore()
9898
.getString(IPreferenceConstants.P_BINARY_PATH));
9999
new UpdateCheck(true).check(binaryPath);
100100
return true;

com.googlecode.cppcheclipse.ui/src/com/googlecode/cppcheclipse/ui/preferences/BinaryPathPreferencePage.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ protected boolean checkState() {
117117
if (super.checkState()) {
118118
// check if it is valid cppcheck binary
119119
try {
120-
String path = PathMacroReplacer.process(getTextControl().getText());
120+
String path = PathMacroReplacer.performMacroSubstitution(getTextControl().getText());
121121
VersionCommand versionCommand = new VersionCommand(
122122
Console.getInstance(), path);
123123
Version version = versionCommand

0 commit comments

Comments
 (0)