Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlena Laskavaia2015-03-15 22:01:18 -0400
committerGerrit Code Review @ Eclipse.org2015-03-18 21:03:03 -0400
commit50775fe2fb7fdda8f4f5d21537ec75a661e675fc (patch)
tree9b20b28a2e9d696910acba079ac405cffeede5b0 /codan/org.eclipse.cdt.codan.core
parent6f8579a796bfe77147e854b84d434645bb8c8c08 (diff)
downloadorg.eclipse.cdt-50775fe2fb7fdda8f4f5d21537ec75a661e675fc.tar.gz
org.eclipse.cdt-50775fe2fb7fdda8f4f5d21537ec75a661e675fc.tar.xz
org.eclipse.cdt-50775fe2fb7fdda8f4f5d21537ec75a661e675fc.zip
codan: encapsulated builder and added vm var to disable (for tests)
- refactored the code so client who run codan always go though builder to call checkers - added vm arg -Dcodan.disabled=true to be used mostly by junit to not run codan at all Change-Id: Ie85e20f23b6ded8fffe5064adc1f9193a6f9a146
Diffstat (limited to 'codan/org.eclipse.cdt.codan.core')
-rw-r--r--codan/org.eclipse.cdt.codan.core/META-INF/MANIFEST.MF2
-rw-r--r--codan/org.eclipse.cdt.codan.core/pom.xml2
-rw-r--r--codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/ICodanBuilder.java11
-rw-r--r--codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CodanBuilder.java41
-rw-r--r--codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CodanRunner.java6
5 files changed, 58 insertions, 4 deletions
diff --git a/codan/org.eclipse.cdt.codan.core/META-INF/MANIFEST.MF b/codan/org.eclipse.cdt.codan.core/META-INF/MANIFEST.MF
index d04f0821e5..04d45c3928 100644
--- a/codan/org.eclipse.cdt.codan.core/META-INF/MANIFEST.MF
+++ b/codan/org.eclipse.cdt.codan.core/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Bundle-SymbolicName: org.eclipse.cdt.codan.core;singleton:=true
-Bundle-Version: 3.2.0.qualifier
+Bundle-Version: 3.3.0.qualifier
Bundle-Activator: org.eclipse.cdt.codan.core.CodanCorePlugin
Bundle-Vendor: %Bundle-Vendor
Require-Bundle: org.eclipse.core.runtime,
diff --git a/codan/org.eclipse.cdt.codan.core/pom.xml b/codan/org.eclipse.cdt.codan.core/pom.xml
index b017ce0733..8f5ff33d2a 100644
--- a/codan/org.eclipse.cdt.codan.core/pom.xml
+++ b/codan/org.eclipse.cdt.codan.core/pom.xml
@@ -11,7 +11,7 @@
<relativePath>../../pom.xml</relativePath>
</parent>
- <version>3.2.0-SNAPSHOT</version>
+ <version>3.3.0-SNAPSHOT</version>
<artifactId>org.eclipse.cdt.codan.core</artifactId>
<packaging>eclipse-plugin</packaging>
</project>
diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/ICodanBuilder.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/ICodanBuilder.java
index a9463a92e3..e32147487b 100644
--- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/ICodanBuilder.java
+++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/ICodanBuilder.java
@@ -40,4 +40,15 @@ public interface ICodanBuilder {
* @since 2.0
*/
public void processResource(IResource resource, IProgressMonitor monitor, CheckerLaunchMode mode);
+
+ /**
+ * Run code analysis on given resource in a given mode
+ *
+ * @param resource - resource to process
+ * @param monitor - progress monitor
+ * @param mode - launch mode, @see {@link CheckerLaunchMode}
+ * @param model - runtime code model, such as AST, used when model is not in sync with resource
+ * @since 3.3
+ */
+ public void processResource(IResource resource, IProgressMonitor monitor, CheckerLaunchMode mode, Object model);
} \ No newline at end of file
diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CodanBuilder.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CodanBuilder.java
index 364cf586aa..af27abf769 100644
--- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CodanBuilder.java
+++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CodanBuilder.java
@@ -31,6 +31,13 @@ public class CodanBuilder extends IncrementalProjectBuilder implements ICodanBui
* Codan builder id
*/
public static final String BUILDER_ID = "org.eclipse.cdt.codan.core.codanBuilder"; //$NON-NLS-1$
+ private boolean enabled = true;
+
+ {
+ if (Boolean.valueOf(System.getProperty("codan.disabled"))) { //$NON-NLS-1$
+ enabled = false;
+ }
+ }
private class CodanDeltaVisitor implements IResourceDeltaVisitor {
private IProgressMonitor monitor;
@@ -63,6 +70,8 @@ public class CodanBuilder extends IncrementalProjectBuilder implements ICodanBui
@SuppressWarnings("rawtypes")
@Override
protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException {
+ if (!enabled)
+ return null;
if (kind == FULL_BUILD) {
fullBuild(monitor);
} else {
@@ -78,7 +87,7 @@ public class CodanBuilder extends IncrementalProjectBuilder implements ICodanBui
@Override
public void processResource(IResource resource, IProgressMonitor monitor) {
- CodanRunner.processResource(resource, CheckerLaunchMode.RUN_ON_FULL_BUILD, monitor);
+ processResource(resource, monitor, CheckerLaunchMode.RUN_ON_FULL_BUILD);
}
/**
@@ -91,6 +100,8 @@ public class CodanBuilder extends IncrementalProjectBuilder implements ICodanBui
*/
@Override
public void processResource(IResource resource, IProgressMonitor monitor, CheckerLaunchMode mode) {
+ if (!enabled)
+ return;
CodanRunner.processResource(resource, mode, monitor);
}
@@ -106,4 +117,32 @@ public class CodanBuilder extends IncrementalProjectBuilder implements ICodanBui
// The visitor does the work.
delta.accept(new CodanDeltaVisitor(monitor));
}
+
+ @Override
+ public void processResource(IResource resource, IProgressMonitor monitor, CheckerLaunchMode mode, Object model) {
+ if (!enabled) return;
+ if (model != null) {
+ if (mode == CheckerLaunchMode.RUN_AS_YOU_TYPE)
+ CodanRunner.runInEditor(model, resource, monitor);
+ else
+ throw new IllegalArgumentException("This mode is not supported"); //$NON-NLS-1$
+ } else {
+ processResource(resource, monitor, mode);
+ }
+ }
+
+ /**
+ * @return true if build is enable, i.e. running codan
+ */
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ /**
+ * Globally disable/enable of running codan
+ * @param enabled the enabled to set
+ */
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
}
diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CodanRunner.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CodanRunner.java
index 4b41a4d921..0edb4710ab 100644
--- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CodanRunner.java
+++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CodanRunner.java
@@ -26,6 +26,10 @@ import org.eclipse.osgi.util.NLS;
/**
* Collection of methods for running checkers.
+ *
+ * Clients: this should not be called directly, use ICodanBuilder interface instead
+ *
+ * CodanRuntime.getInstance().getBuilder()
*/
public class CodanRunner {
/** Do not instantiate. All methods are static */
@@ -39,7 +43,7 @@ public class CodanRunner {
* @param monitor - the progress monitor
*/
public static void runInEditor(Object model, IResource resource, IProgressMonitor monitor) {
- CodanRunner.processResource(resource, model, CheckerLaunchMode.RUN_AS_YOU_TYPE, monitor);
+ processResource(resource, model, CheckerLaunchMode.RUN_AS_YOU_TYPE, monitor);
}
/**

Back to the top