Skip to content

Commit 033c50d

Browse files
committed
SONARJAVA-7236 Analyze the corpus with the classpath the rule tests use
1 parent 5c54c48 commit 033c50d

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

‎benchmark/compare.py‎

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,23 @@ def java_tools(major: int) -> tuple[str, str]:
111111
return "java", "javac"
112112

113113

114-
def dump(checkout: Path, classpath: str, corpus: Path, files: list[Path], out: Path) -> None:
114+
def corpus_classpath(corpus: Path) -> str:
115+
"""Classpath the rule tests analyze the corpus with: its compiled classes and test-classpath.txt."""
116+
entries = []
117+
classes = corpus / "target" / "classes"
118+
if classes.exists():
119+
entries.append(str(classes))
120+
listing = corpus / "target" / "test-classpath.txt"
121+
if listing.exists():
122+
repository = os.environ.get("M2_REPO") or str(Path.home() / ".m2" / "repository")
123+
for entry in listing.read_text().split(":"):
124+
entry = entry.strip()
125+
if entry:
126+
entries.append(entry.replace("M2_REPO", repository))
127+
return os.pathsep.join(entries)
128+
129+
130+
def dump(checkout: Path, classpath: str, corpus: Path, files: list[Path], out: Path, corpus_cp: str) -> None:
115131
java, javac = java_tools(class_major(checkout))
116132
build = checkout / "java-frontend" / "target" / "ast-semantic-dump"
117133
build.mkdir(parents=True, exist_ok=True)
@@ -128,6 +144,8 @@ def dump(checkout: Path, classpath: str, corpus: Path, files: list[Path], out: P
128144
str(out),
129145
"--root",
130146
str(corpus),
147+
"--classpath",
148+
corpus_cp,
131149
]
132150
command.extend(str(path) for path in files)
133151
subprocess.run(command, check=True)
@@ -539,12 +557,13 @@ def main() -> None:
539557
ecj_cp = tool_classpath(ecj)
540558
print(f"classpath {args.semsitter}", file=sys.stderr)
541559
sem_cp = tool_classpath(args.semsitter.resolve())
560+
corpus_cp = corpus_classpath(corpus)
542561
ecj_dump = out / "ecj.jsonl"
543562
sem_dump = out / "semsitter.jsonl"
544563
print(f"dump ECJ ({len(files)} files)", file=sys.stderr)
545-
dump(ecj.resolve(), ecj_cp, corpus, files, ecj_dump)
564+
dump(ecj.resolve(), ecj_cp, corpus, files, ecj_dump, corpus_cp)
546565
print("dump SemSitter", file=sys.stderr)
547-
dump(args.semsitter.resolve(), sem_cp, corpus, files, sem_dump)
566+
dump(args.semsitter.resolve(), sem_cp, corpus, files, sem_dump, corpus_cp)
548567
summary = compare(
549568
ecj_dump,
550569
sem_dump,

0 commit comments

Comments
 (0)