Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Ruiz2012-04-18 15:50:11 -0400
committerSergey Prigogin2012-04-18 15:52:48 -0400
commit1f83e4aa213209926b082cc53db587314d1d9f0b (patch)
treeb6c7f0ac5e4f1fcf3c67216ea51b9f9d1fc9a751 /codan/org.eclipse.cdt.codan.examples
parent4a8860255eea49dae2ec96d302088b39bd80f3b5 (diff)
downloadorg.eclipse.cdt-1f83e4aa213209926b082cc53db587314d1d9f0b.tar.gz
org.eclipse.cdt-1f83e4aa213209926b082cc53db587314d1d9f0b.tar.xz
org.eclipse.cdt-1f83e4aa213209926b082cc53db587314d1d9f0b.zip
Bug 372551. Codan support for writing checkers that invoke external
tools. Change-Id: Ia5cfd24d54ec6e67e08f24a367a6bc689ae407d0 Reviewed-on: https://git.eclipse.org/r/5586 Reviewed-by: Sergey Prigogin <eclipse.sprigogin@gmail.com> IP-Clean: Sergey Prigogin <eclipse.sprigogin@gmail.com> Tested-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
Diffstat (limited to 'codan/org.eclipse.cdt.codan.examples')
-rw-r--r--codan/org.eclipse.cdt.codan.examples/.classpath2
-rw-r--r--codan/org.eclipse.cdt.codan.examples/.settings/org.eclipse.jdt.core.prefs12
-rw-r--r--codan/org.eclipse.cdt.codan.examples/META-INF/MANIFEST.MF2
-rw-r--r--codan/org.eclipse.cdt.codan.examples/OSGI-INF/l10n/bundle.properties13
-rw-r--r--codan/org.eclipse.cdt.codan.examples/plugin.xml49
-rw-r--r--codan/org.eclipse.cdt.codan.examples/src/org/eclipse/cdt/codan/examples/checkers/cppcheck/CppcheckChecker.java69
-rw-r--r--codan/org.eclipse.cdt.codan.examples/src/org/eclipse/cdt/codan/examples/checkers/cppcheck/CppcheckOutputParser.java54
-rw-r--r--codan/org.eclipse.cdt.codan.examples/src/org/eclipse/cdt/codan/examples/checkers/cppcheck/Messages.java26
-rw-r--r--codan/org.eclipse.cdt.codan.examples/src/org/eclipse/cdt/codan/examples/checkers/cppcheck/Messages.properties11
-rw-r--r--codan/org.eclipse.cdt.codan.examples/src/org/eclipse/cdt/codan/examples/checkers/cppcheck/Severity.java50
10 files changed, 280 insertions, 8 deletions
diff --git a/codan/org.eclipse.cdt.codan.examples/.classpath b/codan/org.eclipse.cdt.codan.examples/.classpath
index 64c5e31b7a..4c62a8048e 100644
--- a/codan/org.eclipse.cdt.codan.examples/.classpath
+++ b/codan/org.eclipse.cdt.codan.examples/.classpath
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/codan/org.eclipse.cdt.codan.examples/.settings/org.eclipse.jdt.core.prefs b/codan/org.eclipse.cdt.codan.examples/.settings/org.eclipse.jdt.core.prefs
index f0c8e22e49..24697a7ea7 100644
--- a/codan/org.eclipse.cdt.codan.examples/.settings/org.eclipse.jdt.core.prefs
+++ b/codan/org.eclipse.cdt.codan.examples/.settings/org.eclipse.jdt.core.prefs
@@ -1,8 +1,7 @@
-#Wed Feb 23 19:44:01 EST 2011
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
-org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
@@ -70,7 +69,7 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disa
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
-org.eclipse.jdt.core.compiler.source=1.5
+org.eclipse.jdt.core.compiler.source=1.6
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0
@@ -149,9 +148,12 @@ org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true
org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true
org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=true
org.eclipse.jdt.core.formatter.indentation.size=4
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field=insert
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert
-org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package=insert
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type=insert
org.eclipse.jdt.core.formatter.insert_new_line_after_label=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert
diff --git a/codan/org.eclipse.cdt.codan.examples/META-INF/MANIFEST.MF b/codan/org.eclipse.cdt.codan.examples/META-INF/MANIFEST.MF
index 481af5b636..39ffaa2d7d 100644
--- a/codan/org.eclipse.cdt.codan.examples/META-INF/MANIFEST.MF
+++ b/codan/org.eclipse.cdt.codan.examples/META-INF/MANIFEST.MF
@@ -11,7 +11,7 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.cdt.core,
org.eclipse.core.resources,
org.eclipse.cdt.codan.ui;bundle-version="1.0.0"
-Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Export-Package: org.eclipse.cdt.codan.examples,
org.eclipse.cdt.codan.examples.checkers,
diff --git a/codan/org.eclipse.cdt.codan.examples/OSGI-INF/l10n/bundle.properties b/codan/org.eclipse.cdt.codan.examples/OSGI-INF/l10n/bundle.properties
index fb989db8b5..430384b280 100644
--- a/codan/org.eclipse.cdt.codan.examples/OSGI-INF/l10n/bundle.properties
+++ b/codan/org.eclipse.cdt.codan.examples/OSGI-INF/l10n/bundle.properties
@@ -10,4 +10,15 @@
###############################################################################
#Properties file for org.eclipse.cdt.codan.examples
Bundle-Vendor = Eclipse CDT
-Bundle-Name = Code Analysis Checker Examples \ No newline at end of file
+Bundle-Name = Code Analysis Checker Examples
+
+checker.name.Cppcheck = Cppcheck
+problem.description.Cppcheck.Error = Errors reported by Cppcheck (http://cppcheck.sourceforge.net/)
+problem.name.Cppcheck.Error = Errors
+problem.description.Cppcheck.Warning = Warnings reported by Cppcheck (http://cppcheck.sourceforge.net/)
+problem.name.Cppcheck.Warning = Warnings
+problem.description.Cppcheck.Syntax = Syntax problems reported by Cppcheck (http://cppcheck.sourceforge.net/)
+problem.name.Cppcheck.Syntax = Syntax Problems
+problem.messagePattern.Cppcheck.all = {0}
+
+errorparser.name.cppcheck = Cppcheck Output Parser \ No newline at end of file
diff --git a/codan/org.eclipse.cdt.codan.examples/plugin.xml b/codan/org.eclipse.cdt.codan.examples/plugin.xml
index f12f7a82af..dacd7a972f 100644
--- a/codan/org.eclipse.cdt.codan.examples/plugin.xml
+++ b/codan/org.eclipse.cdt.codan.examples/plugin.xml
@@ -42,6 +42,42 @@
name="Search string error">
</problem>
</checker>
+ <category
+ id="org.eclipse.cdt.codan.checkers.cppcheck"
+ name="%checker.name.Cppcheck">
+ </category>
+ <checker
+ class="org.eclipse.cdt.codan.examples.checkers.cppcheck.CppcheckChecker"
+ id="org.eclipse.cdt.codan.checkers.CppcheckChecker"
+ name="Cppcheck">
+ <problem
+ category="org.eclipse.cdt.codan.checkers.cppcheck"
+ defaultEnabled="false"
+ defaultSeverity="Error"
+ description="%problem.description.Cppcheck.Error"
+ id="org.eclipse.cdt.codan.checkers.cppcheck.error"
+ messagePattern="%problem.messagePattern.Cppcheck.all"
+ name="%problem.name.Cppcheck.Error">
+ </problem>
+ <problem
+ category="org.eclipse.cdt.codan.checkers.cppcheck"
+ defaultEnabled="false"
+ defaultSeverity="Warning"
+ description="%problem.description.Cppcheck.Warning"
+ id="org.eclipse.cdt.codan.checkers.cppcheck.warning"
+ messagePattern="%problem.messagePattern.Cppcheck.all"
+ name="%problem.name.Cppcheck.Warning">
+ </problem>
+ <problem
+ category="org.eclipse.cdt.codan.checkers.cppcheck"
+ defaultEnabled="false"
+ defaultSeverity="Warning"
+ description="%problem.description.Cppcheck.Syntax"
+ id="org.eclipse.cdt.codan.checkers.cppcheck.style"
+ messagePattern="%problem.messagePattern.Cppcheck.all"
+ name="%problem.name.Cppcheck.Syntax">
+ </problem>
+ </checker>
</extension>
<extension
point="org.eclipse.cdt.codan.ui.codanProblemDetails">
@@ -54,4 +90,17 @@
>
</problemDetails>
</extension>
+ <extension
+ id="CodanErrorParser"
+ name="name"
+ point="org.eclipse.cdt.core.ErrorParser">
+ <errorparser
+ class="org.eclipse.cdt.codan.examples.checkers.cppcheck.CppcheckOutputParser"
+ id="org.eclipse.cdt.codan.checkers.externaltool.CppcheckChecker"
+ name="%errorparser.name.cppcheck">
+ <context
+ type="codan">
+ </context>
+ </errorparser>
+ </extension>
</plugin>
diff --git a/codan/org.eclipse.cdt.codan.examples/src/org/eclipse/cdt/codan/examples/checkers/cppcheck/CppcheckChecker.java b/codan/org.eclipse.cdt.codan.examples/src/org/eclipse/cdt/codan/examples/checkers/cppcheck/CppcheckChecker.java
new file mode 100644
index 0000000000..c82a4d7f74
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.examples/src/org/eclipse/cdt/codan/examples/checkers/cppcheck/CppcheckChecker.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Google, Inc and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alex Ruiz (Google) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.codan.examples.checkers.cppcheck;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.cdt.codan.core.cxx.externaltool.AbstractExternalToolBasedChecker;
+import org.eclipse.cdt.codan.core.cxx.externaltool.ConfigurationSettings;
+import org.eclipse.cdt.core.ProblemMarkerInfo;
+
+/**
+ * Checker that invokes <a href="http://cppcheck.sourceforge.net/">Cppcheck</a> when a C/C++ file is
+ * saved.
+ */
+public class CppcheckChecker extends AbstractExternalToolBasedChecker {
+ private static final String TOOL_NAME = Messages.CppcheckChecker_toolName;
+ private static final String EXECUTABLE_NAME = "cppcheck"; //$NON-NLS-1$
+ private static final String DEFAULT_ARGS = "--enable=all"; //$NON-NLS-1$
+
+ private static final String DESCRIPTION_FORMAT = "[" + TOOL_NAME + "] %s"; //$NON-NLS-1$ //$NON-NLS-2$
+
+ private static final String ERROR_PROBLEM_ID;
+
+ // key: severity (error, warning, etc.) - value : problem ID associated to severity
+ private static final Map<Severity, String> PROBLEM_IDS = new HashMap<Severity, String>();
+
+ static {
+ ERROR_PROBLEM_ID = addProblemId(Severity.ERROR);
+ addProblemId(Severity.WARNING);
+ addProblemId(Severity.STYLE);
+ }
+
+ private static String addProblemId(Severity severity) {
+ String problemId = "org.eclipse.cdt.codan.checkers.cppcheck." + severity; //$NON-NLS-1$
+ PROBLEM_IDS.put(severity, problemId);
+ return problemId;
+ }
+
+ public CppcheckChecker() {
+ super(new ConfigurationSettings(TOOL_NAME, new File(EXECUTABLE_NAME), DEFAULT_ARGS));
+ }
+
+ @Override
+ protected String[] getParserIDs() {
+ return new String[] { "org.eclipse.cdt.codan.checkers.externaltool.CppcheckChecker" }; //$NON-NLS-1$
+ }
+
+ @Override
+ public void addMarker(ProblemMarkerInfo info) {
+ Severity severity = Severity.findSeverity(info.severity);
+ String description = String.format(DESCRIPTION_FORMAT, info.description);
+ reportProblem(PROBLEM_IDS.get(severity), createProblemLocation(info), description);
+ }
+
+ @Override
+ protected String getReferenceProblemId() {
+ return ERROR_PROBLEM_ID;
+ }
+}
diff --git a/codan/org.eclipse.cdt.codan.examples/src/org/eclipse/cdt/codan/examples/checkers/cppcheck/CppcheckOutputParser.java b/codan/org.eclipse.cdt.codan.examples/src/org/eclipse/cdt/codan/examples/checkers/cppcheck/CppcheckOutputParser.java
new file mode 100644
index 0000000000..c9ff4ce889
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.examples/src/org/eclipse/cdt/codan/examples/checkers/cppcheck/CppcheckOutputParser.java
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Google, Inc and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alex Ruiz (Google) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.codan.examples.checkers.cppcheck;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.cdt.core.ErrorParserManager;
+import org.eclipse.cdt.core.IErrorParser;
+import org.eclipse.cdt.core.ProblemMarkerInfo;
+import org.eclipse.core.resources.IFile;
+
+/**
+ * Parses the output of Cppcheck.
+ */
+public class CppcheckOutputParser implements IErrorParser {
+ // sample line to parse:
+ //
+ // [/src/HelloWorld.cpp:19]: (style) The scope of the variable 'i' can be reduced
+ // ----------1--------- -2 --3-- ------------------4-------------------------
+ //
+ // groups:
+ // 1: file path and name
+ // 2: line where problem was found
+ // 3: problem severity
+ // 4: problem description
+ private static Pattern pattern = Pattern.compile("\\[(.*):(\\d+)\\]:\\s*\\((.*)\\)\\s*(.*)"); //$NON-NLS-1$
+
+ @Override
+ public boolean processLine(String line, ErrorParserManager eoParser) {
+ Matcher matcher = pattern.matcher(line);
+ if (!matcher.matches()) {
+ return false;
+ }
+ IFile fileName = eoParser.findFileName(matcher.group(1));
+ if (fileName != null) {
+ int lineNumber = Integer.parseInt(matcher.group(2));
+ String description = matcher.group(4);
+ int severity = Severity.findSeverityCode(matcher.group(3));
+ ProblemMarkerInfo info = new ProblemMarkerInfo(fileName, lineNumber, description, severity, null);
+ eoParser.addProblemMarker(info);
+ return true;
+ }
+ return false;
+ }
+}
diff --git a/codan/org.eclipse.cdt.codan.examples/src/org/eclipse/cdt/codan/examples/checkers/cppcheck/Messages.java b/codan/org.eclipse.cdt.codan.examples/src/org/eclipse/cdt/codan/examples/checkers/cppcheck/Messages.java
new file mode 100644
index 0000000000..b194e9f2b4
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.examples/src/org/eclipse/cdt/codan/examples/checkers/cppcheck/Messages.java
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Google, Inc and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alex Ruiz (Google) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.codan.examples.checkers.cppcheck;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+ public static String CppcheckChecker_toolName;
+
+ static {
+ // initialize resource bundle
+ Class<Messages> clazz = Messages.class;
+ NLS.initializeMessages(clazz.getName(), clazz);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/codan/org.eclipse.cdt.codan.examples/src/org/eclipse/cdt/codan/examples/checkers/cppcheck/Messages.properties b/codan/org.eclipse.cdt.codan.examples/src/org/eclipse/cdt/codan/examples/checkers/cppcheck/Messages.properties
new file mode 100644
index 0000000000..8dda9c9c3e
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.examples/src/org/eclipse/cdt/codan/examples/checkers/cppcheck/Messages.properties
@@ -0,0 +1,11 @@
+###############################################################################
+# Copyright (c) 2012 Google, Inc and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+# Alex Ruiz (Google) - initial API and implementation
+###############################################################################
+CppcheckChecker_toolName=Cppcheck
diff --git a/codan/org.eclipse.cdt.codan.examples/src/org/eclipse/cdt/codan/examples/checkers/cppcheck/Severity.java b/codan/org.eclipse.cdt.codan.examples/src/org/eclipse/cdt/codan/examples/checkers/cppcheck/Severity.java
new file mode 100644
index 0000000000..f8f91cfda4
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.examples/src/org/eclipse/cdt/codan/examples/checkers/cppcheck/Severity.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Google, Inc and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alex Ruiz (Google) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.codan.examples.checkers.cppcheck;
+
+import org.eclipse.cdt.core.IMarkerGenerator;
+
+enum Severity {
+ ERROR(IMarkerGenerator.SEVERITY_ERROR_RESOURCE, "error"), //$NON-NLS-1$
+ WARNING(IMarkerGenerator.SEVERITY_WARNING, "warning"), //$NON-NLS-1$
+ STYLE(IMarkerGenerator.SEVERITY_INFO, "style"); //$NON-NLS-1$
+
+ private final int code;
+ private final String text;
+
+ private Severity(int code, String text) {
+ this.code = code;
+ this.text = text;
+ }
+
+ static int findSeverityCode(String text) {
+ for (Severity severity : values()) {
+ if (severity.text.equals(text)) {
+ return severity.code;
+ }
+ }
+ return STYLE.code;
+ }
+
+ static Severity findSeverity(int code) {
+ for (Severity severity : values()) {
+ if (severity.code == code) {
+ return severity;
+ }
+ }
+ return STYLE;
+ }
+
+ @Override
+ public String toString() {
+ return text;
+ }
+} \ No newline at end of file

Back to the top