Skip to content

Commit c093cb4

Browse files
Phillip KrallPhillip Krall
authored andcommitted
Code clean up
1 parent 0f066b8 commit c093cb4

File tree

10 files changed

+33
-66
lines changed

10 files changed

+33
-66
lines changed

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

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import org.eclipse.ui.IWorkingSet;
4848
import org.eclipse.ui.ResourceWorkingSetFilter;
4949

50+
import name.herlin.command.Timer;
5051
import net.sourceforge.pmd.PMD;
5152
import net.sourceforge.pmd.PMDConfiguration;
5253
import net.sourceforge.pmd.PMDException;
@@ -55,7 +56,6 @@
5556
import net.sourceforge.pmd.Report.ProcessingError;
5657
import net.sourceforge.pmd.Rule;
5758
import net.sourceforge.pmd.RuleContext;
58-
import net.sourceforge.pmd.RuleSet;
5959
import net.sourceforge.pmd.RuleSetFactory;
6060
import net.sourceforge.pmd.RuleSetNotFoundException;
6161
import net.sourceforge.pmd.RuleSets;
@@ -78,8 +78,6 @@
7878
import net.sourceforge.pmd.util.datasource.DataSource;
7979
import net.sourceforge.pmd.util.datasource.ReaderDataSource;
8080

