auryn-java 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,56 @@
1
+ """Graph schema (node/edge labels) the Java ingestor writes. git_sync passes NODE_SCHEMAS to
2
+ setup_schema()/read_fingerprints() so the delta-sync pipeline (core/graph_sync.py) can index
3
+ and diff this project's Java subgraph.
4
+
5
+ Mirrors ingestors/csharp/schema.py -- Java and C# are structural siblings (a namespace/package
6
+ tier over types with methods/fields; no free functions). Differences track the language: the
7
+ tier is `Package` (with HAS_PACKAGE/HAS_SUBPACKAGE, as in the Python ingestor) rather than C#'s
8
+ `Namespace`; there are no Property/Event/Delegate/Struct labels (Java has none); and the C#
9
+ DTO/APIEndpoint classification layer is deferred (a Spring `@RestController` enrichment is the
10
+ natural future analog).
11
+
12
+ The shared cross-ingestor set is held to the contract: callables are `Method`, the call edge is
13
+ `CALLS` (carrying a `resolution` provenance), and `Parameter`/`HAS_PARAMETER`/`EXTENDS`/
14
+ `IMPLEMENTS` match the other ingestors."""
15
+
16
+ from __future__ import annotations
17
+
18
+ from auryn.core.graph_model import EdgeSchema, NodeSchema
19
+
20
+ NODE_SCHEMAS = [
21
+ NodeSchema(label="Project", indexed_properties=("name",)),
22
+ NodeSchema(label="Module", indexed_properties=("name",)), # Maven/Gradle subproject (scope root; no linkage_key -- see javamod)
23
+ NodeSchema(label="Package", indexed_properties=("name",)),
24
+ NodeSchema(label="File", indexed_properties=("path",)),
25
+ NodeSchema(label="Class", indexed_properties=("name",)),
26
+ NodeSchema(label="Interface", indexed_properties=("name",)),
27
+ NodeSchema(label="Enum", indexed_properties=("name",)),
28
+ NodeSchema(label="Record", indexed_properties=("name",)),
29
+ NodeSchema(label="Method", indexed_properties=("name", "linkage_key")), # linkage_key: ADR 0004 cross-repo
30
+ NodeSchema(label="Field", indexed_properties=("name",)),
31
+ NodeSchema(label="Parameter", indexed_properties=("name",)),
32
+ NodeSchema(label="EnumMember", indexed_properties=("name",)),
33
+ ]
34
+
35
+ EDGE_SCHEMAS = [
36
+ # Containment backbone -- pure structure, no properties (as in C#/Python).
37
+ EdgeSchema(rel_type="HAS_MODULE"), # Project -> Module (one per Maven/Gradle subproject)
38
+ EdgeSchema(rel_type="HAS_PACKAGE"), # Module|Project -> Package (first segment; Project for root files)
39
+ EdgeSchema(rel_type="HAS_SUBPACKAGE"), # Package -> Package
40
+ EdgeSchema(rel_type="HAS_FILE"), # Project -> File
41
+ EdgeSchema(rel_type="HAS_TYPE"), # Package|Module|Project -> Class|Interface|Enum|Record
42
+ EdgeSchema(rel_type="HAS_NESTED_TYPE"), # type -> type
43
+ EdgeSchema(rel_type="DEFINED_IN"), # type -> File
44
+ EdgeSchema(rel_type="HAS_METHOD"), # type -> Method
45
+ EdgeSchema(rel_type="HAS_FIELD"), # type -> Field
46
+ EdgeSchema(rel_type="HAS_PARAMETER"), # Method|Record -> Parameter
47
+ EdgeSchema(rel_type="HAS_ENUM_MEMBER"), # Enum -> EnumMember
48
+ # Semantic layer.
49
+ EdgeSchema(rel_type="EXTENDS"), # Class -> Class ; Interface -> Interface(s)
50
+ EdgeSchema(rel_type="IMPLEMENTS"), # Class|Enum|Record -> Interface
51
+ EdgeSchema(rel_type="CALLS"), # Method -> Method; {resolution, receiver_type?}
52
+ EdgeSchema(rel_type="DEPENDS_ON"), # Method|Field -> type (parameter/return/field type refs)
53
+ ]
54
+
55
+ # Every label that can be an EXTENDS/IMPLEMENTS/HAS_TYPE/DEPENDS_ON type endpoint.
56
+ TYPE_LABELS = ("Class", "Interface", "Enum", "Record")
@@ -0,0 +1,12 @@
1
+ """Java web-framework enrichment -- a registered graph enrichment (post-pass), not a BaseIngestor or a
2
+ CLI command. It runs after the language engines and synthesizes Spring MVC route endpoints (APIEndpoint +
3
+ EXPOSES_ENDPOINT) from controller `@*Mapping` annotations, so a Java controller is a first-class HTTP
4
+ entry point the cross-language http-endpoints stitch resolves against any-language callers. See
5
+ synthesize.py (the Java analogue of pyframework)."""
6
+
7
+ from auryn.core.registry import GraphEnrichment, register_graph_enrichment
8
+ from auryn.ingestors.javaframework.synthesize import run as _run
9
+
10
+ register_graph_enrichment(GraphEnrichment(name="java-routes", run=_run))
11
+
12
+ __all__ = ["_run"]
@@ -0,0 +1,187 @@
1
+ """Java web-framework enrichment: the Spring (and Spring-Boot/JAX-RS-style) analogue of pyframework --
2
+ a post-pass that turns Spring MVC route annotations into `APIEndpoint` + `EXPOSES_ENDPOINT`, so a Java
3
+ controller method becomes a first-class HTTP entry point that the cross-language `http-endpoints` stitch
4
+ then resolves against ANY-language callers (`caller -CALLS_API-> APIEndpoint <-EXPOSES_ENDPOINT- handler`).
5
+
6
+ Java controllers were previously the one big web stack with NO endpoint graph (C#, Python FastAPI/Flask,
7
+ and HTTP callers were already covered; Java had nothing). It reads each controller method's stored
8
+ `source` (the method annotation `@GetMapping("/x")` is in the Method source; the class-level base
9
+ `@RequestMapping("/api")` is in the owning Class source) -- no source re-parsing of files, like orm.
10
+
11
+ Recognizes `@GetMapping/@PostMapping/@PutMapping/@DeleteMapping/@PatchMapping` (verb from the name) and
12
+ `@RequestMapping` (verb(s) from `method = RequestMethod.X`, else ANY), with the path from the first
13
+ positional string or `value=`/`path=` (a `produces=`/`consumes=` media type is NOT mistaken for a path).
14
+ Idempotent: recomputes only its own `provenance:"javaframework"` APIEndpoint layer."""
15
+
16
+ from __future__ import annotations
17
+
18
+ import logging
19
+ import re
20
+
21
+ from auryn.core import http_seam
22
+ from auryn.core.graph_client import GraphWriter, semantic_label
23
+ from auryn.core.graph_model import EdgeSchema, GraphEdge, GraphNode, NodeSchema
24
+
25
+ logger = logging.getLogger("auryn.javaframework")
26
+
27
+ _PROVENANCE = "javaframework"
28
+ _SCHEMA = [NodeSchema(label="APIEndpoint", indexed_properties=("route",))]
29
+ _EDGES = [EdgeSchema(rel_type="EXPOSES_ENDPOINT")]
30
+
31
+ _VERB_BY_ANN = {"GetMapping": "GET", "PostMapping": "POST", "PutMapping": "PUT",
32
+ "DeleteMapping": "DELETE", "PatchMapping": "PATCH"}
33
+ _ANN_NAME = re.compile(r"@(Get|Post|Put|Delete|Patch|Request)Mapping\b") # just the annotation name
34
+ _REQUEST_METHOD = re.compile(r"RequestMethod\.(\w+)")
35
+
36
+
37
+ def _balanced_args(text: str, start: int) -> str | None:
38
+ """The `(...)` args immediately after `start`, matched balanced + quote-aware (so a `)` inside a
39
+ quoted regex path var `{kind:(foo|bar)}` doesn't end the args early). None when there is no `(`."""
40
+ i = start
41
+ while i < len(text) and text[i] in " \t\r\n":
42
+ i += 1
43
+ if i >= len(text) or text[i] != "(":
44
+ return None
45
+ depth, j, in_str = 0, i, None
46
+ while j < len(text):
47
+ ch = text[j]
48
+ if in_str:
49
+ if ch == "\\":
50
+ j += 2
51
+ continue
52
+ if ch == in_str:
53
+ in_str = None
54
+ elif ch in "\"'":
55
+ in_str = ch
56
+ elif ch == "(":
57
+ depth += 1
58
+ elif ch == ")":
59
+ depth -= 1
60
+ if depth == 0:
61
+ return text[i + 1:j]
62
+ j += 1
63
+ return text[i + 1:] # unbalanced (malformed) -- take the rest
64
+
65
+
66
+ _VALUE_KW = re.compile(r"(?:\bvalue|\bpath)\s*=\s*")
67
+
68
+
69
+ def _route_arg(args: str) -> str | None:
70
+ """The route PATH from an annotation's `(...)` args, three-valued:
71
+ - a string -> the path (from `value=`/`path=` or the first positional string literal);
72
+ - `""` -> the annotation declares NO path (bare `@GetMapping`, or only kwargs like
73
+ `produces=`/`method=`) -> the route is the class base;
74
+ - `None` -> the path is an UNRESOLVABLE constant (`@GetMapping(Routes.USERS)`,
75
+ `@RequestMapping(path = Routes.USERS)`) -> skip (don't emit a wrong endpoint)."""
76
+ a = (args or "").strip()
77
+ if not a:
78
+ return "" # @X or @X() -> base
79
+ m = _VALUE_KW.search(a)
80
+ if m: # explicit value=/path= : a string is the path, anything else is an unresolvable constant
81
+ sm = re.match(r'\{?\s*["\']([^"\']*)["\']', a[m.end():].lstrip())
82
+ return sm.group(1) if sm else None
83
+ if a[0] in "\"'": # positional string (incl. "")
84
+ sm = re.match(r'["\']([^"\']*)["\']', a)
85
+ return sm.group(1) if sm else None
86
+ if a[0] == "{": # a {"/a","/b"} positional array
87
+ sm = re.search(r'["\']([^"\']*)["\']', a)
88
+ return sm.group(1) if sm else None
89
+ if re.match(r"\w+\s*=", a): # kwargs-only (produces=/consumes=/method=), no path -> base
90
+ return ""
91
+ return None # a bare positional constant (Routes.USERS) -> unresolvable
92
+
93
+
94
+ def _verbs(ann_name: str, args: str) -> list[str]:
95
+ """HTTP verb(s) for one annotation: the @<Verb>Mapping name, or @RequestMapping's `method =
96
+ RequestMethod.X` (possibly several), defaulting to ANY when a @RequestMapping names no method."""
97
+ if ann_name != "Request":
98
+ return [_VERB_BY_ANN[f"{ann_name}Mapping"]]
99
+ verbs = [m.group(1).upper() for m in _REQUEST_METHOD.finditer(args or "")]
100
+ return verbs or ["ANY"]
101
+
102
+
103
+ def _mappings(source: str) -> list[tuple[list[str], str]]:
104
+ """[(verbs, path)] for every mapping annotation in a source snippet (a method). Skips an annotation
105
+ whose path is an UNRESOLVABLE constant (`@GetMapping(Routes.USERS)` -- args present, no string literal,
106
+ not a verb-only `@RequestMapping(method=...)`): emitting it at the controller base would be wrong."""
107
+ out: list[tuple[list[str], str]] = []
108
+ for m in _ANN_NAME.finditer(source or ""):
109
+ args = _balanced_args(source, m.end())
110
+ path = _route_arg(args or "")
111
+ if path is None:
112
+ continue # an unresolvable constant path -> skip rather than materialize a wrong base endpoint
113
+ out.append((_verbs(m.group(1), args or ""), path))
114
+ return out
115
+
116
+
117
+ def _base_path(class_source: str) -> tuple[str, list[str]]:
118
+ """The class-level `@RequestMapping` base path + its default verb(s), read ONLY from the class HEADER
119
+ (before the body) so a method's own `@GetMapping("/x")` inside the body is never mistaken for the base.
120
+ Returns ("", ["ANY"]) when the controller declares no class-level @RequestMapping path."""
121
+ src = class_source or ""
122
+ kw = re.search(r"\b(?:class|interface|enum|record)\s+\w", src) # keyword + the class NAME, so `.class` in
123
+ header = src[:kw.start()] if kw else src # `@Validated(Group.class)` or `record` in a route string is not a false boundary
124
+ for m in _ANN_NAME.finditer(header):
125
+ if m.group(1) == "Request":
126
+ args = _balanced_args(header, m.end())
127
+ path = _route_arg(args or "")
128
+ if path:
129
+ return path, _verbs("Request", args or "")
130
+ return "", ["ANY"]
131
+
132
+
133
+ def _join(base: str, path: str) -> str:
134
+ """Join a controller base and a method path into one normalized route."""
135
+ combined = "/".join(p.strip("/") for p in (base, path) if p and p.strip("/"))
136
+ return http_seam.normalize_route("/" + combined if combined else (base or path or "/"))
137
+
138
+
139
+ def run(writer: GraphWriter, repo, target_sha: str) -> dict | None:
140
+ """GraphEnrichment entrypoint. Reads controller Class/Method source from the graph and synthesizes
141
+ the Java endpoint layer. Returns None when there are no Spring mappings."""
142
+ writer.setup_schema(_SCHEMA)
143
+ _clear_prior_layer(writer)
144
+
145
+ rows = writer.ro_query(
146
+ f"MATCH (c:Class)-[:HAS_METHOD]->(m:Method) "
147
+ f"WHERE m.source IS NOT NULL AND m.source CONTAINS 'Mapping' "
148
+ f"RETURN c.id, c.source, m.id, {semantic_label('m')}, m.name, m.source"
149
+ ).result_set
150
+
151
+ base_by_class: dict[str, tuple[str, list[str]]] = {}
152
+ nodes: list[GraphNode] = []
153
+ edges: list[GraphEdge] = []
154
+ handler_ids: set[str] = set()
155
+ for cid, csource, mid, mlabel, mname, msource in rows:
156
+ cid = str(cid)
157
+ if cid not in base_by_class:
158
+ base_by_class[cid] = _base_path(str(csource) if csource else "")
159
+ base, class_verbs = base_by_class[cid]
160
+ for verbs, path in _mappings(str(msource)):
161
+ route = _join(base, path)
162
+ # a method with no verb of its own (`@RequestMapping("/x")`) inherits the class-level default
163
+ # verb when the controller's `@RequestMapping` specified one (method = RequestMethod.X).
164
+ if verbs == ["ANY"] and class_verbs != ["ANY"]:
165
+ verbs = class_verbs
166
+ for verb in verbs:
167
+ endpoint_id = f"javaapi://{mid}#{verb}:{route}"
168
+ nodes.append(GraphNode("APIEndpoint", {"id": endpoint_id},
169
+ {"route": route, "http_method": verb, "framework": "spring",
170
+ "name": f"{verb} {route}", "handler": str(mname), "provenance": _PROVENANCE}))
171
+ edges.append(GraphEdge("EXPOSES_ENDPOINT", str(mlabel), {"id": str(mid)},
172
+ "APIEndpoint", {"id": endpoint_id}))
173
+ handler_ids.add(str(mid))
174
+
175
+ if not nodes:
176
+ return None
177
+ writer.merge_nodes(nodes)
178
+ writer.merge_edges(edges)
179
+ report = {"endpoints": len(nodes), "handlers": len(handler_ids)}
180
+ logger.info("java routes: %d endpoints across %d handlers", report["endpoints"], report["handlers"])
181
+ return report
182
+
183
+
184
+ def _clear_prior_layer(writer: GraphWriter) -> None:
185
+ """Recompute-from-scratch: DETACH DELETE this pass's own APIEndpoints (+ their EXPOSES_ENDPOINT),
186
+ scoped by provenance so C#/Python endpoints in the same graph are untouched."""
187
+ writer.query(f"MATCH (e:APIEndpoint {{provenance: '{_PROVENANCE}'}}) DETACH DELETE e")
@@ -0,0 +1,11 @@
1
+ Metadata-Version: 2.5
2
+ Name: auryn-java
3
+ Version: 0.1.0
4
+ Summary: Java language plugin for Auryn: a fast tree-sitter-java engine extracting packages/classes/interfaces/enums/records/methods/fields/params, the type hierarchy (EXTENDS/IMPLEMENTS), and calls. A deep pass (Eclipse JDT / javac symbol resolution) is the planned second phase.
5
+ Author-email: Roi Lipman <roi.lipman@falkordb.com>
6
+ License: SSPL-1.0
7
+ License-File: LICENSE
8
+ Requires-Python: >=3.12
9
+ Requires-Dist: auryn-core
10
+ Requires-Dist: tree-sitter-java>=0.23.5
11
+ Requires-Dist: tree-sitter>=0.26.0
@@ -0,0 +1,18 @@
1
+ auryn/ingestors/java/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ auryn/ingestors/java/file_parser.py,sha256=Y2qAXa0TnP5zPsmPUyJlFpnpgIZMGbtinWRov567DVs,13454
3
+ auryn/ingestors/java/git_sync.py,sha256=AbWO87LHThQoIfC_uKTrFbiRIEASFhF3iyx3kxlHP04,7814
4
+ auryn/ingestors/java/grammar.py,sha256=VjgPGiTZgAR5QOpySDlK-_nqDiWZCPaeISByHlMCB0E,467
5
+ auryn/ingestors/java/ids.py,sha256=cN_Eu96wlwKYaAmPffMHgi9tpgx8m9jE0065QTc3j1A,3380
6
+ auryn/ingestors/java/incremental.py,sha256=xquxjSEFmqQ4YjiNC8grEbzn9eQR6ZtkYUBCdiJeJfk,16626
7
+ auryn/ingestors/java/javamod.py,sha256=Es-owqXgEMi0inHYav93J6H0B2bYC4Jxk-grfp9SJGM,2887
8
+ auryn/ingestors/java/plugin.py,sha256=RRnzpMKZZRLtxTeMDNQ52RFAIItMA2D4BjPMW4-GCoc,1329
9
+ auryn/ingestors/java/raw_model.py,sha256=4tR2JoA_84Rn2a523j8Z-xvw0w1LEt9t3DC93FXGRHk,4485
10
+ auryn/ingestors/java/resolution.py,sha256=XLSoqR9m-ZbuDKwYoVkwodayMemaiEHQRWu_wTMU1FM,33818
11
+ auryn/ingestors/java/schema.py,sha256=z6efjI-_RLjUtWZPXD84Khgx4X_NER8lUnKIr8zEt8o,3370
12
+ auryn/ingestors/javaframework/__init__.py,sha256=AHadVxhdtEW_yX5zOQj-8u4FyfxwOSLo-uE3ont5M_0,695
13
+ auryn/ingestors/javaframework/synthesize.py,sha256=xujIZb60RSueuACKT1i80p6E1B0i6rGSbMHcqpZKBoU,9337
14
+ auryn_java-0.1.0.dist-info/METADATA,sha256=zhSeBG_vuHDASsdPl-MyJKW13qh3p2NSStkIZAuQuC4,551
15
+ auryn_java-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
16
+ auryn_java-0.1.0.dist-info/entry_points.txt,sha256=SdODqVbaaTDLOvlEF9_T6RmTCR7AXMMKY-sXujv9FDo,120
17
+ auryn_java-0.1.0.dist-info/licenses/LICENSE,sha256=NOlMUIe6bp-zTzWucd9eZTPF_Hy79sRBhqcegoBraeE,30582
18
+ auryn_java-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.33.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,5 @@
1
+ [auryn.enrichments]
2
+ javaframework = auryn.ingestors.javaframework
3
+
4
+ [auryn.languages]
5
+ java = auryn.ingestors.java.plugin