Skip to content

Commit ec7f4d1

Browse files
author
Benjamin Muskalla
committed
Avoid duplicates and support modular runtime
1 parent 8127f63 commit ec7f4d1

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

java/ql/src/Telemetry/ExternalAPI.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ class ExternalAPI extends Callable {
2323
}
2424

2525
predicate isSupported() { not supportKind(this) = "?" }
26+
27+
string jarContainer() {
28+
result = containerAsJar(any(ExternalAPI api).getCompilationUnit().getParentContainer*())
29+
}
30+
31+
private string containerAsJar(Container container) {
32+
if container instanceof JarFile then result = container.getBaseName() else result = "rt.jar"
33+
}
2634
}
2735

2836
private class TestLibrary extends RefType {
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
/**
22
* @name External libraries
33
* @description A list of external libraries used in the code
4-
* @kind diagnostic
4+
* @kind metric
5+
* @metricType callable
56
* @id java/telemetry/external-libs
67
*/
78

89
import java
910
import ExternalAPI
1011

11-
from int Usages, JarFile jar
12+
from int Usages, string jarname
1213
where
13-
jar = any(ExternalAPI api).getCompilationUnit().getParentContainer*() and
14+
jarname = any(ExternalAPI api).jarContainer() and
1415
Usages =
1516
strictcount(Call c, ExternalAPI a |
1617
c.getCallee() = a and
1718
not c.getFile() instanceof GeneratedFile and
18-
a.getCompilationUnit().getParentContainer*() = jar and
19+
a.jarContainer() = jarname and
1920
not a.isTestLibrary()
2021
)
21-
select jar.getFile().getBaseName(), Usages order by Usages desc
22+
select jarname, Usages order by Usages desc

0 commit comments

Comments
 (0)