Skip to content

Commit 284aa1e

Browse files
committed
slim json
Signed-off-by: Rahul Krishna <i.m.ralk@gmail.com>
1 parent 96325a8 commit 284aa1e

4 files changed

Lines changed: 30 additions & 97 deletions

File tree

cldk/analysis/analysis_level.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
class AnalysisLevel(str, Enum):
2525
"""Analysis levels"""
2626

27-
symbol_table = "symbol-table"
28-
call_graph = "call-graph"
29-
program_dependency_graph = "program-dependency-graph"
30-
system_dependency_graph = "system-dependency-graph"
27+
symbol_table = "symbol table"
28+
call_graph = "call graph"
29+
program_dependency_graph = "program dependency graph"
30+
system_dependency_graph = "system dependency graph"

cldk/models/java/models.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,10 @@ class JGraphEdges(BaseModel):
360360
@field_validator("source", "target", mode="before")
361361
@classmethod
362362
def validate_source(cls, value) -> JMethodDetail:
363-
file_path, type_declaration, signature = value["file_path"], value["type_declaration"], value["signature"]
364-
if file_path == "":
365-
j_callable = JCallable(
363+
_, type_declaration, signature = value["file_path"], value["type_declaration"], value["signature"]
364+
j_callable = _CALLABLES_LOOKUP_TABLE.get(
365+
(type_declaration, signature),
366+
JCallable(
366367
signature=signature,
367368
is_implicit=True,
368369
is_constructor="<init>" in value["callable_declaration"],
@@ -380,11 +381,9 @@ def validate_source(cls, value) -> JMethodDetail:
380381
call_sites=[],
381382
variable_declarations=[],
382383
cyclomatic_complexity=0,
383-
)
384-
else:
385-
j_callable = _CALLABLES_LOOKUP_TABLE.get((type_declaration, signature), None)
386-
if j_callable is None:
387-
raise ValueError(f"Callable not found in lookup table: {file_path}, {type_declaration}, {signature}")
384+
),
385+
)
386+
_CALLABLES_LOOKUP_TABLE[(type_declaration, signature)] = j_callable
388387
class_name = type_declaration
389388
method_decl = j_callable.declaration
390389
return JMethodDetail(method_declaration=method_decl, klass=class_name, method=j_callable)

tests/analysis/java/test_java.py

Lines changed: 19 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -13,90 +13,38 @@
1313
from urllib.request import urlretrieve
1414

1515

16-
@pytest.fixture(scope="session", autouse=True)
17-
def test_fixture(application: str = ''):
18-
"""
19-
Returns the path to the test data directory.
20-
21-
Yields:
22-
Path : The path to the test data directory.
23-
"""
24-
# ----------------------------------[ SETUP ]----------------------------------
25-
# Path to your pyproject.toml
26-
pyproject_path = Path(__file__).parent.parent.parent.parent / "pyproject.toml"
27-
28-
# Load the configuration
29-
config = toml.load(pyproject_path)
30-
31-
# Access the test data path
32-
test_data_path = config["tool"]["cldk"]["testing"]["sample-application"]
33-
34-
if not Path(__file__).parent.parent.parent.parent.joinpath(test_data_path).exists():
35-
Path(test_data_path).mkdir(parents=True)
36-
if application == "daytrader":
37-
url = "https://github.com/OpenLiberty/sample.daytrader8/archive/refs/tags/v1.2.zip"
38-
filename = Path(test_data_path).absolute() / "v1.2.zip"
39-
elif application == "CLI" or application == "":
40-
url = "https://github.com/apache/commons-cli/archive/refs/tags/commons-cli-1.8.0-RC2.zip"
41-
filename = Path(__file__).parent.parent.parent.parent.joinpath(test_data_path).joinpath("commons-cli-1.8.0-RC2.zip")
42-
urlretrieve(url, filename)
43-
44-
# Extract the zip file to the test data path
45-
with zipfile.ZipFile(filename, "r") as zip_ref:
46-
zip_ref.extractall(Path(__file__).parent.parent.parent.parent.joinpath(test_data_path))
47-
48-
# Remove the zip file
49-
filename.unlink()
50-
# --------------------------------------------------------------------------------
51-
if application == "daytrader":
52-
# Daytrader8 sample application path
53-
yield Path(Path(__file__).parent.parent.parent.parent.joinpath(test_data_path)) / "sample.daytrader8-1.2"
54-
else:
55-
yield Path(Path(__file__).parent.parent.parent.parent.joinpath(test_data_path)) / "commons-cli-commons-cli-1.8.0-RC2"
56-
57-
# -----------------------------------[ TEARDOWN ]----------------------------------
58-
# Remove the daytrader8 sample application that was downloaded for testing
59-
for directory in Path(test_data_path).iterdir():
60-
if directory.exists() and directory.is_dir():
61-
shutil.rmtree(directory)
62-
# ---------------------------------------------------------------------------------
63-
64-
65-
@pytest.mark.parametrize('test_fixture', ['daytrader'], indirect=['test_fixture'])
66-
def test_get_class_call_graph(test_fixture):
16+
# @pytest.mark.parametrize("test_fixture", ["daytrader"], indirect=["test_fixture"])
17+
def test_get_class_call_graph(test_fixture, codeanalyzer_jar_path):
6718
# Initialize the CLDK object with the project directory, language, and analysis_backend.
6819
cldk = CLDK(language="java")
6920

