Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/codan
diff options
context:
space:
mode:
authorAlena Laskavaia2009-08-10 18:31:46 +0000
committerAlena Laskavaia2009-08-10 18:31:46 +0000
commite93f96dd519ea88de490916f724e668b64d71431 (patch)
treebc6ea8777c023c6606100a489162e89bc986d3dc /codan
parenta774350786e42d824073438407208c5fa8699080 (diff)
downloadorg.eclipse.cdt-e93f96dd519ea88de490916f724e668b64d71431.tar.gz
org.eclipse.cdt-e93f96dd519ea88de490916f724e668b64d71431.tar.xz
org.eclipse.cdt-e93f96dd519ea88de490916f724e668b64d71431.zip
- added headless launch support (application), based on patch of Francois Rigault
Diffstat (limited to 'codan')
-rw-r--r--codan/org.eclipse.cdt.codan.core/.settings/org.eclipse.jdt.core.prefs2
-rw-r--r--codan/org.eclipse.cdt.codan.core/plugin.xml15
-rw-r--r--codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CodanApplication.java95
-rw-r--r--codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CodanProblemReporter.java15
-rw-r--r--codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CodanRuntime.java4
5 files changed, 125 insertions, 6 deletions
diff --git a/codan/org.eclipse.cdt.codan.core/.settings/org.eclipse.jdt.core.prefs b/codan/org.eclipse.cdt.codan.core/.settings/org.eclipse.jdt.core.prefs
index 26314eab25b..4452aeeb4a3 100644
--- a/codan/org.eclipse.cdt.codan.core/.settings/org.eclipse.jdt.core.prefs
+++ b/codan/org.eclipse.cdt.codan.core/.settings/org.eclipse.jdt.core.prefs
@@ -1,4 +1,4 @@
-#Tue Jun 02 17:09:29 EDT 2009
+#Mon Aug 10 14:23:53 EDT 2009
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
diff --git a/codan/org.eclipse.cdt.codan.core/plugin.xml b/codan/org.eclipse.cdt.codan.core/plugin.xml
index 3c594aa859e..64d7402159f 100644
--- a/codan/org.eclipse.cdt.codan.core/plugin.xml
+++ b/codan/org.eclipse.cdt.codan.core/plugin.xml
@@ -53,5 +53,20 @@
</category>
</extension>
+
+ <extension
+ id="application"
+ point="org.eclipse.core.runtime.applications">
+ <application
+ cardinality="singleton-global"
+ thread="main"
+ visible="true">
+ <run
+ class="org.eclipse.cdt.codan.core.CodanApplication">
+ </run>
+ </application>
+ </extension>
+
+
</plugin>
diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CodanApplication.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CodanApplication.java
new file mode 100644
index 00000000000..5f04cb63c4f
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CodanApplication.java
@@ -0,0 +1,95 @@
+package org.eclipse.cdt.codan.core;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.eclipse.cdt.codan.core.builder.CodanBuilder;
+import org.eclipse.cdt.codan.core.model.CodanProblemReporter;
+import org.eclipse.cdt.codan.core.model.CodanRuntime;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.equinox.app.IApplication;
+import org.eclipse.equinox.app.IApplicationContext;
+
+public class CodanApplication implements IApplication {
+ private Collection<String> projects = new ArrayList<String>();
+ private boolean verbose = false;
+ private boolean all = false;
+
+ public Object start(IApplicationContext context) throws Exception {
+ String[] args = (String[]) context.getArguments().get(
+ "application.args");
+ if (args == null || args.length == 0) {
+ help();
+ return EXIT_OK;
+ }
+ extractArguments(args);
+ CodanBuilder codanBuilder = new CodanBuilder();
+ CodanRuntime runtime = CodanRuntime.getInstance();
+ runtime.setProblemReporter(new CodanProblemReporter() {
+ @Override
+ public void reportProblem(String id, IFile file, int lineNumber,
+ String message) {
+ System.out.println(file.getLocation() + ":" + lineNumber + ": "
+ + message);
+ }
+ });
+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+ if (all) {
+ log("Launching analysis on workspace");
+ root.accept(codanBuilder.new CodanResourceVisitor());
+ } else {
+ for (String project : projects) {
+ log("Launching analysis on project " + project);
+ IProject wProject = root.getProject(project);
+ if (!wProject.exists()) {
+ System.err.println("Error: project " + project
+ + " does not exist");
+ continue;
+ }
+ wProject.accept(codanBuilder.new CodanResourceVisitor());
+ }
+ }
+ return EXIT_OK;
+ }
+
+ /**
+ * @param string
+ */
+ private void log(String string) {
+ if (verbose)
+ System.err.println(string);
+ }
+
+ /**
+ * @param args
+ */
+ private void extractArguments(String[] args) {
+ for (int i = 0; i < args.length; i++) {
+ String string = args[i];
+ if (string.equals("-verbose")) {
+ verbose = true;
+ } else if (string.equals("-all")) {
+ all = true;
+ } else {
+ projects.add(string);
+ }
+ }
+ }
+
+ /**
+ *
+ */
+ private void help() {
+ System.out.println("Usage: [options] <project1> <project2> ...");
+ System.out.println("Options:");
+ System.out.println(" -all - run on all projects in workspace");
+ System.out.println(" -verbose - print extra build information");
+ }
+
+ public void stop() {
+ // nothing
+ }
+}
diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CodanProblemReporter.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CodanProblemReporter.java
index 7b5bb830ccd..84dffad37d9 100644
--- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CodanProblemReporter.java
+++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CodanProblemReporter.java
@@ -34,13 +34,17 @@ public class CodanProblemReporter {
return; // skip
int severity = problem.getSeverity().intValue();
// Do not put in duplicates
- IMarker[] cur = file.findMarkers(GENERIC_CODE_ANALYSIS_MARKER_TYPE, false, IResource.DEPTH_ZERO);
+ IMarker[] cur = file.findMarkers(GENERIC_CODE_ANALYSIS_MARKER_TYPE,
+ false, IResource.DEPTH_ZERO);
if (cur != null) {
for (IMarker element : cur) {
- int line = ((Integer) element.getAttribute(IMarker.LINE_NUMBER)).intValue();
- if (line==lineNumber) {
- String mesg = (String) element.getAttribute(IMarker.MESSAGE);
- int sev = ((Integer) element.getAttribute(IMarker.SEVERITY)).intValue();
+ int line = ((Integer) element
+ .getAttribute(IMarker.LINE_NUMBER)).intValue();
+ if (line == lineNumber) {
+ String mesg = (String) element
+ .getAttribute(IMarker.MESSAGE);
+ int sev = ((Integer) element
+ .getAttribute(IMarker.SEVERITY)).intValue();
if (sev == severity && mesg.equals(message))
return;
}
@@ -64,6 +68,7 @@ public class CodanProblemReporter {
file.deleteMarkers(GENERIC_CODE_ANALYSIS_MARKER_TYPE, false,
IResource.DEPTH_ZERO);
} catch (CoreException ce) {
+ ce.printStackTrace();
}
}
diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CodanRuntime.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CodanRuntime.java
index 13f8926afb1..d7b3be7462f 100644
--- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CodanRuntime.java
+++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CodanRuntime.java
@@ -22,6 +22,10 @@ public class CodanRuntime {
return problemReporter;
}
+ public void setProblemReporter(CodanProblemReporter reporter) {
+ problemReporter = reporter;
+ }
+
public static CodanRuntime getInstance() {
return instance;
}

Back to the top