Skip to content

Commit d384150

Browse files
Phillip KrallPhillip Krall
authored andcommitted
Code Clean up
1 parent c093cb4 commit d384150

File tree

11 files changed

+50
-56
lines changed

11 files changed

+50
-56
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@
77
import org.junit.Before;
88
import org.junit.Test;
99

10+
import name.herlin.command.CommandException;
1011
import net.sourceforge.pmd.Rule;
1112
import net.sourceforge.pmd.RuleSet;
1213
import net.sourceforge.pmd.RuleSetFactory;
14+
import net.sourceforge.pmd.RuleSets;
1315
import net.sourceforge.pmd.eclipse.EclipseUtils;
1416
import net.sourceforge.pmd.eclipse.plugin.PMDPlugin;
1517
import net.sourceforge.pmd.eclipse.runtime.properties.IProjectProperties;
1618
import net.sourceforge.pmd.eclipse.runtime.properties.IProjectPropertiesManager;
1719
import net.sourceforge.pmd.eclipse.runtime.properties.PropertiesException;
1820
import net.sourceforge.pmd.eclipse.ui.actions.RuleSetUtil;
1921

20-
import name.herlin.command.CommandException;
21-
2222
public class UpdateProjectPropertiesCmdTest {
2323
private IProject testProject;
2424

@@ -71,7 +71,8 @@ public void testBug() throws CommandException, PropertiesException {
7171
final UpdateProjectPropertiesCmd cmd = new UpdateProjectPropertiesCmd();
7272
cmd.setPmdEnabled(true);
7373
cmd.setProject(this.testProject);
74-
cmd.setProjectRuleSet(newRuleSet);
74+
RuleSets ruleSets = new RuleSets(newRuleSet);
75+
cmd.setProjectRuleSets(ruleSets);
7576
cmd.setProjectWorkingSet(null);
7677
cmd.setRuleSetStoredInProject(false);
7778
cmd.execute();

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import net.sourceforge.pmd.Report.ProcessingError;
5757
import net.sourceforge.pmd.Rule;
5858
import net.sourceforge.pmd.RuleContext;
59+
import net.sourceforge.pmd.RuleSet;
5960
import net.sourceforge.pmd.RuleSetFactory;
6061
import net.sourceforge.pmd.RuleSetNotFoundException;
6162
import net.sourceforge.pmd.RuleSets;
@@ -218,6 +219,24 @@ public RuleSets getRuleSets() {
218219
return this.ruleSets;
219220
}
220221

222+
/**
223+
* This returns the first ruleset file.
224+
* @return
225+
*/
226+
public RuleSet getRuleSet() {
227+
return this.ruleSets.getAllRuleSets()[0];
228+
}
229+
230+
/**
231+
* This removes all the Rulesets from the rulesets
232+
* and sets the only ruleset to the one passed in.
233+
*
234+
* @param ruleSet
235+
*/
236+
public void setRuleSet(RuleSet ruleSet) {
237+
this.ruleSets = new RuleSets(ruleSet);
238+
}
239+
221240
/**
222241
* @param ruleSet
223242
* The ruleSet to set.

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,6 @@ private void processResourceDelta() throws CommandException {
614614
logInfo("ReviewCodeCmd started on resource delta " + resource.getName() + " in project " + project.getName());
615615

616616
RuleSets ruleSets = properties.getProjectRuleSets();
617-
// RuleSet ruleSet = rulesetFromResourceDelta(); // properties.getProjectRuleSet();
618617

619618
// PMDEngine pmdEngine = getPmdEngineForProject(project);
620619
int targetCount = countDeltaElement(resourceDelta);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -639,15 +639,17 @@ private void updateConfiguredProjects(RuleSet updatedRuleSet) {
639639
try {
640640
IProjectProperties properties = PMDPlugin.getDefault().loadProjectProperties(project);
641641
RuleSets projectRuleSet = properties.getProjectRuleSets();
642+
RuleSets newProjectRuleSet = new RuleSets();
642643
if (projectRuleSet != null) {
643644
projectRuleSet.getAllRules().addAll(getNewRules(updatedRuleSet));
644645
for(RuleSet rs : projectRuleSet.getAllRuleSets()) {
645646
rs = RuleSetUtil.setExcludePatterns(rs,
646647
updatedRuleSet.getExcludePatterns());
647648
rs = RuleSetUtil.setIncludePatterns(rs,
648649
updatedRuleSet.getIncludePatterns());
650+
newProjectRuleSet.addRuleSet(rs);
649651
}
650-
properties.setProjectRuleSets(projectRuleSet);
652+
properties.setProjectRuleSets(newProjectRuleSet);
651653
properties.sync();
652654
}
653655
} catch (PropertiesException e) {
@@ -668,9 +670,7 @@ private void storeRuleSetInStateLocation(RuleSet ruleSet) {
668670
IPath ruleSetLocation = plugin.getStateLocation().append(PREFERENCE_RULESET_FILE);
669671
out = new FileOutputStream(ruleSetLocation.toOSString());
670672
IRuleSetWriter writer = plugin.getRuleSetWriter();
671-
RuleSets ruleSets = new RuleSets();
672-
ruleSets.addRuleSet(ruleSet);
673-
writer.write(out, ruleSets);
673+
writer.write(out, ruleSet);
674674
out.flush();
675675

676676
} catch (IOException e) {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.eclipse.core.resources.IProject;
4444
import org.eclipse.ui.IWorkingSet;
4545

46+
import net.sourceforge.pmd.RuleSet;
4647
import net.sourceforge.pmd.RuleSets;
4748

4849
/**
@@ -73,6 +74,11 @@ public interface IProjectProperties {
7374
* @return Returns the project Rule Set.
7475
*/
7576
RuleSets getProjectRuleSets() throws PropertiesException;
77+
78+
/**
79+
* @return Returns the first rule set in the project rulesets
80+
*/
81+
RuleSet getProjectRuleSet() throws PropertiesException;
7682

7783
/**
7884
* @param projectRuleSet

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import org.eclipse.ui.IWorkingSet;
5858

5959
import net.sourceforge.pmd.PMD;
60+
import net.sourceforge.pmd.RuleSet;
6061
import net.sourceforge.pmd.RuleSets;
6162
import net.sourceforge.pmd.eclipse.plugin.PMDPlugin;
6263
import net.sourceforge.pmd.eclipse.runtime.cmd.JavaProjectClassLoader;
@@ -177,6 +178,13 @@ public void setPmdEnabled(final boolean pmdEnabled) {
177178
public RuleSets getProjectRuleSets() throws PropertiesException {
178179
return projectRuleSets;
179180
}
181+
182+
/**
183+
* @see net.sourceforge.pmd.eclipse.runtime.properties.IProjectProperties#getProjectRuleSet()
184+
*/
185+
public RuleSet getProjectRuleSet() throws PropertiesException {
186+
return projectRuleSets.getAllRuleSets()[0];
187+
}
180188

181189
/**
182190
* @see net.sourceforge.pmd.eclipse.runtime.properties.IProjectProperties#setProjectRuleSet(net.sourceforge.pmd.RuleSet)
@@ -374,7 +382,9 @@ public void createDefaultRuleSetFile() throws PropertiesException {
374382
try {
375383
IRuleSetWriter writer = PMDPlugin.getDefault().getRuleSetWriter();
376384
baos = new ByteArrayOutputStream();
377-
writer.write(baos, projectRuleSets);
385+
for(RuleSet rs: projectRuleSets.getAllRuleSets()) {
386+
writer.write(baos, rs);
387+
}
378388

379389
final IFile file = project.getFile(PROJECT_RULESET_FILE);
380390
if (file.exists() && file.isAccessible()) {

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

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -180,38 +180,6 @@ private void loadRuleSetFromProject(IProjectProperties projectProperties)
180180
for (final File ruleSetFile : projectProperties.getResolvedRuleSetFile()) {
181181
RuleSet ruleSet = factory.createRuleSets(ruleSetFile.getPath()).getAllRuleSets()[0];
182182
allRulesets.addRuleSet(ruleSet);
183-
// This is the old rule stuff used to combine all the rulesets into one file.
184-
// if (allRuleSets == null) {
185-
// /* The first ruleset file */
186-
// allRuleSets = rs;
187-
// } else {
188-
// /*
189-
// * Loop through all the rules in an additional ruleset file. If a previous file
190-
// * has defined the rule, then remove it. If it is not found, then add the new
191-
// * rule.
192-
// */
193-
// List<Rule> rules = new ArrayList<Rule>(allRuleSets.getRules());
194-
// for (Rule rule2 : rs.getRules()) {
195-
// boolean processed = false;
196-
// for (Rule rule1 : allRuleSets.getRules()) {
197-
// if (rule2.getName().equals(rule1.getName())) {
198-
// for (Iterator<Rule> iter = rules.listIterator(); iter.hasNext();) {
199-
// Rule r = iter.next();
200-
// if (r.getName().equals(rule1.getName())) {
201-
// iter.remove();
202-
// }
203-
// }
204-
// rules.add(rule2);
205-
// processed = true;
206-
// }
207-
// if (!processed) {
208-
// rules.add(rule2);
209-
// }
210-
// }
211-
// }
212-
// allRuleSets.getRules().removeAll(allRuleSets.getRules());
213-
// allRuleSets.getRules().addAll(rules);
214-
// }
215183
}
216184
projectProperties.setProjectRuleSets(allRulesets);
217185
projectProperties.setNeedRebuild(false);

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/runtime/writer/IRuleSetWriter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
import java.io.OutputStream;
2727

28-
import net.sourceforge.pmd.RuleSets;
28+
import net.sourceforge.pmd.RuleSet;
2929

3030
/**
3131
* Interface for a rule set writer. A rule set writer is an object used to
@@ -44,5 +44,5 @@ public interface IRuleSetWriter {
4444
* @param ruleSet
4545
* the ruleset to serialize
4646
*/
47-
void write(OutputStream outputStream, RuleSets ruleSet) throws WriterException;
47+
void write(OutputStream outputStream, RuleSet ruleSet) throws WriterException;
4848
}

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/runtime/writer/impl/RuleSetWriterImpl.java

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

