Improve progress indicator accuracy
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@1990 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -17,6 +17,9 @@ import org.eclipse.core.runtime.IProgressMonitor;
|
||||
* @author Philippe Herlin
|
||||
* @version $Revision$
|
||||
* $Log$
|
||||
* Revision 1.5 2003/06/19 20:56:59 phherlin
|
||||
* Improve progress indicator accuracy
|
||||
*
|
||||
* Revision 1.4 2003/05/19 22:27:32 phherlin
|
||||
* Refactoring to improve performance
|
||||
*
|
||||
@ -59,6 +62,11 @@ public class PMDDeltaVisitor implements IResourceDeltaVisitor {
|
||||
} else { // other kinds are not visited
|
||||
log.debug("Resource " + delta.getResource().getName() + " not visited.");
|
||||
}
|
||||
|
||||
if (monitor != null) {
|
||||
monitor.worked(1);
|
||||
log.debug("Monitor worked");
|
||||
}
|
||||
} else {
|
||||
fProcessChildren = false;
|
||||
}
|
||||
@ -96,10 +104,6 @@ public class PMDDeltaVisitor implements IResourceDeltaVisitor {
|
||||
}
|
||||
|
||||
PMDProcessor.getInstance().run((IFile) resource, useTaskMarker, getAccumulator());
|
||||
|
||||
if (monitor != null) {
|
||||
monitor.worked(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -30,6 +30,9 @@ import org.eclipse.core.runtime.CoreException;
|
||||
* @version $Revision$
|
||||
*
|
||||
* $Log$
|
||||
* Revision 1.6 2003/06/19 20:56:59 phherlin
|
||||
* Improve progress indicator accuracy
|
||||
*
|
||||
* Revision 1.5 2003/05/19 22:26:58 phherlin
|
||||
* Updating PMD engine to v1.05
|
||||
* Refactoring to improve performance
|
||||
@ -83,7 +86,8 @@ public class PMDProcessor {
|
||||
} catch (CoreException e) {
|
||||
PMDPlugin.getDefault().showError(getMessage(PMDConstants.MSGKEY_ERROR_CORE_EXCEPTION), e);
|
||||
} catch (PMDException e) {
|
||||
log.warn(getMessage(PMDConstants.MSGKEY_ERROR_PMD_EXCEPTION), e);
|
||||
log.warn(getMessage(PMDConstants.MSGKEY_ERROR_PMD_EXCEPTION));
|
||||
log.debug("", e);
|
||||
} finally {
|
||||
log.info("Processing done");
|
||||
}
|
||||
|
@ -22,6 +22,9 @@ import org.eclipse.core.runtime.IProgressMonitor;
|
||||
* @version $Revision$
|
||||
*
|
||||
* $Log$
|
||||
* Revision 1.13 2003/06/19 20:56:59 phherlin
|
||||
* Improve progress indicator accuracy
|
||||
*
|
||||
* Revision 1.12 2003/05/19 22:27:32 phherlin
|
||||
* Refactoring to improve performance
|
||||
*
|
||||
@ -58,19 +61,21 @@ public class PMDVisitor implements IResourceVisitor {
|
||||
if ((resource instanceof IFile)
|
||||
&& (((IFile) resource).getFileExtension() != null)
|
||||
&& ((IFile) resource).getFileExtension().equals("java")) {
|
||||
|
||||
|
||||
if (monitor != null) {
|
||||
monitor.subTask(((IFile) resource).getName());
|
||||
}
|
||||
|
||||
|
||||
PMDProcessor.getInstance().run((IFile) resource, useTaskMarker, getAccumulator());
|
||||
|
||||
if (monitor != null) {
|
||||
monitor.worked(1);
|
||||
}
|
||||
|
||||
|
||||
fVisitChildren = false;
|
||||
}
|
||||
|
||||
if (monitor != null) {
|
||||
monitor.worked(1);
|
||||
log.debug("Monitor worked");
|
||||
}
|
||||
|
||||
} else {
|
||||
fVisitChildren = false;
|
||||
}
|
||||
|
@ -7,10 +7,11 @@ import net.sourceforge.pmd.eclipse.PMDConstants;
|
||||
import net.sourceforge.pmd.eclipse.PMDPlugin;
|
||||
import net.sourceforge.pmd.eclipse.PMDVisitor;
|
||||
import net.sourceforge.pmd.eclipse.PMDVisitorRunner;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IResourceVisitor;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.jdt.core.ICompilationUnit;
|
||||
@ -33,6 +34,9 @@ import org.eclipse.ui.IWorkbenchPart;
|
||||
* @version $Revision$
|
||||
*
|
||||
* $Log$
|
||||
* Revision 1.6 2003/06/19 20:58:13 phherlin
|
||||
* Improve progress indicator accuracy
|
||||
*
|
||||
* Revision 1.5 2003/05/19 22:27:33 phherlin
|
||||
* Refactoring to improve performance
|
||||
*
|
||||
@ -95,9 +99,9 @@ public class PMDCheckAction implements IObjectActionDelegate {
|
||||
|
||||
if (sel instanceof IStructuredSelection) {
|
||||
IStructuredSelection structuredSel = (IStructuredSelection) sel;
|
||||
monitor.beginTask(
|
||||
PMDPlugin.getDefault().getMessage(PMDConstants.MSGKEY_PMD_PROCESSING),
|
||||
structuredSel.toArray().length);
|
||||
int elementCount = countElement(structuredSel);
|
||||
monitor.beginTask(PMDPlugin.getDefault().getMessage(PMDConstants.MSGKEY_PMD_PROCESSING), elementCount);
|
||||
log.debug("Monitor beginTask(" + elementCount + ")");
|
||||
|
||||
for (Iterator i = structuredSel.iterator(); i.hasNext();) {
|
||||
Object element = i.next();
|
||||
@ -119,7 +123,6 @@ public class PMDCheckAction implements IObjectActionDelegate {
|
||||
new PMDVisitorRunner().run(resource, visitor);
|
||||
} else { // else no processing for other types
|
||||
log.info(element.getClass().getName() + " : PMD check on this resource's type is not supported");
|
||||
monitor.worked(1);
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
PMDPlugin.getDefault().showError(
|
||||
@ -129,7 +132,62 @@ public class PMDCheckAction implements IObjectActionDelegate {
|
||||
}
|
||||
|
||||
monitor.done();
|
||||
log.debug("Monitor done");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Count the number of resources of a selection
|
||||
* @param selection a selection
|
||||
* @return the element count
|
||||
*/
|
||||
private int countElement(IStructuredSelection selection) {
|
||||
final class CountVisitor implements IResourceVisitor {
|
||||
public int count = 0;
|
||||
public boolean visit(IResource resource) {
|
||||
boolean fVisitChildren = true;
|
||||
count++;
|
||||
|
||||
if ((resource instanceof IFile)
|
||||
&& (((IFile) resource).getFileExtension() != null)
|
||||
&& ((IFile) resource).getFileExtension().equals("java")) {
|
||||
|
||||
fVisitChildren = false;
|
||||
}
|
||||
|
||||
return fVisitChildren;
|
||||
}
|
||||
};
|
||||
|
||||
CountVisitor visitor = new CountVisitor();
|
||||
|
||||
for (Iterator i = selection.iterator(); i.hasNext();) {
|
||||
Object element = i.next();
|
||||
|
||||
try {
|
||||
if (element instanceof IResource) {
|
||||
((IResource) element).accept(visitor);
|
||||
} else if (element instanceof ICompilationUnit) {
|
||||
IResource resource = ((ICompilationUnit) element).getResource();
|
||||
resource.accept(visitor);
|
||||
} else if (element instanceof IJavaProject) {
|
||||
IResource resource = ((IJavaProject) element).getResource();
|
||||
resource.accept(visitor);
|
||||
} else if (element instanceof IPackageFragment) {
|
||||
IResource resource = ((IPackageFragment) element).getResource();
|
||||
resource.accept(visitor);
|
||||
} else if (element instanceof PackageFragmentRoot) {
|
||||
IResource resource = ((PackageFragmentRoot) element).getResource();
|
||||
resource.accept(visitor);
|
||||
} else { // else no processing for other types
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
// Ignore any exception
|
||||
}
|
||||
}
|
||||
|
||||
return visitor.count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,8 +9,12 @@ import net.sourceforge.pmd.eclipse.PMDVisitor;
|
||||
import net.sourceforge.pmd.eclipse.PMDVisitorRunner;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IResourceDelta;
|
||||
import org.eclipse.core.resources.IResourceDeltaVisitor;
|
||||
import org.eclipse.core.resources.IResourceVisitor;
|
||||
import org.eclipse.core.resources.IncrementalProjectBuilder;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
@ -23,6 +27,9 @@ import org.eclipse.core.runtime.IProgressMonitor;
|
||||
* @version $Revision$
|
||||
*
|
||||
* $Log$
|
||||
* Revision 1.6 2003/06/19 20:58:33 phherlin
|
||||
* Improve progress indicator accuracy
|
||||
*
|
||||
* Revision 1.5 2003/05/19 22:27:33 phherlin
|
||||
* Refactoring to improve performance
|
||||
*
|
||||
@ -99,10 +106,13 @@ public class PMDBuilder extends IncrementalProjectBuilder {
|
||||
if (currentProject != null) {
|
||||
IResourceDelta resourceDelta = getDelta(currentProject);
|
||||
if ((resourceDelta != null) && (resourceDelta.getAffectedChildren().length != 0)) {
|
||||
monitor.beginTask(PMDPlugin.getDefault().getMessage(PMDConstants.MSGKEY_PMD_PROCESSING), IProgressMonitor.UNKNOWN);
|
||||
int elementCount = countDeltaElement(resourceDelta);
|
||||
monitor.beginTask(PMDPlugin.getDefault().getMessage(PMDConstants.MSGKEY_PMD_PROCESSING), elementCount);
|
||||
log.debug("Monitor beginTask(" + elementCount + ")");
|
||||
PMDDeltaVisitor visitor = new PMDDeltaVisitor(monitor);
|
||||
new PMDVisitorRunner().run(resourceDelta, visitor);
|
||||
monitor.done();
|
||||
log.debug("Monitor done");
|
||||
} else {
|
||||
log.info("No change reported. Performing a full build");
|
||||
result = buildFull(args, monitor);
|
||||
@ -118,10 +128,72 @@ public class PMDBuilder extends IncrementalProjectBuilder {
|
||||
* @param monitor a progress indicator
|
||||
*/
|
||||
private void processProjectFiles(IProject project, IProgressMonitor monitor) throws CoreException {
|
||||
monitor.beginTask(PMDPlugin.getDefault().getMessage(PMDConstants.MSGKEY_PMD_PROCESSING), IProgressMonitor.UNKNOWN);
|
||||
int elementCount = countProjectElement(project);
|
||||
monitor.beginTask(PMDPlugin.getDefault().getMessage(PMDConstants.MSGKEY_PMD_PROCESSING), elementCount);
|
||||
log.debug("Monitor beginTask(" + elementCount + ")");
|
||||
PMDVisitor visitor = new PMDVisitor(monitor);
|
||||
new PMDVisitorRunner().run(project, visitor);
|
||||
monitor.done();
|
||||
log.debug("Monitor done");
|
||||
}
|
||||
|
||||
/**
|
||||
* Count the number of sub-resources of a project
|
||||
* @param project a project
|
||||
* @return the element count
|
||||
*/
|
||||
private int countProjectElement(IProject project) {
|
||||
final class CountVisitor implements IResourceVisitor {
|
||||
public int count = 0;
|
||||
public boolean visit(IResource resource) {
|
||||
boolean fVisitChildren = true;
|
||||
count++;
|
||||
|
||||
if ((resource instanceof IFile)
|
||||
&& (((IFile) resource).getFileExtension() != null)
|
||||
&& ((IFile) resource).getFileExtension().equals("java")) {
|
||||
|
||||
fVisitChildren = false;
|
||||
}
|
||||
|
||||
return fVisitChildren;
|
||||
}
|
||||
};
|
||||
|
||||
CountVisitor visitor = new CountVisitor();
|
||||
|
||||
try {
|
||||
project.accept(visitor);
|
||||
} catch (CoreException e) {
|
||||
// no exception processing
|
||||
}
|
||||
|
||||
return visitor.count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Count the number of sub-resources of a delta
|
||||
* @param delta a resource delta
|
||||
* @return the element count
|
||||
*/
|
||||
private int countDeltaElement(IResourceDelta delta) {
|
||||
final class CountVisitor implements IResourceDeltaVisitor {
|
||||
public int count = 0;
|
||||
public boolean visit(IResourceDelta delta) {
|
||||
count++;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
CountVisitor visitor = new CountVisitor();
|
||||
|
||||
try {
|
||||
delta.accept(visitor);
|
||||
} catch (CoreException e) {
|
||||
// no exception processing
|
||||
}
|
||||
|
||||
return visitor.count;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user