Skip to content

Commit c881559

Browse files
committed
Merge pull request #137 from adangel:deprecations
Resolve deprecations #137
2 parents 461504e + 542cde4 commit c881559

File tree

82 files changed

+858
-843
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+858
-843
lines changed

ReleaseNotes.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,34 @@ This is a minor release.
1717

1818
### API Changes
1919

20+
* The following methods in `net.sourceforge.pmd.eclipse.ui.actions.RuleSetUtil` are deprecated:
21+
* `setExcludePatterns(RuleSet ruleSet, Collection<String> excludePatterns)`
22+
* `setIncludePatterns(RuleSet ruleSet, Collection<String> includePatterns)`
23+
* `addExcludePatterns(RuleSet ruleSet, Collection<String> activeExclusionPatterns, Collection<String> buildPathExcludePatterns)`
24+
* `addIncludePatterns(RuleSet ruleSet, Collection<String> activeInclusionPatterns, Collection<String> buildPathIncludePatterns)`
25+
* `addExcludePatterns(RuleSet rs, Collection<String> excludePatterns)`
26+
* `addIncludePatterns(RuleSet rs, Collection<String> includePatterns)`
27+
* These methods are not supposed to be public API and will be removed eventually.
28+
* The property `net.sourceforge.pmd.eclipse.runtime.PMDRuntimeConstants.MAX_VIOLATIONS_DESCRIPTOR`
29+
is deprecated and will be removed.
30+
* The preference "net.sourceforge.pmd.eclipse.plugin.max_violations_pfpr" is deprecated and will be removed.
31+
It was never implemented. The following methods and fields are deprecated:
32+
* `net.sourceforge.pmd.eclipse.runtime.preferences.IPreferences.getMaxViolationsPerFilePerRule()`
33+
* `net.sourceforge.pmd.eclipse.runtime.preferences.IPreferences.setMaxViolationsPerFilePerRule(int)`
34+
* `net.sourceforge.pmd.eclipse.runtime.preferences.IPreferences.MAX_VIOLATIONS_PFPR_DEFAULT`
35+
* `net.sourceforge.pmd.eclipse.runtime.cmd.DetectCutAndPasteCmd.setRenderer(Renderer)` is deprecated.
36+
* Removed usages of deprecated class `net.sourceforge.pmd.RuleSets`. Therefore the following methods are
37+
deprecated now:
38+
* `net.sourceforge.pmd.eclipse.runtime.cmd.BaseVisitor.getRuleSets()`
39+
* `net.sourceforge.pmd.eclipse.runtime.cmd.BaseVisitor.setRuleSets(RuleSets)`
40+
* `net.sourceforge.pmd.eclipse.runtime.properties.IProjectProperties.getProjectRuleSets()`
41+
* `net.sourceforge.pmd.eclipse.runtime.properties.IProjectProperties.setProjectRuleSets(RuleSets)`
42+
* `net.sourceforge.pmd.eclipse.runtime.properties.impl.ProjectPropertiesImpl.getProjectRuleSets()`
43+
* `net.sourceforge.pmd.eclipse.runtime.properties.impl.ProjectPropertiesImpl.setProjectRuleSets(RuleSets)`
44+
* `net.sourceforge.pmd.eclipse.ui.properties.PMDPropertyPageBean.getProjectRuleSets()`
45+
* `net.sourceforge.pmd.eclipse.ui.properties.PMDPropertyPageBean.setProjectRuleSets(RuleSets)`
46+
* `net.sourceforge.pmd.eclipse.ui.properties.UpdateProjectPropertiesCmd.setProjectRuleSets(RuleSets)`
47+
2048
### External Contributions
2149

2250
## 27-March-2021: 4.22.0.v20210327-1603

net.sourceforge.pmd.eclipse.plugin.test.fragment/src/main/java/test/RuleSetsExtension.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import net.sourceforge.pmd.RuleSet;
1212
import net.sourceforge.pmd.RuleSetFactory;
1313
import net.sourceforge.pmd.RuleSetNotFoundException;
14+
import net.sourceforge.pmd.RulesetsFactoryUtils;
1415
import net.sourceforge.pmd.eclipse.core.IRuleSetsExtension;
1516
import net.sourceforge.pmd.eclipse.plugin.PMDPlugin;
1617

