3
3
import static net .sourceforge .pmd .RuleViolation .CLASS_NAME ;
4
4
import static net .sourceforge .pmd .RuleViolation .PACKAGE_NAME ;
5
5
6
+ import com .github .javaparser .ParserConfiguration ;
7
+ import com .github .javaparser .StaticJavaParser ;
6
8
import java .io .File ;
7
9
import java .io .IOException ;
8
10
import java .nio .file .Files ;
@@ -59,6 +61,7 @@ public CostBenefitCalculator(String repositoryPath) {
59
61
}
60
62
61
63
public List <RankedCycle > runCycleAnalysis (String outputDirectoryPath , boolean renderImages ) {
64
+ StaticJavaParser .getParserConfiguration ().setLanguageLevel (ParserConfiguration .LanguageLevel .BLEEDING_EDGE );
62
65
List <RankedCycle > rankedCycles = new ArrayList <>();
63
66
try {
64
67
Map <String , String > classNamesAndPaths = getClassNamesAndPaths ();
@@ -296,7 +299,15 @@ private List<CBOClass> getCBOClasses() {
296
299
}
297
300
298
301
private String getFileName (RuleViolation violation ) {
299
- return violation .getFileId ().getUriString ().replace ("file:///" + repositoryPath .replace ("\\ " , "/" ) + "/" , "" );
302
+ String uriString = violation .getFileId ().getUriString ();
303
+ return canonicaliseURIStringForRepoLookup (uriString );
304
+ }
305
+
306
+ private String canonicaliseURIStringForRepoLookup (String uriString ) {
307
+ if (repositoryPath .startsWith ("/" ) || repositoryPath .startsWith ("\\ " )) {
308
+ return uriString .replace ("file://" + repositoryPath .replace ("\\ " , "/" ) + "/" , "" );
309
+ }
310
+ return uriString .replace ("file:///" + repositoryPath .replace ("\\ " , "/" ) + "/" , "" );
300
311
}
301
312
302
313
public Map <String , String > getClassNamesAndPaths () throws IOException {
@@ -307,9 +318,8 @@ public Map<String, String> getClassNamesAndPaths() throws IOException {
307
318
walk .forEach (path -> {
308
319
String filename = path .getFileName ().toString ();
309
320
if (filename .endsWith (".java" )) {
310
- fileNamePaths .put (
311
- getClassName (filename ),
312
- path .toUri ().toString ().replace ("file:///" + repositoryPath .replace ("\\ " , "/" ) + "/" , "" ));
321
+ String uriString = path .toUri ().toString ();
322
+ fileNamePaths .put (getClassName (filename ), canonicaliseURIStringForRepoLookup (uriString ));
313
323
}
314
324
});
315
325
}
0 commit comments