Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0c04c9a

Browse files
author
Benjamin Muskalla
committed
Fix aggregation of jar usages
1 parent 722889e commit 0c04c9a

3 files changed

Lines changed: 13 additions & 13 deletions

File tree

java/ql/src/Telemetry/APIUsage.qll

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@ import java
22
private import semmle.code.java.dataflow.FlowSteps
33
private import semmle.code.java.dataflow.ExternalFlow
44

5-
string jarName(CompilationUnit cu) {
6-
result = cu.getParentContainer().toString().regexpCapture(".*/(.*\\.jar)/?.*", 1)
7-
}
8-
95
predicate isJavaRuntime(Callable call) {
10-
jarName(call.getCompilationUnit()) = "rt.jar" or
6+
call.getCompilationUnit().getParentContainer*().getStem() = "rt" and
117
call.getCompilationUnit().getParentContainer().toString().substring(0, 14) = "/modules/java."
128
}
139

java/ql/src/Telemetry/ExternalAPI.qll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ class ExternalAPI extends Callable {
99
not isJavaRuntime(this)
1010
}
1111

12-
string jarName() { result = jarName(this.getCompilationUnit()) }
13-
1412
string simpleName() {
1513
result = getDeclaringType().getSourceDeclaration() + "#" + this.getStringSignature()
1614
}
Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
/**
22
* @name External libraries
33
* @description A list of external libraries used in the code
4+
* @kind diagnostic
45
* @id java/telemetry/external-libs
56
*/
67

78
import java
89
import ExternalAPI
910

10-
from ExternalAPI api
11-
where not api.getDeclaringType() instanceof TestLibrary
12-
// TODO [bm]: the count is not aggregated and we have the same jar with multiple usages, e.g.
13-
// 1 protobuf-java-3.17.3.jar 373
14-
// 2 protobuf-java-3.17.3.jar 48
15-
select api.jarName() as jarname, count(Call c | c.getCallee() = api) as Usages order by Usages desc
11+
from int Usages, JarFile jar
12+
where
13+
jar = any(ExternalAPI api).getCompilationUnit().getParentContainer*() and
14+
Usages =
15+
strictcount(Call c, ExternalAPI a |
16+
c.getCallee() = a and
17+
not c.getFile() instanceof GeneratedFile and
18+
a.getCompilationUnit().getParentContainer*() = jar and
19+
not a.getDeclaringType() instanceof TestLibrary
20+
)
21+
select jar.getFile().getStem() + "." + jar.getFile().getExtension(), Usages order by Usages desc

0 commit comments

Comments
 (0)