Search in sources :

Example 1 with ReviewCodeCmd

use of net.sourceforge.pmd.eclipse.runtime.cmd.ReviewCodeCmd in project pmd-eclipse-plugin by pmd.

the class PMDCheckAction method reviewSingleResource.

/**
 * Run the reviewCode command on a single resource
 *
 * @param resource
 * @throws CommandException
 */
private void reviewSingleResource(IResource resource) throws CommandException {
    ReviewCodeCmd cmd = new ReviewCodeCmd();
    cmd.addResource(resource);
    setupAndExecute(cmd, 1);
}
Also used : ReviewCodeCmd(net.sourceforge.pmd.eclipse.runtime.cmd.ReviewCodeCmd)

Example 2 with ReviewCodeCmd

use of net.sourceforge.pmd.eclipse.runtime.cmd.ReviewCodeCmd in project pmd-eclipse-plugin by pmd.

the class ReviewResourceAction method run.

/**
 * @see org.eclipse.jface.action.IAction#run()
 */
public void run() {
    try {
        ProgressMonitorDialog dialog = new ProgressMonitorDialog(Display.getCurrent().getActiveShell());
        dialog.run(false, false, new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                setMonitor(monitor);
                monitor.beginTask(getString(StringKeys.MONITOR_REVIEW), 5);
                ReviewCodeCmd cmd = new ReviewCodeCmd();
                cmd.addResource(resource);
                cmd.setStepCount(1);
                cmd.setTaskMarker(true);
                cmd.setUserInitiated(true);
                try {
                    cmd.performExecute();
                } catch (CommandException e) {
                    logErrorByKey(StringKeys.ERROR_CORE_EXCEPTION, e);
                }
                monitor.done();
            }
        });
    } catch (InvocationTargetException e) {
        logErrorByKey(StringKeys.ERROR_INVOCATIONTARGET_EXCEPTION, e);
    } catch (InterruptedException e) {
        logErrorByKey(StringKeys.ERROR_INTERRUPTED_EXCEPTION, e);
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) ReviewCodeCmd(net.sourceforge.pmd.eclipse.runtime.cmd.ReviewCodeCmd) CommandException(name.herlin.command.CommandException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 3 with ReviewCodeCmd

use of net.sourceforge.pmd.eclipse.runtime.cmd.ReviewCodeCmd in project pmd-eclipse-plugin by pmd.

the class FileChangeReviewer method resourceChanged.

/**
 * @param event
 */
public void resourceChanged(IResourceChangeEvent event) {
    IWorkspaceDescription workspaceSettings = ResourcesPlugin.getWorkspace().getDescription();
    if (workspaceSettings.isAutoBuilding()) {
        PMDPlugin.getDefault().logInformation("Not running PMD via FileChangeReviewer, as autoBuilding is enabled for this workspace");
        return;
    }
    Set<ResourceChange> itemsChanged = new HashSet<ResourceChange>();
    switch(event.getType()) {
        case IResourceChangeEvent.POST_CHANGE:
            changed(itemsChanged, event.getDelta(), new NullProgressMonitor());
            break;
        default:
    }
    if (itemsChanged.isEmpty()) {
        return;
    }
    // separate one for each thread
    ReviewCodeCmd cmd = new ReviewCodeCmd();
    cmd.reset();
    for (ResourceChange chg : itemsChanged) {
        cmd.addResource(chg.file);
    }
    try {
        cmd.performExecute();
    } catch (CommandException e) {
        PMDPlugin.getDefault().log(IStatus.ERROR, "Error processing code review upon file changes", e);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IWorkspaceDescription(org.eclipse.core.resources.IWorkspaceDescription) ReviewCodeCmd(net.sourceforge.pmd.eclipse.runtime.cmd.ReviewCodeCmd) CommandException(name.herlin.command.CommandException) HashSet(java.util.HashSet)

Example 4 with ReviewCodeCmd

use of net.sourceforge.pmd.eclipse.runtime.cmd.ReviewCodeCmd in project pmd-eclipse-plugin by pmd.

the class PMDBuilder method processProjectFiles.

/**
 * Process all files in the project
 *
 * @param project
 *            the project
 * @param monitor
 *            a progress monitor
 * @throws CommandException
 */
private void processProjectFiles(IProject project, IProgressMonitor monitor) throws CommandException {
    ReviewCodeCmd cmd = new ReviewCodeCmd();
    cmd.addResource(project);
    cmd.setTaskMarker(false);
    cmd.setMonitor(monitor);
    // a builder is always asynchronous; execute a command synchronously whatever its processor
    cmd.performExecute();
}
Also used : ReviewCodeCmd(net.sourceforge.pmd.eclipse.runtime.cmd.ReviewCodeCmd)

Example 5 with ReviewCodeCmd

use of net.sourceforge.pmd.eclipse.runtime.cmd.ReviewCodeCmd in project pmd-eclipse-plugin by pmd.

the class PMDBuilder method buildIncremental.

/**
 * Incremental build
 *
 * @param monitor
 *            a progress monitor.
 * @throws CommandException
 */
private void buildIncremental(IProgressMonitor monitor) throws CommandException {
    /*
        * Check the user preference to see if the user wants to run PMD on a save
        * */
    if (!PMDPlugin.getDefault().loadPreferences().isCheckAfterSaveEnabled()) {
        return;
    }
    IProject currentProject = getProject();
    if (currentProject != null) {
        IResourceDelta resourceDelta = this.getDelta(currentProject);
        if (resourceDelta != null && resourceDelta.getAffectedChildren().length != 0) {
            ReviewCodeCmd cmd = new ReviewCodeCmd();
            cmd.setResourceDelta(resourceDelta);
            cmd.setTaskMarker(false);
            cmd.setMonitor(monitor);
            // a builder is always asynchronous;
            // execute a command synchronously
            // whatever its processor
            cmd.performExecute();
        } else {
            LOG.info("No change reported. Performing no build");
        }
    }
}
Also used : ReviewCodeCmd(net.sourceforge.pmd.eclipse.runtime.cmd.ReviewCodeCmd) IProject(org.eclipse.core.resources.IProject) IResourceDelta(org.eclipse.core.resources.IResourceDelta)

Aggregations

ReviewCodeCmd (net.sourceforge.pmd.eclipse.runtime.cmd.ReviewCodeCmd)7 CommandException (name.herlin.command.CommandException)3 IResource (org.eclipse.core.resources.IResource)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 HashSet (java.util.HashSet)1 AbstractPMDRecord (net.sourceforge.pmd.eclipse.ui.model.AbstractPMDRecord)1 IProject (org.eclipse.core.resources.IProject)1 IResourceDelta (org.eclipse.core.resources.IResourceDelta)1 IWorkspaceDescription (org.eclipse.core.resources.IWorkspaceDescription)1 IAdaptable (org.eclipse.core.runtime.IAdaptable)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1 IWorkingSet (org.eclipse.ui.IWorkingSet)1