Skip to content

Update get entrypoint classes and methods #85

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 6, 2025

Conversation

rahlk
Copy link
Collaborator

@rahlk rahlk commented Feb 6, 2025

Motivation and Context

We had a number of problems with singleton classes for entrypoint detection. So we moved the logic to codeanalyzer-java v2.1.0 and CLDK just uses the data model to decipher if the class or method is an entrypoint.

How Has This Been Tested?

Added 2 test cases in tests/analysis/java/test_jcodeanalyzer.py:

def test_get_all_entrypoint_methods_in_application(test_fixture, codeanalyzer_jar_path):
    """It should return all of the methods in an application"""
    code_analyzer = JCodeanalyzer(
        project_dir=test_fixture,
        source_code=None,
        analysis_backend_path=codeanalyzer_jar_path,
        analysis_json_path=None,
        analysis_level=AnalysisLevel.symbol_table,
        use_graalvm_binary=False,
        eager_analysis=False,
        target_files=None,
    )
    entrypoint_methods = code_analyzer.get_all_entry_point_methods()
    assert entrypoint_methods is not None
    assert isinstance(entrypoint_methods, Dict)
    assert len(entrypoint_methods) > 0
    # Validate structure
    for _, method in entrypoint_methods.items():
        assert method is not None
        assert isinstance(method, Dict)
        for _, callable in method.items():
            assert callable is not None
            assert isinstance(callable, JCallable)
            assert callable.is_entrypoint


def test_get_all_entrypoint_classes_in_the_application(test_fixture, codeanalyzer_jar_path):
    """It should return all of the methods in an application"""
    code_analyzer = JCodeanalyzer(
        project_dir=test_fixture,
        source_code=None,
        analysis_backend_path=codeanalyzer_jar_path,
        analysis_json_path=None,
        analysis_level=AnalysisLevel.symbol_table,
        use_graalvm_binary=False,
        eager_analysis=False,
        target_files=None,
    )
    entrypoint_classes = code_analyzer.get_all_entry_point_classes()
    assert entrypoint_classes is not None
    assert isinstance(entrypoint_classes, Dict)
    assert len(entrypoint_classes) > 0
    # Validate structure
    for _, cls in entrypoint_classes.items():
        assert cls is not None
        assert isinstance(cls, JType)
        assert cls.is_entrypoint_class

These can be run with

pytest --pspec --cov=cldk --disable-warnings tests/analysis/java/test_jcodeanalyzer.py -k "test_get_all_entrypoint_methods_in_application or test_get_all_entrypoint_classes_in_the_application" -s

Breaking Changes

No

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the Codellm-Devkit Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

  • This PR includes some C analysis updates to pyproject.toml so that the test cases run.
  • Also fixed find_libclang() so that the lookup for libclang.so works:
         lib_paths = [Path("/usr/lib"), Path("/usr/lib64")]
         possible_paths = [
             - "/usr/lib/llvm-14/lib/libclang.so",
             - "/usr/lib/llvm-13/lib/libclang.so",
             - "/usr/lib/llvm-12/lib/libclang.so",
             - "/usr/lib/x86_64-linux-gnu/libclang-14.so.1",
             - "/usr/lib/libclang.so",
             + str(p) for base in lib_paths if base.exists()
             + for p in base.rglob("libclang*.so*")
         ]

Signed-off-by: Rahul Krishna <i.m.ralk@gmail.com>
@rahlk rahlk requested review from rofrano and pavuluri February 6, 2025 16:03
@rahlk rahlk self-assigned this Feb 6, 2025
Copy link
Collaborator

@pavuluri pavuluri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good to me in terms of moving entry point detection out of CLDK and keeping the same interface.

Signed-off-by: Rahul Krishna <i.m.ralk@gmail.com>
@rahlk rahlk merged commit 2589257 into main Feb 6, 2025
@rahlk rahlk deleted the update-entrypoints-from-latest-codeanalyzer branch February 6, 2025 17:27
@rahlk rahlk added breaking Breaking Changes fix Bug fixes refactoring Refactoring performance Performance updates labels Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking Breaking Changes fix Bug fixes performance Performance updates refactoring Refactoring
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants