Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] Static code analysis - > Codan and Sonar

Hi François,

Thank for this feedback.

In fact, as I thought,  Valtech guys has managed to extract the CPP Parser from the CDT plugin in order to allow a fully "eclipseless" use in their Dependometer tool (dependencies on org.eclipse.cdt.core-5.0.0.200806130802 and org.eclipse.equinox.common-3.3.0.v20070426.jar) :

http://source.valtech.com/display/dpm/Dependometer

In the Sonar platform we don't want to rely on any local eclipse installation and would like to do the same thing with Codan along with CPP Parser.


On Thu, Jul 30, 2009 at 6:24 PM, Francois Rigault <francois.rigault@xxxxxxxxxxx> wrote:
Actually it's totally possible to get Codan running headlessly with a few
minor modifications (following
http://www.developertesting.com/archives/month200508/20050823-HeadlessHelloWorldInEclipse.html
)

As a proof of concept, the following patch will add an application entry
so that you can run the analysis
headlessly - in order for this to work, you must have the project opened
in a workspace somewhere.


-----

### Eclipse Workspace Patch 1.0
#P org.eclipse.cdt.codan.core
Index: plugin.xml
===================================================================
RCS file:
/cvsroot/tools/org.eclipse.cdt/codan/org.eclipse.cdt.codan.core/plugin.xml,v
retrieving revision 1.3
diff -u -r1.3 plugin.xml
--- plugin.xml  29 Jul 2009 17:01:46 -0000      1.3
+++ plugin.xml  30 Jul 2009 16:20:32 -0000
@@ -53,5 +53,17 @@

      </category>
   </extension>
+      <extension
+            id="codan"
+            point="org.eclipse.core.runtime.applications">
+         <application
+               cardinality="singleton-global"
+               thread="main"
+               visible="true">
+            <run
+                  class="org.eclipse.cdt.codan.core.Application">
+            </run>
+         </application>
+      </extension>

 </plugin>
Index: src/org/eclipse/cdt/codan/core/model/CodanRuntime.java
===================================================================
RCS file:
/cvsroot/tools/org.eclipse.cdt/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CodanRuntime.java,v
retrieving revision 1.1
diff -u -r1.1 CodanRuntime.java
--- src/org/eclipse/cdt/codan/core/model/CodanRuntime.java      21 Apr
2009 00:53:33 -0000     1.1
+++ src/org/eclipse/cdt/codan/core/model/CodanRuntime.java      30 Jul
2009 16:20:32 -0000
@@ -16,7 +16,11 @@
 */
 public class CodanRuntime {
       private static CodanRuntime instance = new CodanRuntime();
-       private CodanProblemReporter problemReporter = new
CodanProblemReporter();
+       private CodanProblemReporter problemReporter = new
CodanProblemReporter() {
+               public void reportProblem(String id,
org.eclipse.core.resources.IFile file, int lineNumber, String message) {
+                       System.out.println(file.getLocation() + ":" +
lineNumber + " " + id);
+               };
+       };

       public CodanProblemReporter getProblemReporter() {
               return problemReporter;
Index: src/org/eclipse/cdt/codan/core/Application.java
===================================================================
RCS file: src/org/eclipse/cdt/codan/core/Application.java
diff -N src/org/eclipse/cdt/codan/core/Application.java
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/cdt/codan/core/Application.java     1 Jan 1970
00:00:00 -0000
@@ -0,0 +1,24 @@
+package org.eclipse.cdt.codan.core;
+
+import org.eclipse.cdt.codan.core.builder.CodanBuilder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.equinox.app.IApplication;
+import org.eclipse.equinox.app.IApplicationContext;
+
+public class Application implements IApplication {
+
+       public Object start(IApplicationContext context) throws Exception
{
+               String[] args = (String[])
context.getArguments().get("application.args");
+
+               System.out.println("Launching analysis on project " +
args[0]);
+ ResourcesPlugin.getWorkspace().getRoot().getProject(args[0]).accept(
+                               new CodanBuilder().new
CodanResourceVisitor());
+
+               return EXIT_OK;
+       }
+
+       public void stop() {
+       }
+
+}






Back to the top