├── .gitignore ├── .mvn └── extensions.xml ├── .project ├── .travis.yml ├── LICENSE ├── bundles ├── org.codechecker.eclipse.plugin │ ├── .checkstyle │ ├── .classpath │ ├── .project │ ├── .settings │ │ ├── org.eclipse.core.resources.prefs │ │ ├── org.eclipse.jdt.core.prefs │ │ └── org.eclipse.m2e.core.prefs │ ├── META-INF │ │ └── MANIFEST.MF │ ├── build.properties │ ├── contexts.xml │ ├── icons │ │ ├── analyze.png │ │ ├── arrow_down.png │ │ ├── arrow_left.png │ │ ├── arrow_right.png │ │ ├── arrow_up.png │ │ ├── double_down.png │ │ ├── double_left.png │ │ ├── double_right.png │ │ ├── double_up.png │ │ ├── filter.png │ │ └── sample.gif │ ├── log4j.properties │ ├── plugin.xml │ └── src │ │ └── org │ │ └── codechecker │ │ └── eclipse │ │ └── plugin │ │ ├── Activator.java │ │ ├── CodeCheckerNature.java │ │ ├── ExternalLogger.java │ │ ├── Logger.java │ │ ├── codechecker │ │ ├── CodeChecker.java │ │ ├── CodeCheckerFactory.java │ │ ├── ICodeChecker.java │ │ ├── ICodeCheckerFactory.java │ │ ├── locator │ │ │ ├── CodeCheckerLocatorFactory.java │ │ │ ├── CodeCheckerLocatorService.java │ │ │ ├── EnvCodeCheckerLocatorService.java │ │ │ ├── InvalidCodeCheckerException.java │ │ │ ├── PreBuiltCodeCheckerLocatorService.java │ │ │ ├── ResolutionMethodTypes.java │ │ │ └── package-info.java │ │ └── package-info.java │ │ ├── command │ │ └── AddProjectNature.java │ │ ├── config │ │ ├── .CodeCheckerContext.java.swn │ │ ├── CcConfiguration.java │ │ ├── CcConfigurationBase.java │ │ ├── CodeCheckerContext.java │ │ ├── CommonGui.java │ │ ├── Config.java │ │ ├── EnvironmentVariables.java │ │ ├── filter │ │ │ ├── Filter.java │ │ │ ├── FilterConfiguration.java │ │ │ └── store │ │ │ │ └── FilterStore.java │ │ ├── global │ │ │ ├── CcGlobalConfiguration.java │ │ │ ├── CcGlobalProperties.java │ │ │ └── package-info.java │ │ ├── package-info.java │ │ └── project │ │ │ ├── CcProjectProperties.java │ │ │ ├── CodeCheckerProject.java │ │ │ └── package-info.java │ │ ├── init │ │ ├── EditorPartListener.java │ │ ├── ProjectExplorerSelectionListener.java │ │ └── StartupJob.java │ │ ├── perspective │ │ └── CodeCheckerPerspectiveFactory.java │ │ ├── report │ │ ├── BugPathItem.java │ │ ├── FileInfo.java │ │ ├── Listener.java │ │ ├── PlistParser.java │ │ ├── ProblemInfo.java │ │ ├── ReportInfo.java │ │ ├── ReportParser.java │ │ ├── ResultCount.java │ │ ├── ResultFilter.java │ │ ├── ResultList.java │ │ ├── RunInfo.java │ │ ├── SearchList.java │ │ ├── SearchListener.java │ │ ├── Severity.java │ │ ├── job │ │ │ ├── AnalyzeJob.java │ │ │ ├── JobDoneChangeListener.java │ │ │ ├── PlistParseJob.java │ │ │ └── package-info.java │ │ └── package-info.java │ │ ├── runtime │ │ ├── IShellExecutorHelperFactory.java │ │ ├── LogI.java │ │ ├── OnCheckCallback.java │ │ ├── SLogger.java │ │ ├── ShellExecutorHelper.java │ │ ├── ShellExecutorHelperFactory.java │ │ └── package-info.java │ │ └── views │ │ ├── config │ │ └── filter │ │ │ ├── FilterConfigurationDialog.java │ │ │ └── ListContentProvider.java │ │ ├── console │ │ └── ConsoleFactory.java │ │ └── report │ │ └── list │ │ ├── ReportListView.java │ │ ├── ReportListViewCustom.java │ │ ├── ReportListViewListener.java │ │ ├── ReportListViewProject.java │ │ ├── action │ │ ├── NewInstanceAction.java │ │ ├── ShowFilterConfigurationDialog.java │ │ ├── rerun │ │ │ ├── RefreshAction.java │ │ │ ├── RerunAllAction.java │ │ │ └── RerunSelectedAction.java │ │ └── showas │ │ │ ├── CheckerGroupAction.java │ │ │ ├── CheckerTreeAction.java │ │ │ └── TreeAwareAction.java │ │ └── provider │ │ ├── content │ │ ├── CheckerGroupContentProvider.java │ │ └── TreeCheckerContentProvider.java │ │ └── label │ │ ├── BasicViewLabelProvider.java │ │ └── LastPartLabelProvider.java └── pom.xml ├── checkstyle.xml ├── docs ├── allperspective.png ├── checkershow.png ├── checkstyle.md ├── config.png ├── developer.md ├── example.png ├── img │ └── checkstyle │ │ ├── ide_config.png │ │ └── ide_proj_conf.png └── nature.png ├── features ├── org.codechecker.eclipse.feature │ ├── .project │ ├── build.properties │ └── feature.xml └── pom.xml ├── mavendeps └── pom.xml ├── pom.xml ├── readme.md ├── releng ├── org.codechecker.eclipse.configuration │ ├── .project │ └── pom.xml ├── org.codechecker.eclipse.target │ ├── .project │ ├── org.codechecker.eclipse.target.target │ └── pom.xml ├── org.codechecker.eclipse.update │ ├── .project │ ├── category.xml │ └── pom.xml └── pom.xml └── tests ├── org.codechecker.eclipse.rcp.it.tests ├── .checkstyle ├── .classpath ├── .gitignore ├── .project ├── .settings │ ├── org.eclipse.core.resources.prefs │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.m2e.core.prefs ├── META-INF │ └── MANIFEST.MF ├── build.properties ├── fragment.xml ├── pom.xml ├── resources │ ├── .gitkeep │ └── cppTest │ │ ├── .cproject │ │ ├── .project │ │ ├── .settings │ │ └── language.settings.xml │ │ └── src │ │ └── cppTest.cpp └── src │ └── org │ └── codechecker │ └── eclipse │ └── plugin │ ├── AllTests.java │ ├── AnalysisTest.java │ ├── ConfigurationTest.java │ ├── IndicatorTest.java │ ├── ParameterPassThroughTest.java │ ├── PluginTest.java │ ├── package-info.java │ └── utils │ ├── CompilationLogHelper.java │ ├── GuiUtils.java │ ├── ProjectImporter.java │ └── package-info.java ├── org.codechecker.eclipse.rcp.shared ├── .classpath ├── .project ├── .settings │ └── org.eclipse.jdt.core.prefs ├── META-INF │ └── MANIFEST.MF ├── build.properties ├── resources │ └── CodeChecker │ │ └── bin │ │ ├── CodeChecker │ │ └── plists │ │ ├── cppTest.cpp_1.plist │ │ └── cppTest.cpp_2.plist └── src │ └── org │ └── codechecker │ └── eclipse │ └── rcp │ └── shared │ └── utils │ ├── Utils.java │ └── package-info.java ├── org.codechecker.eclipse.rcp.unit.tests ├── .checkstyle ├── .classpath ├── .gitignore ├── .project ├── .settings │ └── org.eclipse.jdt.core.prefs ├── META-INF │ └── MANIFEST.MF ├── build.properties ├── pom.xml ├── resources │ └── plists │ │ ├── test_plist_1.plist │ │ └── test_plist_2.plist └── src │ └── org │ └── codechecker │ └── eclipse │ └── plugin │ ├── codechecker │ ├── CodeCheckerTest.java │ ├── locator │ │ ├── CodeCheckerLocatorTest.java │ │ └── package-info.java │ └── package-info.java │ ├── report │ └── PlistParserTest.java │ └── runtime │ ├── ShellExecutorHelperTest.java │ └── package-info.java └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # vim 4 | *.swp 5 | *.swo 6 | 7 | # Eclipse 8 | bin/ 9 | .idea 10 | *.iml 11 | target/ 12 | logs/ 13 | 14 | # Package Files # 15 | *.jar 16 | *.war 17 | *.ear 18 | 19 | # maven 20 | pom.xml.tag 21 | pom.xml.releaseBackup 22 | pom.xml.versionsBackup 23 | pom.xml.next 24 | release.properties 25 | dependency-reduced-pom.xml 26 | -------------------------------------------------------------------------------- /.mvn/extensions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.eclipse.tycho.extras 4 | tycho-pomless 5 | 1.3.0 6 | 7 | 8 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.codechecker.eclipse 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | dist: trusty 2 | install: true 3 | language: java 4 | jdk: 5 | - oraclejdk8 6 | - oraclejdk9 7 | - oraclejdk11 8 | - openjdk8 9 | 10 | env: DISPLAY=:99.0 11 | 12 | matrix: 13 | include: 14 | - jdk: openjdk10 15 | before_install: 16 | - rm "${JAVA_HOME}/lib/security/cacerts" 17 | - ln -s /etc/ssl/certs/java/cacerts "${JAVA_HOME}/lib/security/cacerts" 18 | - jdk: openjdk11 19 | before_install: 20 | - rm "${JAVA_HOME}/lib/security/cacerts" 21 | - ln -s /etc/ssl/certs/java/cacerts "${JAVA_HOME}/lib/security/cacerts" 22 | 23 | before_install: 24 | - sudo apt-get install at-spi2-core 25 | 26 | before_script: 27 | - sh -e /etc/init.d/xvfb start 28 | - sleep 10 # give xvfb some time to start 29 | 30 | script: mvn -f mavendeps/pom.xml p2:site && mvn clean verify 31 | 32 | after_failure: 33 | - cat $TRAVIS_BUILD_DIR/tests/org.codechecker.eclipse.rcp.it.tests/target/work/data/.metadata/.log 34 | - cat $TRAVIS_BUILD_DIR/tests/org.codechecker.eclipse.rcp.it.tests/target/surefire-reports/* 35 | - cat $TRAVIS_BUILD_DIR/tests/org.codechecker.eclipse.rcp.unit.tests/target/work/configuration/*.log 36 | - cat $TRAVIS_BUILD_DIR/tests/org.codechecker.eclipse.rcp.unit.tests/target/surefire-reports/* 37 | 38 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/.checkstyle: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.codechecker.eclipse.plugin 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.pde.ManifestBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.pde.SchemaBuilder 20 | 21 | 22 | 23 | 24 | org.eclipse.m2e.core.maven2Builder 25 | 26 | 27 | 28 | 29 | 30 | org.eclipse.m2e.core.maven2Nature 31 | org.eclipse.pde.PluginNature 32 | org.eclipse.jdt.core.javanature 33 | 34 | 35 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding/=UTF-8 3 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate 4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 6 | org.eclipse.jdt.core.compiler.compliance=1.8 7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.source=1.8 13 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: org.codechecker.eclipse 4 | Bundle-SymbolicName: org.codechecker.eclipse.plugin;singleton:=true 5 | Bundle-Version: 0.0.6.qualifier 6 | Require-Bundle: org.eclipse.ui, 7 | org.eclipse.ui.ide, 8 | org.eclipse.core.runtime, 9 | org.eclipse.core.resources;bundle-version="3.9.1", 10 | org.eclipse.ui.forms;bundle-version="3.6.100", 11 | org.eclipse.core.databinding, 12 | org.eclipse.core.databinding.beans, 13 | org.eclipse.core.databinding.observable, 14 | org.eclipse.core.databinding.property, 15 | org.eclipse.jface.databinding, 16 | org.eclipse.swt, 17 | org.eclipse.cdt.core, 18 | org.eclipse.ui.console, 19 | com.googlecode.plist.dd-plist;bundle-version="1.21.0", 20 | com.google.guava;bundle-version="26.0.0", 21 | org.apache.commons.lang;bundle-version="3.0.0", 22 | org.apache.commons.exec;bundle-version="1.3.0", 23 | joda-time;bundle-version="2.10.1", 24 | com.google.gson;bundle-version="2.3.1", 25 | log4j;bundle-version="1.2.17", 26 | org.eclipse.jdt.annotation;bundle-version="2.1.100" 27 | Bundle-RequiredExecutionEnvironment: JavaSE-1.8 28 | Export-Package: org.codechecker.eclipse.plugin, 29 | org.codechecker.eclipse.plugin.runtime 30 | Import-Package: com.google.gson 31 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/build.properties: -------------------------------------------------------------------------------- 1 | source..=src/ 2 | output..=target/classes/ 3 | bin.includes = plugin.xml,\ 4 | META-INF/,\ 5 | .,\ 6 | icons/,\ 7 | contexts.xml,\ 8 | log4j.properties 9 | 10 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/contexts.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | This is the context help for the sample view with a tree viewer. It was 5 | generated by a PDE template. 6 | 7 | 9 | 10 | 11 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/icons/analyze.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ericsson/CodeCheckerEclipsePlugin/bd79c2631d81cf077864ddfac6068dd062c3aa91/bundles/org.codechecker.eclipse.plugin/icons/analyze.png -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/icons/arrow_down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ericsson/CodeCheckerEclipsePlugin/bd79c2631d81cf077864ddfac6068dd062c3aa91/bundles/org.codechecker.eclipse.plugin/icons/arrow_down.png -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/icons/arrow_left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ericsson/CodeCheckerEclipsePlugin/bd79c2631d81cf077864ddfac6068dd062c3aa91/bundles/org.codechecker.eclipse.plugin/icons/arrow_left.png -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/icons/arrow_right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ericsson/CodeCheckerEclipsePlugin/bd79c2631d81cf077864ddfac6068dd062c3aa91/bundles/org.codechecker.eclipse.plugin/icons/arrow_right.png -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/icons/arrow_up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ericsson/CodeCheckerEclipsePlugin/bd79c2631d81cf077864ddfac6068dd062c3aa91/bundles/org.codechecker.eclipse.plugin/icons/arrow_up.png -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/icons/double_down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ericsson/CodeCheckerEclipsePlugin/bd79c2631d81cf077864ddfac6068dd062c3aa91/bundles/org.codechecker.eclipse.plugin/icons/double_down.png -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/icons/double_left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ericsson/CodeCheckerEclipsePlugin/bd79c2631d81cf077864ddfac6068dd062c3aa91/bundles/org.codechecker.eclipse.plugin/icons/double_left.png -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/icons/double_right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ericsson/CodeCheckerEclipsePlugin/bd79c2631d81cf077864ddfac6068dd062c3aa91/bundles/org.codechecker.eclipse.plugin/icons/double_right.png -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/icons/double_up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ericsson/CodeCheckerEclipsePlugin/bd79c2631d81cf077864ddfac6068dd062c3aa91/bundles/org.codechecker.eclipse.plugin/icons/double_up.png -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/icons/filter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ericsson/CodeCheckerEclipsePlugin/bd79c2631d81cf077864ddfac6068dd062c3aa91/bundles/org.codechecker.eclipse.plugin/icons/filter.png -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/icons/sample.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ericsson/CodeCheckerEclipsePlugin/bd79c2631d81cf077864ddfac6068dd062c3aa91/bundles/org.codechecker.eclipse.plugin/icons/sample.gif -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=DEBUG, log, console 2 | 3 | log4j.appender.log=org.apache.log4j.DailyRollingFileAppender 4 | log4j.appender.log.datePattern='.'yyyy-MM-dd 5 | log4j.appender.log.Append=true 6 | log4j.appender.log.File=logs/codechecker_plugin.log 7 | log4j.appender.log.encoding=UTF-8 8 | log4j.appender.log.layout=org.apache.log4j.PatternLayout 9 | log4j.appender.log.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %t %x %-5p %c{1}:%L - %m%n 10 | 11 | # You can specify the log level here 12 | # log levels 13 | # TRACE, 14 | # DEBUG, 15 | # INFO, 16 | # WARN, 17 | # ERROR, 18 | # FATAL 19 | log4j.appender.log.threshold=ERROR 20 | 21 | log4j.appender.console=org.apache.log4j.ConsoleAppender 22 | log4j.appender.console.target=System.err 23 | log4j.appender.console.threshold=ERROR 24 | log4j.appender.console.layout = org.apache.log4j.PatternLayout 25 | log4j.appender.console.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %t %x %-5p %c{1}:%L - %m%n 26 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/Activator.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin; 2 | 3 | import org.eclipse.cdt.utils.Platform; 4 | import org.eclipse.core.runtime.FileLocator; 5 | import org.eclipse.core.runtime.IPath; 6 | import org.eclipse.core.runtime.Path; 7 | import org.eclipse.core.runtime.jobs.Job; 8 | import org.eclipse.jface.resource.ImageDescriptor; 9 | import org.eclipse.ui.IStartup; 10 | import org.eclipse.ui.plugin.AbstractUIPlugin; 11 | import org.osgi.framework.Bundle; 12 | import org.osgi.framework.BundleContext; 13 | 14 | import org.codechecker.eclipse.plugin.init.StartupJob; 15 | import org.codechecker.eclipse.plugin.views.console.ConsoleFactory; 16 | 17 | import java.net.URL; 18 | 19 | import org.apache.log4j.PropertyConfigurator; 20 | 21 | /** 22 | * The activator class controls the plug-in life cycle 23 | */ 24 | public class Activator extends AbstractUIPlugin implements IStartup { 25 | 26 | // The plug-in ID 27 | public static final String PLUGIN_ID = "org.codechecker.eclipse.plugin"; //$NON-NLS-1$ 28 | 29 | // The shared instance 30 | private static Activator plugin; 31 | 32 | private static IPath preferencesPath; 33 | 34 | /** 35 | * The constructor 36 | */ 37 | public Activator() { 38 | Bundle bundle = Platform.getBundle(Activator.PLUGIN_ID); 39 | final URL fullPathString = FileLocator.find(bundle, new Path("log4j.properties"), null); 40 | PropertyConfigurator.configure(fullPathString); 41 | } 42 | 43 | public static IPath getPreferencesPath() { 44 | return preferencesPath; 45 | } 46 | 47 | /** 48 | * Returns the shared instance 49 | * 50 | * @return the shared instance 51 | */ 52 | public static Activator getDefault() { 53 | return plugin; 54 | } 55 | 56 | /** 57 | * Returns an image descriptor for the image file at the given plug-in relative path 58 | * 59 | * @param path the path 60 | * @return the image descriptor 61 | */ 62 | public static ImageDescriptor getImageDescriptor(String path) { 63 | return imageDescriptorFromPlugin(PLUGIN_ID, path); 64 | } 65 | 66 | /* 67 | * (non-Javadoc) 68 | * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) 69 | */ 70 | public void start(BundleContext context) throws Exception { 71 | ConsoleFactory.consoleWrite("CodeChecker Plugin Started"); 72 | super.start(context); 73 | 74 | //earlyStartup(); 75 | } 76 | 77 | /* 78 | * (non-Javadoc) 79 | * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) 80 | */ 81 | public void stop(BundleContext context) throws Exception { 82 | plugin = null; 83 | ConsoleFactory.consoleWrite("CodeChecker Plugin Stopped"); 84 | super.stop(context); 85 | } 86 | 87 | @Override 88 | public void earlyStartup() { 89 | plugin = this; 90 | 91 | preferencesPath = getStateLocation(); 92 | 93 | Job j = new StartupJob(); 94 | j.setPriority(Job.INTERACTIVE); 95 | j.schedule(); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/CodeCheckerNature.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin; 2 | 3 | import org.eclipse.core.resources.IProject; 4 | import org.eclipse.core.resources.IProjectNature; 5 | import org.eclipse.core.runtime.CoreException; 6 | 7 | import org.codechecker.eclipse.plugin.config.CodeCheckerContext; 8 | import org.codechecker.eclipse.plugin.config.project.CodeCheckerProject; 9 | 10 | /** 11 | * Eclipse uses natures as project feature indicators. 12 | * This class adds CodeChecker related nature. 13 | * 14 | */ 15 | public class CodeCheckerNature implements IProjectNature { 16 | 17 | public static final String NATURE_ID = "org.codechecker.eclipse.plugin.CodeCheckerNature"; 18 | IProject project; 19 | 20 | @Override 21 | public void configure() throws CoreException { 22 | CodeCheckerProject cCProject = new CodeCheckerProject(project); 23 | cCProject.modifyProjectEnvironmentVariables(); 24 | CodeCheckerContext.getInstance().addCodeCheckerProject(cCProject); 25 | } 26 | 27 | @Override 28 | public void deconfigure() throws CoreException {} 29 | 30 | @Override 31 | public IProject getProject() { 32 | return project; 33 | } 34 | 35 | @Override 36 | public void setProject(IProject project) { 37 | this.project = project; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/ExternalLogger.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin; 2 | 3 | import org.codechecker.eclipse.plugin.runtime.LogI; 4 | import org.codechecker.eclipse.plugin.views.console.ConsoleFactory;; 5 | 6 | //logger service for non plugin internal 7 | //components (such as the codechecker service) 8 | public class ExternalLogger implements LogI{ 9 | public void log(int severity,String message){ 10 | Logger.extLog(severity, message); 11 | } 12 | //logs to CodeChecker console 13 | public void consoleLog(String message){ 14 | ConsoleFactory.consoleWrite(message); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/Logger.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin; 2 | 3 | import java.io.PrintWriter; 4 | import java.io.StringWriter; 5 | 6 | import org.eclipse.core.runtime.ILog; 7 | import org.eclipse.core.runtime.Status; 8 | 9 | import org.codechecker.eclipse.plugin.views.console.ConsoleFactory; 10 | 11 | 12 | public class Logger { 13 | private static ILog logger = Activator.getDefault().getLog(); 14 | public static void log(int level,String message){ 15 | StackTraceElement s[] = Thread.currentThread().getStackTrace(); 16 | if (s.length>2){ 17 | StackTraceElement caller=s[2]; 18 | String place=caller.getFileName()+":"+caller.getLineNumber()+" "+caller.getMethodName()+"(): "; 19 | logger.log(new Status(level,Activator.PLUGIN_ID,place+message)); 20 | } 21 | } 22 | public static void extLog(int level,String message){ 23 | StackTraceElement s[] = Thread.currentThread().getStackTrace(); 24 | if (s.length>4){//we do not want to show the ExternalLogger.log function in the trace 25 | StackTraceElement caller=s[4]; 26 | String place=caller.getFileName()+":"+caller.getLineNumber()+" "+caller.getMethodName()+"(): "; 27 | logger.log(new Status(level,Activator.PLUGIN_ID,place+message)); 28 | } 29 | } 30 | //logs to CodeChecker console 31 | public static void consoleLog(String message){ 32 | ConsoleFactory.consoleWrite(message); 33 | } 34 | 35 | /** 36 | * Returns Stack Trace as String. 37 | * @param throwable The exception in question. 38 | * @return The Stack Trace as String. 39 | */ 40 | public static String getStackTrace(final Throwable throwable) { 41 | final StringWriter sw = new StringWriter(); 42 | final PrintWriter pw = new PrintWriter(sw, true); 43 | throwable.printStackTrace(pw); 44 | return sw.getBuffer().toString(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/codechecker/CodeCheckerFactory.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.codechecker; 2 | 3 | import java.nio.file.Path; 4 | 5 | import org.codechecker.eclipse.plugin.codechecker.locator.InvalidCodeCheckerException; 6 | import org.codechecker.eclipse.plugin.runtime.ShellExecutorHelper; 7 | 8 | /** 9 | * Implementation of the {@link ICodeCheckerFactory} interface. 10 | */ 11 | public class CodeCheckerFactory implements ICodeCheckerFactory { 12 | @Override 13 | public ICodeChecker createCodeChecker(Path pathToBin, ShellExecutorHelper she) 14 | throws InvalidCodeCheckerException { 15 | return new CodeChecker(pathToBin, she); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/codechecker/ICodeChecker.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.codechecker; 2 | 3 | import java.nio.file.Path; 4 | 5 | import org.codechecker.eclipse.plugin.codechecker.locator.InvalidCodeCheckerException; 6 | import org.codechecker.eclipse.plugin.config.CcConfigurationBase; 7 | import org.eclipse.core.runtime.IProgressMonitor; 8 | import org.eclipse.jdt.annotation.NonNull; 9 | import org.eclipse.jdt.annotation.Nullable; 10 | 11 | /** 12 | * Interface representing a CodeChecker package. 13 | */ 14 | public interface ICodeChecker { 15 | /** 16 | * Returns the unformatted output of the CodeChecker checkers command. 17 | * 18 | * @return The checker list. 19 | */ 20 | @NonNull 21 | public String getCheckers(); 22 | 23 | /** 24 | * Returns the full and complete version string of the CodeChecker package. The 25 | * returned String will never be empty. 26 | * 27 | * @return The version String. 28 | * @throws InvalidCodeCheckerException 29 | * Thrown when no version string can be returned. 30 | */ 31 | @NonNull 32 | public String getVersion() throws InvalidCodeCheckerException; 33 | 34 | /** 35 | * To get the location of the CodeChecker binary. The returned String will never 36 | * be empty. 37 | * 38 | * @return The path. 39 | */ 40 | public Path getLocation(); 41 | 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 | * @param skipFile 51 | * Skipfile to be used. 52 | * @return The analyze command as String. 53 | */ 54 | public String getAnalyzeString(CcConfigurationBase config, @Nullable Path logFile, @Nullable Path skipFile); 55 | 56 | /** 57 | * Executes CodeChecker check command on the build log received in the logFile 58 | * parameter. 59 | * 60 | * @param logFile 61 | * A Path to the build log in the following format: 62 | * http://clang.llvm.org/docs/JSONCompilationDatabase.html . 63 | * @param logToConsole 64 | * Flag for indicating console logging. 65 | * @param monitor 66 | * ProgressMonitor for to be able to increment progress bar. 67 | * @param taskCount 68 | * How many analyze step to be taken. 69 | * @param config 70 | * The configuration being used. 71 | * @param FileToBeAnalyzed Filesystem path of the analysis target. 72 | * @return CodeChecker The full analyze command output. 73 | */ 74 | public String analyze(Path logFile, boolean logToConsole, IProgressMonitor monitor, int taskCount, 75 | CcConfigurationBase config, Path FileToBeAnalyzed); 76 | 77 | public void cancelAnalyze(); 78 | } 79 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/codechecker/ICodeCheckerFactory.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.codechecker; 2 | 3 | import java.nio.file.Path; 4 | 5 | import org.codechecker.eclipse.plugin.codechecker.locator.InvalidCodeCheckerException; 6 | import org.codechecker.eclipse.plugin.runtime.ShellExecutorHelper; 7 | 8 | /** 9 | * Interface for CodeChecker factory. 10 | */ 11 | public interface ICodeCheckerFactory { 12 | /** 13 | * Method for creating CodeChecker instances. 14 | * 15 | * @param pathToBin 16 | * Path to the CodeChecker binary. (Not to root!) 17 | * @param she 18 | * The shell executor helper that will be used. 19 | * @return A newly created {@link ICodeChecker} ICodeChecker instance. 20 | * @throws InvalidCodeCheckerException 21 | * Thrown when a new instance couldn't be created. 22 | */ 23 | public ICodeChecker createCodeChecker(Path pathToBin, ShellExecutorHelper she) 24 | throws InvalidCodeCheckerException; 25 | } 26 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/codechecker/locator/CodeCheckerLocatorFactory.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.codechecker.locator; 2 | 3 | /** 4 | * Class responsible to create {@link CodeCheckerLocatorService} instances. 5 | */ 6 | public class CodeCheckerLocatorFactory { 7 | /** 8 | * Returns a {@link CodeCheckerLocatorService} depending on a the input 9 | * parameter. 10 | * 11 | * @param t 12 | * Any of the {@link ResolutionMethodTypes} enum values. 13 | * @return A {@link CodeCheckerLocatorService} instance. 14 | */ 15 | public CodeCheckerLocatorService create(ResolutionMethodTypes t) { 16 | switch (t) { 17 | case PATH: 18 | return new EnvCodeCheckerLocatorService(); 19 | case PRE: 20 | return new PreBuiltCodeCheckerLocatorService(); 21 | default: 22 | return null; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/codechecker/locator/CodeCheckerLocatorService.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.codechecker.locator; 2 | 3 | import java.nio.file.Path; 4 | 5 | import org.codechecker.eclipse.plugin.codechecker.ICodeChecker; 6 | import org.codechecker.eclipse.plugin.codechecker.ICodeCheckerFactory; 7 | import org.codechecker.eclipse.plugin.runtime.IShellExecutorHelperFactory; 8 | 9 | /** 10 | * Implementations of this interface should return the location of the 11 | * CodeChecker package. 12 | */ 13 | public abstract class CodeCheckerLocatorService { 14 | /** 15 | * @param pathToBin 16 | * Path to CodeChecker package root. 17 | * @param ccfactory 18 | * An {@link ICodeCheckerFactory} that will create the CodeChecker. 19 | * @param sheFactory 20 | * A {@link IShellExecutorHelperFactory} to be used. 21 | * @return A CodeChecker Instance. 22 | * @throws InvalidCodeCheckerException 23 | * Thrown when the {@link ICodeChecker} instantiation fails. 24 | */ 25 | public abstract ICodeChecker findCodeChecker(Path pathToBin, ICodeCheckerFactory ccfactory, IShellExecutorHelperFactory sheFactory) 26 | throws InvalidCodeCheckerException; 27 | } 28 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/codechecker/locator/EnvCodeCheckerLocatorService.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.codechecker.locator; 2 | 3 | import java.nio.file.Path; 4 | import java.nio.file.Paths; 5 | 6 | import org.codechecker.eclipse.plugin.codechecker.ICodeChecker; 7 | import org.codechecker.eclipse.plugin.codechecker.ICodeCheckerFactory; 8 | import org.codechecker.eclipse.plugin.runtime.IShellExecutorHelperFactory; 9 | import org.codechecker.eclipse.plugin.runtime.ShellExecutorHelper; 10 | 11 | /** 12 | * Provides a CodeChecker instance tied to a CodeChecker package resulting of 13 | * "which CodeChecker". 14 | */ 15 | public class EnvCodeCheckerLocatorService extends CodeCheckerLocatorService { 16 | public static final String CC_NOT_FOUND = "CodeChecker wasn't found in PATH environment variable!"; 17 | 18 | @Override 19 | public ICodeChecker findCodeChecker(Path path, ICodeCheckerFactory ccFactory, 20 | IShellExecutorHelperFactory sheFactory) throws InvalidCodeCheckerException { 21 | 22 | ShellExecutorHelper she = sheFactory.createShellExecutorHelper(System.getenv()); 23 | String location = she.quickReturnFirstLine("which CodeChecker", null).or(""); 24 | try { 25 | return ccFactory.createCodeChecker(Paths.get(location), she); 26 | } catch (InvalidCodeCheckerException e) { 27 | throw new InvalidCodeCheckerException(CC_NOT_FOUND); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/codechecker/locator/InvalidCodeCheckerException.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.codechecker.locator; 2 | 3 | /** 4 | * Custom exception indicating a failed CodeChecker instance creation. 5 | */ 6 | @SuppressWarnings("serial") 7 | public class InvalidCodeCheckerException extends Exception { 8 | /** 9 | * Ctor. 10 | * 11 | * @param errorMessage 12 | * Error message. 13 | */ 14 | public InvalidCodeCheckerException(String errorMessage) { 15 | super(errorMessage); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/codechecker/locator/PreBuiltCodeCheckerLocatorService.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.codechecker.locator; 2 | 3 | import java.nio.file.Path; 4 | 5 | import org.codechecker.eclipse.plugin.codechecker.ICodeChecker; 6 | import org.codechecker.eclipse.plugin.codechecker.ICodeCheckerFactory; 7 | import org.codechecker.eclipse.plugin.runtime.IShellExecutorHelperFactory; 8 | 9 | /** 10 | * Provides a CodeChecker instance which is tied to a pre-built CodeChecker 11 | * package. 12 | */ 13 | public class PreBuiltCodeCheckerLocatorService extends CodeCheckerLocatorService { 14 | public static final String CC_INVALID = "The path to the CodeChecker binary is not valid"; 15 | public static final String CC_NOT_FOUND = "Couldn't find CodeChecker at the given destination!"; 16 | 17 | @Override 18 | public ICodeChecker findCodeChecker(Path pathToBin, ICodeCheckerFactory ccfactory, 19 | IShellExecutorHelperFactory sheFactory) throws InvalidCodeCheckerException { 20 | if (pathToBin == null) 21 | throw new IllegalArgumentException(CC_INVALID); 22 | try { 23 | return ccfactory.createCodeChecker(pathToBin, sheFactory.createShellExecutorHelper(System.getenv())); 24 | } catch (InvalidCodeCheckerException e) { 25 | throw new InvalidCodeCheckerException(CC_NOT_FOUND); 26 | } 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/codechecker/locator/ResolutionMethodTypes.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.codechecker.locator; 2 | 3 | /** 4 | * This enum represents the available types of CodeChecker resolution methods. 5 | */ 6 | public enum ResolutionMethodTypes { 7 | PATH, PRE; 8 | } 9 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/codechecker/locator/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * CodeChecker locator related classes. 3 | */ 4 | package org.codechecker.eclipse.plugin.codechecker.locator; -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/codechecker/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * CodeChecker related classes. 3 | */ 4 | package org.codechecker.eclipse.plugin.codechecker; -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/command/AddProjectNature.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.command; 2 | 3 | import org.eclipse.core.commands.AbstractHandler; 4 | import org.eclipse.core.commands.ExecutionEvent; 5 | import org.eclipse.core.commands.ExecutionException; 6 | import org.eclipse.ui.IWorkbenchWindow; 7 | import org.eclipse.core.resources.IProject; 8 | import org.eclipse.core.resources.IProjectDescription; 9 | import org.eclipse.core.runtime.CoreException; 10 | import org.eclipse.core.runtime.IAdaptable; 11 | import org.eclipse.core.runtime.IPath; 12 | import org.eclipse.core.runtime.IProgressMonitor; 13 | import org.eclipse.jface.viewers.IStructuredSelection; 14 | import org.eclipse.ui.PlatformUI; 15 | 16 | import org.codechecker.eclipse.plugin.CodeCheckerNature; 17 | import org.codechecker.eclipse.plugin.views.console.ConsoleFactory; 18 | 19 | 20 | import org.codechecker.eclipse.plugin.Logger; 21 | import org.eclipse.core.runtime.IStatus; 22 | 23 | public class AddProjectNature extends AbstractHandler { 24 | 25 | @Override 26 | public Object execute(ExecutionEvent event) throws ExecutionException { 27 | // TODO Auto-generated method stub 28 | 29 | IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); 30 | if (window != null) { 31 | IStructuredSelection selection = (IStructuredSelection) window.getSelectionService() 32 | .getSelection(); 33 | Object firstElement = selection.getFirstElement(); 34 | if (firstElement instanceof IAdaptable) { 35 | IProject project = (IProject) ((IAdaptable) firstElement).getAdapter(IProject 36 | .class); 37 | if (project == null) { 38 | Logger.log(IStatus.INFO, "Not a project."); 39 | return null; 40 | } 41 | IPath path = project.getFullPath(); 42 | Logger.log(IStatus.INFO, "" + path); 43 | 44 | try { 45 | if (project.hasNature(CodeCheckerNature.NATURE_ID)) { 46 | return null; 47 | } 48 | 49 | IProjectDescription description = project.getDescription(); 50 | String[] prevNatures = description.getNatureIds(); 51 | String[] newNatures = new String[prevNatures.length + 1]; 52 | System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length); 53 | newNatures[prevNatures.length] = CodeCheckerNature.NATURE_ID; 54 | description.setNatureIds(newNatures); 55 | 56 | IProgressMonitor monitor = null; 57 | project.setDescription(description, monitor); 58 | ConsoleFactory.consoleWrite(project.getName() + ": Sucessfully added CodeChecker Nature"); 59 | Logger.log(IStatus.INFO, "Project nature added!"); 60 | 61 | } catch (CoreException e) { 62 | // TODO Auto-generated catch block 63 | Logger.log(IStatus.ERROR, e.toString()); 64 | Logger.log(IStatus.INFO, e.getStackTrace().toString()); 65 | } 66 | 67 | } 68 | } 69 | 70 | return null; 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/config/.CodeCheckerContext.java.swn: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ericsson/CodeCheckerEclipsePlugin/bd79c2631d81cf077864ddfac6068dd062c3aa91/bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/config/.CodeCheckerContext.java.swn -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/config/CcConfigurationBase.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.config; 2 | 3 | import java.util.HashSet; 4 | import java.util.Map; 5 | import java.util.Set; 6 | 7 | import org.codechecker.eclipse.plugin.codechecker.ICodeChecker; 8 | import org.codechecker.eclipse.plugin.config.Config.ConfigTypes; 9 | import org.eclipse.core.runtime.preferences.IEclipsePreferences; 10 | 11 | /** 12 | * Interface for CodeChecker configuration. 13 | */ 14 | public abstract class CcConfigurationBase { 15 | 16 | protected static final String STR_EMPTY = ""; 17 | 18 | protected Map config; 19 | protected IEclipsePreferences preferences; 20 | protected ICodeChecker codeChecker; 21 | 22 | private final Set listeners = new HashSet<>(); 23 | 24 | /** 25 | * Base Constructor. 26 | */ 27 | public CcConfigurationBase() {} 28 | 29 | /** 30 | * For Updates the configuration. 31 | * @param config The new configuration. 32 | */ 33 | public abstract void update(Map config); 34 | 35 | /** 36 | * For initializing the internal configuration. 37 | */ 38 | public abstract void load(); 39 | 40 | /** 41 | * For checking that the loaded configuration is valid. 42 | */ 43 | protected abstract void validate(); 44 | 45 | /** 46 | * @return The CodeChecker being used. 47 | */ 48 | public ICodeChecker getCodeChecker() { 49 | return codeChecker; 50 | } 51 | 52 | /** 53 | * Sets the currently used CodeChecker. 54 | * 55 | * @param codeChecker 56 | * The CodeChecker that will be stored. 57 | */ 58 | public void setCodeChecker(ICodeChecker codeChecker) { 59 | this.codeChecker = codeChecker; 60 | } 61 | 62 | /** 63 | * @return the internal configuration. 64 | */ 65 | public Map get() { 66 | return config; 67 | } 68 | 69 | /** 70 | * @param type The key of the value that we are interested in. 71 | * @return The value. 72 | */ 73 | public String get(ConfigTypes type) { 74 | return config.get(type); 75 | } 76 | 77 | /** 78 | * Returns the default configuration for the plug-in. 79 | * @return An Unmodifiable view of the default configuration Map. 80 | */ 81 | public Map getDefaultConfig() { 82 | return ConfigTypes.getCommonDefault(); 83 | } 84 | 85 | /** 86 | * @param listener The listener to be added. 87 | */ 88 | public void registerChangeListener(ConfigurationChangedListener listener) { 89 | listeners.add(listener); 90 | } 91 | 92 | /** 93 | * @param listener The listener to be removed. 94 | */ 95 | public void deRegisterChangeListener(ConfigurationChangedListener listener) { 96 | if (listener != null) 97 | listeners.remove(listener); 98 | } 99 | 100 | /** 101 | * Notifies registered listeners that the configuration had been changed. 102 | * @param config the new configuration. 103 | */ 104 | public void notifyListeners(Map config) { 105 | for (ConfigurationChangedListener configurationChangedListener : listeners) { 106 | configurationChangedListener.configUpdated(config); 107 | } 108 | } 109 | 110 | /** 111 | * Implement this interface and use {@link registerChangeListener} to get 112 | * notifications about configuration changes. 113 | */ 114 | public interface ConfigurationChangedListener{ 115 | /** 116 | * {@link notifyListenersn} will call this method when the configuration changes. 117 | * @param config The new configuration. 118 | */ 119 | public void configUpdated(Map config); 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/config/Config.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.config; 2 | 3 | import java.util.EnumSet; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | import java.util.Set; 7 | 8 | import org.codechecker.eclipse.plugin.Logger; 9 | import org.eclipse.core.runtime.IStatus; 10 | 11 | /** 12 | * Classes for handling actual configuration entries, and logging. 13 | * 14 | */ 15 | public class Config { 16 | /** 17 | * Represents all available configuraton values. 18 | * Watch form marking comments, because specialized sets (Common, Project) 19 | * are returned using enumset range, 20 | * 21 | */ 22 | public enum ConfigTypes { 23 | // Common configuration values 24 | CHECKER_PATH("codechecker_path"), 25 | RES_METHOD("PATH"), 26 | COMPILERS("gcc:g++:clang:clang++:c++:cc"), 27 | ANAL_THREADS("4"), 28 | ANAL_OPTIONS(""), 29 | // Project configuration values 30 | IS_GLOBAL("true"), 31 | CHECKER_WORKSPACE("codechecker_workdir"); 32 | 33 | public static Set COMMON_TYPE = EnumSet.range(CHECKER_PATH, ANAL_OPTIONS); 34 | public static Set PROJECT_TYPE = EnumSet.range(IS_GLOBAL, CHECKER_WORKSPACE); 35 | private String defaultValue; 36 | 37 | /** 38 | * 39 | * @param def utility method for setting the default value. 40 | */ 41 | private ConfigTypes(String def) { 42 | this.defaultValue = def; 43 | } 44 | 45 | /** 46 | * 47 | * @return Returns the default value associated with the enum. 48 | */ 49 | public String getDefaultValue() { 50 | return defaultValue; 51 | } 52 | 53 | /** 54 | * 55 | * @param s The query string. 56 | * @return The matching ConfigType if exists null otherwise. 57 | */ 58 | public static ConfigTypes getFromString(String s) { 59 | for (ConfigTypes c :ConfigTypes.values()) { 60 | if (s.equals(c.toString())) 61 | return c; 62 | } 63 | return null; 64 | } 65 | 66 | /** 67 | * 68 | * @return Returns the default configuration values to the common configuration keys. 69 | */ 70 | public static Map getCommonDefault() { 71 | Map map = new HashMap(); 72 | for (ConfigTypes ct : ConfigTypes.COMMON_TYPE) 73 | map.put(ct, ct.defaultValue); 74 | return map; 75 | } 76 | } 77 | 78 | /** 79 | * Utility class for easier config logging. 80 | * 81 | */ 82 | public static class ConfigLogger { 83 | 84 | public static final String SEP = "="; 85 | 86 | private String header; 87 | private StringBuilder messageBuilder; 88 | 89 | /** 90 | * Initializes the header with a message. 91 | * @param header This will be the headline of the log. 92 | */ 93 | public ConfigLogger(String header) { 94 | this(header, IStatus.INFO); 95 | } 96 | 97 | /** 98 | * Initializes the header with a message to be logged with, and 99 | * a log level if something other is desired than ISTATUS.INFO. 100 | * @param header This will be the headline of the log. 101 | * @param info The log level thats used for logging. 102 | */ 103 | public ConfigLogger(String header, int info) { 104 | this.header = header + System.lineSeparator(); 105 | } 106 | 107 | /** 108 | * Called on first append for flagging log need. 109 | */ 110 | public void init() { if (messageBuilder == null) messageBuilder = new StringBuilder(); } 111 | 112 | /** 113 | * Appends a String to the message. 114 | * @param message Custom String. 115 | */ 116 | public void append(String message){ 117 | init(); 118 | messageBuilder.append(message + System.lineSeparator()); 119 | } 120 | 121 | /** 122 | * Appends a stringified entry to the message. 123 | * @param entry A {@link ConfigTypes} String pair. 124 | */ 125 | public void append(Map.Entry entry) { 126 | init(); 127 | messageBuilder.append(entry.getKey() + SEP + entry.getValue() + System.lineSeparator()); 128 | } 129 | 130 | /** 131 | * Only logs when there is a message added. 132 | */ 133 | public void log(){ 134 | if (messageBuilder != null) 135 | Logger.log(IStatus.WARNING, header + messageBuilder.toString()); 136 | } 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/config/EnvironmentVariables.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.config; 2 | 3 | import org.eclipse.cdt.core.envvar.IEnvironmentVariable; 4 | 5 | /** 6 | * Environment variables to added to the C/C++ project environment variables. 7 | */ 8 | public enum EnvironmentVariables { 9 | LD_LIBRARY_PATH("/ld_logger/lib", IEnvironmentVariable.ENVVAR_REPLACE), 10 | _("/bin/CodeChecker", IEnvironmentVariable.ENVVAR_REPLACE), 11 | CC_LOGGER_GCC_LIKE("clang", IEnvironmentVariable.ENVVAR_REPLACE), 12 | LD_PRELOAD("ldlogger.so", IEnvironmentVariable.ENVVAR_REPLACE), 13 | CC_LOGGER_FILE("logfile", IEnvironmentVariable.ENVVAR_REPLACE), 14 | CC_LOGGER_BIN("/bin/ldlogger", IEnvironmentVariable.ENVVAR_REPLACE); 15 | 16 | private String defaultValue; 17 | private int method; 18 | 19 | /** 20 | * 21 | * @param def 22 | * utility method for setting the default value. 23 | * @param method 24 | * default addition method. 25 | */ 26 | EnvironmentVariables(String def, int method) { 27 | this.defaultValue = def; 28 | this.method = method; 29 | } 30 | 31 | /** 32 | * 33 | * @return Returns the default value associated with the enum. 34 | */ 35 | public String getDefaultValue() { 36 | return defaultValue; 37 | } 38 | 39 | /** 40 | * 41 | * @return Returns Environment variable addition method associated with the key. 42 | */ 43 | public int getMethod( ) { 44 | return method; 45 | } 46 | 47 | /** 48 | * 49 | * @param s The query string. 50 | * @return The matching ConfigType if exists null otherwise. 51 | */ 52 | public static EnvironmentVariables getFromString(String s) { 53 | for (EnvironmentVariables ev :EnvironmentVariables.values()) { 54 | if (s.equals(ev.toString())) 55 | return ev; 56 | } 57 | return null; 58 | } 59 | } -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/config/filter/Filter.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.config.filter; 2 | 3 | import org.codechecker.eclipse.plugin.Logger; 4 | import org.codechecker.eclipse.plugin.report.Severity; 5 | 6 | import org.eclipse.core.runtime.IStatus; 7 | 8 | public class Filter { 9 | 10 | private String filepath = ""; 11 | private String checkerMsg = ""; 12 | private Severity severity = Severity.ANY; 13 | private String checkerId = ""; 14 | private String buildTarget = ""; 15 | private boolean showSuppressedErrors = false; 16 | 17 | public Filter() { 18 | } 19 | 20 | public Filter(String filepath, String checkerMsg, Severity severity, String checkerId, String 21 | buildTarget, boolean showSuppressedErrors) { 22 | super(); 23 | this.filepath = filepath; 24 | this.checkerMsg = checkerMsg; 25 | this.severity = severity; 26 | this.checkerId = checkerId; 27 | this.buildTarget = buildTarget; 28 | this.showSuppressedErrors = showSuppressedErrors; 29 | } 30 | 31 | public Filter dup() { 32 | return new Filter(filepath, checkerMsg, severity, checkerId, buildTarget, 33 | showSuppressedErrors); 34 | } 35 | 36 | public String getFilepath() { 37 | return filepath; 38 | } 39 | 40 | public void setFilepath(String filepath) { 41 | this.filepath = filepath; 42 | } 43 | 44 | public String getCheckerMsg() { 45 | return checkerMsg; 46 | } 47 | 48 | public void setCheckerMsg(String checkerMsg) { 49 | this.checkerMsg = checkerMsg; 50 | } 51 | 52 | public Severity getSeverity() { 53 | return severity; 54 | } 55 | 56 | public void setSeverity(Severity severity) { 57 | this.severity = severity; 58 | } 59 | 60 | public String getCheckerId() { 61 | return checkerId; 62 | } 63 | 64 | public void setCheckerId(String checkerId) { 65 | this.checkerId = checkerId; 66 | } 67 | 68 | public String getBuildTarget() { 69 | return buildTarget; 70 | } 71 | 72 | public void setBuildTarget(String buildTarget) { 73 | this.buildTarget = buildTarget; 74 | } 75 | 76 | public boolean isShowSuppressedErrors() { 77 | return showSuppressedErrors; 78 | } 79 | 80 | public void setShowSuppressedErrors(boolean showSuppressedErrors) { 81 | this.showSuppressedErrors = showSuppressedErrors; 82 | } 83 | 84 | 85 | } 86 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/config/filter/FilterConfiguration.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.config.filter; 2 | 3 | import java.util.LinkedList; 4 | 5 | import org.codechecker.eclipse.plugin.report.ResultFilter; 6 | import org.codechecker.eclipse.plugin.report.Severity; 7 | 8 | import com.google.common.base.Optional; 9 | import com.google.common.collect.ImmutableList; 10 | 11 | public class FilterConfiguration { 12 | 13 | private String name = ""; 14 | 15 | private boolean linkToCurrentEditorByDefalt = true; 16 | 17 | private boolean globallySaved = false; 18 | 19 | private LinkedList filters = new LinkedList(); 20 | 21 | public FilterConfiguration() { 22 | } 23 | 24 | public FilterConfiguration(String name, boolean linkToCurrentEditorByDefalt, 25 | LinkedList filters) { 26 | super(); 27 | this.name = name; 28 | this.linkToCurrentEditorByDefalt = linkToCurrentEditorByDefalt; 29 | this.filters = new LinkedList<>(); 30 | for (Filter f : filters) { 31 | this.filters.add(f.dup()); 32 | } 33 | } 34 | 35 | public String getName() { 36 | return name; 37 | } 38 | 39 | public void setName(String name) { 40 | this.name = name; 41 | } 42 | 43 | public boolean isGloballySaved() { 44 | return globallySaved; 45 | } 46 | 47 | public void setGloballySaved(boolean globallySaved) { 48 | this.globallySaved = globallySaved; 49 | } 50 | 51 | public boolean isLinkToCurrentEditorByDefalt() { 52 | return linkToCurrentEditorByDefalt; 53 | } 54 | 55 | public void setLinkToCurrentEditorByDefalt(boolean linkToCurrentEditorByDefalt) { 56 | this.linkToCurrentEditorByDefalt = linkToCurrentEditorByDefalt; 57 | } 58 | 59 | public LinkedList getFilters() { 60 | return filters; 61 | } 62 | 63 | public void setFilters(LinkedList filters) { 64 | this.filters = filters; 65 | } 66 | 67 | public FilterConfiguration dup() { 68 | return new FilterConfiguration(name, linkToCurrentEditorByDefalt, filters); 69 | } 70 | 71 | public ImmutableList convertToResultList() { 72 | ImmutableList.Builder builder = new ImmutableList.Builder<>(); 73 | 74 | for (Filter f : filters) { 75 | builder.add(new ResultFilter(f.getFilepath().equals("") ? Optional.absent() : 76 | Optional.of(f.getFilepath()), f.getCheckerMsg().equals("") ? Optional 77 | .absent() : Optional.of(f.getCheckerMsg()), f.getSeverity(), f 78 | .getCheckerId().equals("") ? Optional.absent() : Optional.of(f 79 | .getCheckerId()), f.getBuildTarget().equals("") ? Optional.absent() : 80 | Optional.of(f.getBuildTarget()), f.isShowSuppressedErrors())); 81 | } 82 | 83 | return builder.build(); 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/config/filter/store/FilterStore.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.config.filter.store; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.File; 5 | import java.io.FileInputStream; 6 | import java.io.FileOutputStream; 7 | import java.io.InputStreamReader; 8 | import java.lang.reflect.Type; 9 | import java.util.LinkedList; 10 | 11 | import org.eclipse.core.runtime.IPath; 12 | 13 | import com.google.gson.Gson; 14 | import com.google.gson.reflect.TypeToken; 15 | 16 | import org.codechecker.eclipse.plugin.Activator; 17 | import org.codechecker.eclipse.plugin.config.filter.FilterConfiguration; 18 | import org.codechecker.eclipse.plugin.Logger; 19 | import org.eclipse.core.runtime.IStatus; 20 | 21 | public class FilterStore { 22 | 23 | private final String projectName; 24 | 25 | private LinkedList filterList; 26 | 27 | public FilterStore(String projectName) { 28 | super(); 29 | this.projectName = projectName; 30 | this.filterList = new LinkedList<>(); 31 | load(); 32 | } 33 | 34 | public void addFilterConfiguration(FilterConfiguration n) { 35 | if (filterList.contains(n)) { 36 | return; //rename or other change 37 | } 38 | filterList.add(n); 39 | save(); 40 | } 41 | 42 | public void removeFilterConfiguration(FilterConfiguration n) { 43 | filterList.remove(n); 44 | save(); 45 | } 46 | 47 | public LinkedList getFilterList() { 48 | return filterList; 49 | } 50 | 51 | private void save() { 52 | //saveFile("global", true); -- TODO! 53 | saveFile(projectName, false); 54 | } 55 | 56 | private void load() { 57 | // loadFile("global", true); -- TODO! handle global configuration 58 | loadFile(projectName, false); 59 | } 60 | 61 | public String[] getNames() { 62 | LinkedList names = new LinkedList<>(); 63 | 64 | for (FilterConfiguration fc : filterList) { 65 | names.add(fc.getName()); 66 | } 67 | 68 | return names.toArray(new String[]{}); 69 | } 70 | 71 | private void loadFile(String name, boolean isGlobal) { 72 | IPath p = Activator.getPreferencesPath(); 73 | p = p.append("filters-" + name + ".json"); 74 | Gson gson = new Gson(); 75 | File f = p.toFile(); 76 | 77 | if (!f.exists()) { 78 | saveFile(name, isGlobal); 79 | } 80 | 81 | FileInputStream fis; 82 | try { 83 | fis = new FileInputStream(f); 84 | InputStreamReader isr = new InputStreamReader(fis); 85 | BufferedReader bufferedReader = new BufferedReader(isr); 86 | StringBuilder sb = new StringBuilder(); 87 | String line; 88 | while ((line = bufferedReader.readLine()) != null) { 89 | sb.append(line); 90 | } 91 | 92 | String json = sb.toString(); 93 | LinkedList subList; 94 | 95 | Type listType = new TypeToken>() { 96 | }.getType(); 97 | 98 | subList = gson.fromJson(json, listType); 99 | 100 | for (FilterConfiguration fc : subList) { 101 | filterList.add(fc); 102 | } 103 | 104 | } catch (Exception e) { 105 | Logger.log(IStatus.ERROR, " " + e); 106 | Logger.log(IStatus.ERROR, " " + e.getStackTrace()); 107 | } 108 | 109 | } 110 | 111 | private void saveFile(String name, boolean isGlobal) { 112 | LinkedList subList = new LinkedList<>(); 113 | 114 | for (FilterConfiguration fc : filterList) { 115 | if (fc.isGloballySaved() == isGlobal) { 116 | subList.add(fc); 117 | } 118 | } 119 | 120 | IPath p = Activator.getPreferencesPath(); 121 | p = p.append("filters-" + name + ".json"); 122 | Gson gson = new Gson(); 123 | File f = p.toFile(); 124 | try { 125 | FileOutputStream outputStream = new FileOutputStream(f); 126 | outputStream.write(gson.toJson(subList).getBytes()); 127 | outputStream.close(); 128 | } catch (Exception e) { 129 | Logger.log(IStatus.ERROR, " " + e); 130 | Logger.log(IStatus.INFO, " " + e.getStackTrace()); 131 | } 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/config/global/CcGlobalProperties.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.config.global; 2 | 3 | import org.eclipse.jface.preference.PreferencePage; 4 | import org.eclipse.swt.widgets.Control; 5 | import org.eclipse.swt.widgets.Composite; 6 | import org.eclipse.ui.IWorkbench; 7 | import org.eclipse.ui.IWorkbenchPreferencePage; 8 | import org.codechecker.eclipse.plugin.config.CommonGui; 9 | 10 | import org.codechecker.eclipse.plugin.Logger; 11 | import org.eclipse.core.runtime.IStatus; 12 | 13 | public class CcGlobalProperties extends PreferencePage implements IWorkbenchPreferencePage { 14 | 15 | private static CommonGui commonGUI; 16 | 17 | public CcGlobalProperties(){ 18 | super(); 19 | 20 | commonGUI=new CommonGui(); 21 | } 22 | @Override 23 | protected Control createContents(final Composite parent) { 24 | 25 | return commonGUI.createContents(parent); 26 | } 27 | 28 | @Override 29 | public void performDefaults() { 30 | 31 | commonGUI.performDefaults(); 32 | super.performDefaults(); 33 | 34 | } 35 | 36 | @Override 37 | public boolean isValid() { 38 | 39 | return true; 40 | } 41 | 42 | @Override 43 | public boolean performOk() { 44 | 45 | commonGUI.performOk(); 46 | return super.performOk(); 47 | } 48 | 49 | @Override 50 | public void init(IWorkbench workbench) { 51 | Logger.log(IStatus.INFO, "init called"); 52 | // TODO Auto-generated method stub 53 | 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/config/global/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Global configuration related package. 3 | */ 4 | package org.codechecker.eclipse.plugin.config.global; -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/config/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Configuration related package for the plugin. 3 | */ 4 | package org.codechecker.eclipse.plugin.config; -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/config/project/CcProjectProperties.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.config.project; 2 | import org.eclipse.core.resources.IProject; 3 | import org.eclipse.swt.widgets.Composite; 4 | import org.eclipse.swt.widgets.Control; 5 | 6 | import org.eclipse.ui.IWorkbenchPropertyPage; 7 | import org.eclipse.ui.dialogs.PropertyPage; 8 | import org.codechecker.eclipse.plugin.config.CommonGui; 9 | 10 | import org.codechecker.eclipse.plugin.Logger; 11 | import org.eclipse.core.runtime.IStatus; 12 | 13 | public class CcProjectProperties extends PropertyPage implements IWorkbenchPropertyPage { 14 | 15 | private CommonGui commonGUI; 16 | 17 | public CcProjectProperties(){ 18 | super(); 19 | } 20 | 21 | @Override 22 | protected Control createContents(Composite parent) { 23 | IProject project = (IProject) this.getElement().getAdapter(IProject.class); 24 | commonGUI=new CommonGui(project); 25 | return commonGUI.createContents(parent); 26 | } 27 | 28 | 29 | @Override 30 | public void performDefaults() { 31 | if (commonGUI!=null) 32 | commonGUI.performDefaults(); 33 | super.performDefaults(); 34 | } 35 | 36 | @Override 37 | public boolean isValid() { 38 | return true; 39 | } 40 | 41 | @Override 42 | public boolean performOk() { 43 | if (commonGUI!=null) 44 | commonGUI.performOk(); 45 | return super.performOk(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/config/project/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Project level configuration related package. 3 | */ 4 | package org.codechecker.eclipse.plugin.config.project; -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/init/EditorPartListener.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.init; 2 | 3 | import org.codechecker.eclipse.plugin.Logger; 4 | import org.codechecker.eclipse.plugin.config.CodeCheckerContext; 5 | import org.codechecker.eclipse.plugin.report.job.AnalyzeJob; 6 | import org.codechecker.eclipse.plugin.report.job.JobDoneChangeListener; 7 | import org.codechecker.eclipse.plugin.report.job.PlistParseJob; 8 | import org.eclipse.core.resources.IFile; 9 | import org.eclipse.core.resources.IProject; 10 | import org.eclipse.core.runtime.IStatus; 11 | import org.eclipse.core.runtime.jobs.IJobChangeEvent; 12 | import org.eclipse.ui.IEditorPart; 13 | import org.eclipse.ui.IFileEditorInput; 14 | import org.eclipse.ui.IPartListener; 15 | import org.eclipse.ui.IWorkbenchPart; 16 | 17 | public class EditorPartListener implements IPartListener { 18 | 19 | @Override 20 | public void partActivated(IWorkbenchPart partRef) { 21 | if (!(partRef instanceof IEditorPart)) { 22 | return; 23 | } 24 | Logger.log(IStatus.INFO, "Editor changed : " + partRef.getClass().getName()); 25 | CodeCheckerContext.getInstance().refreshChangeEditorPart((IEditorPart) partRef); 26 | } 27 | 28 | @Override 29 | public void partBroughtToTop(IWorkbenchPart part) { 30 | } 31 | 32 | @Override 33 | public void partClosed(IWorkbenchPart part) { 34 | } 35 | 36 | @Override 37 | public void partDeactivated(IWorkbenchPart part) { 38 | } 39 | 40 | @Override 41 | public void partOpened(IWorkbenchPart part) { 42 | Logger.log(IStatus.INFO, "Editor Opened : " + part.getClass().getName()); 43 | // if an editor is opened parse the reports if there is any. 44 | IFile file; 45 | try { 46 | file = ((IFileEditorInput) ((IEditorPart) part).getEditorInput()).getFile(); 47 | } catch (ClassCastException e) { 48 | Logger.log(IStatus.WARNING, "Not a File Editor,early returning"); 49 | return; 50 | } 51 | 52 | IProject project = file.getProject(); 53 | if (CodeCheckerContext.getInstance().getCcProject(project) == null) 54 | return; 55 | 56 | AnalyzeJob analyzeJob = new AnalyzeJob(project, file.getLocation().toFile().toPath()); 57 | PlistParseJob plistParseJob = new PlistParseJob(project); 58 | analyzeJob.setRule(project); 59 | plistParseJob.setRule(project); 60 | plistParseJob.addJobChangeListener(new JobDoneChangeListener() { 61 | @Override 62 | public void done(IJobChangeEvent event) { 63 | CodeCheckerContext.getInstance().refresAsync(project); 64 | } 65 | }); 66 | analyzeJob.schedule(); 67 | plistParseJob.schedule(); 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/init/ProjectExplorerSelectionListener.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.init; 2 | 3 | import org.codechecker.eclipse.plugin.config.CodeCheckerContext; 4 | import org.eclipse.core.resources.IProject; 5 | import org.eclipse.core.resources.IResource; 6 | import org.eclipse.core.runtime.IAdaptable; 7 | import org.eclipse.jface.viewers.ISelection; 8 | import org.eclipse.jface.viewers.IStructuredSelection; 9 | import org.eclipse.ui.ISelectionListener; 10 | import org.eclipse.ui.IWorkbenchPart; 11 | 12 | public class ProjectExplorerSelectionListener implements ISelectionListener { 13 | 14 | @Override 15 | public void selectionChanged(IWorkbenchPart part, ISelection selection) { 16 | if (selection instanceof IStructuredSelection) { 17 | Object element = ((IStructuredSelection) selection).getFirstElement(); 18 | if (element instanceof IAdaptable) { 19 | IResource resource = (IResource) ((IAdaptable) element).getAdapter(IResource.class); 20 | if (resource != null) { 21 | final IProject project = resource.getProject(); 22 | if (project != null) 23 | CodeCheckerContext.getInstance().refreshChangeProject(project); 24 | 25 | } 26 | } 27 | } 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/perspective/CodeCheckerPerspectiveFactory.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.perspective; 2 | 3 | import org.eclipse.ui.IFolderLayout; 4 | import org.eclipse.ui.IPageLayout; 5 | import org.eclipse.ui.IPerspectiveFactory; 6 | import org.eclipse.ui.console.IConsoleConstants; 7 | 8 | import org.codechecker.eclipse.plugin.views.report.list.ReportListView; 9 | import org.codechecker.eclipse.plugin.views.report.list.ReportListViewProject; 10 | 11 | public class CodeCheckerPerspectiveFactory implements IPerspectiveFactory { 12 | 13 | @Override 14 | public void createInitialLayout(IPageLayout layout) { 15 | defineActions(layout); 16 | defineLayout(layout); 17 | } 18 | 19 | private void defineLayout(IPageLayout layout) { 20 | // TODO Auto-generated method stub 21 | 22 | } 23 | 24 | private void defineActions(IPageLayout layout) { 25 | String editorArea = layout.getEditorArea(); 26 | 27 | IFolderLayout left = layout.createFolder("left", IPageLayout.LEFT, (float) 0.26, 28 | editorArea); 29 | left.addView(IPageLayout.ID_PROJECT_EXPLORER); 30 | 31 | IFolderLayout middleLeft = layout.createFolder("middleLeft", IPageLayout.BOTTOM, (float) 32 | 0.33, "left"); 33 | middleLeft.addView(ReportListView.ID); 34 | middleLeft.addView(ReportListViewProject.ID); 35 | 36 | IFolderLayout right = layout.createFolder("right", IPageLayout.RIGHT, (float) 0.8, 37 | editorArea); 38 | right.addView(IConsoleConstants.ID_CONSOLE_VIEW); 39 | right.addView(IPageLayout.ID_OUTLINE); 40 | right.addView(IPageLayout.ID_TASK_LIST); 41 | 42 | IFolderLayout bottom = layout.createFolder("bottom", IPageLayout.BOTTOM, (float) 0.8, 43 | editorArea); 44 | bottom.addView(IPageLayout.ID_PROBLEM_VIEW); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/report/BugPathItem.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.report; 2 | 3 | import com.google.common.base.MoreObjects; 4 | import com.google.common.collect.ComparisonChain; 5 | 6 | import java.util.Objects; 7 | 8 | public class BugPathItem implements Comparable { 9 | 10 | private final Position startPosition; 11 | private final Position endPosition; 12 | private final String message; 13 | private final String file; 14 | 15 | public BugPathItem(Position startPosition, Position endPosition, String message, String file) { 16 | this.startPosition = startPosition; 17 | this.endPosition = endPosition; 18 | this.message = message; 19 | this.file = file; 20 | } 21 | 22 | @Override 23 | public int compareTo(BugPathItem o) { 24 | return ComparisonChain.start().compare(file, o.file).compare(startPosition, o 25 | .startPosition).compare(endPosition, o.endPosition).compare(message, o.message) 26 | .result(); 27 | } 28 | 29 | public Position getStartPosition() { 30 | return startPosition; 31 | } 32 | 33 | public Position getEndPosition() { 34 | return endPosition; 35 | } 36 | 37 | public String getMessage() { 38 | return message; 39 | } 40 | 41 | public String getFile() { 42 | return file; 43 | } 44 | 45 | @Override 46 | public String toString() { 47 | return MoreObjects.toStringHelper(this).add("file", file).add("start", startPosition).add 48 | ("end", endPosition).add("message", message).toString(); 49 | } 50 | 51 | @Override 52 | public int hashCode() { 53 | return Objects.hash(startPosition, endPosition, message, file); 54 | } 55 | 56 | public boolean equalPosition(Object obj) { 57 | if (obj instanceof BugPathItem) { 58 | BugPathItem oth = (BugPathItem) obj; 59 | 60 | return Objects.equals(startPosition, oth.startPosition) && Objects.equals 61 | (endPosition, oth.endPosition) && Objects.equals(file, oth.file); 62 | } 63 | 64 | return false; 65 | } 66 | 67 | @Override 68 | public boolean equals(Object obj) { 69 | if (obj instanceof BugPathItem) { 70 | BugPathItem oth = (BugPathItem) obj; 71 | 72 | return Objects.equals(startPosition, oth.startPosition) && Objects.equals 73 | (endPosition, oth.endPosition) && Objects.equals(message, oth.message) && 74 | Objects.equals(file, oth.file); 75 | } 76 | 77 | return false; 78 | } 79 | 80 | public static class Position implements Comparable { 81 | private final long line; 82 | private final long column; 83 | 84 | public Position(long line, long column) { 85 | this.line = line; 86 | this.column = column; 87 | } 88 | 89 | public long getLine() { 90 | return line; 91 | } 92 | 93 | public long getColumn() { 94 | return column; 95 | } 96 | 97 | @Override 98 | public String toString() { 99 | return MoreObjects.toStringHelper(this).add("l", line).add("c", column).toString(); 100 | } 101 | 102 | @Override 103 | public int hashCode() { 104 | return Objects.hash(line, column); 105 | } 106 | 107 | @Override 108 | public boolean equals(Object obj) { 109 | if (obj instanceof Position) { 110 | Position oth = (Position) obj; 111 | 112 | return Objects.equals(line, oth.line) && Objects.equals(column, oth.column); 113 | } 114 | 115 | return false; 116 | } 117 | 118 | @Override 119 | public int compareTo(Position o) { 120 | return ComparisonChain.start().compare(line, o.line).compare(column, o.column).result(); 121 | } 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/report/FileInfo.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.report; 2 | 3 | import com.google.common.base.MoreObjects; 4 | 5 | import java.util.Objects; 6 | 7 | public class FileInfo { 8 | 9 | private final long fileId; 10 | private final String filePath; 11 | private final String fileContent; 12 | 13 | public FileInfo(long fileId, String filePath, String fileContent) { 14 | this.fileId = fileId; 15 | this.filePath = filePath; 16 | this.fileContent = fileContent; 17 | } 18 | 19 | public long getFileId() { 20 | return fileId; 21 | } 22 | 23 | public String getFilePath() { 24 | return filePath; 25 | } 26 | 27 | public String getFileContent() { 28 | return fileContent; 29 | } 30 | 31 | @Override 32 | public String toString() { 33 | return MoreObjects.toStringHelper(this).add("fileId", fileContent).add("filePath", 34 | filePath).toString(); 35 | } 36 | 37 | @Override 38 | public int hashCode() { 39 | return Objects.hash(fileId); 40 | } 41 | 42 | @Override 43 | public boolean equals(Object obj) { 44 | if (obj instanceof FileInfo) { 45 | FileInfo oth = (FileInfo) obj; 46 | 47 | return Objects.equals(fileId, oth.fileId); 48 | } 49 | 50 | return false; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/report/Listener.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.report; 2 | 3 | /** 4 | * Basic listener for job events. 5 | */ 6 | public interface Listener { 7 | 8 | /** 9 | * Called when the job is started. 10 | * 11 | * Always called, unless an internal error happens during initialization. 12 | */ 13 | void onStart(Object obj); 14 | 15 | /** 16 | * Called after the job is finished (no actions remain, every processing is done) 17 | */ 18 | void onComplete(); 19 | 20 | /** 21 | * Called after the job stops with a timeout. 22 | * 23 | * More result may come in after this, because timeout only means it won't start new ones. 24 | */ 25 | void onTimeout(); 26 | 27 | /** 28 | * Called when an internal error happens. 29 | * 30 | * Might be called before (without) start. 31 | */ 32 | void onJobInternalError(RuntimeException e); 33 | 34 | } -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/report/PlistParser.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.report; 2 | 3 | import java.io.File; 4 | import java.io.FilenameFilter; 5 | import java.io.IOException; 6 | import java.text.ParseException; 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | import javax.xml.parsers.ParserConfigurationException; 11 | 12 | import org.codechecker.eclipse.plugin.Logger; 13 | 14 | import org.eclipse.core.resources.IProject; 15 | import org.eclipse.core.resources.ResourcesPlugin; 16 | import org.eclipse.core.runtime.IStatus; 17 | import org.xml.sax.SAXException; 18 | 19 | import com.dd.plist.NSArray; 20 | import com.dd.plist.NSDictionary; 21 | import com.dd.plist.NSNumber; 22 | import com.dd.plist.NSObject; 23 | import com.dd.plist.NSString; 24 | import com.dd.plist.PropertyListFormatException; 25 | import com.dd.plist.PropertyListParser; 26 | import com.google.common.base.Optional; 27 | import com.google.common.collect.ImmutableList; 28 | import com.google.common.collect.Iterables; 29 | 30 | import org.codechecker.eclipse.plugin.report.BugPathItem.Position; 31 | 32 | /** 33 | * Class for parsing the analysis result plist files. 34 | */ 35 | public class PlistParser { 36 | IProject project; 37 | 38 | public PlistParser(IProject project) { 39 | this.project = project; 40 | } 41 | 42 | /** 43 | * Parses exactly one .plist file. 44 | * @param pathToFile The file to be parsed. 45 | */ 46 | public SearchList parsePlist(File file, SearchList sl) { 47 | List riList = new ArrayList<>(); 48 | 49 | NSDictionary dict; 50 | try { 51 | dict = (NSDictionary) PropertyListParser.parse(file); 52 | NSObject[] sourceFiles = ((NSArray) dict.objectForKey("files")).getArray(); 53 | NSObject[] diagnostics = ((NSArray) dict.objectForKey("diagnostics")).getArray(); 54 | 55 | for (NSObject diagnostic : diagnostics) { 56 | NSDictionary diag = (NSDictionary) diagnostic; 57 | String checkerName = ((NSString) diag.get("check_name")).getContent(); 58 | String description = ((NSString) diag.get("description")).getContent(); 59 | 60 | NSObject[] path = ((NSArray) diag.objectForKey("path")).getArray(); 61 | 62 | List bugPathItemList = new ArrayList<>(); 63 | 64 | for (NSObject bp : path) { 65 | NSDictionary bugPath = (NSDictionary) bp; 66 | 67 | // We are only interested in bug events 68 | if (((NSString) bugPath.get("kind")).getContent().equals("event")) { 69 | String message = ((NSString) bugPath.get("message")).getContent(); 70 | NSDictionary location = (NSDictionary) bugPath.get("location"); 71 | Integer fileIndex = ((NSNumber) location.get("file")).intValue(); 72 | Integer line = ((NSNumber) location.get("line")).intValue(); 73 | Integer col = ((NSNumber) location.get("col")).intValue(); 74 | String filePath = ((NSString) sourceFiles[fileIndex]).getContent(); 75 | 76 | BugPathItem bItem = new BugPathItem(new Position(line, col), new Position(line, col), message, 77 | filePath); 78 | bugPathItemList.add(bItem); 79 | } 80 | } 81 | 82 | ProblemInfo pInfo = new ProblemInfo(ImmutableList.copyOf(bugPathItemList)); 83 | 84 | riList.add(new ReportInfo(checkerName, "testHash", Iterables.getLast(bugPathItemList).getFile(), 85 | description, 1, false, "testFile", Iterables.getLast(bugPathItemList), Optional.of(pInfo))); 86 | } 87 | 88 | ImmutableList uriList = ImmutableList.copyOf(riList); 89 | sl.addReports(uriList); 90 | 91 | } catch (ParserConfigurationException | ParseException | SAXException | PropertyListFormatException 92 | | IOException e) { 93 | // TODO Auto-generated catch block 94 | Logger.log(IStatus.ERROR, "Cannot Parse File :" + e.getMessage() + " in file: " + file.getName()); 95 | //e.printStackTrace(); 96 | } 97 | 98 | return sl; 99 | } 100 | 101 | // TODO javadoc!, and return parse results for storing them 102 | public SearchList processResultsForProject() { 103 | // TODO Get This 104 | String ws = ResourcesPlugin.getWorkspace().getRoot().getLocation().toString() + "/.codechecker/" 105 | + project.getName() + "/results"; 106 | Logger.log(IStatus.INFO, "Parsing plists in :" + ws); 107 | File file = new File(ws); 108 | SearchList sl = new SearchList(); 109 | if (file.exists()) { 110 | for (File f : file.listFiles(new FilenameFilter() { 111 | 112 | @Override 113 | public boolean accept(File dir, String name) { 114 | if (name.toLowerCase().endsWith(".plist")) 115 | return true; 116 | return false; 117 | } 118 | })) { 119 | //Logger.log(IStatus.INFO, "Parsing plist :" + f); 120 | parsePlist(f, sl); 121 | } 122 | } 123 | return sl; 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/report/ProblemInfo.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.report; 2 | 3 | import com.google.common.base.MoreObjects; 4 | import com.google.common.collect.ImmutableList; 5 | 6 | import java.util.Objects; 7 | 8 | //TODO Refactor this to be called BugPathList. 9 | /** 10 | * Contains a list of BugPathItems. 11 | */ 12 | public class ProblemInfo { 13 | 14 | private final ImmutableList items; 15 | 16 | public ProblemInfo(ImmutableList items) { 17 | this.items = items; 18 | } 19 | 20 | public ImmutableList getItems() { 21 | return items; 22 | } 23 | 24 | @Override 25 | public String toString() { 26 | return MoreObjects.toStringHelper(this).add("items", items).toString(); 27 | } 28 | 29 | @Override 30 | public int hashCode() { 31 | return Objects.hash(items); 32 | } 33 | 34 | @Override 35 | public boolean equals(Object obj) { 36 | if (obj instanceof ProblemInfo) { 37 | ProblemInfo oth = (ProblemInfo) obj; 38 | 39 | return Objects.equals(items, oth.items); 40 | } 41 | 42 | return false; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/report/ReportInfo.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.report; 2 | 3 | import com.google.common.base.MoreObjects; 4 | import com.google.common.base.Optional; 5 | import com.google.common.collect.ComparisonChain; 6 | 7 | import java.util.Objects; 8 | 9 | /** 10 | * Responsible for storing all informaiton of a report. 11 | * Created by Zsolt on 2015.02.25.. 12 | */ 13 | public class ReportInfo implements Comparable { 14 | 15 | private final String checkerId; 16 | private final String bugHash; 17 | private final String checkedFile; 18 | private final String checkerMsg; 19 | private final long reportId; 20 | private final boolean suppressed; 21 | private final String file; 22 | private final BugPathItem lastBugPathItem; 23 | private final Optional bugPath; 24 | 25 | /** 26 | * Set every member at instantiation, there are no setter for the members. 27 | * @param checkerId The Checker that generated the report. 28 | * @param bugHash The hash associated with the repprt. 29 | * @param checkedFile TODO whats this the plist or the plist file section??? 30 | * @param checkerMsg The detailed message of the checker 31 | * @param reportId ID 32 | * @param suppressed TODO DEPRECATED in this form? 33 | * @param file TODO meh 34 | * @param getLastBugPathItem TODO why do we need this 35 | * @param bugPath TODO when we have this? 36 | */ 37 | public ReportInfo(String checkerId, String bugHash, String checkedFile, String checkerMsg, 38 | long reportId, boolean suppressed, String file, BugPathItem lastBugPathItem, 39 | Optional bugPath) { 40 | this.checkerId = checkerId; 41 | this.bugHash = bugHash; 42 | this.checkedFile = checkedFile; 43 | this.checkerMsg = checkerMsg; 44 | this.reportId = reportId; 45 | this.suppressed = suppressed; 46 | this.file = file; 47 | this.lastBugPathItem = lastBugPathItem; 48 | this.bugPath = bugPath; 49 | } 50 | 51 | public Optional getChildren() { 52 | return this.bugPath; 53 | } 54 | 55 | public String getCheckerId() { 56 | return checkerId; 57 | } 58 | 59 | public String getBugHash() { 60 | return bugHash; 61 | } 62 | 63 | public String getCheckedFile() { 64 | return checkedFile; 65 | } 66 | 67 | public String getCheckerMsg() { 68 | return checkerMsg; 69 | } 70 | 71 | public long getReportId() { 72 | return reportId; 73 | } 74 | 75 | public boolean isSuppressed() { 76 | return suppressed; 77 | } 78 | 79 | public String getFile() { 80 | return file; 81 | } 82 | 83 | public BugPathItem getLastBugPathItem() { 84 | return lastBugPathItem; 85 | } 86 | 87 | @Override 88 | public String toString() { 89 | return MoreObjects.toStringHelper(this).add("checkerId", checkerId).add("checkedFile", 90 | checkedFile).add("checkerMsg", checkerMsg).add("reportId", reportId).add 91 | ("suppressed", suppressed).add("file", file).add("lastBugPathItem", 92 | lastBugPathItem).toString(); 93 | } 94 | 95 | @Override 96 | public int hashCode() { 97 | return Objects.hash(checkerId, checkedFile, checkerMsg, reportId, suppressed, file, 98 | lastBugPathItem); 99 | } 100 | 101 | @Override 102 | public boolean equals(Object obj) { 103 | if (obj instanceof ReportInfo) { 104 | ReportInfo oth = (ReportInfo) obj; 105 | return Objects.equals(checkerId, oth.checkerId) && Objects.equals(checkedFile, oth 106 | .checkedFile) && Objects.equals(checkerMsg, oth.checkerMsg) && Objects.equals 107 | (reportId, oth.reportId) && Objects.equals(suppressed, oth.suppressed) && 108 | Objects.equals(file, oth.file) && Objects.equals(lastBugPathItem, oth 109 | .lastBugPathItem); 110 | } 111 | 112 | return false; 113 | } 114 | 115 | @Override 116 | public int compareTo(ReportInfo o) { 117 | return ComparisonChain.start().compare(file, o.file).compare(suppressed, o.suppressed) 118 | .compare(checkerMsg, o.checkerMsg).compare(lastBugPathItem.getStartPosition(), o 119 | .lastBugPathItem.getStartPosition()).compare(reportId, o.reportId).result(); 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/report/ReportParser.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.report; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.eclipse.jdt.annotation.Nullable; 7 | 8 | import com.google.common.collect.ImmutableList; 9 | 10 | /** 11 | * This class is for filtering the reports in memory. 12 | * 13 | */ 14 | public class ReportParser implements Runnable { 15 | private List listeners = new ArrayList(); 16 | private SearchList reports; 17 | private String currentFileName; 18 | 19 | /** 20 | * 21 | * @param reports The in memory representation of the reports. 22 | * @param currentFileName The filename {@link @Nullable}. If null there will be no filtering. 23 | */ 24 | public ReportParser(SearchList reports, @Nullable String currentFileName) { 25 | this.reports = reports; 26 | this.currentFileName = currentFileName; 27 | } 28 | 29 | /** 30 | * Processes reports for displaying. If filename is null no report gets filtered. 31 | */ 32 | public void processReports(){ 33 | //Parse The reports given the current filename 34 | if (reports == null ) return; 35 | if (currentFileName.isEmpty() || currentFileName == null) 36 | for (SearchListener listener : listeners){ 37 | listener.onTotalCountAvailable(reports, 1); 38 | } 39 | else { 40 | //TODO really needs a test for ensuring that all reports get coped over 41 | SearchList filteredReoports = new SearchList(); 42 | for (String checker : reports.getCheckers()) 43 | for (ReportInfo rep : reports.getReportsFor(checker)) 44 | for (BugPathItem bp : rep.getChildren().orNull().getItems()) 45 | if (bp.getFile().equals(currentFileName)) { 46 | filteredReoports.addReports(ImmutableList.of(rep)); 47 | for (SearchListener listener : listeners) { 48 | listener.onPartsArrived(filteredReoports); 49 | } 50 | } 51 | for (SearchListener listener : listeners){ 52 | listener.onTotalCountAvailable(filteredReoports, 1); 53 | } 54 | } 55 | } 56 | 57 | /** 58 | * Adds a {@link SearchListener} listener to this instance. 59 | * @param listener The listener to be added. 60 | */ 61 | public void addListener(SearchListener listener){ 62 | listeners.add(listener); 63 | } 64 | 65 | @Override 66 | public void run() { 67 | processReports(); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/report/ResultCount.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.report; 2 | 3 | import com.google.common.base.MoreObjects; 4 | 5 | import java.util.Objects; 6 | 7 | public class ResultCount { 8 | 9 | private final long count; 10 | 11 | public ResultCount(long count) { 12 | this.count = count; 13 | } 14 | 15 | public long getCount() { 16 | return count; 17 | } 18 | 19 | @Override 20 | public String toString() { 21 | return MoreObjects.toStringHelper(this).add("count", count).toString(); 22 | } 23 | 24 | @Override 25 | public int hashCode() { 26 | return Objects.hash(count); 27 | } 28 | 29 | @Override 30 | public boolean equals(Object obj) { 31 | if (obj instanceof ResultCount) { 32 | ResultCount oth = (ResultCount) obj; 33 | return Objects.equals(count, oth.count); 34 | } 35 | 36 | return false; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/report/ResultFilter.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.report; 2 | 3 | import org.codechecker.eclipse.plugin.report.Severity; 4 | 5 | import com.google.common.base.MoreObjects; 6 | import com.google.common.base.Optional; 7 | 8 | import java.util.Objects; 9 | 10 | public class ResultFilter { 11 | private final Optional filepath; 12 | private final Optional checkerMsg; 13 | private final Severity severity; 14 | private final Optional checkerId; 15 | private final Optional buildTarget; 16 | private final boolean showSuppressedErrors; 17 | 18 | public ResultFilter(Optional filepath, Optional checkerMsg, 19 | Severity severity, Optional checkerId, Optional buildTarget, boolean 20 | showSuppressedErrors) { 21 | this.filepath = filepath; 22 | this.checkerMsg = checkerMsg; 23 | this.severity = severity; 24 | this.checkerId = checkerId; 25 | this.buildTarget = buildTarget; 26 | this.showSuppressedErrors = showSuppressedErrors; 27 | } 28 | 29 | public Optional getFilepath() { 30 | return filepath; 31 | } 32 | 33 | public Optional getCheckerMsg() { 34 | return checkerMsg; 35 | } 36 | 37 | public org.codechecker.eclipse.plugin.report.Severity getSeverity() { 38 | return severity; 39 | } 40 | 41 | public Optional getCheckerId() { 42 | return checkerId; 43 | } 44 | 45 | public Optional getBuildTarget() { 46 | return buildTarget; 47 | } 48 | 49 | public boolean isShowSuppressedErrors() { 50 | return showSuppressedErrors; 51 | } 52 | 53 | @Override 54 | public String toString() { 55 | return MoreObjects.toStringHelper(this).add("filepath", filepath).add("checkerMsg", 56 | checkerMsg).add("severity", severity).add("checkerID", checkerId).add 57 | ("buildTarget", buildTarget).add("suppressed", showSuppressedErrors).toString(); 58 | } 59 | 60 | @Override 61 | public int hashCode() { 62 | return Objects.hash(filepath, checkerMsg, severity, checkerId, buildTarget, 63 | showSuppressedErrors); 64 | } 65 | 66 | @Override 67 | public boolean equals(Object obj) { 68 | if (obj instanceof ResultFilter) { 69 | ResultFilter oth = (ResultFilter) obj; 70 | 71 | return Objects.equals(filepath, oth.filepath) && Objects.equals(checkerMsg, oth 72 | .checkerMsg) && Objects.equals(severity, oth.severity) && Objects.equals 73 | (checkerId, oth.checkerId) && Objects.equals(buildTarget, oth.buildTarget) && 74 | Objects.equals(showSuppressedErrors, oth.showSuppressedErrors); 75 | } 76 | return false; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/report/ResultList.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.report; 2 | 3 | import com.google.common.base.MoreObjects; 4 | import com.google.common.collect.ImmutableList; 5 | 6 | import java.util.Objects; 7 | 8 | public class ResultList { 9 | 10 | private final ImmutableList runResultList; 11 | 12 | public ResultList(ImmutableList runResultList) { 13 | this.runResultList = runResultList; 14 | } 15 | 16 | public ImmutableList getRunResultList() { 17 | return runResultList; 18 | } 19 | 20 | @Override 21 | public String toString() { 22 | return MoreObjects.toStringHelper(this).add("result", runResultList).toString(); 23 | } 24 | 25 | @Override 26 | public int hashCode() { 27 | return Objects.hash(runResultList); 28 | } 29 | 30 | @Override 31 | public boolean equals(Object obj) { 32 | if (obj instanceof ResultList) { 33 | ResultList oth = (ResultList) obj; 34 | return Objects.equals(runResultList, oth.runResultList); 35 | } 36 | 37 | return false; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/report/RunInfo.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.report; 2 | 3 | import com.google.common.base.MoreObjects; 4 | 5 | import org.joda.time.DateTime; 6 | 7 | import java.util.Objects; 8 | 9 | public class RunInfo { 10 | private final long runId; 11 | private final DateTime runDate; 12 | private final String name; 13 | private final long duration; 14 | private final long resultCount; 15 | 16 | public RunInfo(long runId, DateTime runDate, String name, long duration, long resultCount) { 17 | this.runId = runId; 18 | this.runDate = runDate; 19 | this.name = name; 20 | this.duration = duration; 21 | this.resultCount = resultCount; 22 | } 23 | 24 | public long getRunId() { 25 | return runId; 26 | } 27 | 28 | public DateTime getRunDate() { 29 | return runDate; 30 | } 31 | 32 | public String getName() { 33 | return name; 34 | } 35 | 36 | public long getDuration() { 37 | return duration; 38 | } 39 | 40 | public long getResultCount() { 41 | return resultCount; 42 | } 43 | 44 | @Override 45 | public String toString() { 46 | return MoreObjects.toStringHelper(this).add("runID", runId).add("runDate", runDate).add 47 | ("name", name).add("duration", duration).add("count", resultCount).toString(); 48 | } 49 | 50 | @Override 51 | public int hashCode() { 52 | return Objects.hash(runId, runDate, name, duration, resultCount); 53 | } 54 | 55 | @Override 56 | public boolean equals(Object obj) { 57 | if (obj instanceof RunInfo) { 58 | RunInfo oth = (RunInfo) obj; 59 | 60 | return Objects.equals(runId, oth.runId) && Objects.equals(runDate, oth.runDate) && 61 | Objects.equals(name, oth.name) && Objects.equals(duration, oth.duration) && 62 | Objects.equals(resultCount, oth.resultCount); 63 | } 64 | 65 | return false; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/report/SearchList.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.report; 2 | 3 | 4 | import org.codechecker.eclipse.plugin.report.ReportInfo; 5 | import org.codechecker.eclipse.plugin.runtime.LogI; 6 | import org.codechecker.eclipse.plugin.runtime.SLogger; 7 | 8 | import com.google.common.base.Optional; 9 | import com.google.common.collect.ImmutableList; 10 | import com.google.common.collect.Multimap; 11 | import com.google.common.collect.TreeMultimap; 12 | 13 | 14 | import java.util.Collection; 15 | import java.util.Set; 16 | 17 | /** 18 | * Stores all report information for a project. 19 | * 20 | */ 21 | public class SearchList { 22 | 23 | private final Multimap reports; 24 | 25 | private Optional totalReportCount; 26 | 27 | public SearchList() { 28 | this.reports = TreeMultimap.create(); 29 | totalReportCount = Optional.absent(); 30 | } 31 | 32 | public void addReports(ImmutableList reports) { 33 | for (ReportInfo report : reports) { 34 | if (this.reports.containsValue(report)) { 35 | //SLogger.log(LogI.WARNING, "Duplicate report in the result list: " + report); 36 | } 37 | this.reports.put(report.getCheckerId(), report); 38 | } 39 | } 40 | 41 | public Optional getTotalReportCount() { 42 | return totalReportCount; 43 | } 44 | 45 | public void setTotalReportCount(Integer totalReportCount) { 46 | this.totalReportCount = Optional.of(totalReportCount); 47 | } 48 | 49 | public Integer getRecordCount() { 50 | return reports.size(); 51 | } 52 | 53 | public Set getCheckers() { 54 | return reports.keySet(); 55 | } 56 | 57 | public Collection getReportsFor(String checker) { 58 | return reports.get(checker); 59 | } 60 | 61 | /*public ProblemInfoJob getBugPathJobFor(ReportInfo report, int priority, Optional 62 | deadline) { 63 | return new ProblemInfoJob(new ProblemInfoRequest(this.request.getServer(), report 64 | .getReportId()), priority, deadline); 65 | }*/ 66 | } 67 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/report/SearchListener.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.report; 2 | 3 | import org.codechecker.eclipse.plugin.report.ReportInfo; 4 | 5 | import com.google.common.collect.ImmutableList; 6 | 7 | public interface SearchListener extends Listener { 8 | //TODO Refactor without jobs 9 | // void onTotalCountAvailable(SearchJob searchJob, SearchList result, int count); 10 | void onTotalCountAvailable(SearchList result, int count); 11 | 12 | // void onPartsArrived(SearchJob searchJob, SearchList result, ImmutableList runResultList); 13 | void onPartsArrived(SearchList result); 14 | } 15 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/report/Severity.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.report; 2 | 3 | public enum Severity { 4 | STYLE(0), LOW(1), MEDIUM(2), HIGH(3), CRITICAL(4), ANY(5); 5 | 6 | private final int value; 7 | 8 | private Severity(int value) { 9 | this.value = value; 10 | } 11 | 12 | public int getValue() { 13 | return value; 14 | } 15 | } -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/report/job/JobDoneChangeListener.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.report.job; 2 | 3 | import org.eclipse.core.runtime.jobs.IJobChangeEvent; 4 | import org.eclipse.core.runtime.jobs.IJobChangeListener; 5 | 6 | /** 7 | * Reducer Class for JobChangeListener interface. 8 | * 9 | */ 10 | public abstract class JobDoneChangeListener implements IJobChangeListener { 11 | 12 | @Override 13 | public abstract void done(IJobChangeEvent event); 14 | 15 | @Override 16 | public void aboutToRun(IJobChangeEvent arg0) {} 17 | 18 | @Override 19 | public void awake(IJobChangeEvent arg0) {} 20 | 21 | @Override 22 | public void running(IJobChangeEvent arg0) {} 23 | 24 | @Override 25 | public void scheduled(IJobChangeEvent arg0) {} 26 | 27 | @Override 28 | public void sleeping(IJobChangeEvent arg0) {} 29 | 30 | } 31 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/report/job/PlistParseJob.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.report.job; 2 | 3 | import org.eclipse.core.resources.IProject; 4 | import org.eclipse.core.runtime.IProgressMonitor; 5 | import org.eclipse.core.runtime.IStatus; 6 | import org.eclipse.core.runtime.Status; 7 | import org.eclipse.core.runtime.jobs.Job; 8 | 9 | import org.codechecker.eclipse.plugin.Logger; 10 | import org.codechecker.eclipse.plugin.config.CodeCheckerContext; 11 | import org.codechecker.eclipse.plugin.report.PlistParser; 12 | import org.codechecker.eclipse.plugin.report.SearchList; 13 | 14 | /** 15 | * This {@link Job} manages the parsing of the CodeChecker Analysis results. 16 | * Should be scheduled when: 17 | * - A project is opened. 18 | * - A project is being built, after an {@link AnalyzeJob}. 19 | * 20 | */ 21 | public class PlistParseJob extends Job{ 22 | 23 | private IProject project; 24 | 25 | /** 26 | * Hidden default ctor to avoid incorrect usage, project is always needed. 27 | * @param name NOT USED 28 | */ 29 | private PlistParseJob(String name) { 30 | super(name); 31 | } 32 | 33 | /** 34 | * Use this ctor to create a PlistParseJob with a valid project. 35 | * @param project The project that's being processed. 36 | */ 37 | public PlistParseJob(IProject project) { 38 | super("PlistParseJob"); 39 | this.project = project; 40 | } 41 | 42 | @Override 43 | protected IStatus run(IProgressMonitor arg0) { 44 | Logger.log(IStatus.INFO, "Parsing analysis results."); 45 | parsePlistForProject(project); 46 | return Status.OK_STATUS; 47 | } 48 | 49 | /** 50 | * Method for parsing every plist result generated by the analyzer. 51 | * @param project the project that's results is needed to be parsed. 52 | */ 53 | public void parsePlistForProject(final IProject project) { 54 | Logger.log(IStatus.INFO, 55 | "Started Plist Parsing for project: "+project.getName()); 56 | final PlistParser parser = new PlistParser(project); 57 | SearchList sl; 58 | sl = parser.processResultsForProject(); 59 | CodeCheckerContext.getInstance().setReportForProject(project, sl); 60 | Logger.log(IStatus.INFO, 61 | "Finished Plist Parsing for project: "+project.getName()); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/report/job/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Report related job and job utility classes. 3 | */ 4 | package org.codechecker.eclipse.plugin.report.job; -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/report/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Report related classes. 3 | */ 4 | package org.codechecker.eclipse.plugin.report; -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/runtime/IShellExecutorHelperFactory.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.runtime; 2 | 3 | import java.util.Map; 4 | 5 | /** 6 | * Interface for {@link ShellExecutorHelper} factory. 7 | */ 8 | public interface IShellExecutorHelperFactory { 9 | /** 10 | * Method for creating {@link ShellExecutorHelper}. 11 | * 12 | * @param env 13 | * An environment to be used with the ShellExecutorHelper. 14 | * @return A {@link ShellExecutorHelper} instance. 15 | */ 16 | public ShellExecutorHelper createShellExecutorHelper(Map env); 17 | } 18 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/runtime/LogI.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.runtime; 2 | 3 | public interface LogI { 4 | //IStatus severities 5 | static int CANCEL=8; 6 | static int ERROR=4; 7 | static int INFO=1; 8 | static int OK=0; 9 | static int WARNING=2; 10 | public void log(int severity,String message); 11 | public void consoleLog(String message); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/runtime/OnCheckCallback.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.runtime; 2 | 3 | public interface OnCheckCallback { 4 | void analysisStarted(String command);//called when the analysis starts 5 | void analysisFinished(String result);//called when analysis finished 6 | } 7 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/runtime/SLogger.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.runtime; 2 | 3 | 4 | public class SLogger { 5 | private static LogI logger = null; 6 | public static void setLogger(LogI l){ 7 | logger=l; 8 | } 9 | public static void log(int level,String message){ 10 | if (logger!=null){ 11 | logger.log(level,message); 12 | } 13 | } 14 | public static void consoleLog(String message){ 15 | if (logger!=null){ 16 | logger.consoleLog(message); 17 | } 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/runtime/ShellExecutorHelperFactory.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.runtime; 2 | 3 | import java.util.Map; 4 | 5 | /** 6 | * Implementation of {@link IShellExecutorHelperFactory}. 7 | */ 8 | public class ShellExecutorHelperFactory implements IShellExecutorHelperFactory { 9 | 10 | @Override 11 | public ShellExecutorHelper createShellExecutorHelper(Map env) { 12 | return new ShellExecutorHelper(env); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/runtime/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Command line related package. 3 | */ 4 | package org.codechecker.eclipse.plugin.runtime; -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/views/config/filter/ListContentProvider.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.views.config.filter; 2 | 3 | import java.util.List; 4 | 5 | import org.apache.commons.lang3.ArrayUtils; 6 | import org.eclipse.jface.viewers.IContentProvider; 7 | import org.eclipse.jface.viewers.IStructuredContentProvider; 8 | import org.eclipse.jface.viewers.Viewer; 9 | 10 | import org.codechecker.eclipse.plugin.Logger; 11 | import org.eclipse.core.runtime.IStatus; 12 | 13 | public class ListContentProvider implements IContentProvider, IStructuredContentProvider { 14 | 15 | @Override 16 | public Object[] getElements(Object inputElement) { 17 | if (inputElement instanceof List) { 18 | Logger.log(IStatus.INFO, "SERVER_GUI_MSG >> Displaying list"); 19 | return ((List) inputElement).toArray(); 20 | } 21 | return ArrayUtils.toArray(); 22 | } 23 | 24 | @Override 25 | public void dispose() { 26 | } 27 | 28 | @Override 29 | public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/views/console/ConsoleFactory.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.views.console; 2 | 3 | import org.eclipse.ui.IWorkbenchPage; 4 | import org.eclipse.ui.PartInitException; 5 | import org.eclipse.ui.PlatformUI; 6 | import org.eclipse.ui.console.ConsolePlugin; 7 | import org.eclipse.ui.console.IConsole; 8 | import org.eclipse.ui.console.IConsoleFactory; 9 | import org.eclipse.ui.console.IConsoleManager; 10 | import org.eclipse.ui.console.MessageConsole; 11 | import org.eclipse.ui.console.MessageConsoleStream; 12 | 13 | public class ConsoleFactory implements IConsoleFactory{ 14 | 15 | private static MessageConsole console; 16 | 17 | private static MessageConsole getConsole() { 18 | if(console == null) { 19 | console = new MessageConsole("CodeChecker Console", null); 20 | } 21 | return console; 22 | } 23 | 24 | public static void consoleWrite(String msg) { 25 | console = getConsole(); 26 | MessageConsoleStream out = console.newMessageStream(); 27 | out.println(msg); 28 | } 29 | 30 | public static void setActiveConsole() { 31 | IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); 32 | try { 33 | page.showView(console.getName()); 34 | } catch (PartInitException e) {} 35 | } 36 | 37 | @Override 38 | public void openConsole() { 39 | console = getConsole(); 40 | if (console != null) { 41 | IConsoleManager manager = ConsolePlugin.getDefault().getConsoleManager(); 42 | IConsole[] existing = manager.getConsoles(); 43 | boolean exists = false; 44 | for (int i = 0; i < existing.length; i++) { 45 | if(console == existing[i]) 46 | exists = true; 47 | } 48 | if(!exists) 49 | manager.addConsoles(new IConsole[] {console}); 50 | manager.showConsoleView(console); 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/views/report/list/ReportListViewCustom.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.views.report.list; 2 | 3 | import java.util.LinkedList; 4 | 5 | import org.eclipse.core.resources.IProject; 6 | 7 | import org.codechecker.eclipse.plugin.config.filter.Filter; 8 | import org.codechecker.eclipse.plugin.config.filter.FilterConfiguration; 9 | 10 | public class ReportListViewCustom extends ReportListView { 11 | 12 | public static final String ID = "org.codechecker.eclipse.plugin.views.ReportListViewCustom"; 13 | 14 | public void onEditorChanged(IProject project) { 15 | super.onEditorChanged(project, ""); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/views/report/list/ReportListViewListener.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.views.report.list; 2 | 3 | import java.util.List; 4 | import java.util.ArrayList; 5 | import java.util.Collections; 6 | 7 | import org.eclipse.swt.widgets.Display; 8 | 9 | import com.google.common.base.Optional; 10 | import com.google.common.collect.ImmutableList; 11 | 12 | import org.codechecker.eclipse.plugin.report.BugPathItem; 13 | import org.codechecker.eclipse.plugin.report.BugPathItem.Position; 14 | import org.codechecker.eclipse.plugin.report.ProblemInfo; 15 | import org.codechecker.eclipse.plugin.report.ReportInfo; 16 | import org.codechecker.eclipse.plugin.report.SearchList; 17 | import org.codechecker.eclipse.plugin.report.SearchListener; 18 | 19 | public class ReportListViewListener implements SearchListener { 20 | 21 | 22 | private final ReportListView target; 23 | 24 | public ReportListViewListener(ReportListView target) { 25 | this.target = target; 26 | } 27 | 28 | @Override 29 | public void onComplete() { 30 | } 31 | 32 | @Override 33 | public void onJobInternalError(RuntimeException arg1) { 34 | } 35 | 36 | @Override 37 | public void onStart(final Object job) { 38 | Display.getDefault().syncExec(new Runnable() { 39 | @Override 40 | public void run() { 41 | // Invalidate target. 42 | //target.changeModel(job.getResult()); 43 | } 44 | }); 45 | } 46 | 47 | @Override 48 | public void onTimeout() {} 49 | 50 | //TODO UPLIFT use arguments in function. 51 | @Override 52 | public void onPartsArrived(SearchList sl) { 53 | // append insted of replace model? 54 | target.changeModel(sl); 55 | Display.getDefault().syncExec(new Runnable() { 56 | @Override 57 | public void run() { 58 | target.refresh(null); 59 | } 60 | }); 61 | } 62 | 63 | @Override 64 | public void onTotalCountAvailable(SearchList sl, int arg2) { 65 | target.changeModel(sl); 66 | Display.getDefault().syncExec(new Runnable() { 67 | @Override 68 | public void run() { 69 | target.refresh(null); 70 | } 71 | }); 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/views/report/list/ReportListViewProject.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.views.report.list; 2 | 3 | import org.eclipse.core.resources.IProject; 4 | 5 | public class ReportListViewProject extends ReportListView { 6 | 7 | public static final String ID = "org.codechecker.eclipse.plugin.views.ReportListProject"; 8 | 9 | public void onEditorChanged(IProject project) { 10 | super.onEditorChanged(project, ""); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/views/report/list/action/NewInstanceAction.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.views.report.list.action; 2 | 3 | import org.eclipse.jface.action.IAction; 4 | import org.eclipse.ui.ISharedImages; 5 | import org.eclipse.ui.IWorkbenchPage; 6 | import org.eclipse.ui.PartInitException; 7 | import org.eclipse.ui.PlatformUI; 8 | 9 | import org.codechecker.eclipse.plugin.config.CodeCheckerContext; 10 | import org.codechecker.eclipse.plugin.views.report.list.ReportListViewCustom; 11 | import org.codechecker.eclipse.plugin.views.report.list.action.showas.TreeAwareAction; 12 | import org.codechecker.eclipse.plugin.Logger; 13 | import org.eclipse.core.runtime.IStatus; 14 | 15 | public class NewInstanceAction extends TreeAwareAction { 16 | 17 | 18 | public NewInstanceAction(ReportListViewCustom listView) { 19 | super(listView, "Create new ReportList", IAction.AS_PUSH_BUTTON); 20 | setToolTipText("Create new ReportList"); 21 | setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor 22 | (ISharedImages.IMG_OBJ_ADD)); 23 | } 24 | 25 | @Override 26 | public void run() { 27 | IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); 28 | 29 | try { 30 | String secondaryId = "ReportList" + Math.ceil(Math.random() * 100); 31 | page.showView(ReportListViewCustom.ID, secondaryId, IWorkbenchPage.VIEW_ACTIVATE); 32 | CodeCheckerContext.getInstance().refreshAddCustomReportListView(secondaryId); 33 | } catch (PartInitException e) { 34 | // TODO Auto-generated catch block 35 | Logger.log(IStatus.ERROR, " " + e); 36 | Logger.log(IStatus.INFO, " " + e.getStackTrace()); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/views/report/list/action/ShowFilterConfigurationDialog.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.views.report.list.action; 2 | 3 | import org.eclipse.cdt.utils.Platform; 4 | import org.eclipse.core.runtime.FileLocator; 5 | import org.eclipse.core.runtime.Path; 6 | import org.eclipse.jface.action.IAction; 7 | import org.eclipse.jface.resource.ImageDescriptor; 8 | import org.eclipse.swt.widgets.Shell; 9 | import org.eclipse.ui.PlatformUI; 10 | import org.osgi.framework.Bundle; 11 | 12 | import org.codechecker.eclipse.plugin.Activator; 13 | import org.codechecker.eclipse.plugin.views.config.filter.FilterConfigurationDialog; 14 | import org.codechecker.eclipse.plugin.views.report.list.ReportListView; 15 | import org.codechecker.eclipse.plugin.views.report.list.action.showas.TreeAwareAction; 16 | 17 | 18 | import java.net.URL; 19 | 20 | public class ShowFilterConfigurationDialog extends TreeAwareAction { 21 | 22 | 23 | public ShowFilterConfigurationDialog(ReportListView listView) { 24 | super(listView, "Show Filter Configurators", IAction.AS_PUSH_BUTTON); 25 | setToolTipText("Show Filter Configurators"); 26 | Bundle bundle = Platform.getBundle(Activator.PLUGIN_ID); 27 | final URL fullPathString = FileLocator.find(bundle, new Path("icons/filter.png"), null); 28 | setImageDescriptor(ImageDescriptor.createFromURL(fullPathString)); 29 | } 30 | 31 | @Override 32 | public void run() { 33 | Shell activeShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); 34 | 35 | FilterConfigurationDialog dialog = new FilterConfigurationDialog(activeShell, listView 36 | .getActiveConfiguration().dup(), listView.getCurrentProject().getName()); 37 | 38 | int result = dialog.open(); 39 | 40 | if (result == 0) { 41 | listView.setActiveConfiguration(dialog.getCurrentConfiguration()); 42 | } 43 | 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/views/report/list/action/rerun/RefreshAction.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.views.report.list.action.rerun; 2 | 3 | import org.eclipse.jface.action.IAction; 4 | 5 | import org.codechecker.eclipse.plugin.views.report.list.ReportListView; 6 | import org.codechecker.eclipse.plugin.views.report.list.action.showas.TreeAwareAction; 7 | 8 | public class RefreshAction extends TreeAwareAction { 9 | 10 | public RefreshAction(ReportListView listView) { 11 | super(listView, "Refresh reports", IAction.AS_PUSH_BUTTON); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/views/report/list/action/rerun/RerunAllAction.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.views.report.list.action.rerun; 2 | 3 | import org.eclipse.jface.action.IAction; 4 | 5 | import org.codechecker.eclipse.plugin.views.report.list.ReportListView; 6 | import org.codechecker.eclipse.plugin.views.report.list.action.showas.TreeAwareAction; 7 | 8 | public class RerunAllAction extends TreeAwareAction { 9 | 10 | public RerunAllAction(ReportListView listView) { 11 | super(listView, "Rerun everything", IAction.AS_PUSH_BUTTON); 12 | setEnabled(false); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/views/report/list/action/rerun/RerunSelectedAction.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.views.report.list.action.rerun; 2 | 3 | import org.eclipse.jface.action.IAction; 4 | 5 | import org.codechecker.eclipse.plugin.views.report.list.ReportListView; 6 | import org.codechecker.eclipse.plugin.views.report.list.action.showas.TreeAwareAction; 7 | 8 | public class RerunSelectedAction extends TreeAwareAction { 9 | 10 | public RerunSelectedAction(ReportListView listView) { 11 | super(listView, "Rerun selected reports", IAction.AS_PUSH_BUTTON); 12 | setEnabled(false); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/views/report/list/action/showas/CheckerGroupAction.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.views.report.list.action.showas; 2 | 3 | import org.eclipse.jface.action.IAction; 4 | 5 | import org.codechecker.eclipse.plugin.views.report.list.ReportListView; 6 | import org.codechecker.eclipse.plugin.views.report.list.provider.content.CheckerGroupContentProvider; 7 | import org.codechecker.eclipse.plugin.views.report.list.provider.label.BasicViewLabelProvider; 8 | 9 | public class CheckerGroupAction extends TreeAwareAction { 10 | 11 | public CheckerGroupAction(ReportListView listView, boolean checked) { 12 | super(listView, "Group by checkers", IAction.AS_RADIO_BUTTON, checked); 13 | } 14 | 15 | @Override 16 | public void run() { 17 | if (isChecked()) { 18 | listView.setProviders(new BasicViewLabelProvider(listView), new 19 | CheckerGroupContentProvider(listView)); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/views/report/list/action/showas/CheckerTreeAction.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.views.report.list.action.showas; 2 | 3 | import org.eclipse.jface.action.IAction; 4 | 5 | import org.codechecker.eclipse.plugin.views.report.list.ReportListView; 6 | import org.codechecker.eclipse.plugin.views.report.list.provider.content.TreeCheckerContentProvider; 7 | import org.codechecker.eclipse.plugin.views.report.list.provider.label.LastPartLabelProvider; 8 | 9 | public class CheckerTreeAction extends TreeAwareAction { 10 | 11 | public CheckerTreeAction(ReportListView listView, boolean checked) { 12 | super(listView, "Group by hierarchical checkers", IAction.AS_RADIO_BUTTON, checked); 13 | } 14 | 15 | @Override 16 | public void run() { 17 | if (isChecked()) { 18 | listView.setProviders(new LastPartLabelProvider(listView), new 19 | TreeCheckerContentProvider(listView)); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/views/report/list/action/showas/TreeAwareAction.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.views.report.list.action.showas; 2 | 3 | import org.eclipse.jface.action.Action; 4 | 5 | import org.codechecker.eclipse.plugin.views.report.list.ReportListView; 6 | 7 | public class TreeAwareAction extends Action { 8 | 9 | protected final ReportListView listView; 10 | 11 | public TreeAwareAction(ReportListView listView, String name, int type) { 12 | super(name, type); 13 | this.listView = listView; 14 | } 15 | 16 | public TreeAwareAction(ReportListView listView, String name, int type, boolean checked) { 17 | super(name, type); 18 | this.listView = listView; 19 | setChecked(checked); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/views/report/list/provider/content/CheckerGroupContentProvider.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.views.report.list.provider.content; 2 | 3 | import java.util.ArrayList; 4 | 5 | import org.apache.commons.lang3.ArrayUtils; 6 | import org.eclipse.jface.viewers.ITreeContentProvider; 7 | import org.eclipse.jface.viewers.Viewer; 8 | 9 | import com.google.common.base.Optional; 10 | import com.google.common.base.Predicate; 11 | import com.google.common.collect.Iterables; 12 | 13 | import org.codechecker.eclipse.plugin.report.BugPathItem; 14 | import org.codechecker.eclipse.plugin.report.ProblemInfo; 15 | import org.codechecker.eclipse.plugin.report.ReportInfo; 16 | import org.codechecker.eclipse.plugin.report.SearchList; 17 | import org.codechecker.eclipse.plugin.views.report.list.ReportListView; 18 | 19 | public class CheckerGroupContentProvider implements ITreeContentProvider { 20 | 21 | private final ReportListView reportListView; 22 | 23 | public CheckerGroupContentProvider(ReportListView reportListView) { 24 | this.reportListView = reportListView; 25 | } 26 | 27 | @Override 28 | public Object getParent(Object child) { 29 | if (child instanceof String) { 30 | return this.reportListView.getReportList().orNull(); 31 | } 32 | 33 | if (child instanceof ReportInfo) { 34 | return ((ReportInfo) child).getCheckerId(); 35 | } 36 | 37 | return null; 38 | } 39 | 40 | @Override 41 | public void dispose() { 42 | // nop 43 | } 44 | 45 | @Override 46 | public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { 47 | // nop 48 | } 49 | 50 | @Override 51 | public Object[] getElements(Object inputElement) { 52 | return getChildren(inputElement); 53 | } 54 | 55 | @Override 56 | public Object[] getChildren(Object parentElement) { 57 | 58 | if (parentElement instanceof SearchList) { 59 | return this.reportListView.getReportList().get().getCheckers().toArray(); 60 | } 61 | 62 | if (parentElement instanceof String) { 63 | return this.reportListView.getReportList().get().getReportsFor((String) 64 | parentElement).toArray(); 65 | } 66 | 67 | if (parentElement instanceof ReportInfo) { 68 | ReportInfo ri = (ReportInfo) parentElement; 69 | Optional bp = ri.getChildren(); 70 | if (bp != null && bp.isPresent()) { 71 | ArrayList result = new ArrayList<>(bp.get().getItems()); 72 | Iterables.removeIf(result, new Predicate() { 73 | @Override 74 | public boolean apply(BugPathItem pi) { 75 | return "".equals(pi.getMessage()); 76 | } 77 | }); 78 | return result.toArray(); 79 | } 80 | } 81 | 82 | return ArrayUtils.toArray(); 83 | } 84 | 85 | @Override 86 | public boolean hasChildren(Object element) { 87 | if(element instanceof ReportInfo || element instanceof SearchList || element instanceof String) { 88 | return true; 89 | } 90 | return false; 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/views/report/list/provider/content/TreeCheckerContentProvider.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.views.report.list.provider.content; 2 | 3 | import java.util.ArrayList; 4 | import java.util.HashSet; 5 | import java.util.Set; 6 | 7 | import org.apache.commons.lang3.ArrayUtils; 8 | import org.codechecker.eclipse.plugin.report.BugPathItem; 9 | import org.codechecker.eclipse.plugin.report.ProblemInfo; 10 | import org.codechecker.eclipse.plugin.report.ReportInfo; 11 | import org.codechecker.eclipse.plugin.report.SearchList; 12 | import org.codechecker.eclipse.plugin.views.report.list.ReportListView; 13 | import org.eclipse.jface.viewers.ITreeContentProvider; 14 | import org.eclipse.jface.viewers.Viewer; 15 | 16 | import com.google.common.base.Optional; 17 | import com.google.common.base.Predicate; 18 | import com.google.common.collect.Iterables; 19 | 20 | public class TreeCheckerContentProvider implements ITreeContentProvider { 21 | 22 | private final ReportListView reportListView; 23 | 24 | public TreeCheckerContentProvider(ReportListView reportListView) { 25 | this.reportListView = reportListView; 26 | } 27 | 28 | @Override 29 | public Object getParent(Object child) { 30 | if (child instanceof String) { 31 | String checker = (String) child; 32 | for (String s : this.reportListView.getReportList().get().getCheckers()) { 33 | if (checker.startsWith(s + ".")) { 34 | return s; 35 | } 36 | } 37 | return this.reportListView.getReportList().orNull(); 38 | } 39 | 40 | if (child instanceof ReportInfo) { 41 | return ((ReportInfo) child).getCheckerId(); 42 | } 43 | 44 | return null; 45 | } 46 | 47 | @Override 48 | public void dispose() { 49 | // nop 50 | } 51 | 52 | @Override 53 | public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { 54 | // nop 55 | } 56 | 57 | @Override 58 | public Object[] getElements(Object inputElement) { 59 | return getChildren(inputElement); 60 | } 61 | 62 | @Override 63 | public Object[] getChildren(Object parentElement) { 64 | 65 | if (parentElement instanceof SearchList) { 66 | Set tops = new HashSet<>(); 67 | for (String s : this.reportListView.getReportList().get().getCheckers()) { 68 | tops.add(s.split("\\.")[0]); 69 | } 70 | return tops.toArray(); 71 | } 72 | 73 | if (parentElement instanceof String) { 74 | 75 | String parent = (String) parentElement; 76 | String[] splittedParent = parent.split("\\."); 77 | int parentLevel = splittedParent.length; 78 | Set tops = new HashSet<>(); 79 | for (String s : this.reportListView.getReportList().get().getCheckers()) { 80 | String[] splitted = s.split("\\."); 81 | if (splitted.length > parentLevel && splitted[parentLevel - 1].equals(splittedParent[parentLevel - 1]) 82 | && !s.equals(parent)) { 83 | tops.add(parent + "." + splitted[parentLevel]); 84 | } 85 | } 86 | 87 | tops.addAll(this.reportListView.getReportList().get().getReportsFor((String) 88 | parentElement)); 89 | 90 | return tops.toArray(); 91 | } 92 | 93 | if (parentElement instanceof ReportInfo) { 94 | ReportInfo ri = (ReportInfo) parentElement; 95 | Optional bp = ri.getChildren(); 96 | if (bp != null && bp.isPresent()) { 97 | ArrayList result = new ArrayList<>(bp.get().getItems()); 98 | Iterables.removeIf(result, new Predicate() { 99 | @Override 100 | public boolean apply(BugPathItem pi) { 101 | return "".equals(pi.getMessage()); 102 | } 103 | }); 104 | return result.toArray(); 105 | } 106 | return ArrayUtils.toArray(); 107 | } 108 | 109 | if(parentElement instanceof BugPathItem) { 110 | //no child! 111 | } 112 | 113 | return ArrayUtils.toArray(); 114 | } 115 | 116 | @Override 117 | public boolean hasChildren(Object element) { 118 | if(element instanceof ReportInfo || element instanceof SearchList || element instanceof String) { 119 | return true; 120 | } 121 | return false; 122 | } 123 | 124 | } 125 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/views/report/list/provider/label/BasicViewLabelProvider.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.views.report.list.provider.label; 2 | 3 | import org.eclipse.core.resources.IFile; 4 | import org.eclipse.core.resources.ResourcesPlugin; 5 | import org.eclipse.core.runtime.Path; 6 | import org.eclipse.jface.viewers.LabelProvider; 7 | import org.eclipse.swt.graphics.Image; 8 | import org.eclipse.ui.ISharedImages; 9 | import org.eclipse.ui.PlatformUI; 10 | 11 | import org.codechecker.eclipse.plugin.report.BugPathItem; 12 | import org.codechecker.eclipse.plugin.report.ReportInfo; 13 | import org.codechecker.eclipse.plugin.report.SearchList; 14 | import org.codechecker.eclipse.plugin.views.report.list.ReportListView; 15 | 16 | public class BasicViewLabelProvider extends LabelProvider { 17 | 18 | private final ReportListView reportListView; 19 | 20 | public BasicViewLabelProvider(ReportListView reportListView) { 21 | this.reportListView = reportListView; 22 | } 23 | 24 | public String getText(Object obj) { 25 | if (obj instanceof ReportInfo) { 26 | ReportInfo ri = (ReportInfo) obj; 27 | Path path = new Path(ri.getCheckedFile()); 28 | IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path); 29 | return "#" + ri.getReportId() + ": " + file.getName() + " [" + ri 30 | .getLastBugPathItem().getStartPosition().getLine() + ":" + ri 31 | .getLastBugPathItem().getStartPosition().getColumn() + "]"; 32 | } 33 | if(obj instanceof BugPathItem) { 34 | BugPathItem bpi = (BugPathItem) obj; 35 | Path path = new Path(bpi.getFile()); 36 | IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path); 37 | 38 | return file.getName() + " : " + bpi.getStartPosition().getLine() + " : " + bpi.getMessage(); 39 | } 40 | if (obj instanceof String) { 41 | // TODO: add counters 42 | //return ((String)obj) + " (?)"; 43 | } 44 | return obj.toString(); 45 | } 46 | 47 | public Image getImage(Object obj) { 48 | String imageKey = ISharedImages.IMG_OBJ_ELEMENT; 49 | if (obj instanceof String || obj instanceof SearchList || obj instanceof ReportInfo) // TODO: provide better images 50 | imageKey = ISharedImages.IMG_OBJ_FOLDER; 51 | return PlatformUI.getWorkbench().getSharedImages().getImage(imageKey); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /bundles/org.codechecker.eclipse.plugin/src/org/codechecker/eclipse/plugin/views/report/list/provider/label/LastPartLabelProvider.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.views.report.list.provider.label; 2 | 3 | import org.codechecker.eclipse.plugin.views.report.list.ReportListView; 4 | 5 | public class LastPartLabelProvider extends BasicViewLabelProvider { 6 | 7 | public LastPartLabelProvider(ReportListView reportListView) { 8 | super(reportListView); 9 | // TODO Auto-generated constructor stub 10 | } 11 | 12 | public String getText(Object obj) { 13 | String sup = super.getText(obj); 14 | if (obj instanceof String) { 15 | String[] parts = sup.split("\\."); 16 | sup = parts[parts.length - 1]; 17 | } 18 | return sup; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /bundles/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | org.codechecker.eclipse 4 | org.codechecker.eclipse.bundles 5 | 1.0.0-SNAPSHOT 6 | pom 7 | 8 | 9 | org.codechecker.eclipse 10 | org.codechecker.eclipse.root 11 | 1.0.0-SNAPSHOT 12 | 13 | 14 | 15 | org.codechecker.eclipse.plugin 16 | 17 | 18 | -------------------------------------------------------------------------------- /checkstyle.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /docs/allperspective.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ericsson/CodeCheckerEclipsePlugin/bd79c2631d81cf077864ddfac6068dd062c3aa91/docs/allperspective.png -------------------------------------------------------------------------------- /docs/checkershow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ericsson/CodeCheckerEclipsePlugin/bd79c2631d81cf077864ddfac6068dd062c3aa91/docs/checkershow.png -------------------------------------------------------------------------------- /docs/checkstyle.md: -------------------------------------------------------------------------------- 1 | # Checkstyle for CodeChecker Eclipse plugin 2 | 3 | ## Maven 4 | ### Usage 5 | Maven is configured to automatically run checksytle plugin during the build, no other action is needed. The current configuration won't fail the build, only emit warnings. 6 | 7 | __Adhering to to these style checks is mandatory.__ 8 | 9 | In the future the the severity level will be changed to error, and will fail the build. 10 | 11 | The `checkstyle.xml` file that defines the checks to be used is under `/eclipse-plugin/eclipse/cc.codechecker.eclipse.parent/` 12 | 13 | The Maven checkstyle plugin also configured in this folders pom.xml under the build section. 14 | 15 | ## Eclipse IDE 16 | 17 | * ### Installation: 18 | * Install`Checkstyle Plug-in` from Eclipse marketplace. 19 | 20 | * ### Confugration: 21 | * To configure Checkstyle plug-in go to `preferences > Checkstyle`. 22 | * Add the checkstyle.xml with `new` as an `External configuration file`, and specify a name also. 23 | ![Config Pages][conf] 24 | * _This step is optional:`Set as Default` the new configuration_ 25 | * Under the project preferences tick `Checkstyle active for this project` 26 | and make sure that the __configuration you added__ is being used. 27 | ![Config Pages][projconf] 28 | 29 | * ### Usage: 30 | * Checkstyle automatically monitors the project for imperfections. 31 | * The lines containing checkstyle problems are yellowed. 32 | * There is a view (Checkstyle violations) that can be opened. 33 | * There is a right click context item. (Apply Checkstyle fixes). 34 | 35 | ## Codacy 36 | 37 | [Codacy](https://app.codacy.com/project/CodeChecker/CodeCheckerEclipsePlugin/dashboard) is set to use the same checkers as the project. 38 | 39 | [conf]: img/checkstyle/ide_config.png "Configuration" 40 | [projconf]: img/checkstyle/ide_proj_conf.png "Project Configuration" 41 | -------------------------------------------------------------------------------- /docs/config.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ericsson/CodeCheckerEclipsePlugin/bd79c2631d81cf077864ddfac6068dd062c3aa91/docs/config.png -------------------------------------------------------------------------------- /docs/developer.md: -------------------------------------------------------------------------------- 1 | # Developer documentation 2 | 3 | ## Troubleshooting 4 | 5 | * In case of compile error, attach the maven output 6 | * Runtime logging is still a big todo, currently most log will appear on stdout/stderr 7 | 8 | ## Development Notes 9 | 10 | * Requires the Tycho Connector, Eclipse will automatically install it for you when you first import the project 11 | * Requires Eclipse PDE (Plug-in Development Environment) 12 | * WindowMaker plugin is recommended 13 | * Adherence to the [Google Java Style](https://google.github.io/styleguide/javaguide.html) is mandatory 14 | * An IntelliJ Idea autoformatter XML configuration file is included in the repo for convenience 15 | 16 | ## Version Update 17 | 18 | Execute the following command in CodeCheckerEclipsePlugin/eclipse-plugin. 19 | ``` mvn -Dtycho.mode=maven org.eclipse.tycho:tycho-versions-plugin:set-version -DnewVersion=X.X.X-SNAPSHOT -Dartifacts=cc.codechecker.eclipse.plugin ``` 20 | 21 | ## Log 22 | 23 | Logging in the plugin is handled by `log4j` from Apache. The default loglevel is `ERROR`, and the following loglevels are used, in increasing severity order: 24 | 25 | * `TRACE` 26 | * `DEBUG` 27 | * `INFO` 28 | * `WARN` 29 | * `ERROR` 30 | * `FATAL` 31 | 32 | The log configuration file's location is `eclipse-plugin/eclipse/cc.codechecker.eclipse.plugin/log4j.properties` before compilation. 33 | 34 | After compiling the plugin, you may change the log level (which specifies which *least severe* category will be logged) by opening the built `cc.codechecker.eclipse.plugin-0.0.1-SNAPSHOT.jar` file (with `mc` or any `zip` editor) and changing the `log4j.properties` file therein. 35 | 36 | The loglevel is specified as follows: 37 | 38 | log4j.appender.log.threshold=ERROR 39 | 40 | After modifying the jar file, you will need to restart eclipse for the changes to take effect. 41 | 42 | ## Checkstyle 43 | Checkstyle is configured for this project. See related [documentation](checkstyle.md) for more information. -------------------------------------------------------------------------------- /docs/example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ericsson/CodeCheckerEclipsePlugin/bd79c2631d81cf077864ddfac6068dd062c3aa91/docs/example.png -------------------------------------------------------------------------------- /docs/img/checkstyle/ide_config.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ericsson/CodeCheckerEclipsePlugin/bd79c2631d81cf077864ddfac6068dd062c3aa91/docs/img/checkstyle/ide_config.png -------------------------------------------------------------------------------- /docs/img/checkstyle/ide_proj_conf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ericsson/CodeCheckerEclipsePlugin/bd79c2631d81cf077864ddfac6068dd062c3aa91/docs/img/checkstyle/ide_proj_conf.png -------------------------------------------------------------------------------- /docs/nature.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ericsson/CodeCheckerEclipsePlugin/bd79c2631d81cf077864ddfac6068dd062c3aa91/docs/nature.png -------------------------------------------------------------------------------- /features/org.codechecker.eclipse.feature/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.codechecker.eclipse.feature 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.pde.FeatureBuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.pde.FeatureNature 16 | 17 | 18 | -------------------------------------------------------------------------------- /features/org.codechecker.eclipse.feature/build.properties: -------------------------------------------------------------------------------- 1 | bin.includes = feature.xml 2 | -------------------------------------------------------------------------------- /features/org.codechecker.eclipse.feature/feature.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | [Enter Feature Description here.] 10 | 11 | 12 | 13 | [Enter Copyright Description here.] 14 | 15 | 16 | 17 | [Enter License Description here.] 18 | 19 | 20 | 26 | 27 | 33 | 34 | 40 | 41 | 47 | 48 | 54 | 55 | 61 | 62 | 68 | 69 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /features/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | org.codechecker.eclipse 4 | org.codechecker.eclipse.features 5 | 1.0.0-SNAPSHOT 6 | pom 7 | 8 | 9 | org.codechecker.eclipse 10 | org.codechecker.eclipse.root 11 | 1.0.0-SNAPSHOT 12 | 13 | 14 | 15 | org.codechecker.eclipse.feature 16 | 17 | 18 | -------------------------------------------------------------------------------- /mavendeps/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.reficio.rcp 7 | codechecker-mavendeps-p2-site 8 | pom 9 | 1.0.0-SNAPSHOT 10 | 11 | 12 | 13 | 14 | org.reficio 15 | p2-maven-plugin 16 | 1.3.0 17 | 18 | 19 | default-cli 20 | 21 | 22 | javax.xml.parsers:jaxp-api:1.4.5 23 | com.github.stefanbirkner:system-rules:1.19.0 24 | com.google.code.gson:gson:2.3.1 25 | com.googlecode.plist:dd-plist:1.21 26 | com.google.guava:guava:26.0-jre 27 | joda-time:joda-time:2.10.1 28 | log4j:log4j:1.2.17 29 | org.apache.commons:commons-exec:1.3 30 | org.apache.commons:commons-lang3:3.0 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | org.codechecker.eclipse 4 | org.codechecker.eclipse.root 5 | 1.0.0-SNAPSHOT 6 | pom 7 | 8 | org.codechecker.eclipse 9 | org.codechecker.eclipse.configuration 10 | 1.0.0-SNAPSHOT 11 | ./releng/org.codechecker.eclipse.configuration 12 | 13 | 14 | 15 | bundles 16 | features 17 | releng 18 | tests 19 | 20 | 21 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # CodeChecker Eclipse Plugin 2 | 3 | [![Build Status](https://travis-ci.org/Ericsson/CodeCheckerEclipsePlugin.svg?branch=master)](https://travis-ci.org/Ericsson/CodeCheckerEclipsePlugin) 4 | 5 | This is a C/C++ code analysis plugin for Eclipse that shows bugs detected by the [Clang Static Analyzer](http://clang-analyzer.llvm.org/) and [Clang Tidy](http://clang.llvm.org/extra/clang-tidy/) analyzers, using [CodeChecker](https://github.com/Ericsson/codechecker) as a backend, 6 | 7 | ## Requirements 8 | 9 | * Linux operating system 10 | 11 | * Recent [CodeChecker](https://github.com/Ericsson/codechecker) (6.8.0 and up) 12 | 13 | * Every eclipse version since [Phtoton](https://www.eclipse.org/downloads/packages/release/photon/r) (v4.8.0) is supported 14 | * Should work with v4.7.0 Oxygen, but this version is untested currently. 15 | 16 | * Eclipse CDT 17 | 18 | * Java SE 1.8 (for building, an equivalent jdk). 19 | 20 | ## Build and install CodeChecker Eclipse Plugin 21 | 22 | ### Build 23 | 24 | Run `mvn -f mavendeps/pom.xml p2:site && mvn clean verify` in the root of the project. 25 | 26 | ### Install 27 | 28 | * Add the generated update site thats located under `path/to/cloned/project/releng/org.codechecker.eclipse.update/target/repository/` to `Help -> Install New Software...` in Eclipse 29 | * Alternatively, use the archive from the Releases page, as an update site. 30 | * Select the newly added repository if not already selected 31 | * Mark CodeChecker Eclipse Plugin then hit next. 32 | * If an alert box comes up with unsigned content. Just accept it. 33 | 34 | ## How to use 35 | Make sure that before staring Eclipse: 36 | 37 | * CodeChecker/bin directory is included in PATH (e.g.: `export PATH="/home//CodeChecker/bin/:$PATH"`) 38 | 39 | __Currently the plugin is only usable with a CDT project.__ 40 | 41 | #### 1. Setup Perspective 42 | In Eclipse, select Window, Perspectives, and activate the CodeChecker perspective. 43 | Alternatively, you can manually add the two windows under the CodeChecker category into any perspective, using the Window - Views menu. 44 | __Make sure to check if CDT is installed properly if you do not see the CodeChecker perspective on the list!__ 45 | 46 | ![Window->Perspective->Open Perspective->Other](docs/allperspective.png) 47 | 48 | #### 2. Setup Nature 49 | The plugin is activated on a per project basis, first you have to add the __CodeChecker Nature__ to a CDT project using the projects context menu in the project explorer with `Add CodeChecker Nature` command. 50 | 51 | ![CodeChecker Nature Add](docs/nature.png) 52 | 53 | #### 3. Configure CodeChecker and checkers 54 | 55 | After the __CodeChecker Nature__ is added to the the project, the plugin can be configured globally in `Window -> Preferences -> CodeChecker` panel, or for the individual project, from the `right click context menu -> Properties -> CodeChecker` page. 56 | In the first section, you select how and which CodeChecker will be used. After that set some analysis related settings. You should build CodeChecker in a __standalone package__ configuration. 57 | 58 | ``` bash 59 | cd codechecker 60 | make standalone_package 61 | export PATH=$PWD/build/CodeChecker/bin:$PATH 62 | ``` 63 | 64 | Then add it to the PATH environment variable, and use the Search in PATH option. Alternatively you can specify a different instance with the Pre built package option. But be aware that the plugin not supports virtual environment, that CodeChecker needs in the default configuration. You can download and compile CodeChecker from [here](https://github.com/Ericsson/codechecker). 65 | 66 | To specify checkers or profiles, please add them to the Extra analysis options field. 67 | 68 | At the bottom the command that is similar to that to be executed is displayed, for easier commandline reproduction. 69 | 70 | ![CodeChecker Configure](docs/config.png) 71 | 72 | After the plugin is successfully configured for a project, it'll listen to build events, and automatically rechecks the project with CodeChecker when needed. 73 | 74 | #### 4. Analyze C/C++ project and view results 75 | 76 | By default the plugin displays the problems related to the currently selected file on the current file reports view. Here the viewer can decide to check the individual reports selected from the reports tree, and view the related bug-path. Double clicking on a bug-path item will jump and set the cursor to that line in the editor. 77 | 78 | The analysis is triggered when opening a file, or on a file save event, for that particular file. Currently there is no full project analysis. *Please note that codechecker will only show analysis results for files that you built. in the Current project View* 79 | 80 | ![CodeChecker Runtime Example](docs/example.png) 81 | 82 | ## Contributing 83 | 84 | For further information see [developer documentation](docs/developer.md). 85 | -------------------------------------------------------------------------------- /releng/org.codechecker.eclipse.configuration/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.codechecker.eclipse.configuration 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /releng/org.codechecker.eclipse.configuration/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | org.codechecker.eclipse 4 | org.codechecker.eclipse.configuration 5 | 1.0.0-SNAPSHOT 6 | pom 7 | 8 | 9 | 1.4.0 10 | UTF-8 11 | 12 | 13 | 14 | 15 | mavendeps 16 | p2 17 | file:mavendeps/target/repository 18 | 19 | 20 | 21 | 22 | 23 | 24 | org.eclipse.tycho 25 | tycho-maven-plugin 26 | ${tycho.version} 27 | true 28 | 29 | 30 | 31 | org.eclipse.tycho 32 | tycho-packaging-plugin 33 | ${tycho.version} 34 | 35 | 36 | package 37 | package-feature 38 | 39 | ${project.artifactId}_${unqualifiedVersion}.${buildQualifier} 40 | 41 | 42 | 43 | 44 | 45 | org.eclipse.tycho 46 | target-platform-configuration 47 | ${tycho.version} 48 | 49 | 50 | 51 | org.codechecker.eclipse 52 | org.codechecker.eclipse.target 53 | 1.0.0-SNAPSHOT 54 | 55 | 56 | 57 | 58 | 59 | eclipse-plugin 60 | org.eclipse.equinox.event 61 | 0.0.0 62 | 63 | 64 | 65 | 66 | 67 | linux 68 | gtk 69 | x86_64 70 | 71 | 72 | 73 | 74 | 75 | org.apache.maven.plugins 76 | maven-checkstyle-plugin 77 | 3.0.0 78 | 79 | 80 | validate 81 | validate 82 | 83 | ./../../checkstyle.xml 84 | UTF-8 85 | true 86 | false 87 | warning 88 | false 89 | false 90 | 91 | 92 | check 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /releng/org.codechecker.eclipse.target/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.codechecker.eclipse.target 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /releng/org.codechecker.eclipse.target/org.codechecker.eclipse.target.target: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /releng/org.codechecker.eclipse.target/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | org.codechecker.eclipse 5 | org.codechecker.eclipse.releng 6 | 1.0.0-SNAPSHOT 7 | 8 | org.codechecker.eclipse 9 | org.codechecker.eclipse.target 10 | 1.0.0-SNAPSHOT 11 | eclipse-target-definition 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /releng/org.codechecker.eclipse.update/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.codechecker.eclipse.update 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /releng/org.codechecker.eclipse.update/category.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /releng/org.codechecker.eclipse.update/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | org.codechecker.eclipse 5 | org.codechecker.eclipse.releng 6 | 1.0.0-SNAPSHOT 7 | 8 | org.codechecker.eclipse.update 9 | 1.0.0-SNAPSHOT 10 | eclipse-repository 11 | 12 | -------------------------------------------------------------------------------- /releng/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | org.codechecker.eclipse 4 | org.codechecker.eclipse.releng 5 | 1.0.0-SNAPSHOT 6 | pom 7 | 8 | 9 | org.codechecker.eclipse 10 | org.codechecker.eclipse.root 11 | 1.0.0-SNAPSHOT 12 | 13 | 14 | 15 | org.codechecker.eclipse.update 16 | org.codechecker.eclipse.target 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /tests/org.codechecker.eclipse.rcp.it.tests/.checkstyle: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /tests/org.codechecker.eclipse.rcp.it.tests/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/org.codechecker.eclipse.rcp.it.tests/.gitignore: -------------------------------------------------------------------------------- 1 | /bin/ 2 | /tests/ 3 | -------------------------------------------------------------------------------- /tests/org.codechecker.eclipse.rcp.it.tests/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.codechecker.eclipse.rcp.it.tests 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.pde.ManifestBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.pde.SchemaBuilder 20 | 21 | 22 | 23 | 24 | org.eclipse.m2e.core.maven2Builder 25 | 26 | 27 | 28 | 29 | 30 | org.eclipse.m2e.core.maven2Nature 31 | org.eclipse.pde.PluginNature 32 | org.eclipse.jdt.core.javanature 33 | 34 | 35 | -------------------------------------------------------------------------------- /tests/org.codechecker.eclipse.rcp.it.tests/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding/=UTF-8 3 | -------------------------------------------------------------------------------- /tests/org.codechecker.eclipse.rcp.it.tests/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.source=1.8 8 | -------------------------------------------------------------------------------- /tests/org.codechecker.eclipse.rcp.it.tests/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /tests/org.codechecker.eclipse.rcp.it.tests/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: Integration Tests 4 | Bundle-SymbolicName: org.codechecker.eclipse.rcp.it.tests 5 | Bundle-Version: 1.0.0.qualifier 6 | Bundle-Vendor: Vodorok 7 | Fragment-Host: org.codechecker.eclipse.plugin 8 | Automatic-Module-Name: org.codechecker.eclipse.rcp.it.tests 9 | Bundle-RequiredExecutionEnvironment: JavaSE-1.8 10 | Require-Bundle: org.junit;bundle-version="4.12.0", 11 | org.hamcrest;bundle-version="1.1.0", 12 | org.eclipse.swtbot.junit4_x;bundle-version="2.7.0", 13 | org.eclipse.swtbot.swt.finder;bundle-version="2.7.0", 14 | org.eclipse.swtbot.eclipse.finder;bundle-version="2.7.0", 15 | org.codechecker.eclipse.rcp.shared;bundle-version="1.0.0", 16 | com.github.stefanbirkner.system-rules;bundle-version="1.19.0", 17 | javax.annotation;bundle-version="1.2.0" 18 | -------------------------------------------------------------------------------- /tests/org.codechecker.eclipse.rcp.it.tests/build.properties: -------------------------------------------------------------------------------- 1 | source.. = src/ 2 | output.. = bin/ 3 | bin.includes = META-INF/,\ 4 | .,\ 5 | fragment.xml,\ 6 | resources/ 7 | -------------------------------------------------------------------------------- /tests/org.codechecker.eclipse.rcp.it.tests/fragment.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /tests/org.codechecker.eclipse.rcp.it.tests/resources/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ericsson/CodeCheckerEclipsePlugin/bd79c2631d81cf077864ddfac6068dd062c3aa91/tests/org.codechecker.eclipse.rcp.it.tests/resources/.gitkeep -------------------------------------------------------------------------------- /tests/org.codechecker.eclipse.rcp.it.tests/resources/cppTest/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | cppTest 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | org.eclipse.cdt.core.cnature 23 | org.eclipse.cdt.core.ccnature 24 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 25 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 26 | 27 | 28 | -------------------------------------------------------------------------------- /tests/org.codechecker.eclipse.rcp.it.tests/resources/cppTest/.settings/language.settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /tests/org.codechecker.eclipse.rcp.it.tests/resources/cppTest/src/cppTest.cpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // Name : cppTest.cpp 3 | // Author : 4 | // Version : 5 | // Copyright : Your copyright notice 6 | // Description : Hello World in C++, Ansi-style 7 | //============================================================================ 8 | 9 | #include 10 | using namespace std; 11 | 12 | void test() { 13 | int *p = (int*)malloc(sizeof(int)); 14 | free(p); 15 | *p = 1; // warn: use after free 16 | } 17 | 18 | void test2() { 19 | long *p = (long*)malloc(sizeof(short)); 20 | free(p); 21 | } 22 | 23 | void f(int *p){}; 24 | 25 | void testUseMiddleArgAfterDelete(int *p) { 26 | delete p; 27 | f(p); // warn: use after free 28 | } 29 | 30 | int main() { 31 | int *i = new int; 32 | int a = *i; 33 | cout << "Hello world!" << endl; // prints !!!Hello World!!! 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /tests/org.codechecker.eclipse.rcp.it.tests/src/org/codechecker/eclipse/plugin/AllTests.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin; 2 | 3 | import org.codechecker.eclipse.plugin.utils.GuiUtils; 4 | import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; 5 | import org.junit.BeforeClass; 6 | import org.junit.runner.RunWith; 7 | import org.junit.runners.Suite; 8 | import org.junit.runners.Suite.SuiteClasses; 9 | 10 | /** 11 | * Test Suite for running the gui tests. Add your class to the Suite class list. 12 | */ 13 | @RunWith(Suite.class) 14 | @SuiteClasses({ PluginTest.class, IndicatorTest.class, ParameterPassThroughTest.class, ConfigurationTest.class, 15 | AnalysisTest.class }) 16 | public class AllTests { 17 | 18 | private static SWTWorkbenchBot bot; 19 | 20 | /** 21 | * Never called. 22 | */ 23 | private AllTests() {} 24 | 25 | /** 26 | * Import cpp project into workspace, and setup SWTBot. 27 | * 28 | */ 29 | @BeforeClass 30 | public static void setup() { 31 | //clearWs(); 32 | bot = new SWTWorkbenchBot(); 33 | GuiUtils.closeWelcomeIfPresent(bot); 34 | GuiUtils.changePerspectiveTo(GuiUtils.C_CPP_PESPECTIVE, bot); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tests/org.codechecker.eclipse.rcp.it.tests/src/org/codechecker/eclipse/plugin/ParameterPassThroughTest.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin; 2 | 3 | import java.nio.file.Path; 4 | 5 | import org.codechecker.eclipse.plugin.config.CommonGui; 6 | import org.codechecker.eclipse.plugin.utils.GuiUtils; 7 | import org.codechecker.eclipse.rcp.shared.utils.Utils; 8 | import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; 9 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; 10 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotText; 11 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; 12 | import org.junit.BeforeClass; 13 | import org.junit.Test; 14 | 15 | import static org.hamcrest.MatcherAssert.assertThat; 16 | 17 | /** 18 | * Test the parameter pass through graphical user interface functionalities. 19 | */ 20 | public class ParameterPassThroughTest { 21 | 22 | private static final String CR_PROJ = "parameterProject"; 23 | private static final String CODECHECKER = "CodeChecker"; 24 | 25 | private static final String EXTRA = "-e unix"; 26 | 27 | private static SWTBotTreeItem project; 28 | private static SWTWorkbenchBot bot; 29 | private static Path ccDir = Utils.prepareCodeChecker(); 30 | 31 | /** 32 | * Setup the bot. 33 | */ 34 | @BeforeClass 35 | public static void setUp() { 36 | bot = new SWTWorkbenchBot(); 37 | } 38 | 39 | /** 40 | * Test the global preferences. 41 | */ 42 | @Test 43 | public void testGlobal() { 44 | SWTBotShell preferencesShell = GuiUtils.getPreferencesTab(CODECHECKER, bot); 45 | 46 | GuiUtils.setCCBinDir(ccDir, bot); 47 | 48 | SWTBotText display = bot.textWithLabel(CommonGui.CC_FINAL_DISP_LABEL); 49 | assertThat("Preferences page Display is incorrect!", display.getText().startsWith(ccDir.toString())); 50 | 51 | GuiUtils.applyClosePreferences(preferencesShell, bot); 52 | } 53 | 54 | /** 55 | * Test in project properties. 56 | */ 57 | @Test 58 | public void testProject() { 59 | bot.menu("File").menu("New").menu(GuiUtils.CPP_PROJECT).click(); 60 | 61 | SWTBotShell shell = bot.shell("C++ Project"); 62 | shell.activate(); 63 | 64 | bot.textWithLabel("&Project name:").setText(CR_PROJ); 65 | bot.tree().getTreeItem("Executable").getNode("Hello World C++ Project").select(); 66 | bot.button(GuiUtils.FINISH).click(); 67 | 68 | bot.sleep(GuiUtils.SHORT_WAIT_TIME); 69 | 70 | project = bot.tree().getTreeItem(CR_PROJ); 71 | project.contextMenu(GuiUtils.ADD_NATURE_MENU).click(); 72 | project.contextMenu(GuiUtils.PROPERTIES).click(); 73 | 74 | SWTBotShell propertiesShell = bot.shell(GuiUtils.PROPERTIES_FOR + CR_PROJ); 75 | propertiesShell.activate(); 76 | bot.tree().getTreeItem(GuiUtils.CODECHECKER).select(); 77 | 78 | bot.radio(GuiUtils.PROJECT_RADIO).click(); 79 | 80 | GuiUtils.setCCBinDir(ccDir, bot); 81 | 82 | SWTBotText display = bot.textWithLabel(CommonGui.CC_FINAL_DISP_LABEL); 83 | assertThat("Properties page Display is incorrect!", display.getText().startsWith(ccDir.toString())); 84 | 85 | SWTBotText extra = bot.textWithLabel(CommonGui.CC_EXTRA_CMD_LABEL); 86 | extra.setText(EXTRA); 87 | 88 | assertThat("Display not contains extra parameters", extra.getText().contains(EXTRA)); 89 | 90 | GuiUtils.applyCloseProperties(propertiesShell, bot); 91 | 92 | project.contextMenu(GuiUtils.PROPERTIES).click(); 93 | propertiesShell = bot.shell(GuiUtils.PROPERTIES_FOR + CR_PROJ); 94 | propertiesShell.activate(); 95 | 96 | extra = bot.textWithLabel(CommonGui.CC_EXTRA_CMD_LABEL); 97 | assertThat("Display does not contains extra parameters after reopen", extra.getText().contains(EXTRA)); 98 | 99 | GuiUtils.applyCloseProperties(propertiesShell, bot); 100 | 101 | GuiUtils.deleteProject(CR_PROJ, true, bot); 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /tests/org.codechecker.eclipse.rcp.it.tests/src/org/codechecker/eclipse/plugin/PluginTest.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.net.URISyntaxException; 6 | import java.nio.file.Path; 7 | import java.nio.file.Paths; 8 | 9 | import org.codechecker.eclipse.plugin.utils.ProjectImporter; 10 | import org.codechecker.eclipse.rcp.shared.utils.Utils; 11 | import org.eclipse.core.resources.ResourcesPlugin; 12 | import org.eclipse.core.runtime.CoreException; 13 | import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; 14 | import org.eclipse.swtbot.eclipse.finder.waits.Conditions; 15 | import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException; 16 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu; 17 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; 18 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; 19 | import org.junit.AfterClass; 20 | import org.junit.BeforeClass; 21 | import org.junit.Rule; 22 | import org.junit.Test; 23 | import org.junit.rules.ExpectedException; 24 | 25 | import static org.hamcrest.MatcherAssert.assertThat; 26 | import static org.hamcrest.Matchers.containsString; 27 | import static org.hamcrest.Matchers.is; 28 | 29 | /** 30 | * Tests for the gui. 31 | */ 32 | public class PluginTest { 33 | 34 | private static final String CPP_PROJ = "cppTest"; 35 | private static final String ADD_NATURE_MENU = "Add CodeChecker Nature"; 36 | 37 | private static SWTWorkbenchBot bot; 38 | 39 | @Rule 40 | public ExpectedException thrown = ExpectedException.none(); 41 | 42 | /** 43 | * Import cpp project into workspace, and setup SWTBot. 44 | */ 45 | @BeforeClass 46 | public static void setup() { 47 | 48 | bot = new SWTWorkbenchBot(); 49 | 50 | Path file = null; 51 | try { 52 | file = Utils.loadFileFromBundle("org.codechecker.eclipse.rcp.it.tests", Utils.RES + CPP_PROJ); 53 | } catch (URISyntaxException | IOException e) { 54 | e.printStackTrace(); 55 | } 56 | 57 | Utils.copyFolder(file, 58 | Paths.get(ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString() + File.separator)); 59 | 60 | File project = new File(ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString() + File.separator 61 | + CPP_PROJ + File.separator + ".project"); 62 | try { 63 | ProjectImporter.importProject(project.toPath(), CPP_PROJ); 64 | } catch (CoreException e1) { 65 | e1.printStackTrace(); 66 | } 67 | } 68 | 69 | /** 70 | * Delete project from Workspace so others can import it. 71 | */ 72 | @AfterClass 73 | public static void afterClass() { 74 | bot.tree().getTreeItem(CPP_PROJ).contextMenu("Delete").click(); 75 | SWTBotShell shell = bot.shell("Delete Resources"); 76 | shell.activate(); 77 | 78 | bot.checkBox("Delete project contents on disk (cannot be undone)").select(); 79 | bot.button("OK").click(); 80 | bot.waitUntil(Conditions.shellCloses(shell)); 81 | } 82 | 83 | /** 84 | * Test that after adding nature to a C project, the add nature menu item 85 | * disappears. 86 | */ 87 | @Test 88 | public void testAddNatureDisappears() { 89 | 90 | SWTBotTreeItem project = bot.tree().getTreeItem(CPP_PROJ).doubleClick(); 91 | SWTBotMenu menu = project.contextMenu(ADD_NATURE_MENU); 92 | 93 | assertThat("Add CodeChecker Nature menu item wasn't enabled", menu.isEnabled(), is(true)); 94 | 95 | menu.click(); 96 | 97 | // Widget should be missing now. 98 | thrown.expect(WidgetNotFoundException.class); 99 | thrown.expectMessage(containsString("Could not find")); 100 | project.contextMenu(ADD_NATURE_MENU); 101 | } 102 | } -------------------------------------------------------------------------------- /tests/org.codechecker.eclipse.rcp.it.tests/src/org/codechecker/eclipse/plugin/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Unit tests. 3 | */ 4 | package org.codechecker.eclipse.plugin; -------------------------------------------------------------------------------- /tests/org.codechecker.eclipse.rcp.it.tests/src/org/codechecker/eclipse/plugin/utils/CompilationLogHelper.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.utils; 2 | 3 | import java.io.IOException; 4 | import java.nio.file.Files; 5 | import java.nio.file.Path; 6 | import java.nio.file.Paths; 7 | 8 | import org.codechecker.eclipse.plugin.config.project.CodeCheckerProject; 9 | import org.eclipse.core.resources.ResourcesPlugin; 10 | 11 | /** 12 | * This class can be used to create an (dummy) analyze log to the specified 13 | * project. 14 | */ 15 | public class CompilationLogHelper { 16 | 17 | /** 18 | * Never called. 19 | */ 20 | private CompilationLogHelper() { 21 | } 22 | 23 | /** 24 | * Creates an empty compilation commands .json file, into the correct 25 | * destination with the correct name. This can be forwarded to the dummy 26 | * analysis tests. 27 | * 28 | * @param projectName 29 | * The project name to be used. 30 | */ 31 | public static void createCompilationLog(String projectName) { 32 | // get the correct location which is eclipseWs/.codechecker/{$projectName}/ 33 | Path workspaceRoot = Paths.get(ResourcesPlugin.getWorkspace().getRoot().getLocation().toString(), 34 | GuiUtils.DOT_CODECHECKER, projectName, CodeCheckerProject.MASTER_COMPILATION_COMMANDS); 35 | // create a compilation log to the project. 36 | try { 37 | Files.createFile(workspaceRoot); 38 | } catch (IOException e) { 39 | e.printStackTrace(); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /tests/org.codechecker.eclipse.rcp.it.tests/src/org/codechecker/eclipse/plugin/utils/ProjectImporter.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.utils; 2 | 3 | import java.nio.file.Path; 4 | 5 | import org.eclipse.core.resources.IProject; 6 | import org.eclipse.core.resources.IProjectDescription; 7 | import org.eclipse.core.resources.ResourcesPlugin; 8 | import org.eclipse.core.runtime.CoreException; 9 | 10 | /** 11 | * Import projects into eclipse with this class. 12 | */ 13 | public class ProjectImporter { 14 | 15 | /** 16 | * Hidden utility ctor. 17 | */ 18 | private ProjectImporter() {} 19 | 20 | /** 21 | * Imports a project into workspace. 22 | * https://www.eclipse.org/forums/index.php/t/560903/ 23 | * 24 | * @param projectFile 25 | * The project file to be imported. 26 | * @param projectName 27 | * The project name that will be used to create the project 28 | * @throws CoreException 29 | * Project cannot be created: if this method fails. Reasons include: 30 | * - This project already exists in the workspace. - The name of 31 | * this resource is not valid (according to 32 | * IWorkspace.validateName). - The project location is not valid 33 | * (according to IWorkspace.validateProjectLocation). - The project 34 | * description file could not be created in the project content 35 | * area. - Resource changes are disallowed during certain types of 36 | * resource change event notification. See IResourceChangeEvent for 37 | * more details. .project file has troubles. Reasons include: - The 38 | * project description file does not exist. - The file cannot be 39 | * opened or read. - The file cannot be parsed as a legal project 40 | * description. or during opening - Resource changes are disallowed 41 | * during certain types of resource change event notification. See 42 | * IResourceChangeEvent for more details. 43 | */ 44 | public static void importProject(final Path projectFile, final String projectName) throws CoreException { 45 | IProjectDescription description = ResourcesPlugin.getWorkspace() 46 | .loadProjectDescription(new org.eclipse.core.runtime.Path(projectFile.toFile().getAbsolutePath())); 47 | description.setName(projectName); 48 | create(description, projectName); 49 | } 50 | 51 | /** 52 | * Convenience method for importing projects with names specified 53 | * from the targeted project file. 54 | * Imports a project into workspace. 55 | * https://www.eclipse.org/forums/index.php/t/560903/ 56 | * 57 | * @param projectFile 58 | * The project file to be imported. 59 | * @throws CoreException 60 | * Project cannot be created: if this method fails. Reasons include: 61 | * - This project already exists in the workspace. - The name of 62 | * this resource is not valid (according to 63 | * IWorkspace.validateName). - The project location is not valid 64 | * (according to IWorkspace.validateProjectLocation). - The project 65 | * description file could not be created in the project content 66 | * area. - Resource changes are disallowed during certain types of 67 | * resource change event notification. See IResourceChangeEvent for 68 | * more details. .project file has troubles. Reasons include: - The 69 | * project description file does not exist. - The file cannot be 70 | * opened or read. - The file cannot be parsed as a legal project 71 | * description. or during opening - Resource changes are disallowed 72 | * during certain types of resource change event notification. See 73 | * IResourceChangeEvent for more details. 74 | */ 75 | public static void importProject(final Path projectFile) throws CoreException { 76 | IProjectDescription description = ResourcesPlugin.getWorkspace() 77 | .loadProjectDescription(new org.eclipse.core.runtime.Path(projectFile.toFile().getAbsolutePath())); 78 | create(description, description.getName()); 79 | } 80 | 81 | /** 82 | * The import happens here. 83 | * @param description Description passed in. 84 | * @param projectName The actual project name. 85 | * @throws CoreException Same as above. 86 | */ 87 | public static void create(final IProjectDescription description, final String projectName) throws CoreException { 88 | IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); 89 | if (!project.exists()) 90 | project.create(description, null); 91 | project.open(null); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /tests/org.codechecker.eclipse.rcp.it.tests/src/org/codechecker/eclipse/plugin/utils/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Helper classes for integration testing. 3 | */ 4 | package org.codechecker.eclipse.plugin.utils; -------------------------------------------------------------------------------- /tests/org.codechecker.eclipse.rcp.shared/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /tests/org.codechecker.eclipse.rcp.shared/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.codechecker.eclipse.rcp.shared 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.pde.ManifestBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.pde.SchemaBuilder 20 | 21 | 22 | 23 | 24 | 25 | org.eclipse.pde.PluginNature 26 | org.eclipse.jdt.core.javanature 27 | 28 | 29 | -------------------------------------------------------------------------------- /tests/org.codechecker.eclipse.rcp.shared/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.source=1.8 8 | -------------------------------------------------------------------------------- /tests/org.codechecker.eclipse.rcp.shared/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: Shared 4 | Bundle-SymbolicName: org.codechecker.eclipse.rcp.shared 5 | Bundle-Version: 1.0.0.qualifier 6 | Bundle-Vendor: Ericsson 7 | Bundle-RequiredExecutionEnvironment: JavaSE-1.8 8 | Require-Bundle: org.eclipse.core.runtime 9 | Export-Package: org.codechecker.eclipse.rcp.shared.utils 10 | -------------------------------------------------------------------------------- /tests/org.codechecker.eclipse.rcp.shared/build.properties: -------------------------------------------------------------------------------- 1 | source.. = src/ 2 | output.. = bin/ 3 | bin.includes = META-INF/,\ 4 | .,\ 5 | resources/ 6 | src.includes = resources/,\ 7 | src/ 8 | -------------------------------------------------------------------------------- /tests/org.codechecker.eclipse.rcp.shared/src/org/codechecker/eclipse/rcp/shared/utils/Utils.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.rcp.shared.utils; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.net.URISyntaxException; 6 | import java.nio.file.Files; 7 | import java.nio.file.Path; 8 | import java.nio.file.Paths; 9 | import java.nio.file.StandardCopyOption; 10 | import java.nio.file.attribute.PosixFilePermissions; 11 | 12 | import org.eclipse.core.runtime.FileLocator; 13 | import org.eclipse.core.runtime.Platform; 14 | import org.osgi.framework.Bundle; 15 | 16 | /** 17 | * Helper functions for: 18 | * * File loading from bundles. 19 | * * Recursive copying of folders. 20 | * * CodeChecker preparation. 21 | */ 22 | public class Utils { 23 | public static final String RES = "resources" + File.separator; 24 | 25 | private static final String CODECHECKER = "CodeChecker"; 26 | private static final String BIN = "bin"; 27 | 28 | /** 29 | * Not called. 30 | */ 31 | private Utils() {} 32 | 33 | /** 34 | * Loads a file from a bundle. 35 | * @param bundlename The bundle to be loaded from. 36 | * @param pathFrom The path to the desired file (use with "resources/"). 37 | * @return returns a Path to the specified resource. 38 | * @throws URISyntaxException If this URL is not formatted strictly according to to RFC2396 and cannot be 39 | * converted to a URI. 40 | * @throws IOException If an error occurs during the conversion. 41 | */ 42 | public static Path loadFileFromBundle(String bundlename, String pathFrom) throws URISyntaxException, IOException { 43 | // http://blog.vogella.com/2010/07/06/reading-resources-from-plugin/ 44 | Bundle bundle = Platform.getBundle(bundlename); 45 | return Paths.get(FileLocator.toFileURL( 46 | FileLocator.find(bundle, new org.eclipse.core.runtime.Path(pathFrom), null)).toURI()); 47 | } 48 | 49 | /** 50 | * Recursively copies folders. 51 | * 52 | * @param src The source folder, will be copied. 53 | * @param dest The destination folder to be copied in. 54 | * @return The path to the copied folder. 55 | * @throws IOException Could be thrown on access denied, 56 | * or if the copy fails. 57 | */ 58 | public static Path copyFolder(Path src, Path dest) { 59 | try { 60 | Files.walk(src).forEach(source -> { 61 | try { 62 | Files.copy(source, dest.resolve(src.getParent().relativize(source)), 63 | StandardCopyOption.REPLACE_EXISTING); 64 | } catch (IOException e) { 65 | e.printStackTrace(); 66 | } 67 | }); 68 | } catch (IOException e) { 69 | e.printStackTrace(); 70 | } 71 | return dest.resolve(src.getFileName()); 72 | } 73 | 74 | /** 75 | * Convenience method for quickly get a runnable CodeChecker. 76 | * Has the same effect to loadCodeChecker("CodeChecker"). 77 | * Copies into the default directory layout, and sets runnable permission to Codechecker. 78 | * The path to the runnable CodeChecker will be tmp//CodeChecker/bin/CodeChecker 79 | * @return The path to To the CodeChecker root directory. 80 | * Will point to tmp//CodeChecker . 81 | */ 82 | public static Path prepareCodeChecker() { 83 | return prepareCodeChecker(CODECHECKER); 84 | } 85 | 86 | /** 87 | * Copies into the specified directory, and sets runnable permission to Codechecker. 88 | * The path to the runnable CodeChecker will be tmp///bin/CodeChecker 89 | * @param into This will be the name of the CodeChecker root folder. 90 | * @return The path to To the CodeChecker root directory. 91 | * Will point to tmp// . 92 | */ 93 | public static Path prepareCodeChecker(String into) { 94 | if (into.isEmpty() || into == null) throw new IllegalArgumentException(); 95 | 96 | Path testDir = null; 97 | Path ccRoot = null; 98 | try { 99 | testDir = Files.createTempDirectory("CCTest"); 100 | testDir.toFile().deleteOnExit(); 101 | testDir = Files.createDirectory(Paths.get(testDir.toString(), into)); 102 | ccRoot = Utils.loadFileFromBundle("org.codechecker.eclipse.rcp.shared", 103 | Utils.RES + CODECHECKER); 104 | } catch (IOException | URISyntaxException e1) { 105 | e1.printStackTrace(System.out); 106 | } 107 | // Get the CodeChecker stub from the test resources, and copy it to a temporary folder. 108 | Path ccDir = Utils.copyFolder(ccRoot, testDir); 109 | Path ccBinDir = Paths.get( testDir.toAbsolutePath().toString(), CODECHECKER, BIN, CODECHECKER); 110 | try { 111 | // CodeChecker must be runnable. 112 | Files.setPosixFilePermissions(ccBinDir, PosixFilePermissions.fromString("rwxrwxrwx")); 113 | } catch (IOException e) { 114 | e.printStackTrace(); 115 | } 116 | return ccDir; 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /tests/org.codechecker.eclipse.rcp.shared/src/org/codechecker/eclipse/rcp/shared/utils/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Helper utilities for both unit and integration testing. 3 | */ 4 | package org.codechecker.eclipse.rcp.shared.utils; -------------------------------------------------------------------------------- /tests/org.codechecker.eclipse.rcp.unit.tests/.checkstyle: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /tests/org.codechecker.eclipse.rcp.unit.tests/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/org.codechecker.eclipse.rcp.unit.tests/.gitignore: -------------------------------------------------------------------------------- 1 | /bin/ 2 | -------------------------------------------------------------------------------- /tests/org.codechecker.eclipse.rcp.unit.tests/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.codechecker.eclipse.rcp.unit.tests 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.pde.ManifestBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.pde.SchemaBuilder 20 | 21 | 22 | 23 | 24 | 25 | org.eclipse.pde.PluginNature 26 | org.eclipse.jdt.core.javanature 27 | 28 | 29 | -------------------------------------------------------------------------------- /tests/org.codechecker.eclipse.rcp.unit.tests/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.source=1.8 8 | -------------------------------------------------------------------------------- /tests/org.codechecker.eclipse.rcp.unit.tests/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: Tests 4 | Bundle-SymbolicName: org.codechecker.eclipse.rcp.unit.tests 5 | Bundle-Version: 1.0.0.qualifier 6 | Bundle-Vendor: Vodorok 7 | Fragment-Host: org.codechecker.eclipse.plugin 8 | Automatic-Module-Name: org.codechecker.eclipse.rcp.unit.tests 9 | Bundle-RequiredExecutionEnvironment: JavaSE-1.8 10 | Require-Bundle: org.junit, 11 | org.hamcrest;bundle-version="1.1.0", 12 | org.mockito;bundle-version="1.9.5", 13 | org.objenesis;bundle-version="1.0.0", 14 | org.codechecker.eclipse.rcp.shared;bundle-version="1.0.0", 15 | com.google.guava, 16 | com.github.stefanbirkner.system-rules;bundle-version="1.19.0", 17 | javax.annotation;bundle-version="1.2.0" 18 | Bundle-ClassPath: ., 19 | resources/ 20 | -------------------------------------------------------------------------------- /tests/org.codechecker.eclipse.rcp.unit.tests/build.properties: -------------------------------------------------------------------------------- 1 | source.. = src/ 2 | output.. = bin/ 3 | bin.includes = META-INF/,\ 4 | .,\ 5 | resources/ 6 | -------------------------------------------------------------------------------- /tests/org.codechecker.eclipse.rcp.unit.tests/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | org.codechecker.eclipse 8 | org.codechecker.eclipse.tests 9 | 1.0.0-SNAPSHOT 10 | 11 | 12 | org.codechecker.eclipse.rcp.unit.tests 13 | 1.0.0-SNAPSHOT 14 | eclipse-test-plugin 15 | 16 | 17 | 18 | 19 | org.eclipse.tycho 20 | tycho-surefire-plugin 21 | ${tycho.version} 22 | 23 | false 24 | false 25 | org.codechecker.eclipse.feature 26 | org.eclipse.ui.ide.workbench 27 | 28 | 29 | 30 | org.apache.maven.plugins 31 | maven-checkstyle-plugin 32 | 3.0.0 33 | 34 | 35 | validate 36 | 37 | false 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /tests/org.codechecker.eclipse.rcp.unit.tests/src/org/codechecker/eclipse/plugin/codechecker/locator/CodeCheckerLocatorTest.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.codechecker.locator; 2 | 3 | import java.nio.file.Path; 4 | import java.nio.file.Paths; 5 | 6 | import org.codechecker.eclipse.plugin.codechecker.CodeCheckerFactory; 7 | import org.codechecker.eclipse.plugin.codechecker.ICodeCheckerFactory; 8 | import org.codechecker.eclipse.plugin.runtime.IShellExecutorHelperFactory; 9 | import org.codechecker.eclipse.plugin.runtime.ShellExecutorHelperFactory; 10 | import org.codechecker.eclipse.rcp.shared.utils.Utils; 11 | import org.junit.BeforeClass; 12 | import org.junit.Rule; 13 | import org.junit.Test; 14 | import org.junit.contrib.java.lang.system.EnvironmentVariables; 15 | import org.junit.rules.ExpectedException; 16 | 17 | import static org.junit.Assert.fail; 18 | 19 | /** 20 | * {@link CodeCheckerLocatorService} tests. 21 | */ 22 | public class CodeCheckerLocatorTest { 23 | 24 | private static final String ENV_PATH = "PATH"; 25 | private static final String DUMMY = "/home"; 26 | private static final String ERROR_COULDNT_CREATE_CC = "Couldn't create CodeChecker instance!"; 27 | private static final Path CC_PATH = Utils.prepareCodeChecker(); 28 | private static final Path PATH_CC_PATH = Utils.prepareCodeChecker(); 29 | private static final Path NOT_CC_PATH = Paths.get(DUMMY); 30 | private static final ICodeCheckerFactory CC_FACTORY = new CodeCheckerFactory(); 31 | private static final IShellExecutorHelperFactory SHEF = new ShellExecutorHelperFactory(); 32 | 33 | private static CodeCheckerLocatorFactory cclf; 34 | 35 | @Rule 36 | public ExpectedException thrown = ExpectedException.none(); 37 | 38 | @Rule 39 | public final EnvironmentVariables environmentVariables = new EnvironmentVariables(); 40 | 41 | /** 42 | * This factory can be used for the entire test. 43 | */ 44 | @BeforeClass 45 | public static void setUpBeforeClass() { 46 | cclf = new CodeCheckerLocatorFactory(); 47 | } 48 | 49 | /** 50 | * Test {@link EnvCodeCheckerLocatorService}. 51 | * 52 | * @throws InvalidCodeCheckerException 53 | * For testing purposes. 54 | */ 55 | @Test 56 | public void testPath() throws InvalidCodeCheckerException { 57 | CodeCheckerLocatorService serv = cclf.create(ResolutionMethodTypes.PATH); 58 | thrown.expect(InvalidCodeCheckerException.class); 59 | thrown.expectMessage(EnvCodeCheckerLocatorService.CC_NOT_FOUND); 60 | 61 | serv.findCodeChecker(null, CC_FACTORY, SHEF); 62 | // prepare PATH envval 63 | String origPath = System.getenv(ENV_PATH); 64 | String newPath = origPath.concat(":" + PATH_CC_PATH.toAbsolutePath().toString() + "/bin/"); 65 | 66 | // Set the prepared PATH 67 | environmentVariables.set(ENV_PATH, newPath); 68 | 69 | serv = cclf.create(ResolutionMethodTypes.PATH); 70 | try { 71 | serv.findCodeChecker(null, CC_FACTORY, SHEF); 72 | } catch (InvalidCodeCheckerException e) { 73 | fail(ERROR_COULDNT_CREATE_CC); 74 | } 75 | // reset env 76 | environmentVariables.set(ENV_PATH, origPath); 77 | } 78 | 79 | /** 80 | * Test {@link PreBuiltCodeCheckerLocatorService}. 81 | * 82 | * @throws InvalidCodeCheckerException 83 | * For testing purposes. 84 | */ 85 | @Test 86 | public void testPre() throws InvalidCodeCheckerException { 87 | CodeCheckerLocatorService serv = cclf.create(ResolutionMethodTypes.PRE); 88 | 89 | thrown.expect(RuntimeException.class); 90 | thrown.expectMessage(PreBuiltCodeCheckerLocatorService.CC_INVALID); 91 | // Test null 92 | serv.findCodeChecker(null, CC_FACTORY, SHEF); 93 | 94 | thrown.expect(InvalidCodeCheckerException.class); 95 | thrown.expectMessage(PreBuiltCodeCheckerLocatorService.CC_NOT_FOUND); 96 | // Test garbage 97 | serv.findCodeChecker(Paths.get("gdfsg"), CC_FACTORY, SHEF); 98 | 99 | // Test not valid 100 | serv.findCodeChecker(NOT_CC_PATH, CC_FACTORY, SHEF); 101 | 102 | // Test valid 103 | serv = cclf.create(ResolutionMethodTypes.PATH); 104 | try { 105 | serv.findCodeChecker(CC_PATH, CC_FACTORY, SHEF); 106 | } catch (InvalidCodeCheckerException e) { 107 | fail(ERROR_COULDNT_CREATE_CC); 108 | } 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /tests/org.codechecker.eclipse.rcp.unit.tests/src/org/codechecker/eclipse/plugin/codechecker/locator/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Unit tests. 3 | */ 4 | package org.codechecker.eclipse.plugin.codechecker.locator; -------------------------------------------------------------------------------- /tests/org.codechecker.eclipse.rcp.unit.tests/src/org/codechecker/eclipse/plugin/codechecker/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Unit tests. 3 | */ 4 | package org.codechecker.eclipse.plugin.codechecker; -------------------------------------------------------------------------------- /tests/org.codechecker.eclipse.rcp.unit.tests/src/org/codechecker/eclipse/plugin/report/PlistParserTest.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.report; 2 | 3 | import java.io.IOException; 4 | import java.net.URISyntaxException; 5 | import java.nio.file.Path; 6 | 7 | import org.codechecker.eclipse.rcp.shared.utils.Utils; 8 | import org.eclipse.core.resources.IProject; 9 | import org.junit.Before; 10 | import org.junit.Test; 11 | 12 | import static org.hamcrest.CoreMatchers.equalTo; 13 | import static org.hamcrest.CoreMatchers.hasItem; 14 | import static org.hamcrest.CoreMatchers.is; 15 | import static org.hamcrest.MatcherAssert.assertThat; 16 | import static org.mockito.Mockito.mock; 17 | 18 | public class PlistParserTest { 19 | private PlistParser parser; 20 | private IProject proj = mock(IProject.class); 21 | 22 | @Before 23 | public void initParser(){ 24 | parser = new PlistParser(proj); 25 | } 26 | 27 | @Test 28 | public void ParserTest1() { 29 | 30 | Path file = null; 31 | try { 32 | file = Utils.loadFileFromBundle("org.codechecker.eclipse.rcp.unit.tests", 33 | Utils.RES + "plists/test_plist_1.plist"); 34 | } catch (URISyntaxException | IOException e) { 35 | e.printStackTrace(); 36 | } 37 | assertThat(file.toFile().exists(), is(equalTo(true))); 38 | 39 | SearchList sl = new SearchList(); 40 | parser.parsePlist(file.toFile(), sl); 41 | assertThat(sl.getCheckers(), hasItem("alpha.core.SizeofPtr")); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /tests/org.codechecker.eclipse.rcp.unit.tests/src/org/codechecker/eclipse/plugin/runtime/ShellExecutorHelperTest.java: -------------------------------------------------------------------------------- 1 | package org.codechecker.eclipse.plugin.runtime; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.nio.file.Files; 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | 9 | import org.apache.commons.exec.environment.EnvironmentUtils; 10 | import org.junit.Before; 11 | import org.junit.Test; 12 | 13 | import static org.hamcrest.CoreMatchers.equalTo; 14 | import static org.hamcrest.CoreMatchers.is; 15 | import static org.hamcrest.MatcherAssert.assertThat; 16 | 17 | public class ShellExecutorHelperTest { 18 | 19 | private ShellExecutorHelper emptyEnvExecutor; 20 | private ShellExecutorHelper defaultEnvExecutor; 21 | 22 | @Before 23 | public void setupExecutors() throws IOException { 24 | emptyEnvExecutor = new ShellExecutorHelper(new HashMap()); 25 | defaultEnvExecutor = new ShellExecutorHelper(EnvironmentUtils.getProcEnvironment()); 26 | } 27 | 28 | /** 29 | * Test that Change Directory command succeds on a directory with spaces. 30 | */ 31 | @Test 32 | public void cdSucceeds() { 33 | File file = null; 34 | try { 35 | file = Files.createTempDirectory("dir with spaces").toFile(); 36 | file.deleteOnExit(); 37 | } catch (IOException e) { 38 | e.printStackTrace(); 39 | } 40 | assertThat("File not exists", file.exists(), is(true)); 41 | Map map = new HashMap(); 42 | map.put("FILE", file); 43 | 44 | assertThat(defaultEnvExecutor.quickAndSuccessfull("cd '${FILE}'", map), is(true)); 45 | } 46 | 47 | @Test 48 | public void emptyEnvironmentEchoes() { 49 | assertThat(emptyEnvExecutor.quickReturnFirstLine("/bin/echo 6", null).or(""), is(equalTo("6"))); 50 | } 51 | 52 | @Test 53 | public void emptyEnvironmentSequence() { 54 | assertThat(emptyEnvExecutor.quickReturnFirstLine("/bin/echo 4 ; /bin/echo 10", null).or(""), is 55 | (equalTo("4"))); 56 | } 57 | 58 | @Test 59 | public void defaultEnvironmentEcho() { /* Should work on any sane POSIX system */ 60 | assertThat(defaultEnvExecutor.quickReturnFirstLine("echo 5", null).or(""), is(equalTo("5"))); 61 | } 62 | 63 | @Test 64 | public void echoSucceeds() { 65 | assertThat(emptyEnvExecutor.quickAndSuccessfull("/bin/echo 3", null), is(true)); 66 | } 67 | 68 | @Test 69 | public void echoooFails() { 70 | assertThat(emptyEnvExecutor.quickAndSuccessfull("echooo 4;", null), is(false)); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /tests/org.codechecker.eclipse.rcp.unit.tests/src/org/codechecker/eclipse/plugin/runtime/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Runtime classes Unit tests. 3 | */ 4 | package org.codechecker.eclipse.plugin.runtime; -------------------------------------------------------------------------------- /tests/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | org.codechecker.eclipse 4 | org.codechecker.eclipse.tests 5 | 1.0.0-SNAPSHOT 6 | pom 7 | 8 | 9 | org.codechecker.eclipse 10 | org.codechecker.eclipse.root 11 | 1.0.0-SNAPSHOT 12 | 13 | 14 | 15 | org.codechecker.eclipse.rcp.unit.tests 16 | org.codechecker.eclipse.rcp.it.tests 17 | org.codechecker.eclipse.rcp.shared 18 | 19 | 20 | 21 | 22 | 23 | org.apache.maven.plugins 24 | maven-checkstyle-plugin 25 | 3.0.0 26 | 27 | 28 | validate 29 | 30 | true 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | --------------------------------------------------------------------------------