Skip to main content
summaryrefslogtreecommitdiffstats
path: root/codan
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
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')
-rw-r--r--codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/internal/model/CxxCodanReconciler.java5
-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
-rw-r--r--codan/org.eclipse.cdt.codan.ui.cxx/src/org/eclipse/cdt/codan/internal/ui/cxx/CodanPartListener.java4
-rw-r--r--codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/CodanPreferencePage.java8
8 files changed, 67 insertions, 12 deletions
diff --git a/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/internal/model/CxxCodanReconciler.java b/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/internal/model/CxxCodanReconciler.java
index 3fd01ca1fe..39c7278581 100644
--- a/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/internal/model/CxxCodanReconciler.java
+++ b/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/internal/model/CxxCodanReconciler.java
@@ -11,7 +11,8 @@
*******************************************************************************/
package org.eclipse.cdt.codan.core.cxx.internal.model;
-import org.eclipse.cdt.codan.internal.core.CodanRunner;
+import org.eclipse.cdt.codan.core.CodanRuntime;
+import org.eclipse.cdt.codan.core.model.CheckerLaunchMode;
import org.eclipse.cdt.core.CCProjectNature;
import org.eclipse.cdt.core.CProjectNature;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
@@ -33,7 +34,7 @@ public class CxxCodanReconciler {
return;
try {
if (project.hasNature(CProjectNature.C_NATURE_ID) || project.hasNature(CCProjectNature.CC_NATURE_ID)) {
- CodanRunner.runInEditor(ast, resource, monitor);
+ CodanRuntime.getInstance().getBuilder().processResource(resource, monitor, CheckerLaunchMode.RUN_AS_YOU_TYPE, ast);
}
} catch (CoreException e) {
// ignore
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);
}
/**
diff --git a/codan/org.eclipse.cdt.codan.ui.cxx/src/org/eclipse/cdt/codan/internal/ui/cxx/CodanPartListener.java b/codan/org.eclipse.cdt.codan.ui.cxx/src/org/eclipse/cdt/codan/internal/ui/cxx/CodanPartListener.java
index 2f3fd38d42..9798681944 100644
--- a/codan/org.eclipse.cdt.codan.ui.cxx/src/org/eclipse/cdt/codan/internal/ui/cxx/CodanPartListener.java
+++ b/codan/org.eclipse.cdt.codan.ui.cxx/src/org/eclipse/cdt/codan/internal/ui/cxx/CodanPartListener.java
@@ -12,8 +12,8 @@
*******************************************************************************/
package org.eclipse.cdt.codan.internal.ui.cxx;
+import org.eclipse.cdt.codan.core.CodanRuntime;
import org.eclipse.cdt.codan.core.model.CheckerLaunchMode;
-import org.eclipse.cdt.codan.internal.core.CodanRunner;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.ui.editor.CEditor;
import org.eclipse.cdt.internal.ui.editor.IPostSaveListener;
@@ -71,7 +71,7 @@ class CodanPartListener implements IPartListener2 {
Job job = new Job(NLS.bind(Messages.Startup_AnalyzingFile, resource.getName())) {
@Override
protected IStatus run(IProgressMonitor monitor) {
- CodanRunner.processResource(resource, launchMode, monitor);
+ CodanRuntime.getInstance().getBuilder().processResource(resource, monitor, launchMode);
return Status.OK_STATUS;
}
};
diff --git a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/CodanPreferencePage.java b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/CodanPreferencePage.java
index 5c9f5cbbd1..ed194213d8 100644
--- a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/CodanPreferencePage.java
+++ b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/CodanPreferencePage.java
@@ -23,11 +23,11 @@ import org.eclipse.cdt.codan.core.CodanRuntime;
import org.eclipse.cdt.codan.core.model.CheckerLaunchMode;
import org.eclipse.cdt.codan.core.model.IChecker;
import org.eclipse.cdt.codan.core.model.ICheckersRegistry;
+import org.eclipse.cdt.codan.core.model.ICodanBuilder;
import org.eclipse.cdt.codan.core.model.ICodanProblemMarker;
import org.eclipse.cdt.codan.core.model.IProblem;
import org.eclipse.cdt.codan.core.model.IProblemProfile;
import org.eclipse.cdt.codan.internal.core.CheckersRegistry;
-import org.eclipse.cdt.codan.internal.core.CodanRunner;
import org.eclipse.cdt.codan.internal.ui.CodanUIActivator;
import org.eclipse.cdt.codan.internal.ui.CodanUIMessages;
import org.eclipse.cdt.codan.internal.ui.dialogs.CustomizeProblemDialog;
@@ -281,11 +281,11 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements IWork
new ASTRunnable() {
@Override
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) {
+ ICodanBuilder builder = CodanRuntime.getInstance().getBuilder();
if (ast != null) {
- CodanRunner.runInEditor(ast, file, submonitor.newChild(1));
+ builder.processResource(file, submonitor.newChild(1), CheckerLaunchMode.RUN_AS_YOU_TYPE, ast);
} else {
- CodanRunner.processResource(file, CheckerLaunchMode.RUN_ON_FILE_OPEN,
- submonitor.newChild(1));
+ builder.processResource(file, submonitor.newChild(1), CheckerLaunchMode.RUN_ON_FILE_OPEN, null);
}
return Status.OK_STATUS;
}

Back to the top