use of name.herlin.command.CommandException in project pmd-eclipse-plugin by pmd.
the class ReviewResourceForRuleCommand method execute.
/*
* (non-Javadoc)
*
* @see
* net.sourceforge.pmd.eclipse.runtime.cmd.AbstractDefaultCommand#execute()
*/
@Override
public void execute() throws CommandException {
// IProject project = resource.getProject();
IFile file = (IFile) resource.getAdapter(IFile.class);
beginTask("PMD checking for rule: " + rule.getName(), 1);
if (file != null) {
RuleSet ruleSet = RuleSetUtil.newSingle(rule);
// final PMDEngine pmdEngine = getPmdEngineForProject(project);
File sourceCodeFile = file.getFullPath().toFile();
if (ruleSet.applies(sourceCodeFile)) {
try {
context = PMD.newRuleContext(file.getName(), sourceCodeFile);
// Reader input = new InputStreamReader(file.getContents(),
// file.getCharset());
RuleSets rSets = new RuleSets(ruleSet);
new SourceCodeProcessor(new PMDConfiguration()).processSourceCode(file.getContents(), rSets, context);
// input.close();
// } catch (CoreException e) {
// throw new CommandException(e);
} catch (PMDException e) {
throw new CommandException(e);
} catch (CoreException e) {
throw new CommandException(e);
}
// trigger event propertyChanged for all listeners
Display.getDefault().asyncExec(new Runnable() {
public void run() {
for (IPropertyListener listener : listenerList) {
listener.propertyChanged(context.getReport().iterator(), PMDRuntimeConstants.PROPERTY_REVIEW);
}
}
});
}
}
}
use of name.herlin.command.CommandException in project pmd-eclipse-plugin by pmd.
the class BuildProjectCommand method execute.
/**
* @see name.herlin.command.AbstractProcessableCommand#execute()
*/
public void execute() throws CommandException {
try {
project().build(IncrementalProjectBuilder.FULL_BUILD, this.getMonitor());
projectProperties().setNeedRebuild(false);
} catch (CoreException e) {
throw new CommandException(e);
} catch (PropertiesException e) {
throw new CommandException(e);
} finally {
this.setTerminated(true);
}
}
use of name.herlin.command.CommandException in project pmd-eclipse-plugin by pmd.
the class DeleteMarkersCommand method execute.
/* (non-Javadoc)
* @see net.sourceforge.pmd.eclipse.runtime.cmd.AbstractDefaultCommand#execute()
*/
public void execute() throws CommandException {
try {
beginTask("Deleting single markers", markers.length);
for (int j = 0; j < markers.length && !isCanceled(); j++) {
markers[j].delete();
worked(1);
}
done();
} catch (CoreException e) {
throw new CommandException(e);
}
}
use of name.herlin.command.CommandException in project pmd-eclipse-plugin by pmd.
the class DetectCutAndPasteCmd method renderReport.
/**
* Renders a report using the matches of the CPD. Creates a report folder
* and report file.
*
* @param matches
* matches of the CPD
* @throws CommandException
*/
private void renderReport(Iterator<Match> matches) throws CommandException {
InputStream contentsStream = null;
try {
LOG.debug("Rendering CPD report");
subTask("Rendering CPD report");
final String reportString = renderer.render(matches);
// Create the report folder if not already existing
LOG.debug("Create the report folder");
final IFolder folder = getProjectFolder(PMDRuntimeConstants.REPORT_FOLDER);
if (!folder.exists()) {
folder.create(true, true, getMonitor());
}
// Create the report file
LOG.debug("Create the report file");
final IFile reportFile = folder.getFile(reportName);
contentsStream = new ByteArrayInputStream(reportString.getBytes());
if (reportFile.exists()) {
LOG.debug(" Overwriting report file");
reportFile.setContents(contentsStream, true, false, getMonitor());
} else {
LOG.debug(" Creating report file");
reportFile.create(contentsStream, true, getMonitor());
}
reportFile.refreshLocal(IResource.DEPTH_INFINITE, getMonitor());
} catch (CoreException e) {
LOG.debug("Core Exception: " + e.getMessage(), e);
throw new CommandException(e);
} finally {
IOUtil.closeQuietly(contentsStream);
}
}
use of name.herlin.command.CommandException in project pmd-eclipse-plugin by pmd.
the class CPDCheckProjectAction method detectCutAndPaste.
/**
* Run the DetectCutAndPaste command against the selected project
* and creates optionally the report file.
*
* @param project a project
* @param dialog the object of the dialog with the selected values
* @throws CommandException
*/
private void detectCutAndPaste(final IProject project, CPDCheckDialog dialog) {
final String selectedLanguage = dialog.getSelectedLanguage();
final int tilesize = dialog.getTileSize();
final boolean createReport = dialog.isCreateReportSelected();
final Renderer selectedRenderer = this.createRenderer(dialog.getSelectedFormat());
final String fileName = this.createFileName(dialog.getSelectedFormat());
final CPDView2 view = showView();
try {
final DetectCutAndPasteCmd detectCmd = new DetectCutAndPasteCmd();
detectCmd.setProject(project);
detectCmd.setCreateReport(createReport);
detectCmd.setLanguage(selectedLanguage);
detectCmd.setMinTileSize(tilesize);
detectCmd.setRenderer(selectedRenderer);
detectCmd.setReportName(fileName);
detectCmd.setUserInitiated(true);
detectCmd.addPropertyListener(view);
detectCmd.performExecute();
} catch (CommandException e) {
logError(getString(StringKeys.ERROR_PMD_EXCEPTION), e);
}
}
Aggregations