Skip to content

Commit ebad04b

Browse files
author
Anton Krug
committed
Using a util class to avoid code duplication code smell
1 parent a9555eb commit ebad04b

File tree

5 files changed

+22
-12
lines changed

5 files changed

+22
-12
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import com.googlecode.cppcheclipse.core.command.CppcheckCommand;
1919
import com.googlecode.cppcheclipse.core.command.ProcessExecutionException;
20+
import com.googlecode.cppcheclipse.core.utils.PathMacroReplacer;
2021

2122
/**
2223
* This class should abstract from the eclipse concepts for easier testability.
@@ -73,9 +74,8 @@ public Checker(IConsole console, IPreferenceStore projectPreferences,
7374
symbols = new Symbols();
7475
}
7576

76-
String binaryPath = CppcheclipsePlugin.getConfigurationPreferenceStore()
77-
.getString(IPreferenceConstants.P_BINARY_PATH)
78-
.replace("${eclipse_home}", System.getProperty("eclipse.home.location").replace("file:/", ""));
77+
String binaryPath = PathMacroReplacer.process(CppcheclipsePlugin.getConfigurationPreferenceStore()
78+
.getString(IPreferenceConstants.P_BINARY_PATH));
7979

8080
command = new CppcheckCommand(console, binaryPath, settingsPreferences,
8181
projectPreferences, toolchainSettings.getUserIncludes(), toolchainSettings.getSystemIncludes(), symbols);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import com.googlecode.cppcheclipse.core.command.ProcessExecutionException;
2828
import com.googlecode.cppcheclipse.core.utils.IHttpClientService;
29+
import com.googlecode.cppcheclipse.core.utils.PathMacroReplacer;
2930

3031
/**
3132
* The activator class controls the plug-in life cycle
@@ -156,9 +157,8 @@ public boolean removeChangeListener(IPropertyChangeListener listener) {
156157

157158
private synchronized ProblemProfile getInternalNewProblemProfile(IConsole console, IPreferenceStore store) throws CloneNotSupportedException, XPathExpressionException, IOException, InterruptedException, ParserConfigurationException, SAXException, ProcessExecutionException {
158159
if (profile == null) {
159-
String binaryPath = CppcheclipsePlugin.getConfigurationPreferenceStore()
160-
.getString(IPreferenceConstants.P_BINARY_PATH)
161-
.replace("${eclipse_home}", System.getProperty("eclipse.home.location").replace("file:/", ""));
160+
String binaryPath = PathMacroReplacer.process(CppcheclipsePlugin.getConfigurationPreferenceStore()
161+
.getString(IPreferenceConstants.P_BINARY_PATH));
162162
profile = new ProblemProfile(console, binaryPath);
163163
registerChangeListener();
164164
addChangeListener(profile);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.googlecode.cppcheclipse.core.utils;
2+
3+
public class PathMacroReplacer {
4+
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:/", ""));
9+
}
10+
11+
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.googlecode.cppcheclipse.core.IPreferenceConstants;
2323
import com.googlecode.cppcheclipse.core.command.UpdateCheckCommand;
2424
import com.googlecode.cppcheclipse.core.command.Version;
25+
import com.googlecode.cppcheclipse.core.utils.PathMacroReplacer;
2526

2627
public class UpdateCheck {
2728
private static final String DATE_PATTERN = "yyyy.MM.dd HH:mm:ss"; //$NON-NLS-1$
@@ -93,9 +94,8 @@ private static boolean needUpdateCheck() {
9394
public static boolean startUpdateCheck() {
9495
// do not start another update check, if one is already running
9596
if (UpdateCheck.needUpdateCheck()) {
96-
String binaryPath = CppcheclipsePlugin.getConfigurationPreferenceStore()
97-
.getString(IPreferenceConstants.P_BINARY_PATH)
98-
.replace("${eclipse_home}", System.getProperty("eclipse.home.location").replace("file:/", ""));
97+
String binaryPath = PathMacroReplacer.process(CppcheclipsePlugin.getConfigurationPreferenceStore()
98+
.getString(IPreferenceConstants.P_BINARY_PATH));
9999
new UpdateCheck(true).check(binaryPath);
100100
return true;
101101
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import com.googlecode.cppcheclipse.core.IPreferenceConstants;
3838
import com.googlecode.cppcheclipse.core.command.Version;
3939
import com.googlecode.cppcheclipse.core.command.VersionCommand;
40+
import com.googlecode.cppcheclipse.core.utils.PathMacroReplacer;
4041
import com.googlecode.cppcheclipse.ui.Console;
4142
import com.googlecode.cppcheclipse.ui.Messages;
4243
import com.googlecode.cppcheclipse.ui.UpdateCheck;
@@ -116,9 +117,7 @@ protected boolean checkState() {
116117
if (super.checkState()) {
117118
// check if it is valid cppcheck binary
118119
try {
119-
String path = getTextControl().getText()
120-
.replace("${eclipse_home}", System.getProperty("eclipse.home.location").replace("file:/", ""));
121-
120+
String path = PathMacroReplacer.process(getTextControl().getText());
122121
VersionCommand versionCommand = new VersionCommand(
123122
Console.getInstance(), path);
124123
Version version = versionCommand

0 commit comments

Comments
 (0)