Skip to content

Commit 34d80d3

Browse files
committed
Adapt to PMD 7.0.0-rc3 changes
1 parent c014043 commit 34d80d3

File tree

10 files changed

+34
-22
lines changed

10 files changed

+34
-22
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import net.sourceforge.pmd.RuleSet;
1717
import net.sourceforge.pmd.RuleSetLoader;
1818
import net.sourceforge.pmd.RuleViolation;
19+
import net.sourceforge.pmd.lang.document.FileId;
1920

2021
/**
2122
* Test if PMD can be run correctly.
@@ -42,7 +43,7 @@ private void runPmd() {
4243
final String sourceCode = "public class Foo {\n public void foo() {\nreturn;\n}}";
4344

4445
try (PmdAnalysis pmd = PmdAnalysis.create(configuration)) {
45-
pmd.files().addSourceFile(sourceCode, "Foo.java");
46+
pmd.files().addSourceFile(FileId.fromPathLikeString("Foo.java"), sourceCode);
4647
Report result = pmd.performAnalysisAndCollectReport();
4748

4849
Assert.assertFalse("There should be at least one violation", result.getViolations().isEmpty());

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import net.sourceforge.pmd.lang.LanguageRegistry;
4747
import net.sourceforge.pmd.lang.LanguageVersion;
4848
import net.sourceforge.pmd.lang.LanguageVersionDiscoverer;
49+
import net.sourceforge.pmd.lang.document.FileId;
4950
import net.sourceforge.pmd.lang.java.JavaLanguageModule;
5051

5152
/**
@@ -290,6 +291,7 @@ protected final void reviewResource(IResource resource) {
290291
configuration().setIgnoreIncrementalAnalysis(true);
291292

292293
final File sourceCodeFile = file.getRawLocation().toFile();
294+
final FileId fileId = FileId.fromPathLikeString(sourceCodeFile.getAbsolutePath());
293295
if (included && InternalRuleSetUtil.ruleSetsApplies(ruleSets, sourceCodeFile) && isFileInWorkingSet(file)
294296
&& languageVersion != null) {
295297
subTask("PMD checking: " + file.getProject() + ": " + file.getName());
@@ -308,7 +310,7 @@ protected final void reviewResource(IResource resource) {
308310
PmdAnalysis pmdAnalysis = PmdAnalysis.create(configuration());) {
309311

310312
String sourceContents = IOUtil.toString(input);
311-
pmdAnalysis.files().addSourceFile(sourceContents, sourceCodeFile.getAbsolutePath());
313+
pmdAnalysis.files().addSourceFile(fileId, sourceContents);
312314

313315
pmdAnalysis.addRuleSets(getRuleSetList());
314316

@@ -331,7 +333,7 @@ protected final void reviewResource(IResource resource) {
331333
if (!collectingReport.getProcessingErrors().isEmpty()) {
332334
StringBuilder message = new StringBuilder("There were processing errors!\n");
333335
for (ProcessingError error : collectingReport.getProcessingErrors()) {
334-
message.append(error.getFile()).append(": ").append(error.getMsg()).append(' ')
336+
message.append(error.getFileId().getOriginalPath()).append(": ").append(error.getMsg()).append(' ')
335337
.append(error.getDetail())
336338
.append("\n");
337339
}

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import net.sourceforge.pmd.Rule;
1111
import net.sourceforge.pmd.RuleViolation;
12+
import net.sourceforge.pmd.lang.document.FileId;
1213
import net.sourceforge.pmd.lang.document.FileLocation;
1314

1415
/**
@@ -26,7 +27,7 @@ class FakeRuleViolation implements RuleViolation {
2627
private int endLine;
2728
private int endColumn;
2829

29-
private String filename;
30+
private FileId fileId;
3031
private String packageName;
3132
private String className;
3233
private String methodName;
@@ -99,12 +100,12 @@ public void setEndLine(int endLine) {
99100
this.endLine = endLine;
100101
}
101102

103+
102104
/**
103-
* @param filename
104-
* The filename to set.
105+
* @param fileId the fileId to set
105106
*/
106-
public void setFilename(String filename) {
107-
this.filename = filename;
107+
public void setFileId(FileId fileId) {
108+
this.fileId = fileId;
108109
}
109110

110111
/**
@@ -137,8 +138,8 @@ public Rule getRule() {
137138
}
138139

139140
@Override
140-
public String getFilename() {
141-
return filename;
141+
public FileId getFileId() {
142+
return fileId;
142143
}
143144

144145
@Override
@@ -183,7 +184,7 @@ public String getVariableName() {
183184

184185
@Override
185186
public FileLocation getLocation() {
186-
return FileLocation.caret(filename, beginLine, beginColumn);
187+
return FileLocation.caret(fileId, beginLine, beginColumn);
187188
}
188189

189190
@Override

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import net.sourceforge.pmd.eclipse.plugin.PMDPlugin;
3333
import net.sourceforge.pmd.eclipse.runtime.PMDRuntimeConstants;
3434
import net.sourceforge.pmd.eclipse.runtime.builder.MarkerUtil;
35+
import net.sourceforge.pmd.lang.document.FileId;
3536
import net.sourceforge.pmd.renderers.Renderer;
3637

3738
/**
@@ -206,7 +207,8 @@ private static FakeRuleViolation createViolation(IMarker marker, Rule rule) {
206207
ruleViolation.setBeginLine(marker.getAttribute(IMarker.LINE_NUMBER, 0));
207208
ruleViolation.setEndLine(marker.getAttribute(PMDRuntimeConstants.KEY_MARKERATT_LINE2, 0));
208209
ruleViolation.setVariableName(marker.getAttribute(PMDRuntimeConstants.KEY_MARKERATT_LINE2, ""));
209-
ruleViolation.setFilename(marker.getResource().getProjectRelativePath().toString());
210+
FileId fileId = FileId.fromPathLikeString(marker.getResource().getProjectRelativePath().toString());
211+
ruleViolation.setFileId(fileId);
210212
ruleViolation.setDescription(marker.getAttribute(IMarker.MESSAGE, rule.getMessage()));
211213
return ruleViolation;
212214
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import net.sourceforge.pmd.eclipse.runtime.PMDRuntimeConstants;
2424
import net.sourceforge.pmd.eclipse.ui.actions.RuleSetUtil;
2525
import net.sourceforge.pmd.eclipse.util.internal.IOUtil;
26+
import net.sourceforge.pmd.lang.document.FileId;
2627

2728
/**
2829
* This command reviews a resource - a file - for a specific rule.
@@ -86,15 +87,16 @@ public void execute() {
8687
RuleSet ruleSet = RuleSetUtil.newSingle(rule);
8788

8889
File sourceCodeFile = file.getFullPath().toFile();
89-
if (ruleSet.applies(sourceCodeFile.toString())) {
90+
FileId fileId = FileId.fromPathLikeString(sourceCodeFile.toString());
91+
if (ruleSet.applies(fileId)) {
9092
PMDConfiguration configuration = new PMDConfiguration();
9193
Report report = null;
9294

9395
try (Reader input = new InputStreamReader(file.getContents(), file.getCharset());
9496
PmdAnalysis pmdAnalysis = PmdAnalysis.create(configuration)) {
9597

9698
pmdAnalysis.addRuleSet(ruleSet);
97-
pmdAnalysis.files().addSourceFile(IOUtil.toString(input), sourceCodeFile.getAbsolutePath());
99+
pmdAnalysis.files().addSourceFile(fileId, IOUtil.toString(input));
98100

99101
report = pmdAnalysis.performAnalysisAndCollectReport();
100102
} catch (Exception e) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import org.slf4j.Logger;
3030
import org.slf4j.LoggerFactory;
3131

32-
import net.sourceforge.pmd.PMD;
32+
import net.sourceforge.pmd.PmdAnalysis;
3333
import net.sourceforge.pmd.RuleSet;
3434
import net.sourceforge.pmd.eclipse.core.internal.FileModificationUtil;
3535
import net.sourceforge.pmd.eclipse.plugin.PMDPlugin;
@@ -484,7 +484,7 @@ public ClassLoader getAuxClasspath() {
484484
if (auxclasspath == null) {
485485
PMDPlugin.getDefault()
486486
.logInformation("Creating new auxclasspath class loader for project " + project.getName());
487-
auxclasspath = new JavaProjectClassLoader(PMD.class.getClassLoader(), project);
487+
auxclasspath = new JavaProjectClassLoader(PmdAnalysis.class.getClassLoader(), project);
488488
}
489489
return auxclasspath;
490490
}

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/actions/PMDGenerateASTAction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import net.sourceforge.pmd.lang.ast.Parser;
4242
import net.sourceforge.pmd.lang.ast.Parser.ParserTask;
4343
import net.sourceforge.pmd.lang.ast.SemanticErrorReporter;
44+
import net.sourceforge.pmd.lang.document.FileId;
4445
import net.sourceforge.pmd.lang.document.TextDocument;
4546
import net.sourceforge.pmd.lang.document.TextFile;
4647
import net.sourceforge.pmd.lang.java.JavaLanguageModule;
@@ -87,7 +88,7 @@ private void generateAST(IFile file) {
8788
try (Reader reader = new InputStreamReader(file.getContents(), file.getCharset());
8889
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
8990
LanguageProcessor javaProcessor = javaLanguage.createProcessor(new JavaLanguageProperties());
90-
TextDocument textDocument = TextDocument.create(TextFile.forReader(reader, file.getName(), javaLanguage.getDefaultVersion()));) {
91+
TextDocument textDocument = TextDocument.create(TextFile.forReader(reader, FileId.fromPathLikeString(file.getName()), javaLanguage.getDefaultVersion()));) {
9192

9293
Parser parser = javaProcessor.services().getParser();
9394
ParserTask parserTask = new ParserTask(textDocument, SemanticErrorReporter.noop(), LanguageProcessorRegistry.singleton(javaProcessor));

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/actions/internal/InternalRuleSetUtil.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import net.sourceforge.pmd.RuleSet;
1919
import net.sourceforge.pmd.RuleSetLoader;
2020
import net.sourceforge.pmd.RuleSets;
21+
import net.sourceforge.pmd.lang.document.FileId;
2122

2223
public final class InternalRuleSetUtil {
2324
private InternalRuleSetUtil() {}
@@ -91,8 +92,9 @@ public static Collection<Pattern> convertStringPatterns(Collection<String> patte
9192
}
9293

9394
public static boolean ruleSetsApplies(List<RuleSet> rulesets, File file) {
95+
FileId fileId = FileId.fromPathLikeString(file.toString());
9496
for (RuleSet ruleSet : rulesets) {
95-
if (ruleSet.applies(file.toString())) {
97+
if (ruleSet.applies(fileId)) {
9698
return true;
9799
}
98100
}

net.sourceforge.pmd.eclipse.plugin/src/main/java/net/sourceforge/pmd/eclipse/ui/views/ast/XPathEvaluator.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import net.sourceforge.pmd.lang.LanguageRegistry;
1717
import net.sourceforge.pmd.lang.LanguageVersion;
1818
import net.sourceforge.pmd.lang.ast.Node;
19+
import net.sourceforge.pmd.lang.document.FileId;
1920
import net.sourceforge.pmd.lang.java.JavaLanguageModule;
2021
import net.sourceforge.pmd.lang.rule.XPathRule;
2122
import net.sourceforge.pmd.lang.rule.xpath.XPathVersion;
@@ -25,7 +26,7 @@
2526
* @author Brian Remedios
2627
*/
2728
public final class XPathEvaluator {
28-
private static final String SNIPPET_FILENAME = "snippet.java";
29+
private static final FileId SNIPPET_FILENAME = FileId.fromPathLikeString("snippet.java");
2930

3031
public static final XPathEvaluator INSTANCE = new XPathEvaluator();
3132

@@ -43,7 +44,7 @@ public Node getCompilationUnit(String source) {
4344

4445
try (PmdAnalysis pmd = PmdAnalysis.create(configuration)) {
4546
pmd.addRuleSet(ruleset);
46-
pmd.files().addSourceFile(source, SNIPPET_FILENAME);
47+
pmd.files().addSourceFile(SNIPPET_FILENAME, source);
4748
pmd.performAnalysis();
4849
}
4950

@@ -73,7 +74,7 @@ public List<RuleViolation> evaluate(String source, String xpathQuery, String xpa
7374
configuration.setForceLanguageVersion(getLanguageVersion());
7475
try (PmdAnalysis pmd = PmdAnalysis.create(configuration)) {
7576
pmd.addRuleSet(ruleSet);
76-
pmd.files().addSourceFile(source, SNIPPET_FILENAME);
77+
pmd.files().addSourceFile(SNIPPET_FILENAME, source);
7778
Report report = pmd.performAnalysisAndCollectReport();
7879
return report.getViolations();
7980
}

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<!-- https://github.com/eclipse/tycho/blob/master/RELEASE_NOTES.md and https://github.com/eclipse-tycho/tycho/releases -->
2222
<tycho.version>3.0.4</tycho.version>
2323
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
24-
<pmd.version>7.0.0-rc2</pmd.version>
24+
<pmd.version>7.0.0-SNAPSHOT</pmd.version>
2525
<pmd.build-tools.version>20</pmd.build-tools.version>
2626
<checkstyle.version>10.7.0</checkstyle.version>
2727
<checkstyle.plugin.version>3.2.2</checkstyle.plugin.version>

0 commit comments

Comments
 (0)