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);
}
}
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;
}
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());
}
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);
}
}
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());
}
Aggregations