81-
import name.herlin.command.Timer;
82-
8381
/**
8482
* Factor some useful features for visitors
8583
*
@@ -216,17 +214,15 @@ public void worked(final int work) {
216214
/**
217215
* @return Returns the ruleSet.
218216
*/
219-
// TODO (pk) rename
220-
public RuleSets getRuleSet() {
217+
public RuleSets getRuleSets() {
221218
return this.ruleSets;
222219
}
223220

224221
/**
225222
* @param ruleSet
226223
* The ruleSet to set.
227224
*/
228-
// TODO (pk) Rename
229-
public void setRuleSet(final RuleSets ruleSets) {
225+
public void setRuleSets(final RuleSets ruleSets) {
230226
this.ruleSets = ruleSets;
231227
}
232228

@@ -295,7 +291,7 @@ protected final void reviewResource(IResource resource) {
295291
}
296292

297293
final File sourceCodeFile = file.getRawLocation().toFile();
298-
if (included && getRuleSet().applies(sourceCodeFile) && isFileInWorkingSet(file)
294+
if (included && getRuleSets().applies(sourceCodeFile) && isFileInWorkingSet(file)
299295
&& languageVersion != null) {
300296
subTask("PMD checking: " + file.getName());
301297

@@ -309,25 +305,14 @@ protected final void reviewResource(IResource resource) {
309305
// getPmdEngine().processFile(sourceCodeFile, getRuleSet(),
310306
// context);
311307

312-
DataSource dataSource = new ReaderDataSource(input, file.getName());
308+
DataSource dataSource = new ReaderDataSource(input, file.getRawLocation().toFile().getPath());
313309
RuleSetFactory ruleSetFactory = new RuleSetFactory() {
314310
@Override
315311
public synchronized RuleSets createRuleSets(String referenceString)
316312
throws RuleSetNotFoundException {
317-
return new RuleSets(getRuleSet());
313+
return new RuleSets(getRuleSets());
318314
}
319315
};
320-
321-
System.out.println("");
322-
System.out.println("");
323-
System.out.println("");
324-
System.out.println("");
325-
System.out.println("(pk): " + sourceCodeFile.getName());
326-
for(RuleSet ruleSet: new RuleSets(getRuleSet()).getAllRuleSets()) {
327-
System.out.println("(pk): " + ruleSet.getName());
328-
System.out.println("(pk): " + ruleSet.getExcludePatterns());
329-
System.out.println("(pk): " + ruleSet.getRules().size());
330-
}
331316
// need to disable multi threading, as the ruleset is
332317
// not recreated and shared between threads...
333318
// but as we anyway have only one file to process, it won't hurt
@@ -352,7 +337,6 @@ public void start() throws IOException {
352337
@Override
353338
public void renderFileReport(Report report) throws IOException {
354339
for (RuleViolation v : report) {
355-
System.out.println("(pk): " + v.getRule().getName() );
356340
collectingReport.addRuleViolation(v);
357341
}
358342
for (Iterator<ProcessingError> it = report.errors(); it.hasNext();) {

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ private void processResource(IResource resource) throws CommandException {
476476
if (resource.exists()) {
477477
final ResourceVisitor visitor = new ResourceVisitor();
478478
visitor.setMonitor(getMonitor());
479-
visitor.setRuleSet(ruleSets);
479+
visitor.setRuleSets(ruleSets);
480480
// visitor.setPmdEngine(pmdEngine);
481481
visitor.setAccumulator(markersByFile);
482482
visitor.setUseTaskMarker(taskMarker);
@@ -560,8 +560,6 @@ private void taskScope(int activeRuleCount, int totalRuleCount) {
560560
}
561561

562562
private RuleSet filteredRuleSet(IProjectProperties properties) throws CommandException, PropertiesException {
563-
564-
// TODO (pk) Is this ok?
565563
final RuleSet ruleSet = properties.getProjectRuleSets().getAllRuleSets()[0];
566564
IPreferences preferences = PMDPlugin.getDefault().getPreferencesManager().loadPreferences();
567565
Set<String> onlyActiveRuleNames = preferences.getActiveRuleNames();
@@ -625,10 +623,9 @@ private void processResourceDelta() throws CommandException {
625623
setStepCount(targetCount);
626624
LOG.debug("Visiting delta of resource " + resource.getName() + " : " + getStepCount());
627625

628-
for(RuleSet ruleSet: ruleSets.getAllRuleSets()) {
629626
DeltaVisitor visitor = new DeltaVisitor();
630627
visitor.setMonitor(getMonitor());
631-
visitor.setRuleSet(ruleSets);
628+
visitor.setRuleSets(ruleSets);
632629
// visitor.setPmdEngine(pmdEngine);
633630
visitor.setAccumulator(markersByFile);
634631
visitor.setUseTaskMarker(taskMarker);
@@ -638,7 +635,6 @@ private void processResourceDelta() throws CommandException {
638635
ruleCount = ruleSets.getAllRules().size();
639636
fileCount += visitor.getProcessedFilesCount();
640637
pmdDuration += visitor.getActualPmdDuration();
641-
}
642638
} else {
643639
String message = "Skipping resourceDelta " + resource.getName()
644640
+ " because of fullBuildEnabled flag and " + "targetCount is " + targetCount

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/runtime/preferences/impl/PreferencesManagerImpl.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -641,20 +641,14 @@ private void updateConfiguredProjects(RuleSet updatedRuleSet) {
641641
RuleSets projectRuleSet = properties.getProjectRuleSets();
642642
if (projectRuleSet != null) {
643643
projectRuleSet.getAllRules().addAll(getNewRules(updatedRuleSet));
644-
//projectRuleSet = RuleSetUtil.addRules(projectRuleSet, getNewRules(updatedRuleSet));
645-
// TODO (pk) Is this wrong?
646644
for(RuleSet rs : projectRuleSet.getAllRuleSets()) {
647645
rs = RuleSetUtil.setExcludePatterns(rs,
648646
updatedRuleSet.getExcludePatterns());
649647
rs = RuleSetUtil.setIncludePatterns(rs,
650648
updatedRuleSet.getIncludePatterns());
651649
}
652-
// projectRuleSet = RuleSetUtil.setExcludePatterns(projectRuleSet,
653-
// updatedRuleSet.getExcludePatterns());
654-
// projectRuleSet = RuleSetUtil.setIncludePatterns(projectRuleSet,
655-
// updatedRuleSet.getIncludePatterns());
656-
properties.setProjectRuleSets(projectRuleSet);
657-
properties.sync();
650+
properties.setProjectRuleSets(projectRuleSet);
651+
properties.sync();
658652
}
659653
} catch (PropertiesException e) {
660654
PMDPlugin.getDefault().logError("Unable to add new rules for project: " + project, e);

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/runtime/properties/impl/ProjectPropertiesImpl.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ public void setProjectRuleSets(final RuleSets projectRuleSets) throws Properties
188188
throw new PropertiesException("Setting a project rule set to null");
189189
}
190190

191-
// TODO (pk) Think about needing to rebuild and some of the issues I have seen
192191
this.needRebuild = true;
193192
this.projectRuleSets = projectRuleSets;
194193
if (this.ruleSetStoredInProject) {
@@ -464,8 +463,7 @@ public String toString() {
464463
projectName = project.getName();
465464
}
466465
if (projectRuleSets != null) {
467-
// TODO (pk) Need to figure out what I am doing for a name here.
468-
projectRuleSetName = "NO NAME PHILL";//projectRuleSets.getName();
466+
projectRuleSetName = projectRuleSets.getAllRuleSets()[0].getName();
469467
}
470468
if (projectWorkingSet != null) {
471469
projectWorkingSetName = projectWorkingSet.getName();

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/runtime/properties/impl/ProjectPropertiesManagerImpl.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -435,10 +435,8 @@ private boolean synchronizeRuleSet(IProjectProperties projectProperties)
435435
// 1-If rules have been deleted from preferences, delete them also
436436
// from the project ruleset
437437
// 2-For all other rules, replace the current one by the plugin one
438-
// TODO (pk) Figure otu what needs done here
439-
// RuleSet newRuleSet = RuleSetUtil.newEmpty(projectRuleSet.getName(),
440-
// projectRuleSet.getDescription());
441-
RuleSet newRuleSet = RuleSetUtil.newEmpty("PHILL NAME", "PHILL DESC");
438+
RuleSet ruleset = projectRuleSet.getAllRuleSets()[0];
439+
RuleSet newRuleSet = RuleSetUtil.newEmpty(ruleset.getName(), ruleset.getDescription());
442440
List<Rule> newRules = new ArrayList<Rule>();
443441
List<Rule> haystack = new ArrayList<Rule>(pluginRuleSet.getRules());
444442
for (Rule projectRule : projectRuleSet.getAllRules()) {
@@ -454,7 +452,7 @@ private boolean synchronizeRuleSet(IProjectProperties projectProperties)
454452
haystack.remove(pluginRule);
455453
}
456454
}
457-
newRuleSet = RuleSetUtil.addRules(newRuleSet, newRules);
455+
newRuleSet = RuleSetUtil.addRules(newRuleSet, projectRuleSet.getAllRules());
458456

459457
if (!newRuleSet.getRules().equals(projectRuleSet.getAllRules())) {
460458
LOG.info("Set the project ruleset according to preferences.");

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/properties/PMDProjectPropertyPage.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ public void widgetSelected(SelectionEvent e) {
555555
*/
556556
private void populateAvailableRulesTable() {
557557
availableRulesTableViewer.setInput(controller.getAvailableRules());
558-
final RuleSets activeRuleSet = model.getProjectRuleSet();
558+
final RuleSets activeRuleSet = model.getProjectRuleSets();
559559
if (activeRuleSet != null) {
560560
final Collection<Rule> activeRules = activeRuleSet.getAllRules();
561561

@@ -579,7 +579,7 @@ public boolean performOk() {
579579
model.setProjectWorkingSet(selectedWorkingSet);
580580
RuleSets ruleSets = new RuleSets();
581581
ruleSets.addRuleSet(getProjectRuleSet());
582-
model.setProjectRuleSet(ruleSets);
582+
model.setProjectRuleSets(ruleSets);
583583
model.setRuleSetStoredInProject(ruleSetStoredInProjectButton.getSelection());
584584
model.setRuleSetFile(ruleSetFileText.getText());
585585
model.setIncludeDerivedFiles(includeDerivedFilesButton.getSelection());
@@ -614,7 +614,7 @@ private RuleSet getProjectRuleSet() {
614614
}
615615
}
616616

617-
final RuleSets activeRuleSet = model.getProjectRuleSet();
617+
final RuleSets activeRuleSet = model.getProjectRuleSets();
618618
for(RuleSet rs : activeRuleSet.getAllRuleSets()) {
619619
ruleSet = RuleSetUtil.addExcludePatterns(ruleSet, rs.getExcludePatterns());
620620
ruleSet = RuleSetUtil.addIncludePatterns(ruleSet, rs.getIncludePatterns());

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/properties/PMDPropertyPage.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ public void widgetSelected(SelectionEvent e) {
467467
*/
468468
private void populateAvailableRulesTable() {
469469
availableRulesTableViewer.setInput(controller.getAvailableRules());
470-
final RuleSets activeRuleSet = model.getProjectRuleSet();
470+
final RuleSets activeRuleSet = model.getProjectRuleSets();
471471
if (activeRuleSet != null) {
472472
final Collection<Rule> activeRules = activeRuleSet.getAllRules();
473473

@@ -491,7 +491,7 @@ public boolean performOk() {
491491
model.setProjectWorkingSet(selectedWorkingSet);
492492
RuleSets ruleSets = new RuleSets();
493493
ruleSets.addRuleSet(getProjectRuleSet());
494-
model.setProjectRuleSet(ruleSets);
494+
model.setProjectRuleSets(ruleSets);
495495
model.setRuleSetStoredInProject(ruleSetStoredInProjectButton.getSelection());
496496
model.setRuleSetFile(ruleSetFileText.getText());
497497
model.setIncludeDerivedFiles(includeDerivedFilesButton.getSelection());
@@ -526,7 +526,7 @@ private RuleSet getProjectRuleSet() {
526526
}
527527
}
528528

529-
final RuleSets activeRuleSet = model.getProjectRuleSet();
529+
final RuleSets activeRuleSet = model.getProjectRuleSets();
530530
for(RuleSet rs : activeRuleSet.getAllRuleSets()) {
531531
ruleSet = RuleSetUtil.addExcludePatterns(ruleSet, rs.getExcludePatterns());
532532
ruleSet = RuleSetUtil.addIncludePatterns(ruleSet, rs.getIncludePatterns());

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/properties/PMDPropertyPageBean.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838

3939
import org.eclipse.ui.IWorkingSet;
4040

41-
import net.sourceforge.pmd.RuleSet;
4241
import net.sourceforge.pmd.RuleSets;
4342

4443
/**
@@ -50,7 +49,7 @@
5049
public class PMDPropertyPageBean {
5150
private boolean pmdEnabled;
5251
private IWorkingSet projectWorkingSet;
53-
private RuleSets projectRuleSet;
52+
private RuleSets projectRuleSets;
5453
private boolean ruleSetStoredInProject;
5554
private String ruleSetFile;
5655
private boolean includeDerivedFiles;
@@ -75,17 +74,16 @@ public void setPmdEnabled(final boolean pmdEnabled) {
7574
/**
7675
* @return Returns the projectRuleSet.
7776
*/
78-
public RuleSets getProjectRuleSet() {
79-
return projectRuleSet;
77+
public RuleSets getProjectRuleSets() {
78+
return projectRuleSets;
8079
}
8180

8281
/**
8382
* @param projectRuleSet
8483
* The projectRuleSet to set.
8584
*/
86-
// TODO (pk) rename this
87-
public void setProjectRuleSet(final RuleSets projectRuleSet) {
88-
this.projectRuleSet = projectRuleSet;
85+
public void setProjectRuleSets(final RuleSets projectRuleSets) {
86+
this.projectRuleSets = projectRuleSets;
8987
}
9088

9189
/**

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/properties/PMDPropertyPageController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public PMDPropertyPageBean getPropertyPageBean() {
115115
propertyPageBean = new PMDPropertyPageBean();
116116
propertyPageBean.setPmdEnabled(properties.isPmdEnabled());
117117
propertyPageBean.setProjectWorkingSet(properties.getProjectWorkingSet());
118-
propertyPageBean.setProjectRuleSet(properties.getProjectRuleSets());
118+
propertyPageBean.setProjectRuleSets(properties.getProjectRuleSets());
119119
propertyPageBean.setRuleSetStoredInProject(properties.isRuleSetStoredInProject());
120120
propertyPageBean.setRuleSetFile(properties.getRuleSetFile());
121121
propertyPageBean.setIncludeDerivedFiles(properties.isIncludeDerivedFiles());
@@ -154,7 +154,7 @@ public boolean performOk() {
154154
cmd.setProject(project);
155155
cmd.setPmdEnabled(propertyPageBean.isPmdEnabled());
156156
cmd.setProjectWorkingSet(propertyPageBean.getProjectWorkingSet());
157-
cmd.setProjectRuleSet(propertyPageBean.getProjectRuleSet());
157+
cmd.setProjectRuleSets(propertyPageBean.getProjectRuleSets());
158158
cmd.setRuleSetStoredInProject(propertyPageBean.isRuleSetStoredInProject());
159159
cmd.setRuleSetFile(propertyPageBean.getRuleSetFile());
160160
cmd.setIncludeDerivedFiles(propertyPageBean.isIncludeDerivedFiles());

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/properties/UpdateProjectPropertiesCmd.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public class UpdateProjectPropertiesCmd extends AbstractProjectCommand {
5757
// private IProject project;
5858
private boolean pmdEnabled;
5959
private IWorkingSet projectWorkingSet;
60-
private RuleSets projectRuleSet;
60+
private RuleSets projectRuleSets;
6161
private boolean ruleSetStoredInProject;
6262
private String ruleSetFile;
6363
private boolean needRebuild;
@@ -84,7 +84,7 @@ public void execute() throws CommandException {
8484
try {
8585
final IProjectProperties properties = projectProperties();
8686
properties.setPmdEnabled(pmdEnabled);
87-
properties.setProjectRuleSets(projectRuleSet);
87+
properties.setProjectRuleSets(projectRuleSets);
8888
properties.setProjectWorkingSet(projectWorkingSet);
8989
properties.setRuleSetStoredInProject(ruleSetStoredInProject);
9090
properties.setRuleSetFile(ruleSetFile);
@@ -114,9 +114,8 @@ public void setPmdEnabled(final boolean pmdEnabled) {
114114
* @param projectRuleSet
115115
* The projectRuleSet to set.
116116
*/
117-
// TODO (pk) rename this
118-
public void setProjectRuleSet(final RuleSets projectRuleSet) {
119-
this.projectRuleSet = projectRuleSet;
117+
public void setProjectRuleSets(final RuleSets projectRuleSets) {
118+
this.projectRuleSets = projectRuleSets;
120119
}
121120

122121
/**
@@ -188,7 +187,7 @@ public boolean isRuleSetFileExists() {
188187
public void reset() {
189188
setProject(null);
190189
setPmdEnabled(false);
191-
setProjectRuleSet(null);
190+
setProjectRuleSets(null);
192191
setRuleSetStoredInProject(false);
193192
setRuleSetFile(null);
194193
setIncludeDerivedFiles(false);
@@ -201,6 +200,6 @@ public void reset() {
201200
* @see name.herlin.command.Command#isReadyToExecute()
202201
*/
203202
public boolean isReadyToExecute() {
204-
return super.isReadyToExecute() && projectRuleSet != null;
203+
return super.isReadyToExecute() && projectRuleSets != null;
205204
}
206205
}

0 commit comments

Comments
 (0)