Skip to content

Commit 52d6141

Browse files
vodorokgamesh411
authored andcommitted
Parameter passthrough (#183)
* Parameter passthrough There is a new feature of CodeChecker configuration. Now there is a direct parameter passthrough to the CodeChecker package. It can be configured in the preferences page. There is also a live display of the analyze command right below the passthrough specification Text widget. Uneditable, but can be copied from. With this, an actual analyze run is more easily reproducible.
1 parent 0d7e505 commit 52d6141

File tree

10 files changed

+84
-495
lines changed

10 files changed

+84
-495
lines changed

bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/codechecker/CodeChecker.java

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@
1414
import org.codechecker.eclipse.plugin.runtime.ShellExecutorHelper;
1515
import org.eclipse.core.runtime.IProgressMonitor;
1616
import org.eclipse.jdt.annotation.NonNull;
17+
import org.eclipse.jdt.annotation.Nullable;
1718

1819
import com.google.common.base.Optional;
1920

2021
/**
2122
* Internal representation of a CodeChecker package.
2223
*/
2324
public class CodeChecker implements ICodeChecker {
25+
private static final String OPTION_SEPARATOR = " ";
2426

2527
private static final String LOCATION_KEY = "location";
2628
private static final String RESULTS_KEY = "results";
@@ -82,14 +84,40 @@ public String analyze(Path logFile, boolean logToConsole, IProgressMonitor monit
8284

8385
subMap.put(RESULTS_KEY, logFile.getParent().toAbsolutePath().resolve(Paths.get(RESULTS_FOLDER)).toFile());
8486
subMap.put(LOGFILE_KEY, logFile.toAbsolutePath().toFile());
85-
String cmd = LOCATION_SUB + " analyze " + config.get(ConfigTypes.CHECKER_LIST) + " -j "
86-
+ config.get(ConfigTypes.ANAL_THREADS) + " -n javarunner" + " -o "
87-
+ RESULTS_SUB + " " + LOGFILE_SUB;
87+
String cmd = getSubstituteAnalyzeString(config);
8888

8989
SLogger.log(LogI.INFO, "Running analyze Command: " + cmd);
9090
Optional<String> ccOutput = she.progressableWaitReturnOutput(cmd, subMap, logToConsole, monitor, taskCount);
9191

9292
return ccOutput.or("");
9393
}
9494

95+
@Override
96+
public String getAnalyzeString(CcConfigurationBase config, @Nullable Path logFile) {
97+
if (logFile != null) {
98+
subMap.put(RESULTS_KEY, logFile.getParent().toAbsolutePath().resolve(Paths.get(RESULTS_FOLDER)).toFile());
99+
subMap.put(LOGFILE_KEY, logFile.toAbsolutePath().toFile());
100+
}
101+
102+
String[] temp = getSubstituteAnalyzeString(config).split(OPTION_SEPARATOR);
103+
StringBuilder cmd = new StringBuilder();
104+
for (String s : temp) {
105+
String tempString = s;
106+
if (s.startsWith("${")) {
107+
StringBuilder sb = new StringBuilder(tempString);
108+
sb.delete(0, 2).deleteCharAt(sb.length() - 1);
109+
if (subMap.containsKey(sb.toString()))
110+
tempString = subMap.get(sb.toString()).toString();
111+
}
112+
cmd.append(tempString);
113+
cmd.append(OPTION_SEPARATOR);
114+
}
115+
return cmd.toString();
116+
}
117+
118+
private String getSubstituteAnalyzeString(CcConfigurationBase config) {
119+
return LOCATION_SUB + " analyze" + " -j "
120+
+ config.get(ConfigTypes.ANAL_THREADS) + " -n javarunner" + " -o " + RESULTS_SUB + OPTION_SEPARATOR
121+
+ LOGFILE_SUB + OPTION_SEPARATOR + config.get(ConfigTypes.ANAL_OPTIONS);
122+
}
95123
}

bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/codechecker/ICodeChecker.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.codechecker.eclipse.plugin.config.CcConfigurationBase;
77
import org.eclipse.core.runtime.IProgressMonitor;
88
import org.eclipse.jdt.annotation.NonNull;
9+
import org.eclipse.jdt.annotation.Nullable;
910

1011
/**
1112
* Interface representing a CodeChecker package.
@@ -38,6 +39,18 @@ public interface ICodeChecker {
3839
*/
3940
public Path getLocation();
4041

42+
/**
43+
* Returns the analyze command to be run, without extra parameters.
44+
*
45+
* @param logFile
46+
* A Path to the build log in the following format:
47+
* http://clang.llvm.org/docs/JSONCompilationDatabase.html .
48+
* @param config
49+
* The configuration being used.
50+
* @return The analyze command as String.
51+
*/
52+
public String getAnalyzeString(CcConfigurationBase config, @Nullable Path logFile);
53+
4154
/**
4255
* Executes CodeChecker check command on the build log received in the logFile
4356
* parameter.

bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/config/CcConfiguration.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
import org.codechecker.eclipse.plugin.config.global.CcGlobalConfiguration;
1212
import org.eclipse.core.resources.IProject;
1313
import org.eclipse.core.resources.ProjectScope;
14-
import org.eclipse.core.runtime.CoreException;
1514
import org.eclipse.core.runtime.IStatus;
16-
import org.eclipse.core.runtime.preferences.IScopeContext;
1715
import org.osgi.service.prefs.BackingStoreException;
1816

1917
import com.google.common.collect.Sets;
@@ -81,17 +79,6 @@ protected void validate() {
8179
}
8280
}
8381

84-
/**
85-
* Returns preferences related to this project.
86-
* @return The configuration which the objects internal boolean has chosen.
87-
*/
88-
@Override
89-
public Map<ConfigTypes, String> get() {
90-
Map<ConfigTypes, String> retConfig = new HashMap<>();
91-
retConfig.putAll(config);
92-
return retConfig;
93-
}
94-
9582
/**
9683
* Updates the persistent configuration.
9784
* @param config The new configuration to be saved.

bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/config/CcConfigurationBase.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import java.util.HashSet;
44
import java.util.Map;
55
import java.util.Set;
6-
import java.util.stream.Collectors;
76

87
import org.codechecker.eclipse.plugin.codechecker.ICodeChecker;
98
import org.codechecker.eclipse.plugin.config.Config.ConfigTypes;
@@ -27,14 +26,6 @@ public abstract class CcConfigurationBase {
2726
*/
2827
public CcConfigurationBase() {}
2928

30-
/**
31-
* Copy constructor for initializing.
32-
* @param other The other instance.
33-
*/
34-
public CcConfigurationBase(CcConfigurationBase other) {
35-
this.config = other.get().entrySet().stream().collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue()));
36-
}
37-
3829
/**
3930
* For Updates the configuration.
4031
* @param config The new configuration.

bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/config/CommonGui.java

Lines changed: 37 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package org.codechecker.eclipse.plugin.config;
22

3+
import java.nio.file.Path;
34
import java.nio.file.Paths;
4-
import java.util.ArrayList;
55
import java.util.HashMap;
6-
import java.util.List;
76
import java.util.Map;
87

98
import org.codechecker.eclipse.plugin.Logger;
@@ -17,13 +16,9 @@
1716
import org.codechecker.eclipse.plugin.config.Config.ConfigTypes;
1817
import org.codechecker.eclipse.plugin.config.global.CcGlobalConfiguration;
1918
import org.codechecker.eclipse.plugin.config.project.CodeCheckerProject;
20-
import org.codechecker.eclipse.plugin.itemselector.CheckerView;
2119
import org.codechecker.eclipse.plugin.runtime.ShellExecutorHelperFactory;
22-
import org.codechecker.eclipse.plugin.utils.CheckerItem;
23-
import org.codechecker.eclipse.plugin.utils.CheckerItem.LAST_ACTION;
2420
import org.eclipse.core.resources.IProject;
2521
import org.eclipse.core.runtime.IStatus;
26-
import org.eclipse.jface.action.Action;
2722
import org.eclipse.jface.dialogs.IMessageProvider;
2823
import org.eclipse.jface.layout.GridDataFactory;
2924
import org.eclipse.jface.layout.GridLayoutFactory;
@@ -40,10 +35,8 @@
4035
import org.eclipse.swt.widgets.FileDialog;
4136
import org.eclipse.swt.widgets.Group;
4237
import org.eclipse.swt.widgets.Label;
43-
import org.eclipse.swt.widgets.Shell;
4438
import org.eclipse.swt.widgets.Text;
4539
import org.eclipse.ui.IWorkbench;
46-
import org.eclipse.ui.PlatformUI;
4740
import org.eclipse.ui.forms.widgets.ColumnLayout;
4841
import org.eclipse.ui.forms.widgets.ExpandableComposite;
4942
import org.eclipse.ui.forms.widgets.FormToolkit;
@@ -60,14 +53,14 @@ public class CommonGui {
6053

6154
private static final String VALID_PACKAGE = "CodeChecker being used: ";
6255
private static final String BROSWE = "Browse";
63-
private static final String CHECKER_ENABLED = " -e ";
64-
private static final String CHECKER_DISABLED = " -d ";
65-
private static final String CHECKER_SEPARATOR = " ";
6656

6757
private static final int TEXTWIDTH = 200;
6858
private static final int FORM_COLUMNS = 3;
6959
private static final int FORM_ONE_ROW = 1;
7060

61+
private static final int AN_CMD_DISP_HGT = 300;
62+
private static final int TRI_LINE_TEXT_HGT = 52;
63+
7164
private boolean globalGui;// whether this class is for global or project
7265
// specific preferences
7366
private boolean useGlobalSettings;// if this is project specific page,
@@ -94,6 +87,9 @@ public class CommonGui {
9487
private Button globalcc;
9588
private Button projectcc;
9689

90+
private Text analysisOptions;
91+
private Text analysisCmdDisplay;
92+
9793
/**
9894
* Constructor to be used, when only global preferences are to be set.
9995
*/
@@ -181,32 +177,36 @@ public Control createContents(final Composite parent) {
181177
cLoggers = addTextField(toolkit, comp, "Compiler commands to log", "gcc:g++:clang:clang++");
182178
toolkit.createLabel(comp, "");
183179

184-
final Button checkers = toolkit.createButton(comp, "Toggle enabled checkers", SWT.PUSH);
185-
checkers.addSelectionListener(new SelectionAdapter() {
186-
187-
public void widgetSelected(SelectionEvent e) {
188-
Action action = new Action() {
189-
@Override
190-
public void run() {
191-
Shell activeShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
192-
//Map<ConfigTypes, String> config = getConfigFromFields();
193-
try {
194-
ArrayList<CheckerItem> checkersList = getCheckerList();
195-
CheckerView dialog = new CheckerView(activeShell, checkersList);
196-
197-
int result = dialog.open();
198-
if (result == 0) {
199-
checkerListArg = checkerListToCheckerListArg(dialog.getCheckersList());
200-
}
201-
} catch (IllegalArgumentException e) {
202-
Logger.log(IStatus.INFO, "Codechecker environment is invalid" + e);
203-
}
204-
}
205-
};
206-
action.run();
180+
toolkit.createLabel(comp, "Extra analysis options");
181+
analysisOptions = toolkit.createText(comp, "", SWT.WRAP | SWT.BORDER | SWT.V_SCROLL);
182+
GridDataFactory.fillDefaults().grab(false, true).hint(TEXTWIDTH, TRI_LINE_TEXT_HGT).applyTo(analysisOptions);
183+
analysisOptions.addModifyListener(new ModifyListener() {
184+
185+
@Override
186+
public void modifyText(ModifyEvent e) {
187+
config.get().put(ConfigTypes.ANAL_OPTIONS, analysisOptions.getText());
188+
Path originalLogFile = null;
189+
if (!globalGui) {
190+
originalLogFile = cCProject.getLogFileLocation();
191+
}
192+
if (codeChecker != null)
193+
analysisCmdDisplay.setText(codeChecker.getAnalyzeString(config, originalLogFile));
194+
checkerConfigSection.layout();
195+
checkerConfigSection.getParent().layout();
196+
comp.layout(true);
197+
comp.getParent().layout(true);
207198
}
208199
});
209-
checkers.setData("org.eclipse.swtbot.widget.checkersKey", "checkesButton");
200+
analysisOptions.getVerticalBar().setEnabled(true);
201+
202+
toolkit.createLabel(comp, "");
203+
toolkit.createLabel(comp, "Final analysis command");
204+
analysisCmdDisplay = toolkit.createText(comp, "", SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
205+
GridDataFactory.fillDefaults().grab(false, true).hint(TEXTWIDTH, AN_CMD_DISP_HGT).applyTo(analysisCmdDisplay);
206+
analysisCmdDisplay.setEditable(false);
207+
analysisCmdDisplay.getVerticalBar().setEnabled(true);
208+
toolkit.createLabel(comp, "");
209+
210210
if (!globalGui) {
211211
recursiveSetEnabled(form.getBody(), !useGlobalSettings);
212212
final Composite client3 = toolkit.createComposite(globalConfigSection);
@@ -382,61 +382,6 @@ public void recursiveSetEnabled(Control control, Boolean b) {
382382
}
383383
}
384384

385-
/**
386-
* Returns The all checkers from CodeChecker.
387-
* @return A list of all available checkers.
388-
*/
389-
private ArrayList<CheckerItem> getCheckerList() {
390-
// ArrayList<CheckerItem> defaultCheckersList = new ArrayList<>();
391-
ArrayList<CheckerItem> checkersList = new ArrayList<>(); //
392-
// new Checkers List
393-
String s = codeChecker.getCheckers();
394-
String[] newCheckersSplit = s.split("\n");
395-
// old Checkers Command
396-
//String[] checkersCommand = checkerListArg.split(CHECKER_SEPARATOR);
397-
//List<String> oldCheckersCommand = Arrays.asList(checkersCommand);
398-
for (String it : newCheckersSplit) {
399-
// String checkerName = it.split(" ")[2];
400-
String checkerName = it;
401-
CheckerItem check = new CheckerItem(checkerName);
402-
boolean defaultEnabled = false;
403-
404-
if (it.split(CHECKER_SEPARATOR)[1].equals("+"))
405-
defaultEnabled = true;
406-
if (defaultEnabled) {
407-
if (checkerListArg.contains(CHECKER_DISABLED + checkerName)) {
408-
check.setLastAction(LAST_ACTION.DESELECTION);
409-
} else {
410-
check.setLastAction(LAST_ACTION.SELECTION);
411-
}
412-
} else {
413-
if (checkerListArg.contains(CHECKER_ENABLED + checkerName)) {
414-
check.setLastAction(LAST_ACTION.SELECTION);
415-
} else {
416-
check.setLastAction(LAST_ACTION.DESELECTION);
417-
}
418-
}
419-
checkersList.add(check);
420-
}
421-
return checkersList;
422-
}
423-
424-
/**
425-
* Returns Stringified checkerlist configuration.
426-
* @param chl The internal list of checkers.
427-
* @return The string list of checkers prefixed with state.
428-
*/
429-
protected String checkerListToCheckerListArg(List<CheckerItem> chl) {
430-
StringBuilder checkerListArg = new StringBuilder();
431-
for (int i = 0; i < chl.size(); ++i) {
432-
if (chl.get(i).getLastAction() == LAST_ACTION.SELECTION)
433-
checkerListArg.append(CHECKER_ENABLED + chl.get(i).getText() + CHECKER_SEPARATOR);
434-
else
435-
checkerListArg.append(CHECKER_DISABLED + chl.get(i).getText() + CHECKER_SEPARATOR);
436-
}
437-
return checkerListArg.toString();
438-
}
439-
440385
/**
441386
* Loads config from {@link CcConfiguration}.
442387
* @param resetToDefault If set, the default config is used.
@@ -469,9 +414,9 @@ public void setFields() {
469414
break;
470415
}
471416
codeCheckerDirectoryField.setText(config.get(ConfigTypes.CHECKER_PATH));
472-
checkerListArg = config.get(ConfigTypes.CHECKER_LIST);
473417
cLoggers.setText(config.get(ConfigTypes.COMPILERS));
474418
numThreads.setText(config.get(ConfigTypes.ANAL_THREADS));
419+
analysisOptions.setText(config.get(ConfigTypes.ANAL_OPTIONS));
475420
}
476421

477422
/**
@@ -481,7 +426,6 @@ public void setFields() {
481426
public Map<ConfigTypes, String> getConfigFromFields() {
482427
Map<ConfigTypes, String> conf = new HashMap<>();
483428
conf.put(ConfigTypes.CHECKER_PATH, codeCheckerDirectoryField.getText());
484-
conf.put(ConfigTypes.CHECKER_LIST, checkerListArg);
485429
conf.put(ConfigTypes.ANAL_THREADS, numThreads.getText());
486430
conf.put(ConfigTypes.COMPILERS, cLoggers.getText());
487431
return conf;
@@ -493,7 +437,7 @@ public Map<ConfigTypes, String> getConfigFromFields() {
493437
public void saveConfig() {
494438
Map<ConfigTypes, String> conf = new HashMap<ConfigTypes, String>();
495439
conf.put(ConfigTypes.CHECKER_PATH, codeCheckerDirectoryField.getText());
496-
conf.put(ConfigTypes.CHECKER_LIST, checkerListArg);
440+
conf.put(ConfigTypes.ANAL_OPTIONS, analysisOptions.getText());
497441
conf.put(ConfigTypes.ANAL_THREADS, numThreads.getText());
498442
conf.put(ConfigTypes.COMPILERS, cLoggers.getText());
499443
conf.put(ConfigTypes.RES_METHOD, currentResMethod.toString());

bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/config/Config.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ public enum ConfigTypes {
2525
RES_METHOD("PATH"),
2626
COMPILERS("gcc:g++:clang:clang++"),
2727
ANAL_THREADS("4"),
28-
CHECKER_LIST("enabled_checkers"),
28+
ANAL_OPTIONS(""),
2929
// Project configuration values
3030
IS_GLOBAL("true"),
3131
CHECKER_WORKSPACE("codechecker_workdir");
3232

33-
public static Set<ConfigTypes> COMMON_TYPE = EnumSet.range(CHECKER_PATH, CHECKER_LIST);
33+
public static Set<ConfigTypes> COMMON_TYPE = EnumSet.range(CHECKER_PATH, ANAL_OPTIONS);
3434
public static Set<ConfigTypes> PROJECT_TYPE = EnumSet.range(IS_GLOBAL, CHECKER_WORKSPACE);
3535
private String defaultValue;
3636

0 commit comments

Comments
 (0)