7021
analysis = cldk.analysis(
7122
project_path=test_fixture,
7223
analysis_backend="codeanalyzer",
73-
analysis_json_path="../../../tests/resources/java/analysis_db",
24+
analysis_backend_path=codeanalyzer_jar_path,
7425
eager=True,
75-
analysis_level=AnalysisLevel.call_graph
26+
analysis_level=AnalysisLevel.call_graph,
7627
)
7728
class_call_graph: List[Tuple[JMethodDetail, JMethodDetail]] = analysis.get_class_call_graph(
7829
qualified_class_name="com.ibm.websphere.samples.daytrader.impl.direct.TradeDirectDBUtils"
7930
)
80-
8131
assert class_call_graph is not None
8232

8333

84-
@pytest.mark.parametrize('test_fixture', ['CLI'], indirect=['test_fixture'])
85-
def test_get_class_call_graph_using_symbol_table(test_fixture):
86-
# Initialize the CLDK object with the project directory, language, and analysis_backend.
87-
cldk = CLDK(language="java")
34+
# @pytest.mark.parametrize("test_fixture", ["CLI"], indirect=["test_fixture"])
35+
# def test_get_class_call_graph_using_symbol_table(test_fixture):
36+
# # Initialize the CLDK object with the project directory, language, and analysis_backend.
37+
# cldk = CLDK(language="java")
8838

89-
analysis = cldk.analysis(
90-
project_path=test_fixture,
91-
analysis_backend="codeanalyzer",
92-
analysis_json_path="../../../tests/resources/java/analysis_db",
93-
eager=False,
94-
analysis_level=AnalysisLevel.symbol_table
95-
)
96-
class_call_graph: List[Tuple[JMethodDetail, JMethodDetail]] = analysis.get_class_call_graph(
97-
qualified_class_name="org.apache.commons.cli.DefaultParser",
98-
method_signature="handleConcatenatedOptions(String)",
99-
using_symbol_table=True
100-
)
39+
# analysis = cldk.analysis(
40+
# project_path=test_fixture,
41+
# analysis_backend="codeanalyzer",
42+
# analysis_json_path="../../../tests/resources/java/analysis_db",
43+
# eager=False,
44+
# analysis_level=AnalysisLevel.symbol_table,
45+
# )
46+
# class_call_graph: List[Tuple[JMethodDetail, JMethodDetail]] = analysis.get_class_call_graph(
47+
# qualified_class_name="org.apache.commons.cli.DefaultParser", method_signature="handleConcatenatedOptions(String)", using_symbol_table=True
48+
# )
10149

102-
assert class_call_graph is not None
50+
# assert class_call_graph is not None

tests/test_core.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
# def test_specifiy_codeanalyzer_analysis_backend_manually(test_fixture):
2-
# # Initialize the CLDK object with the project directory, language, and analysis_backend.
3-
# ns = CLDK(
4-
# project_dir=test_fixture[0],
5-
# language="java",
6-
# analysis_backend="codeanalyzer",
7-
# analysis_backend_path=test_fixture[1],
8-
# analysis_json_path="/tmp",
9-
# sdg=True,
10-
# use_graalvm_binary=False,
11-
# eager=False,
12-
# )
13-
# assert ns.preprocessing.get_all_classes() is not None
14-
151
# def test_specifiy_codeanalyzer_backend_manually(test_fixture):
162
# # Initialize the CLDK object with the project directory, language, and backend.
173
# ns = CLDK(

0 commit comments

Comments
 (0)