33import static net .sourceforge .pmd .RuleViolation .CLASS_NAME ;
44import static net .sourceforge .pmd .RuleViolation .PACKAGE_NAME ;
55
6+ import com .github .javaparser .ParserConfiguration ;
7+ import com .github .javaparser .StaticJavaParser ;
68import java .io .File ;
79import java .io .IOException ;
810import java .nio .file .Files ;
@@ -59,6 +61,7 @@ public CostBenefitCalculator(String repositoryPath) {
5961 }
6062
6163 public List <RankedCycle > runCycleAnalysis (String outputDirectoryPath , boolean renderImages ) {
64+ StaticJavaParser .getParserConfiguration ().setLanguageLevel (ParserConfiguration .LanguageLevel .BLEEDING_EDGE );
6265 List <RankedCycle > rankedCycles = new ArrayList <>();
6366 try {
6467 Map <String , String > classNamesAndPaths = getClassNamesAndPaths ();
@@ -296,7 +299,15 @@ private List<CBOClass> getCBOClasses() {
296299 }
297300
298301 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 ("\\ " , "/" ) + "/" , "" );
300311 }
301312
302313 public Map <String , String > getClassNamesAndPaths () throws IOException {
@@ -307,9 +318,8 @@ public Map<String, String> getClassNamesAndPaths() throws IOException {
307318 walk .forEach (path -> {
308319 String filename = path .getFileName ().toString ();
309320 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 ));
313323 }
314324 });
315325 }
0 commit comments