use of name.herlin.command.CommandException in project pmd-eclipse-plugin by pmd.
the class ReviewCodeHandler method execute.
// /**
// * Collects the files out of the given resources.
// *
// * @param resources the resources from which to get the files
// * @return an array of files
// */
// protected static IFile[] collectFiles(IResource[] resources) {
//
// Set<IFile> files= new HashSet<IFile>();
// for (int i= 0; i < resources.length; i++) {
// IResource resource= resources[i];
// if ((IResource.FILE & resource.getType()) > 0)
// files.add((IFile)resource);
// }
// return (IFile[]) files.toArray(new IFile[files.size()]);
// }
public Object execute(ExecutionEvent event) throws ExecutionException {
computeSelectedResources();
try {
if (fResources != null && fResources.length > 0) {
// separate one for each thread
ReviewCodeCmd cmd = new ReviewCodeCmd();
cmd.reset();
for (IResource rsc : fResources) {
cmd.addResource(rsc);
}
try {
cmd.performExecute();
} catch (CommandException e) {
PMDPlugin.getDefault().log(IStatus.ERROR, "Error processing user-initiated code review", e);
}
}
// Standard return value. DO NOT CHANGE.
return null;
} finally {
fResources = null;
fLocation = null;
}
}
use of name.herlin.command.CommandException in project pmd-eclipse-plugin by pmd.
the class ReviewCodeCmd method processResource.
/**
* Review a single resource
*/
private void processResource(IResource resource) throws CommandException {
try {
final IProject project = resource.getProject();
final IProjectProperties properties = getProjectProperties(project);
if (!runAlways && !properties.isPmdEnabled()) {
return;
}
// properties.getProjectRuleSet();
final RuleSet ruleSet = rulesetFrom(resource);
// final PMDEngine pmdEngine = getPmdEngineForProject(project);
int targetCount = 0;
if (resource.exists()) {
targetCount = countResourceElement(resource);
}
// Could add a property that lets us set the max number to analyze
if (properties.isFullBuildEnabled() || isUserInitiated() || targetCount <= MAXIMUM_RESOURCE_COUNT) {
setStepCount(targetCount);
LOG.debug("Visiting resource " + resource.getName() + " : " + getStepCount());
if (resource.exists()) {
final ResourceVisitor visitor = new ResourceVisitor();
visitor.setMonitor(getMonitor());
visitor.setRuleSet(ruleSet);
// visitor.setPmdEngine(pmdEngine);
visitor.setAccumulator(markersByFile);
visitor.setUseTaskMarker(taskMarker);
visitor.setProjectProperties(properties);
resource.accept(visitor);
ruleCount = ruleSet.getRules().size();
fileCount += visitor.getProcessedFilesCount();
pmdDuration += visitor.getActualPmdDuration();
} else {
LOG.debug("Skipping resource " + resource.getName() + " because it doesn't exist.");
}
} else {
String message = "Skipping resource " + resource.getName() + " because of fullBuildEnabled flag and " + "targetCount is " + targetCount + ". This is more than " + MAXIMUM_RESOURCE_COUNT + "." + " If you want to execute PMD, please check \"Full build enabled\" in the project settings";
PMDPlugin.getDefault().logInformation(message);
}
// TODO - temp fix? BR
worked(1);
} catch (PropertiesException e) {
throw new CommandException(e);
} catch (CoreException e) {
throw new CommandException(e);
}
}
use of name.herlin.command.CommandException in project pmd-eclipse-plugin by pmd.
the class ReviewCodeCmd method processProject.
/**
* Review an entire project
*/
private void processProject(IProject project) throws CommandException {
try {
setStepCount(countResourceElement(project));
LOG.debug("Visiting project " + project.getName() + " : " + getStepCount());
if (project.hasNature(JavaCore.NATURE_ID)) {
processJavaProject(project);
} else {
processResource(project);
}
} catch (CoreException e) {
throw new CommandException(e);
}
}
use of name.herlin.command.CommandException in project pmd-eclipse-plugin by pmd.
the class ReviewCodeCmd method processResourceDelta.
/**
* Review a resource delta
*/
private void processResourceDelta() throws CommandException {
try {
IResource resource = resourceDelta.getResource();
final IProject project = resource.getProject();
final IProjectProperties properties = getProjectProperties(project);
// properties.getProjectRuleSet();
RuleSet ruleSet = rulesetFromResourceDelta();
// PMDEngine pmdEngine = getPmdEngineForProject(project);
int targetCount = countDeltaElement(resourceDelta);
// Could add a property that lets us set the max number to analyze
if (properties.isFullBuildEnabled() || isUserInitiated() || targetCount <= MAXIMUM_RESOURCE_COUNT) {
setStepCount(targetCount);
LOG.debug("Visiting delta of resource " + resource.getName() + " : " + getStepCount());
DeltaVisitor visitor = new DeltaVisitor();
visitor.setMonitor(getMonitor());
visitor.setRuleSet(ruleSet);
// visitor.setPmdEngine(pmdEngine);
visitor.setAccumulator(markersByFile);
visitor.setUseTaskMarker(taskMarker);
visitor.setProjectProperties(properties);
resourceDelta.accept(visitor);
ruleCount = ruleSet.getRules().size();
fileCount += visitor.getProcessedFilesCount();
pmdDuration += visitor.getActualPmdDuration();
} else {
String message = "Skipping resourceDelta " + resource.getName() + " because of fullBuildEnabled flag and " + "targetCount is " + targetCount + ". This is more than " + MAXIMUM_RESOURCE_COUNT + "." + " If you want to execute PMD, please check \"Full build enabled\" in the project settings";
PMDPlugin.getDefault().logInformation(message);
LOG.debug(message);
}
} catch (PropertiesException e) {
throw new CommandException(e);
} catch (CoreException e) {
throw new CommandException(e);
}
}
use of name.herlin.command.CommandException in project pmd-eclipse-plugin by pmd.
the class DetectCutAndPasteCmd method execute.
/**
* @see name.herlin.command.AbstractProcessableCommand#execute()
*/
@Override
public void execute() throws CommandException {
try {
List<File> files = findCandidateFiles();
if (files.isEmpty()) {
logInfo("No files found for specified language.");
} else {
logInfo("Found " + files.size() + " files for the specified language. Performing CPD.");
}
setStepCount(files.size());
beginTask("Finding suspect Cut And Paste", getStepCount() * 2);
if (!isCanceled()) {
final CPD cpd = detectCutAndPaste(files);
if (!isCanceled()) {
if (createReport) {
renderReport(cpd.getMatches());
}
notifyListeners(cpd);
}
}
} catch (CoreException e) {
LOG.debug("Core Exception: " + e.getMessage(), e);
throw new CommandException(e);
} catch (PropertiesException e) {
LOG.debug("Properties Exception: " + e.getMessage(), e);
throw new CommandException(e);
} finally {
setTerminated(true);
}
}
Aggregations