77
import net.sourceforge.pmd.RuleSet;
88
import net.sourceforge.pmd.RuleSetWriter;
9-
import net.sourceforge.pmd.RuleSets;
109
import net.sourceforge.pmd.eclipse.runtime.writer.IRuleSetWriter;
1110
import net.sourceforge.pmd.eclipse.runtime.writer.WriterException;
1211

@@ -27,12 +26,10 @@ class RuleSetWriterImpl implements IRuleSetWriter {
2726
* @param ruleSet
2827
* the ruleset to serialize
2928
*/
30-
public void write(OutputStream outputStream, RuleSets ruleSets) throws WriterException {
29+
public void write(OutputStream outputStream, RuleSet ruleSet) throws WriterException {
3130
try {
3231
RuleSetWriter ruleSetWriter = new RuleSetWriter(outputStream);
33-
for (RuleSet ruleSet : ruleSets.getAllRuleSets()) {
34-
ruleSetWriter.write(ruleSet);
35-
}
32+
ruleSetWriter.write(ruleSet);
3633
outputStream.flush();
3734
} catch (RuntimeException e) {
3835
throw new WriterException(e);

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/preferences/PMDPreferencePage.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646

4747
import net.sourceforge.pmd.Rule;
4848
import net.sourceforge.pmd.RuleSet;
49-
import net.sourceforge.pmd.RuleSets;
5049
import net.sourceforge.pmd.eclipse.plugin.PMDPlugin;
5150
import net.sourceforge.pmd.eclipse.plugin.UISettings;
5251
import net.sourceforge.pmd.eclipse.runtime.writer.IRuleSetWriter;
@@ -580,9 +579,7 @@ public void widgetSelected(SelectionEvent event) {
580579
getFileNameWithoutExtension(file.getName()), input.getValue());
581580
OutputStream out = new FileOutputStream(fileName);
582581
IRuleSetWriter writer = PMDPlugin.getDefault().getRuleSetWriter();
583-
RuleSets ruleSets = new RuleSets();
584-
ruleSets.addRuleSet(ruleSet);
585-
writer.write(out, ruleSets);
582+
writer.write(out, ruleSet);
586583
out.close();
587584
MessageDialog.openInformation(getShell(), getMessage(StringKeys.INFORMATION_TITLE),
588585
getMessage(StringKeys.INFORMATION_RULESET_EXPORTED));

0 commit comments

Comments
 (0)