Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,6 @@ public String get(ConfigTypes type) {
return config.get(type);
}

/**
* @return True if the python values are set.
*/
public boolean isPythonConfigured() {
return !(!config.containsKey(ConfigTypes.PYTHON_PATH)
|| (config.containsKey(ConfigTypes.PYTHON_PATH) && config.get(ConfigTypes.PYTHON_PATH).isEmpty()));
}

/**
* Returns the default configuration for the plug-in.
* @return An Unmodifiable view of the default configuration Map.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,21 @@
import java.util.List;
import java.util.Map;

import org.codechecker.eclipse.plugin.Logger;
import org.codechecker.eclipse.plugin.config.Config.ConfigTypes;
import org.codechecker.eclipse.plugin.config.global.CcGlobalConfiguration;
import org.codechecker.eclipse.plugin.config.project.CodeCheckerProject;
import org.codechecker.eclipse.plugin.itemselector.CheckerView;
import org.codechecker.eclipse.plugin.runtime.CodeCheckEnvironmentChecker;
import org.codechecker.eclipse.plugin.utils.CheckerItem;
import org.codechecker.eclipse.plugin.utils.CheckerItem.LAST_ACTION;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
Expand All @@ -18,9 +28,7 @@
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkbench;
Expand All @@ -30,14 +38,6 @@
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.eclipse.ui.forms.widgets.Section;
import org.codechecker.eclipse.plugin.Logger;
import org.codechecker.eclipse.plugin.config.Config.ConfigTypes;
import org.codechecker.eclipse.plugin.config.global.CcGlobalConfiguration;
import org.codechecker.eclipse.plugin.config.project.CodeCheckerProject;
import org.codechecker.eclipse.plugin.itemselector.CheckerView;
import org.codechecker.eclipse.plugin.runtime.CodeCheckEnvironmentChecker;
import org.codechecker.eclipse.plugin.utils.CheckerItem;
import org.codechecker.eclipse.plugin.utils.CheckerItem.LAST_ACTION;

/**
* Global and project level preferences pages.
Expand All @@ -63,7 +63,7 @@ public class CommonGui {
private CcConfigurationBase config;
private CodeCheckerProject cCProject;
private Text codeCheckerDirectoryField;// codechecker dir
private Text pythonEnvField;// CodeChecker python env

private Text numThreads;// #of analysis threads
private Text cLoggers;// #C compiler commands to catch

Expand Down Expand Up @@ -151,9 +151,10 @@ public Control createContents(final Composite parent) {
checkerConfigSection.setText("Configuration");

codeCheckerDirectoryField = addTextField(toolkit, client, "CodeChecker package root directory", "");
codeCheckerDirectoryField.addListener(SWT.FocusOut, new Listener() {
codeCheckerDirectoryField.addModifyListener(new ModifyListener() {

@Override
public void handleEvent(Event event) {
public void modifyText(ModifyEvent e) {
try {
Map<ConfigTypes, String> changedConfig = getConfigFromFields();
CodeCheckEnvironmentChecker.getCheckerEnvironment(changedConfig,
Expand Down Expand Up @@ -187,21 +188,6 @@ public void widgetSelected(SelectionEvent event) {
}
});

pythonEnvField = addTextField(toolkit, client, "Python virtualenv root directory (optional)", "");
final Button pythonEnvFieldBrowse = new Button(client, SWT.PUSH);
pythonEnvFieldBrowse.setText(BROSWE);
pythonEnvFieldBrowse.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
DirectoryDialog dlg = new DirectoryDialog(client.getShell());
dlg.setFilterPath(codeCheckerDirectoryField.getText());
dlg.setText("Browse python environment");
String dir = dlg.open();
if (dir != null) {
pythonEnvField.setText(dir);
}
}
});

numThreads = addTextField(toolkit, client, "Number of analysis threads", "4");
toolkit.createLabel(client, "");
cLoggers = addTextField(toolkit, client, "Compiler commands to log", "gcc:g++:clang:clang++");
Expand Down Expand Up @@ -371,7 +357,6 @@ public Map<ConfigTypes, String> loadConfig(boolean resetToDefault) {
*/
public void setFields(Map<ConfigTypes, String> config) {
codeCheckerDirectoryField.setText(config.get(ConfigTypes.CHECKER_PATH));
pythonEnvField.setText(config.get(ConfigTypes.PYTHON_PATH));
checkerListArg = config.get(ConfigTypes.CHECKER_LIST);
cLoggers.setText(config.get(ConfigTypes.COMPILERS));
numThreads.setText(config.get(ConfigTypes.ANAL_THREADS));
Expand All @@ -384,7 +369,6 @@ public void setFields(Map<ConfigTypes, String> config) {
public Map<ConfigTypes, String> getConfigFromFields() {
Map<ConfigTypes, String> conf = new HashMap<>();
conf.put(ConfigTypes.CHECKER_PATH, codeCheckerDirectoryField.getText());
conf.put(ConfigTypes.PYTHON_PATH, pythonEnvField.getText());
conf.put(ConfigTypes.CHECKER_LIST, checkerListArg);
conf.put(ConfigTypes.ANAL_THREADS, numThreads.getText());
conf.put(ConfigTypes.COMPILERS, cLoggers.getText());
Expand All @@ -397,7 +381,6 @@ public Map<ConfigTypes, String> getConfigFromFields() {
public void saveConfig() {
Map<ConfigTypes, String> conf = new HashMap<ConfigTypes, String>();
conf.put(ConfigTypes.CHECKER_PATH, codeCheckerDirectoryField.getText());
conf.put(ConfigTypes.PYTHON_PATH, pythonEnvField.getText());
conf.put(ConfigTypes.CHECKER_LIST, checkerListArg);
conf.put(ConfigTypes.ANAL_THREADS, numThreads.getText());
conf.put(ConfigTypes.COMPILERS, cLoggers.getText());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
import java.util.Map;
import java.util.Set;

import org.eclipse.core.runtime.IStatus;

import org.codechecker.eclipse.plugin.Logger;
import org.eclipse.core.runtime.IStatus;

/**
* Classes for handling actual configuration entries, and logging.
Expand All @@ -23,7 +22,6 @@ public class Config {
public enum ConfigTypes {
// Common configuration values
CHECKER_PATH("codechecker_path"),
PYTHON_PATH(""),
COMPILERS("gcc:g++:clang:clang++"),
ANAL_THREADS("4"),
CHECKER_LIST("enabled_checkers"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package org.codechecker.eclipse.plugin.config;

import java.util.EnumSet;
import java.util.Set;

import org.eclipse.cdt.core.envvar.IEnvironmentVariable;

/**
Expand All @@ -14,14 +11,7 @@ public enum EnvironmentVariables {
CC_LOGGER_GCC_LIKE("clang", IEnvironmentVariable.ENVVAR_REPLACE),
LD_PRELOAD("ldlogger.so", IEnvironmentVariable.ENVVAR_REPLACE),
CC_LOGGER_FILE("logfile", IEnvironmentVariable.ENVVAR_REPLACE),
CC_LOGGER_BIN("/bin/ldlogger", IEnvironmentVariable.ENVVAR_REPLACE),
//python variables comes after this;
PATH("/bin:", IEnvironmentVariable.ENVVAR_PREPEND),
VIRTUAL_ENV("pythonEnv", IEnvironmentVariable.ENVVAR_REPLACE);

public static Set<EnvironmentVariables> BASE_TYPE = EnumSet.range(LD_LIBRARY_PATH, CC_LOGGER_BIN);
public static Set<EnvironmentVariables> PYTHON_TYPE = EnumSet.range(PATH, VIRTUAL_ENV);
public static Set<EnvironmentVariables> ALL = EnumSet.range(LD_LIBRARY_PATH, VIRTUAL_ENV);
CC_LOGGER_BIN("/bin/ldlogger", IEnvironmentVariable.ENVVAR_REPLACE);

private String defaultValue;
private int method;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void cleanUp() {
*/
private void setEnvironment() {
//Initialize to defaults.
for (EnvironmentVariables ev :EnvironmentVariables.BASE_TYPE) {
for (EnvironmentVariables ev : EnvironmentVariables.values()) {
environmentVariables.put(ev, ev.getDefaultValue());
}
String checkerDir = current.get(ConfigTypes.CHECKER_PATH);
Expand All @@ -107,14 +107,6 @@ private void setEnvironment() {
Paths.get(codeCheckerWorkspace.toString(),
COMPILATION_COMMANDS).toString());

if (current.isPythonConfigured()) {
for (EnvironmentVariables ev :EnvironmentVariables.PYTHON_TYPE) {
environmentVariables.put(ev, ev.getDefaultValue());
}
environmentVariables.put(EnvironmentVariables.PATH,
current.get(ConfigTypes.PYTHON_PATH) + EnvironmentVariables.PATH.getDefaultValue());
environmentVariables.put(EnvironmentVariables.VIRTUAL_ENV, current.get(ConfigTypes.PYTHON_PATH));
}
modifyProjectEnvironmentVariables();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@
import java.util.HashMap;
import java.util.Map;

import org.codechecker.eclipse.plugin.Logger;
import org.codechecker.eclipse.plugin.config.Config.ConfigTypes;
import org.codechecker.eclipse.plugin.config.global.CcGlobalConfiguration;
import org.codechecker.eclipse.plugin.config.project.CodeCheckerProject;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;

import com.google.common.base.Optional;
import com.google.common.collect.ImmutableMap;

/**
* This class checks for Environments used by CodeChecker.
Expand All @@ -24,14 +21,12 @@ public class CodeCheckEnvironmentChecker {

private static final String HELP_ARGUMENT = "-h";
private static final int WAIT_TIME_MULTIPLYER = 1000; // in milliseconds
private static final Map<String, String> SYS_ENV = System.getenv();

public final Optional<String> pythonEnvironment;
public final String checkerDir; // root directory of CodeChecker
public final String codeCheckerCommand; // CodecCheker executable path

public final ImmutableMap<String, String> environmentBefore;

public Map<String, File> commandSubstitutionMap;
private Map<String, File> commandSubstitutionMap;

private Map<ConfigTypes,String> config;
private CodeCheckerProject project;
Expand All @@ -51,22 +46,10 @@ public CodeCheckEnvironmentChecker(CodeCheckerProject project) {
else
config = CcGlobalConfiguration.getInstance().get();

if (!config.containsKey(ConfigTypes.PYTHON_PATH)
|| (config.containsKey(ConfigTypes.PYTHON_PATH) && config.get(ConfigTypes.PYTHON_PATH).isEmpty())){
pythonEnvironment=Optional.absent();
SLogger.log(LogI.INFO, "pythonenv is not set");
}
else{
SLogger.log(LogI.INFO, "pythonenv is set to:" + config.get(ConfigTypes.PYTHON_PATH));
pythonEnvironment=Optional.of(config.get(ConfigTypes.PYTHON_PATH));
}

//checkerList=getConfigValue(ConfigTypes.CHECKER_LIST);
checkerDir=getConfigValue(ConfigTypes.CHECKER_PATH);
environmentBefore = getInitialEnvironment(pythonEnvironment);
codeCheckerCommand = checkerDir+"/bin/CodeChecker";


commandSubstitutionMap = new HashMap<String, File>() {{
put("CC_BIN", new File(codeCheckerCommand));
}};
Expand Down Expand Up @@ -105,8 +88,7 @@ private String getConfigValue(ConfigTypes key) {
public static void getCheckerEnvironment(
Map<ConfigTypes, String> config, String codeCheckerBinaryPath) {

ShellExecutorHelper she = new ShellExecutorHelper(
getInitialEnvironment(Optional.of(config.get(ConfigTypes.PYTHON_PATH))));
ShellExecutorHelper she = new ShellExecutorHelper(SYS_ENV);

String cmd = "'${CC_BINARY}' " + HELP_ARGUMENT;
@SuppressWarnings("serial")
Expand All @@ -130,34 +112,6 @@ public static void getCheckerEnvironment(
}
}

/**
* Returns new environment if using Python virtual environment or System env if not.
* @param pythonEnvironment Path to Python virtual environment activator.
* @return The environment to be used.
*/
private static ImmutableMap<String, String> getInitialEnvironment(Optional<String> pythonEnvironment) {
if (pythonEnvironment.isPresent()) {
ShellExecutorHelper she = new ShellExecutorHelper(System.getenv());
File pyEnv = new File(pythonEnvironment.get() + "/bin/activate");
String cmd = "source '${PY_ENV}' ; env";
@SuppressWarnings("serial")
Map<String, File> substitutionMap = new HashMap<String, File>() {{ put("PY_ENV", pyEnv); }};
Optional<String> output = she.quickReturnOutput(cmd, substitutionMap);
if (!output.isPresent()) {
Logger.log(IStatus.ERROR, "Couldn't check the python environment!");
throw new IllegalArgumentException("Couldn't check the given python environment!");
} else {
ImmutableMap<String, String> environment = (new EnvironmentParser()).parse(output
.get());
return environment;
}

} else {
SLogger.log(LogI.INFO, "Python Env not specified. Using original system env.");
return ImmutableMap.copyOf(System.getenv());
}
}

@Override
public boolean equals(Object obj) {
if (obj == null) return false;
Expand Down Expand Up @@ -194,7 +148,7 @@ public String createAnalyzeCommmand(String buildLog) {
* @return CodeChecker check command output
*/
public String processLog(String buildLog, boolean logToConsole, IProgressMonitor monitor, int taskCount) {
ShellExecutorHelper she = new ShellExecutorHelper(environmentBefore);
ShellExecutorHelper she = new ShellExecutorHelper(SYS_ENV);
String cmd = createAnalyzeCommmand(buildLog);
SLogger.log(LogI.INFO, "SERVER_SER_MSG >> processLog >> "+ cmd);
Optional<String> ccOutput = she.progressableWaitReturnOutput(cmd, commandSubstitutionMap, logToConsole, monitor, taskCount);
Expand All @@ -213,7 +167,7 @@ public String processLog(String buildLog, boolean logToConsole, IProgressMonitor
* @return A String containing the checkers. One at a line.
*/
public String getCheckerList() {
ShellExecutorHelper she = new ShellExecutorHelper(environmentBefore);
ShellExecutorHelper she = new ShellExecutorHelper(SYS_ENV);
String cmd = "'${CC_BIN}' checkers";
Optional<String> ccOutput = she.waitReturnOutput(cmd, commandSubstitutionMap, false);
return ccOutput.or("");
Expand Down
1 change: 0 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ Run `mvn -f mavendeps/pom.xml p2:site && mvn clean verify` in the root of the pr
Make sure that before staring Eclipse:

* CodeChecker/bin directory is included in PATH (e.g.: `export PATH="/home/<username>/CodeChecker/bin/:$PATH"`)
* Python virtualenv with CodeChecker dependencies is sourced (e.g.: `source /home/<username>/venv/bin/activate`)

__Currently the plugin is only usable with a CDT project.__

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotCLabel;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotText;
import org.hamcrest.core.IsNull;
import org.junit.Before;
import org.junit.BeforeClass;
Expand Down Expand Up @@ -74,13 +73,7 @@ public void testNoCodeCheckerFound() {
@Test
public void testCodeCheckerFound() {
Path ccDir = Utils.prepareCodeChecker();

SWTBotText text = bot.textWithLabel("CodeChecker package root directory");
text.setText(ccDir.toString());
text.setFocus();
bot.textWithLabel("Python virtualenv root directory (optional)").setFocus();

bot.sleep(SHORT_WAIT_TIME);
GuiUtils.setCCBinDir(ccDir, bot);

SWTBotCLabel label = null;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public final class GuiUtils {
public static final String ENVIR_LOGGER_BIN = "CC_LOGGER_BIN";
public static final String ENVIR_LOGGER_FILE = "CC_LOGGER_FILE";
public static final String LDOGGER = "ldlogger";
public static final String PY_DIR_WIDGET = "Python virtualenv root directory (optional)";
public static final String THREAD_WIDGET = "Number of analysis threads";
public static final String GLOBAL_RADIO = "Use global configuration";
public static final String PROJECT_RADIO = "Use project configuration";

Expand Down Expand Up @@ -110,10 +110,10 @@ public static void applyCloseProperties(SWTBotShell propertiesShell, SWTWorkbenc
public static void setCCBinDir(Path ccDir, SWTWorkbenchBot bot) {
SWTBotText text = bot.textWithLabel(GuiUtils.CC_DIR_WIDGET);
text.setText(ccDir.toString());
text.setFocus();
bot.textWithLabel(GuiUtils.PY_DIR_WIDGET).setFocus();
// text.setFocus();
// bot.textWithLabel(THREAD_WIDGET).setFocus();

bot.sleep(SHORT_WAIT_TIME);
// bot.sleep(SHORT_WAIT_TIME);
}

/**
Expand Down