Skip to content

Commit c0c3f40

Browse files
committed
#1435 PMD Eclipse is not executed if "Full build" is not enabled
1 parent a4d6125 commit c0c3f40

File tree

3 files changed

+27
-25
lines changed

3 files changed

+27
-25
lines changed

ReleaseNotes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Eclipse Update Site: <https://sourceforge.net/projects/pmd/files/pmd-eclipse/upd
88

99
* Updated PMD to 5.3.4
1010
* Fixed PMD-Plugin does not work if run with IBM JDK 1.7.0 ([bug #1419](https://sourceforge.net/p/pmd/bugs/1419/))
11+
* Fixed PMD Eclipse is not executed if "Full build" is not enabled ([bug #1435](https://sourceforge.net/p/pmd/bugs/1435/))
1112

1213
**API Changes**:
1314

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/plugin/FileChangeReviewer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public boolean equals(Object other) {
6969
public void resourceChanged(IResourceChangeEvent event) {
7070
IWorkspaceDescription workspaceSettings = ResourcesPlugin.getWorkspace().getDescription();
7171
if (workspaceSettings.isAutoBuilding()) {
72-
PMDPlugin.getDefault().logInformation("Not running PMD, as autoBuilding is enabled for this workspace");
72+
PMDPlugin.getDefault().logInformation("Not running PMD via FileChangeReviewer, as autoBuilding is enabled for this workspace");
7373
return;
7474
}
7575

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/runtime/cmd/ReviewCodeCmd.java

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@
5454
import net.sourceforge.pmd.eclipse.runtime.properties.IProjectProperties;
5555
import net.sourceforge.pmd.eclipse.runtime.properties.PropertiesException;
5656
import net.sourceforge.pmd.eclipse.ui.actions.RuleSetUtil;
57-
import net.sourceforge.pmd.lang.LanguageRegistry;
58-
import net.sourceforge.pmd.lang.java.JavaLanguageModule;
5957
import net.sourceforge.pmd.util.StringUtil;
6058

6159
import 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

Comments
 (0)