Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

Commit

Permalink
VariablesPlugin implementation for the path macro substitution
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Krug committed Jan 4, 2018
1 parent ebad04b commit c5cf13b
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 9 deletions.
3 changes: 2 additions & 1 deletion com.googlecode.cppcheclipse.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.5.0",
com.google.guava;bundle-version="12.0.0",
org.apache.commons.codec;bundle-version="1.4.0",
org.apache.commons.io;bundle-version="2.0.1",
org.apache.commons.exec;bundle-version="1.1.0"
org.apache.commons.exec;bundle-version="1.1.0",
org.eclipse.core.variables
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Export-Package: com.googlecode.cppcheclipse.core,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public Checker(IConsole console, IPreferenceStore projectPreferences,
symbols = new Symbols();
}

String binaryPath = PathMacroReplacer.process(CppcheclipsePlugin.getConfigurationPreferenceStore()
String binaryPath = PathMacroReplacer.performMacroSubstitution(CppcheclipsePlugin.getConfigurationPreferenceStore()
.getString(IPreferenceConstants.P_BINARY_PATH));

command = new CppcheckCommand(console, binaryPath, settingsPreferences,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public boolean removeChangeListener(IPropertyChangeListener listener) {

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

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.variables.IStringVariableManager;
import org.eclipse.core.variables.VariablesPlugin;

import com.googlecode.cppcheclipse.core.CppcheclipsePlugin;

/**
* This util class is helping replace path containing macros into real path.
*
* Following macros will resolve to:
* ${eclipse_home} to a Eclipse's installation folder.
* ${project_loc} to the folder of a active project.
* ${workspace_loc} to the current open workspace.
*
* https://help.eclipse.org/luna/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2Fconcepts%2Fcpathvars.htm
*
* @author Anton Krug
*
*/

public class PathMacroReplacer {

// TODO implement the VariablesPlugin

public static String process(String input) {
return input.replace("${eclipse_home}", System.getProperty("eclipse.home.location").replace("file:/", ""));
public static String performMacroSubstitution(String input) {
String ret = input;

IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager();
try {
ret = manager.performStringSubstitution(ret, false);
} catch (CoreException e) {
// in case of a issue, keep the path as it is and log error
CppcheclipsePlugin.logError("Path macro subsitution failed", e); //$NON-NLS-1$
}

return ret;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private static boolean needUpdateCheck() {
public static boolean startUpdateCheck() {
// do not start another update check, if one is already running
if (UpdateCheck.needUpdateCheck()) {
String binaryPath = PathMacroReplacer.process(CppcheclipsePlugin.getConfigurationPreferenceStore()
String binaryPath = PathMacroReplacer.performMacroSubstitution(CppcheclipsePlugin.getConfigurationPreferenceStore()
.getString(IPreferenceConstants.P_BINARY_PATH));
new UpdateCheck(true).check(binaryPath);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ protected boolean checkState() {
if (super.checkState()) {
// check if it is valid cppcheck binary
try {
String path = PathMacroReplacer.process(getTextControl().getText());
String path = PathMacroReplacer.performMacroSubstitution(getTextControl().getText());
VersionCommand versionCommand = new VersionCommand(
Console.getInstance(), path);
Version version = versionCommand
Expand Down

0 comments on commit c5cf13b

Please sign in to comment.