Search in sources :

Example 6 with CommandException

use of name.herlin.command.CommandException 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 7 with CommandException

use of name.herlin.command.CommandException in project pmd-eclipse-plugin by pmd.

the class PMDBuilder method build.

/**
 * @see org.eclipse.core.resources.IncrementalProjectBuilder#build(int,
 *      java.util.Map, org.eclipse.core.runtime.IProgressMonitor)
 */
protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException {
    LOG.info("Incremental builder activated");
    try {
        if (kind == AUTO_BUILD) {
            LOG.debug("Auto build requested.");
            buildAuto(monitor);
        } else if (kind == FULL_BUILD) {
            LOG.debug("Full build requested.");
            buildFull(monitor);
        } else if (kind == INCREMENTAL_BUILD) {
            LOG.debug("Incremental build requested.");
            buildIncremental(monitor);
        } else {
            LOG.warn("This kind of build is not supported : " + kind);
        }
    } catch (CommandException e) {
        throw new CoreException(new Status(IStatus.ERROR, PMDPlugin.getDefault().getBundle().getSymbolicName(), 0, e.getMessage(), e));
    }
    LOG.info("Build done.");
    return EMPTY_PROJECT_ARRAY;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) CoreException(org.eclipse.core.runtime.CoreException) CommandException(name.herlin.command.CommandException)

Example 8 with CommandException

use of name.herlin.command.CommandException in project pmd-eclipse-plugin by pmd.

the class JobCommandProcessor method processCommand.

/**
 * @see name.herlin.command.CommandProcessor#processCommand(name.herlin.command.AbstractProcessableCommand)
 */
public void processCommand(final AbstractProcessableCommand aCommand) throws CommandException {
    LOG.debug("Begining job command " + aCommand.getName());
    if (!aCommand.isReadyToExecute()) {
        throw new UnsetInputPropertiesException();
    }
    final Job job = new Job(aCommand.getName()) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            try {
                if (aCommand instanceof AbstractDefaultCommand) {
                    ((AbstractDefaultCommand) aCommand).setMonitor(monitor);
                }
                Timer timer = new Timer();
                aCommand.execute();
                timer.stop();
                PMDPlugin.getDefault().logInformation("Command " + aCommand.getName() + " excecuted in " + timer.getDuration() + "ms");
            } catch (CommandException e) {
                PMDPlugin.getDefault().logError("Error executing command " + aCommand.getName(), e);
            }
            synchronized (outstanding) {
                count.decrementAndGet();
                Job job = outstanding.poll();
                if (job != null) {
                    job.schedule();
                }
            }
            return Status.OK_STATUS;
        }
    };
    if (aCommand instanceof AbstractDefaultCommand) {
        job.setUser(((AbstractDefaultCommand) aCommand).isUserInitiated());
    }
    synchronized (outstanding) {
        if (count.incrementAndGet() > 10) {
            // too many already running, put in a queue to run later
            outstanding.add(job);
        } else {
            job.schedule();
        }
    }
    this.addJob(aCommand, job);
    LOG.debug("Ending job command " + aCommand.getName());
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Timer(name.herlin.command.Timer) UnsetInputPropertiesException(name.herlin.command.UnsetInputPropertiesException) CommandException(name.herlin.command.CommandException) Job(org.eclipse.core.runtime.jobs.Job)

Example 9 with CommandException

use of name.herlin.command.CommandException in project pmd-eclipse-plugin by pmd.

the class RenderReportsCmd method execute.

/**
 * @see name.herlin.command.AbstractProcessableCommand#execute()
 */
@Override
public void execute() throws CommandException {
    try {
        LOG.debug("Starting RenderReport command");
        LOG.debug("   Create a report object");
        final Report report = createReport(project());
        LOG.debug("   Getting the report folder");
        final IFolder folder = getProjectFolder(PMDRuntimeConstants.REPORT_FOLDER);
        if (!folder.exists()) {
            folder.create(true, true, getMonitor());
        }
        for (Map.Entry<String, Renderer> entry : renderers.entrySet()) {
            String reportName = entry.getKey();
            Renderer renderer = entry.getValue();
            LOG.debug("   Render the report");
            render(report, folder, reportName, renderer);
        }
    } catch (CoreException e) {
        LOG.debug("Core Exception: " + e.getMessage(), e);
        throw new CommandException(e);
    } catch (IOException e) {
        LOG.debug("Core Exception: " + e.getMessage(), e);
        throw new CommandException(e);
    } finally {
        LOG.debug("End of RenderReport command");
        setTerminated(true);
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) Report(net.sourceforge.pmd.Report) Renderer(net.sourceforge.pmd.renderers.Renderer) CommandException(name.herlin.command.CommandException) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) IFolder(org.eclipse.core.resources.IFolder)

