5454import net .sourceforge .pmd .eclipse .runtime .properties .IProjectProperties ;
5555import net .sourceforge .pmd .eclipse .runtime .properties .PropertiesException ;
5656import net .sourceforge .pmd .eclipse .ui .actions .RuleSetUtil ;
57- import net .sourceforge .pmd .lang .LanguageRegistry ;
58- import net .sourceforge .pmd .lang .java .JavaLanguageModule ;
5957import net .sourceforge .pmd .util .StringUtil ;
6058
6159import org .apache .log4j .Logger ;
@@ -104,6 +102,11 @@ public class ReviewCodeCmd extends AbstractDefaultCommand {
104102 private String onErrorIssue = null ;
105103 /** Whether to run the review command, even if PMD is disabled in the project settings. */
106104 private boolean runAlways = false ;
105+ /**
106+ * Maximum count of changed resources, that are considered to be not a full build.
107+ * If more than these resources are changed, PMD will only be executed, if full build option is enabled.
108+ */
109+ private static final int MAXIMUM_RESOURCE_COUNT = 5 ;
107110
108111 private IProjectProperties propertyCache = null ;
109112
@@ -401,7 +404,7 @@ private void processResource(IResource resource) throws CommandException {
401404 targetCount = countResourceElement (resource );
402405 }
403406 // Could add a property that lets us set the max number to analyze
404- if (properties .isFullBuildEnabled () || isUserInitiated () || targetCount == 1 ) {
407+ if (properties .isFullBuildEnabled () || isUserInitiated () || targetCount <= MAXIMUM_RESOURCE_COUNT ) {
405408 setStepCount (targetCount );
406409 log .debug ("Visiting resource " + resource .getName () + " : " + getStepCount ());
407410
@@ -422,7 +425,10 @@ private void processResource(IResource resource) throws CommandException {
422425 log .debug ("Skipping resource " + resource .getName () + " because it doesn't exist." );
423426 }
424427 } else {
425- log .debug ("Skipping resource " + resource .getName () + " because of fullBuildEnabled flag" );
428+ String message = "Skipping resource " + resource .getName () + " because of fullBuildEnabled flag and "
429+ + "targetCount is " + targetCount + ". This is more than " + MAXIMUM_RESOURCE_COUNT + "."
430+ + " If you want to execute PMD, please check \" Full build enabled\" in the project settings" ;
431+ PMDPlugin .getDefault ().logInformation (message );
426432 }
427433
428434 worked (1 ); // TODO - temp fix? BR
@@ -536,7 +542,7 @@ private void processResourceDelta() throws CommandException {
536542 // PMDEngine pmdEngine = getPmdEngineForProject(project);
537543 int targetCount = countDeltaElement (resourceDelta );
538544 // Could add a property that lets us set the max number to analyze
539- if (properties .isFullBuildEnabled () || isUserInitiated () || targetCount == 1 ) {
545+ if (properties .isFullBuildEnabled () || isUserInitiated () || targetCount <= MAXIMUM_RESOURCE_COUNT ) {
540546 setStepCount (targetCount );
541547 log .debug ("Visiting delta of resource " + resource .getName () + " : " + getStepCount ());
542548
@@ -553,7 +559,11 @@ private void processResourceDelta() throws CommandException {
553559 fileCount += visitor .getProcessedFilesCount ();
554560 pmdDuration += visitor .getActualPmdDuration ();
555561 } else {
556- log .debug ("Skipping resource " + resource .getName () + " because of fullBuildEnabled flag" );
562+ String message = "Skipping resourceDelta " + resource .getName () + " because of fullBuildEnabled flag and "
563+ + "targetCount is " + targetCount + ". This is more than " + MAXIMUM_RESOURCE_COUNT + "."
564+ + " If you want to execute PMD, please check \" Full build enabled\" in the project settings" ;
565+ PMDPlugin .getDefault ().logInformation (message );
566+ log .debug (message );
557567 }
558568
559569 } catch (PropertiesException e ) {
@@ -610,7 +620,7 @@ private void applyMarkers() {
610620 private int countResourceElement (IResource resource ) {
611621
612622 if (resource instanceof IFile ) {
613- return isSuitable (( IFile ) resource ) ? 1 : 0 ;
623+ return 1 ;
614624 }
615625
616626 final CountVisitor visitor = new CountVisitor ();
@@ -637,7 +647,7 @@ private int countDeltaElement(IResourceDelta delta) {
637647 try {
638648 delta .accept (visitor );
639649 } catch (CoreException e ) {
640- logError ("Exception counting elemnts in a delta selection" , e );
650+ logError ("Exception counting elements in a delta selection" , e );
641651 }
642652
643653 return visitor .count ;
@@ -655,32 +665,23 @@ private static void switchToPmdPerspective() {
655665 window .getActivePage ().setPerspective (reg .findPerspectiveWithId (PMDRuntimeConstants .ID_PERSPECTIVE ));
656666 }
657667
658- private static boolean isSuitable (IFile file ) {
659- return isLanguageFile (file , LanguageRegistry .getLanguage (JavaLanguageModule .NAME ));
660- }
661-
662668 /**
663- * Private inner class to count the number of resources or delta elements
669+ * Private inner class to count the number of resources or delta elements.
670+ * Only files are counted.
664671 */
665672 private final class CountVisitor implements IResourceVisitor , IResourceDeltaVisitor {
666673 public int count = 0 ;
667674
668675 public boolean visit (IResource resource ) {
669- boolean fVisitChildren = true ;
670- count ++;
671-
672- if (resource instanceof IFile && isSuitable ((IFile ) resource )) {
673-
674- fVisitChildren = false ;
676+ if (resource instanceof IFile ) {
677+ count ++;
675678 }
676-
677- return fVisitChildren ;
679+ return true ;
678680 }
679681
680- // @PMD:REVIEWED:UnusedFormalParameter: by Herlin on 10/05/05 23:46
681682 public boolean visit (IResourceDelta delta ) {
682- count ++ ;
683- return true ;
683+ IResource resource = delta . getResource () ;
684+ return visit ( resource ) ;
684685 }
685686 }
686687
0 commit comments