Search in sources :

Example 16 with CommandException

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;
    }
}
Also used : ReviewCodeCmd(net.sourceforge.pmd.eclipse.runtime.cmd.ReviewCodeCmd) CommandException(name.herlin.command.CommandException) IResource(org.eclipse.core.resources.IResource)

Example 17 with CommandException

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

Example 18 with CommandException

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

Example 19 with CommandException

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

Example 20 with CommandException

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

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