Example 10 with CommandException

use of name.herlin.command.CommandException in project pmd-eclipse-plugin by pmd.

the class ReviewCodeCmd method execute.

/**
 * @see name.herlin.command.AbstractProcessableCommand#execute()
 */
@Override
public void execute() throws CommandException {
    boolean doReview = checkForMisconfiguredRules();
    if (!doReview) {
        return;
    }
    LOG.info("ReviewCode command starting.");
    try {
        fileCount = 0;
        ruleCount = 0;
        pmdDuration = 0;
        beginTask("PMD checking...", getStepCount());
        // resourcesDelta if it is incremental or auto
        if (resources.isEmpty()) {
            processResourceDelta();
        } else {
            processResources();
        }
        // (avoids grabbing the "run" lock for nothing)
        if (!markersByFile.isEmpty()) {
            // Appliquer les marqueurs
            IWorkspaceRunnable action = new IWorkspaceRunnable() {

                public void run(IProgressMonitor monitor) throws CoreException {
                    applyMarkers();
                }
            };
            // for too long
            for (IFile file : markersByFile.keySet()) {
                if (isCanceled()) {
                    break;
                }
                MarkerUtil.deleteAllMarkersIn(file);
            }
            final IWorkspace workspace = ResourcesPlugin.getWorkspace();
            workspace.run(action, getSchedulingRule(), IWorkspace.AVOID_UPDATE, getMonitor());
        }
        // Switch to the PMD perspective if required
        if (openPmdPerspective) {
            Display.getDefault().asyncExec(new Runnable() {

                public void run() {
                    switchToPmdPerspective();
                }
            });
        }
        if (openPmdViolationsOverviewView) {
            PMDPlugin.getDefault().showView(PMDPlugin.VIOLATIONS_OVERVIEW_ID);
        }
        if (openPmdViolationsOutlineView) {
            PMDPlugin.getDefault().showView(PMDPlugin.VIOLATIONS_OUTLINE_ID);
        }
    } catch (CoreException e) {
        throw new CommandException("Core exception when reviewing code", e);
    } finally {
        LOG.info("ReviewCode command has ended.");
        setTerminated(true);
        done();
        // Log performance information
        if (fileCount > 0 && ruleCount > 0) {
            logInfo("Review code command terminated. " + ruleCount + " rules were executed against " + fileCount + " files. Actual PMD duration is about " + pmdDuration + "ms, that is about " + (float) pmdDuration / fileCount + " ms/file, " + (float) pmdDuration / ruleCount + " ms/rule, " + (float) pmdDuration / ((long) fileCount * (long) ruleCount) + " ms/filerule");
        } else {
            logInfo("Review code command terminated. " + ruleCount + " rules were executed against " + fileCount + " files. PMD was not executed.");
        }
    }
    PMDPlugin.getDefault().changedFiles(markedFiles());
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) CommandException(name.herlin.command.CommandException)

Aggregations

CommandException (name.herlin.command.CommandException)21 CoreException (org.eclipse.core.runtime.CoreException)11 PropertiesException (net.sourceforge.pmd.eclipse.runtime.properties.PropertiesException)5 IFile (org.eclipse.core.resources.IFile)4 RuleSet (net.sourceforge.pmd.RuleSet)3 ReviewCodeCmd (net.sourceforge.pmd.eclipse.runtime.cmd.ReviewCodeCmd)3 IProjectProperties (net.sourceforge.pmd.eclipse.runtime.properties.IProjectProperties)3 IProject (org.eclipse.core.resources.IProject)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 File (java.io.File)2 IFolder (org.eclipse.core.resources.IFolder)2 IResource (org.eclipse.core.resources.IResource)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Timer (name.herlin.command.Timer)1