@@ -68,7 +69,7 @@ public void registerDefaultRuleSets(Set<RuleSet> defaultRuleSets) {
6869
*/
6970
private RuleSet getRuleSet1() throws RuleSetNotFoundException {
7071
if (this.ruleSet1 == null) {
71-
RuleSetFactory factory = new RuleSetFactory();
72+
RuleSetFactory factory = RulesetsFactoryUtils.defaultFactory();
7273
this.ruleSet1 = factory.createRuleSets("rulesets/extra1.xml").getAllRuleSets()[0];
7374
}
7475

@@ -82,7 +83,7 @@ private RuleSet getRuleSet1() throws RuleSetNotFoundException {
8283
*/
8384
private RuleSet getRuleSet2() throws RuleSetNotFoundException {
8485
if (this.ruleSet2 == null) {
85-
RuleSetFactory factory = new RuleSetFactory();
86+
RuleSetFactory factory = RulesetsFactoryUtils.defaultFactory();
8687
this.ruleSet2 = factory.createRuleSets("rulesets/extra2.xml").getAllRuleSets()[0];
8788
}
8889

net.sourceforge.pmd.eclipse.plugin.test/src/main/java/net/sourceforge/pmd/eclipse/BasicPMDTest.java

Lines changed: 51 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,30 @@
55
package net.sourceforge.pmd.eclipse;
66

77
import java.io.ByteArrayInputStream;
8+
import java.io.File;
89
import java.io.IOException;
910
import java.io.InputStream;
1011
import java.io.UnsupportedEncodingException;
12+
import java.util.ArrayList;
13+
import java.util.Collections;
1114
import java.util.Iterator;
15+
import java.util.List;
1216

1317
import org.junit.Assert;
1418
import org.junit.Test;
1519

20+
import net.sourceforge.pmd.PMD;
1621
import net.sourceforge.pmd.PMDConfiguration;
17-
import net.sourceforge.pmd.PMDException;
18-
import net.sourceforge.pmd.Report;
1922
import net.sourceforge.pmd.RuleContext;
2023
import net.sourceforge.pmd.RuleSet;
2124
import net.sourceforge.pmd.RuleSetFactory;
2225
import net.sourceforge.pmd.RuleSetNotFoundException;
23-
import net.sourceforge.pmd.RuleSets;
2426
import net.sourceforge.pmd.RuleViolation;
25-
import net.sourceforge.pmd.SourceCodeProcessor;
27+
import net.sourceforge.pmd.RulesetsFactoryUtils;
28+
import net.sourceforge.pmd.ThreadSafeReportListener;
2629
import net.sourceforge.pmd.lang.LanguageRegistry;
30+
import net.sourceforge.pmd.renderers.Renderer;
31+
import net.sourceforge.pmd.stat.Metric;
2732
import net.sourceforge.pmd.util.datasource.DataSource;
2833

2934
/**
@@ -62,13 +67,13 @@ public void close() throws IOException {
6267
}
6368

6469
/**
65-
* Try to load all the plugin known rulesets
70+
* Try to load all the plugin known rulesets.
6671
*
6772
*/
6873
@Test
6974
public void testDefaulltRuleSets() {
7075
try {
71-
final RuleSetFactory factory = new RuleSetFactory();
76+
final RuleSetFactory factory = RulesetsFactoryUtils.defaultFactory();
7277
final Iterator<RuleSet> iterator = factory.getRegisteredRuleSets();
7378
while (iterator.hasNext()) {
7479
iterator.next();
@@ -79,117 +84,65 @@ public void testDefaulltRuleSets() {
7984
}
8085
}
8186

82-
/**
83-
* One first thing the plugin must be able to do is to run PMD
84-
*
85-
*/
86-
@Test
87-
public void testRunPmdJdk13() {
88-
89-
try {
90-
PMDConfiguration configuration = new PMDConfiguration();
91-
configuration.setDefaultLanguageVersion(LanguageRegistry.findLanguageVersionByTerseName("java 1.3"));
87+
private void runPmd(String javaVersion) {
88+
PMDConfiguration configuration = new PMDConfiguration();
89+
configuration.setDefaultLanguageVersion(LanguageRegistry.findLanguageByTerseName("java").getVersion(javaVersion));
90+
configuration.setRuleSets("category/java/codestyle.xml/UnnecessaryReturn");
91+
RuleSetFactory ruleSetFactory = RulesetsFactoryUtils.createFactory(configuration);
92+
93+
List<DataSource> files = new ArrayList<>();
94+
final String sourceCode = "public class Foo {\n public void foo() {\nreturn;\n}}";
95+
files.add(new StringDataSource(sourceCode));
96+
97+
final List<RuleViolation> violations = new ArrayList<>();
98+
final RuleContext ctx = new RuleContext();
99+
ctx.setSourceCodeFile(new File("foo.java"));
100+
ctx.getReport().addListener(new ThreadSafeReportListener() {
101+
@Override
102+
public void ruleViolationAdded(RuleViolation ruleViolation) {
103+
violations.add(ruleViolation);
104+
}
92105

93-
final String sourceCode = "public class Foo {\n public void foo() {\nreturn;\n}}";
106+
@Override
107+
public void metricAdded(Metric metric) {
108+
}
109+
});
94110

95-
final RuleContext context = new RuleContext();
96-
context.setSourceCodeFilename("foo.java");
97-
context.setReport(new Report());
98111

99-
final RuleSet codeStyleRuleSet = new RuleSetFactory().createRuleSet("category/java/codestyle.xml/UnnecessaryReturn");
100-
RuleSets rSets = new RuleSets(codeStyleRuleSet);
101-
new SourceCodeProcessor(configuration).processSourceCode(new StringDataSource(sourceCode).getInputStream(),
102-
rSets, context);
112+
PMD.processFiles(configuration, ruleSetFactory, files, ctx,
113+
Collections.<Renderer>emptyList());
103114

104-
final Iterator<RuleViolation> iter = context.getReport().iterator();
105-
Assert.assertTrue("There should be at least one violation", iter.hasNext());
115+
Assert.assertFalse("There should be at least one violation", violations.isEmpty());
106116

107-
final RuleViolation violation = iter.next();
108-
Assert.assertEquals(violation.getRule().getName(), "UnnecessaryReturn");
109-
Assert.assertEquals(3, violation.getBeginLine());
117+
final RuleViolation violation = violations.get(0);
118+
Assert.assertEquals(violation.getRule().getName(), "UnnecessaryReturn");
119+
Assert.assertEquals(3, violation.getBeginLine());
120+
}
110121

111-
} catch (final RuleSetNotFoundException e) {
112-
e.printStackTrace();
113-
Assert.fail();
114-
} catch (final PMDException e) {
115-
e.printStackTrace();
116-
Assert.fail();
117-
}
122+
/**
123+
* One first thing the plugin must be able to do is to run PMD.
124+
*
125+
*/
126+
@Test
127+
public void testRunPmdJdk13() {
128+
runPmd("1.3");
118129
}
119130

120131
/**
121-
* Let see with Java 1.4
132+
* Let see with Java 1.4.
122133
*
123134
*/
124135
@Test
125136
public void testRunPmdJdk14() {
126-
127-
try {
128-
PMDConfiguration configuration = new PMDConfiguration();
129-
configuration.setDefaultLanguageVersion(LanguageRegistry.findLanguageVersionByTerseName("java 1.4"));
130-
131-
final String sourceCode = "public class Foo {\n public void foo() {\nreturn;\n}}";
132-
133-
final RuleContext context = new RuleContext();
134-
context.setSourceCodeFilename("foo.java");
135-
context.setReport(new Report());
136-
137-
final RuleSet codeStyleRuleSet = new RuleSetFactory().createRuleSet("category/java/codestyle.xml/UnnecessaryReturn");
138-
RuleSets rSets = new RuleSets(codeStyleRuleSet);
139-
new SourceCodeProcessor(configuration).processSourceCode(new StringDataSource(sourceCode).getInputStream(),
140-
rSets, context);
141-
142-
final Iterator<RuleViolation> iter = context.getReport().iterator();
143-
Assert.assertTrue("There should be at least one violation", iter.hasNext());
144-
145-
final RuleViolation violation = iter.next();
146-
Assert.assertEquals(violation.getRule().getName(), "UnnecessaryReturn");
147-
Assert.assertEquals(3, violation.getBeginLine());
148-
149-
} catch (final RuleSetNotFoundException e) {
150-
e.printStackTrace();
151-
Assert.fail();
152-
} catch (final PMDException e) {
153-
e.printStackTrace();
154-
Assert.fail();
155-
}
137+
runPmd("1.4");
156138
}
157139

158140
/**
159-
* Let see with Java 1.5
141+
* Let see with Java 1.5.
160142
*
161143
*/
162144
@Test
163145
public void testRunPmdJdk15() {
164-
165-
try {
166-
PMDConfiguration configuration = new PMDConfiguration();
167-
configuration.setDefaultLanguageVersion(LanguageRegistry.findLanguageVersionByTerseName("java 1.5"));
168-
169-
final String sourceCode = "public class Foo {\n public void foo() {\nreturn;\n}}";
170-
171-
final RuleContext context = new RuleContext();
172-
context.setSourceCodeFilename("foo.java");
173-
context.setReport(new Report());
174-
175-
final RuleSet codeStyleRuleSet = new RuleSetFactory().createRuleSet("category/java/codestyle.xml/UnnecessaryReturn");
176-
RuleSets rSets = new RuleSets(codeStyleRuleSet);
177-
new SourceCodeProcessor(configuration).processSourceCode(new StringDataSource(sourceCode).getInputStream(),
178-
rSets, context);
179-
180-
final Iterator<RuleViolation> iter = context.getReport().iterator();
181-
Assert.assertTrue("There should be at least one violation", iter.hasNext());
182-
183-
final RuleViolation violation = iter.next();
184-
Assert.assertEquals(violation.getRule().getName(), "UnnecessaryReturn");
185-
Assert.assertEquals(3, violation.getBeginLine());
186-
187-
} catch (final RuleSetNotFoundException e) {
188-
e.printStackTrace();
189-
Assert.fail();
190-
} catch (final PMDException e) {
191-
e.printStackTrace();
192-
Assert.fail();
193-
}
146+
runPmd("1.5");
194147
}
195148
}

net.sourceforge.pmd.eclipse.plugin.test/src/main/java/net/sourceforge/pmd/eclipse/EclipseUtils.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ public static void addJavaNature(final IProject project) throws CoreException {
234234
JavaCore.newContainerEntry(new Path("org.eclipse.jdt.launching.JRE_CONTAINER")) },
235235
null);
236236

237-
@SuppressWarnings("unchecked")
238237
Hashtable<String, String> javaOptions = JavaCore.getOptions();
239238
javaOptions.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5);
240239
javaOptions.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5);

net.sourceforge.pmd.eclipse.plugin.test/src/main/java/net/sourceforge/pmd/eclipse/core/PMDCorePluginTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import net.sourceforge.pmd.RuleSet;
1414
import net.sourceforge.pmd.RuleSetFactory;
1515
import net.sourceforge.pmd.RuleSetNotFoundException;
16+
import net.sourceforge.pmd.RulesetsFactoryUtils;
1617
import net.sourceforge.pmd.eclipse.plugin.PMDPlugin;
1718

1819
/**
@@ -33,7 +34,7 @@ public void testDefaultPMDRuleSetsRegistered() throws RuleSetNotFoundException {
3334
final Collection<RuleSet> defaultRuleSets = PMDPlugin.getDefault().getRuleSetManager().getRegisteredRuleSets();
3435
Assert.assertFalse("No registered default rulesets!", defaultRuleSets.isEmpty());
3536

36-
final RuleSetFactory factory = new RuleSetFactory();
37+
final RuleSetFactory factory = RulesetsFactoryUtils.defaultFactory();
3738
final Iterator<RuleSet> iterator = factory.getRegisteredRuleSets();
3839
while (iterator.hasNext()) {
3940
final RuleSet ruleSet = iterator.next();
@@ -71,7 +72,7 @@ public void testStandardPMDRuleSetsRegistered() throws RuleSetNotFoundException
7172
.getRegisteredRuleSets();
7273
Assert.assertFalse("No registered rulesets!", registeredRuleSets.isEmpty());
7374

74-
final RuleSetFactory factory = new RuleSetFactory();
75+
final RuleSetFactory factory = RulesetsFactoryUtils.defaultFactory();
7576
final Iterator<RuleSet> iterator = factory.getRegisteredRuleSets();
7677
while (iterator.hasNext()) {
7778
final RuleSet ruleSet = iterator.next();

net.sourceforge.pmd.eclipse.plugin.test/src/main/java/net/sourceforge/pmd/eclipse/core/ext/RuleSetsExtensionProcessorTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import net.sourceforge.pmd.RuleSet;
1414
import net.sourceforge.pmd.RuleSetFactory;
1515
import net.sourceforge.pmd.RuleSetNotFoundException;
16+
import net.sourceforge.pmd.RulesetsFactoryUtils;
1617
import net.sourceforge.pmd.eclipse.plugin.PMDPlugin;
1718

1819
/**
@@ -33,7 +34,7 @@ public void testAdditionalDefaultRuleSetsRegistered() throws RuleSetNotFoundExce
3334
final Collection<RuleSet> registeredRuleSets = PMDPlugin.getDefault().getRuleSetManager().getDefaultRuleSets();
3435
Assert.assertFalse("No registered default rulesets!", registeredRuleSets.isEmpty());
3536

36-
final RuleSetFactory factory = new RuleSetFactory();
37+
final RuleSetFactory factory = RulesetsFactoryUtils.defaultFactory();
3738
RuleSet ruleSet = factory.createRuleSet("rulesets/extra1.xml");
3839
Assert.assertTrue("RuleSet \"rulesets/extra1.xml\" has not been registered",
3940
ruleSetRegistered(ruleSet, registeredRuleSets));
@@ -54,7 +55,7 @@ public void testAdditionalRuleSetsRegistered() throws RuleSetNotFoundException {
5455
.getRegisteredRuleSets();
5556
Assert.assertFalse("No registered rulesets!", registeredRuleSets.isEmpty());
5657

57-
final RuleSetFactory factory = new RuleSetFactory();
58+
final RuleSetFactory factory = RulesetsFactoryUtils.defaultFactory();
5859
RuleSet ruleSet = factory.createRuleSet("rulesets/extra1.xml");
5960
Assert.assertTrue("RuleSet \"rulesets/extra1.xml\" has not been registered",
6061
ruleSetRegistered(ruleSet, registeredRuleSets));

0 commit comments

Comments
 (0)