mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 06:02:11 +02:00
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
This commit is contained in:
parent
6f8579a796
commit
50775fe2fb
8 changed files with 67 additions and 12 deletions
|
@ -11,7 +11,8 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.codan.core.cxx.internal.model;
|
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.CCProjectNature;
|
||||||
import org.eclipse.cdt.core.CProjectNature;
|
import org.eclipse.cdt.core.CProjectNature;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
|
@ -33,7 +34,7 @@ public class CxxCodanReconciler {
|
||||||
return;
|
return;
|
||||||
try {
|
try {
|
||||||
if (project.hasNature(CProjectNature.C_NATURE_ID) || project.hasNature(CCProjectNature.CC_NATURE_ID)) {
|
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) {
|
} catch (CoreException e) {
|
||||||
// ignore
|
// ignore
|
||||||
|
|
|
@ -2,7 +2,7 @@ Manifest-Version: 1.0
|
||||||
Bundle-ManifestVersion: 2
|
Bundle-ManifestVersion: 2
|
||||||
Bundle-Name: %Bundle-Name
|
Bundle-Name: %Bundle-Name
|
||||||
Bundle-SymbolicName: org.eclipse.cdt.codan.core;singleton:=true
|
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-Activator: org.eclipse.cdt.codan.core.CodanCorePlugin
|
||||||
Bundle-Vendor: %Bundle-Vendor
|
Bundle-Vendor: %Bundle-Vendor
|
||||||
Require-Bundle: org.eclipse.core.runtime,
|
Require-Bundle: org.eclipse.core.runtime,
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<version>3.2.0-SNAPSHOT</version>
|
<version>3.3.0-SNAPSHOT</version>
|
||||||
<artifactId>org.eclipse.cdt.codan.core</artifactId>
|
<artifactId>org.eclipse.cdt.codan.core</artifactId>
|
||||||
<packaging>eclipse-plugin</packaging>
|
<packaging>eclipse-plugin</packaging>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -40,4 +40,15 @@ public interface ICodanBuilder {
|
||||||
* @since 2.0
|
* @since 2.0
|
||||||
*/
|
*/
|
||||||
public void processResource(IResource resource, IProgressMonitor monitor, CheckerLaunchMode mode);
|
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);
|
||||||
}
|
}
|
|
@ -31,6 +31,13 @@ public class CodanBuilder extends IncrementalProjectBuilder implements ICodanBui
|
||||||
* Codan builder id
|
* Codan builder id
|
||||||
*/
|
*/
|
||||||
public static final String BUILDER_ID = "org.eclipse.cdt.codan.core.codanBuilder"; //$NON-NLS-1$
|
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 class CodanDeltaVisitor implements IResourceDeltaVisitor {
|
||||||
private IProgressMonitor monitor;
|
private IProgressMonitor monitor;
|
||||||
|
@ -63,6 +70,8 @@ public class CodanBuilder extends IncrementalProjectBuilder implements ICodanBui
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
@Override
|
@Override
|
||||||
protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException {
|
protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException {
|
||||||
|
if (!enabled)
|
||||||
|
return null;
|
||||||
if (kind == FULL_BUILD) {
|
if (kind == FULL_BUILD) {
|
||||||
fullBuild(monitor);
|
fullBuild(monitor);
|
||||||
} else {
|
} else {
|
||||||
|
@ -78,7 +87,7 @@ public class CodanBuilder extends IncrementalProjectBuilder implements ICodanBui
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processResource(IResource resource, IProgressMonitor monitor) {
|
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
|
@Override
|
||||||
public void processResource(IResource resource, IProgressMonitor monitor, CheckerLaunchMode mode) {
|
public void processResource(IResource resource, IProgressMonitor monitor, CheckerLaunchMode mode) {
|
||||||
|
if (!enabled)
|
||||||
|
return;
|
||||||
CodanRunner.processResource(resource, mode, monitor);
|
CodanRunner.processResource(resource, mode, monitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,4 +117,32 @@ public class CodanBuilder extends IncrementalProjectBuilder implements ICodanBui
|
||||||
// The visitor does the work.
|
// The visitor does the work.
|
||||||
delta.accept(new CodanDeltaVisitor(monitor));
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,10 @@ import org.eclipse.osgi.util.NLS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collection of methods for running checkers.
|
* Collection of methods for running checkers.
|
||||||
|
*
|
||||||
|
* Clients: this should not be called directly, use ICodanBuilder interface instead
|
||||||
|
*
|
||||||
|
* CodanRuntime.getInstance().getBuilder()
|
||||||
*/
|
*/
|
||||||
public class CodanRunner {
|
public class CodanRunner {
|
||||||
/** Do not instantiate. All methods are static */
|
/** Do not instantiate. All methods are static */
|
||||||
|
@ -39,7 +43,7 @@ public class CodanRunner {
|
||||||
* @param monitor - the progress monitor
|
* @param monitor - the progress monitor
|
||||||
*/
|
*/
|
||||||
public static void runInEditor(Object model, IResource resource, IProgressMonitor 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -12,8 +12,8 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.codan.internal.ui.cxx;
|
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.core.model.CheckerLaunchMode;
|
||||||
import org.eclipse.cdt.codan.internal.core.CodanRunner;
|
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
||||||
import org.eclipse.cdt.internal.ui.editor.IPostSaveListener;
|
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())) {
|
Job job = new Job(NLS.bind(Messages.Startup_AnalyzingFile, resource.getName())) {
|
||||||
@Override
|
@Override
|
||||||
protected IStatus run(IProgressMonitor monitor) {
|
protected IStatus run(IProgressMonitor monitor) {
|
||||||
CodanRunner.processResource(resource, launchMode, monitor);
|
CodanRuntime.getInstance().getBuilder().processResource(resource, monitor, launchMode);
|
||||||
return Status.OK_STATUS;
|
return Status.OK_STATUS;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -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.CheckerLaunchMode;
|
||||||
import org.eclipse.cdt.codan.core.model.IChecker;
|
import org.eclipse.cdt.codan.core.model.IChecker;
|
||||||
import org.eclipse.cdt.codan.core.model.ICheckersRegistry;
|
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.ICodanProblemMarker;
|
||||||
import org.eclipse.cdt.codan.core.model.IProblem;
|
import org.eclipse.cdt.codan.core.model.IProblem;
|
||||||
import org.eclipse.cdt.codan.core.model.IProblemProfile;
|
import org.eclipse.cdt.codan.core.model.IProblemProfile;
|
||||||
import org.eclipse.cdt.codan.internal.core.CheckersRegistry;
|
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.CodanUIActivator;
|
||||||
import org.eclipse.cdt.codan.internal.ui.CodanUIMessages;
|
import org.eclipse.cdt.codan.internal.ui.CodanUIMessages;
|
||||||
import org.eclipse.cdt.codan.internal.ui.dialogs.CustomizeProblemDialog;
|
import org.eclipse.cdt.codan.internal.ui.dialogs.CustomizeProblemDialog;
|
||||||
|
@ -281,11 +281,11 @@ public class CodanPreferencePage extends FieldEditorOverlayPage implements IWork
|
||||||
new ASTRunnable() {
|
new ASTRunnable() {
|
||||||
@Override
|
@Override
|
||||||
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) {
|
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) {
|
||||||
|
ICodanBuilder builder = CodanRuntime.getInstance().getBuilder();
|
||||||
if (ast != null) {
|
if (ast != null) {
|
||||||
CodanRunner.runInEditor(ast, file, submonitor.newChild(1));
|
builder.processResource(file, submonitor.newChild(1), CheckerLaunchMode.RUN_AS_YOU_TYPE, ast);
|
||||||
} else {
|
} else {
|
||||||
CodanRunner.processResource(file, CheckerLaunchMode.RUN_ON_FILE_OPEN,
|
builder.processResource(file, submonitor.newChild(1), CheckerLaunchMode.RUN_ON_FILE_OPEN, null);
|
||||||
submonitor.newChild(1));
|
|
||||||
}
|
}
|
||||||
return Status.OK_STATUS;
|
return Status.OK_STATUS;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue