Skip to content

Commit 234f62f

Browse files
committed
Java: Merge packages that likely belong to the same framework.
1 parent 4941d9b commit 234f62f

File tree

2 files changed

+52
-21
lines changed

2 files changed

+52
-21
lines changed

java/ql/src/meta/frameworks/Coverage.ql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
* @name Framework coverage
33
* @description The number of API endpoints covered by CSV models sorted by
44
* package and source-, sink-, and summary-kind.
5-
* @kind metric
5+
* @kind table
66
* @id java/meta/framework-coverage
77
*/
88

99
import java
1010
import semmle.code.java.dataflow.ExternalFlow
1111

12-
from string package, string kind, string part, int n
13-
where modelCoverage(package, kind, part, n)
14-
select package, kind, part, n
12+
from string package, int pkgs, string kind, string part, int n
13+
where modelCoverage(package, pkgs, kind, part, n)
14+
select package, pkgs, kind, part, n

java/ql/src/semmle/code/java/dataflow/ExternalFlow.qll

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -204,27 +204,58 @@ private predicate summaryModel(
204204
)
205205
}
206206

207+
private predicate relevantPackage(string package) {
208+
sourceModel(package, _, _, _, _, _, _, _) or
209+
sinkModel(package, _, _, _, _, _, _, _) or
210+
summaryModel(package, _, _, _, _, _, _, _, _)
211+
}
212+
213+
private predicate packageLink(string shortpkg, string longpkg) {
214+
relevantPackage(shortpkg) and
215+
relevantPackage(longpkg) and
216+
longpkg.prefix(longpkg.indexOf(".")) = shortpkg
217+
}
218+
219+
private predicate canonicalPackage(string package) {
220+
relevantPackage(package) and not packageLink(_, package)
221+
}
222+
223+
private predicate canonicalPkgLink(string package, string subpkg) {
224+
canonicalPackage(package) and
225+
(subpkg = package or packageLink(package, subpkg))
226+
}
227+
207228
/**
208229
* Holds if CSV framework coverage of `package` is `n` api endpoints of the
209230
* kind `(kind, part)`.
210231
*/
211-
predicate modelCoverage(string package, string kind, string part, int n) {
212-
part = "source" and
213-
n =
214-
strictcount(string type, boolean subtypes, string name, string signature, string ext,
215-
string output | sourceModel(package, type, subtypes, name, signature, ext, output, kind))
216-
or
217-
part = "sink" and
218-
n =
219-
strictcount(string type, boolean subtypes, string name, string signature, string ext,
220-
string input | sinkModel(package, type, subtypes, name, signature, ext, input, kind))
221-
or
222-
part = "summary" and
223-
n =
224-
strictcount(string type, boolean subtypes, string name, string signature, string ext,
225-
string input, string output |
226-
summaryModel(package, type, subtypes, name, signature, ext, input, output, kind)
227-
)
232+
predicate modelCoverage(string package, int pkgs, string kind, string part, int n) {
233+
pkgs = strictcount(string subpkg | canonicalPkgLink(package, subpkg)) and
234+
(
235+
part = "source" and
236+
n =
237+
strictcount(string subpkg, string type, boolean subtypes, string name, string signature,
238+
string ext, string output |
239+
canonicalPkgLink(package, subpkg) and
240+
sourceModel(subpkg, type, subtypes, name, signature, ext, output, kind)
241+
)
242+
or
243+
part = "sink" and
244+
n =
245+
strictcount(string subpkg, string type, boolean subtypes, string name, string signature,
246+
string ext, string input |
247+
canonicalPkgLink(package, subpkg) and
248+
sinkModel(subpkg, type, subtypes, name, signature, ext, input, kind)
249+
)
250+
or
251+
part = "summary" and
252+
n =
253+
strictcount(string subpkg, string type, boolean subtypes, string name, string signature,
254+
string ext, string input, string output |
255+
canonicalPkgLink(package, subpkg) and
256+
summaryModel(subpkg, type, subtypes, name, signature, ext, input, output, kind)
257+
)
258+
)
228259
}
229260

230261
/** Provides a query predicate to check the CSV data for validation errors. */

0 commit comments

Comments
 (0)