Skip to content

Commit bfac6b0

Browse files
authored
Merge pull request #155 from Vodorok/pathSpecChar_patch
Fixed commands with paths passed as String to process execution
2 parents 91209b7 + 5861f7e commit bfac6b0

File tree

10 files changed

+310
-118
lines changed

10 files changed

+310
-118
lines changed

bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/runtime/CodeCheckEnvironmentChecker.java

Lines changed: 62 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,42 @@
11
package org.codechecker.eclipse.plugin.runtime;
22

33
import java.io.File;
4+
import java.util.HashMap;
45
import java.util.Map;
56

7+
import org.codechecker.eclipse.plugin.Logger;
68
import org.codechecker.eclipse.plugin.config.Config.ConfigTypes;
79
import org.codechecker.eclipse.plugin.config.global.CcGlobalConfiguration;
810
import org.codechecker.eclipse.plugin.config.project.CodeCheckerProject;
911
import org.eclipse.core.runtime.IProgressMonitor;
12+
import org.eclipse.core.runtime.IStatus;
1013

1114
import com.google.common.base.Optional;
1215
import com.google.common.collect.ImmutableMap;
1316

14-
1517
/**
1618
* This class checks for Environments used by CodeChecker.
1719
*
1820
*/
1921
public class CodeCheckEnvironmentChecker {
2022

23+
private static final String CC_BINARY = "CC_BINARY";
24+
25+
private static final String HELP_ARGUMENT = "-h";
26+
private static final int WAIT_TIME_MULTIPLYER = 1000; // in milliseconds
27+
2128
public final Optional<String> pythonEnvironment;
2229
public final String checkerDir; // root directory of CodeChecker
2330
public final String codeCheckerCommand; // CodecCheker executable path
31+
32+
public final ImmutableMap<String, String> environmentBefore;
33+
34+
public Map<String, File> commandSubstitutionMap;
35+
2436
private Map<ConfigTypes,String> config;
2537
private CodeCheckerProject project;
2638
private String checkerList;
2739

28-
//with specific python. This
29-
// can be used to run CodeChecker
30-
public final ImmutableMap<String, String> environmentBefore;
31-
3240
/**
3341
*
3442
* @param project
@@ -49,14 +57,23 @@ public CodeCheckEnvironmentChecker(CodeCheckerProject project) {
4957
SLogger.log(LogI.INFO, "pythonenv is not set");
5058
}
5159
else{
52-
SLogger.log(LogI.INFO, "pythonenv is set to:"+config.get("PYTHON_PATH"));
60+
SLogger.log(LogI.INFO, "pythonenv is set to:" + config.get(ConfigTypes.PYTHON_PATH));
5361
pythonEnvironment=Optional.of(config.get(ConfigTypes.PYTHON_PATH));
5462
}
5563

5664
//checkerList=getConfigValue(ConfigTypes.CHECKER_LIST);
5765
checkerDir=getConfigValue(ConfigTypes.CHECKER_PATH);
5866
environmentBefore = getInitialEnvironment(pythonEnvironment);
5967
codeCheckerCommand = checkerDir+"/bin/CodeChecker";
68+
69+
70+
commandSubstitutionMap = new HashMap<String, File>() {{
71+
put("CC_BIN", new File(codeCheckerCommand));
72+
}};
73+
if (project != null)
74+
commandSubstitutionMap.put("RESULTS",
75+
new File(project.getLogFileLocation().getParent().toString() + "/results/"));
76+
6077
}
6178

6279
/**
@@ -83,24 +100,31 @@ private String getConfigValue(ConfigTypes key) {
83100
* @param config The Configuration to be used,
84101
* populated with {@link ConfigTypes}.
85102
* @param codeCheckerBinaryPath Path to CodeChecker.
103+
* TODO This method doesn't need codeCheckerBinaryPath in its arguments as it's a field in this class.
86104
*/
87105
public static void getCheckerEnvironment(
88106
Map<ConfigTypes, String> config, String codeCheckerBinaryPath) {
89107

90108
ShellExecutorHelper she = new ShellExecutorHelper(
91109
getInitialEnvironment(Optional.of(config.get(ConfigTypes.PYTHON_PATH))));
92110

93-
String cmd=codeCheckerBinaryPath + " -h";
94-
SLogger.log(LogI.INFO, "Testing " + cmd);
95-
Optional<String> ccEnvOutput = she.quickReturnOutput(cmd);
111+
String cmd = "'${CC_BINARY}' " + HELP_ARGUMENT;
112+
@SuppressWarnings("serial")
113+
Map<String, File> substitutinMap = new HashMap<String, File>() {{
114+
put(CC_BINARY, new File(codeCheckerBinaryPath));
115+
}};
116+
117+
SLogger.log(LogI.INFO, "Testing " + substitutinMap.get(CC_BINARY).getAbsolutePath() + " -h");
118+
Optional<String> ccEnvOutput = she.quickReturnOutput(cmd, substitutinMap);
96119
double test = 0;
97-
// WTF
120+
// TODO WTF -- check the twisted logic behind this, and simplify.
98121
while(!ccEnvOutput.isPresent() && test <= 2){
99-
ccEnvOutput = she.quickReturnOutput(cmd, Math.pow( 2.0 , test ) * 1000);
122+
ccEnvOutput = she.quickReturnOutput(cmd, substitutinMap, Math.pow( 2.0 , test ) * WAIT_TIME_MULTIPLYER);
100123
++test;
101-
}
124+
}
102125
if (!ccEnvOutput.isPresent()) {
103-
SLogger.log(LogI.ERROR, "Cannot run CodeChecker command:"+cmd);
126+
SLogger.log(LogI.ERROR, "Cannot run CodeChecker command:" +
127+
substitutinMap.get(CC_BINARY).getAbsolutePath() + " " + HELP_ARGUMENT);
104128
throw new IllegalArgumentException("Couldn't run the specified CodeChecker for " +
105129
"environment testing!");
106130
}
@@ -114,11 +138,13 @@ public static void getCheckerEnvironment(
114138
private static ImmutableMap<String, String> getInitialEnvironment(Optional<String> pythonEnvironment) {
115139
if (pythonEnvironment.isPresent()) {
116140
ShellExecutorHelper she = new ShellExecutorHelper(System.getenv());
117-
118-
Optional<String> output = she.quickReturnOutput("source " + pythonEnvironment.get() + "/bin/activate" +
119-
" ; env");
141+
File pyEnv = new File(pythonEnvironment.get() + "/bin/activate");
142+
String cmd = "source '${PY_ENV}' ; env";
143+
@SuppressWarnings("serial")
144+
Map<String, File> substitutionMap = new HashMap<String, File>() {{ put("PY_ENV", pyEnv); }};
145+
Optional<String> output = she.quickReturnOutput(cmd, substitutionMap);
120146
if (!output.isPresent()) {
121-
SLogger.log(LogI.INFO, "SERVER_GUI_MSG >> Couldn't check the given python environment!");
147+
Logger.log(IStatus.ERROR, "Couldn't check the python environment!");
122148
throw new IllegalArgumentException("Couldn't check the given python environment!");
123149
} else {
124150
ImmutableMap<String, String> environment = (new EnvironmentParser()).parse(output
@@ -151,40 +177,46 @@ public void setCheckerList(String list) {
151177
* @param buildLog Path to the compile commands file, which the analyze command uses.
152178
* @return The constructed analyze command.
153179
*/
154-
public String createAnalyzeCommmand(String buildLog){
155-
return codeCheckerCommand + " analyze " + getConfigValue(ConfigTypes.CHECKER_LIST) +
156-
" -j "+ getConfigValue(ConfigTypes.ANAL_THREADS) + " -n javarunner" +
157-
" -o "+ project.getLogFileLocation().getParent().toString() +"/results/ " + buildLog;
180+
public String createAnalyzeCommmand(String buildLog) {
181+
commandSubstitutionMap.put("LOG", new File(buildLog));
182+
return "'${CC_BIN}' analyze " + getConfigValue(ConfigTypes.CHECKER_LIST) +
183+
" -j "+ getConfigValue(ConfigTypes.ANAL_THREADS) + " -n javarunner" +
184+
" -o " + "'${RESULTS}' " + "'${LOG}'";
158185
}
159186

160187
/**
161188
* Executes CodeChecker check command
162189
* on the build log received in the fileName parameter.
163-
* @param fileName Build log in the http://clang.llvm.org/docs/JSONCompilationDatabase.html format.
190+
* @param buildLog Build log in the http://clang.llvm.org/docs/JSONCompilationDatabase.html format.
164191
* @param logToConsole Flag for indicating console logging
165192
* @param monitor ProgressMonitor for to be able to increment progress bar.
166193
* @param taskCount How many analyze step to be taken.
167194
* @return CodeChecker check command output
168195
*/
169-
public String processLog(String fileName, boolean logToConsole, IProgressMonitor monitor, int taskCount) {
196+
public String processLog(String buildLog, boolean logToConsole, IProgressMonitor monitor, int taskCount) {
170197
ShellExecutorHelper she = new ShellExecutorHelper(environmentBefore);
171-
String cmd = createAnalyzeCommmand(fileName);
172-
198+
String cmd = createAnalyzeCommmand(buildLog);
173199
SLogger.log(LogI.INFO, "SERVER_SER_MSG >> processLog >> "+ cmd);
174-
//Optional<String> ccOutput = she.waitReturnOutput(cmd,logToConsole);
175-
Optional<String> ccOutput = she.progressableWaitReturnOutput(cmd,logToConsole, monitor, taskCount);
200+
Optional<String> ccOutput = she.progressableWaitReturnOutput(cmd, commandSubstitutionMap, logToConsole, monitor, taskCount);
176201
if (ccOutput.isPresent()) {
177202
// assume it succeeded, and delete the log file...
178-
File f = new File(fileName);
203+
File f = new File(buildLog);
179204
f.delete();
180205
}
181206
return ccOutput.or("");
182207
}
183208

209+
/**
210+
* Returns the list of available checkers.
211+
* Add the following for checker enability checking.
212+
* CodeChecker checkers --details | cut -d " " -f "1-3"
213+
* @return A String containing the checkers. One at a line.
214+
*/
184215
public String getCheckerList() {
185216
ShellExecutorHelper she = new ShellExecutorHelper(environmentBefore);
186-
String cmd = codeCheckerCommand + " checkers";
187-
Optional<String> ccOutput = she.waitReturnOutput(cmd,false);
217+
String cmd = "'${CC_BIN}' checkers";
218+
Optional<String> ccOutput = she.waitReturnOutput(cmd, commandSubstitutionMap, false);
188219
return ccOutput.or("");
189220
}
221+
190222
}

bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/runtime/CodeCheckerLocator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public boolean foundCcExecutable() {
3434
}
3535

3636
private Optional<String> locateSystemCodeChecker() {
37-
return shellExecutor.quickReturnFirstLine("/usr/bin/which CodeChecker");
37+
return shellExecutor.quickReturnFirstLine("/usr/bin/which CodeChecker", null);
3838
}
3939

4040
}

0 commit comments

Comments
 (0)