Search in sources :

Example 11 with CommandException

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);
                    }
                }
            });
        }
    }
}
Also used : RuleSet(net.sourceforge.pmd.RuleSet) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) RuleSets(net.sourceforge.pmd.RuleSets) SourceCodeProcessor(net.sourceforge.pmd.SourceCodeProcessor) PMDException(net.sourceforge.pmd.PMDException) CommandException(name.herlin.command.CommandException) File(java.io.File) IFile(org.eclipse.core.resources.IFile) IPropertyListener(org.eclipse.ui.IPropertyListener) PMDConfiguration(net.sourceforge.pmd.PMDConfiguration)

Example 12 with CommandException

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);
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) PropertiesException(net.sourceforge.pmd.eclipse.runtime.properties.PropertiesException) CommandException(name.herlin.command.CommandException)

Example 13 with CommandException

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);
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) CommandException(name.herlin.command.CommandException)

Example 14 with CommandException

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);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) CommandException(name.herlin.command.CommandException) IFolder(org.eclipse.core.resources.IFolder)

Example 15 with CommandException

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);
    }
}
Also used : CPDView2(net.sourceforge.pmd.eclipse.ui.views.cpd2.CPDView2) DetectCutAndPasteCmd(net.sourceforge.pmd.eclipse.runtime.cmd.DetectCutAndPasteCmd) XMLRenderer(net.sourceforge.pmd.cpd.XMLRenderer) CSVRenderer(net.sourceforge.pmd.cpd.CSVRenderer) Renderer(net.sourceforge.pmd.cpd.Renderer) SimpleRenderer(net.sourceforge.pmd.cpd.SimpleRenderer) 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