Giter VIP home page Giter VIP logo

jcci's Introduction

Visitors

jcci

介绍

Java代码提交影响分析,是一个纯python库,分析Java项目的两次git提交差异对项目的影响,并生成树形图数据。

PYPI: jcci (会落后github几个版本)

实现效果

效果图

软件架构

大致原理同Idea的Find Usage一致,通过代码改动定位代码影响,并不断遍历受影响的类和方法直至找到最上层的controller层

代码主要由python编写,主要涉及2个库:

  • javalang java文件语法解析库
  • unidiff git diff信息解析库

通过javalang语法解析获取每个Java文件的import class extends implements declarators methods 等信息

通过unidiff 解析git diff信息(diff file, added_line_num, removed_lin_num)

然后根据文件增删的代码行去判断影响了哪些类和方法,不断遍历受影响的类和方法直至找到最上层的controller层

通过传入项目git地址 分支 两次的commit id,即可分析出两次commit id之间代码改动所带来的影响,并生成树图数据方便展示影响链路。

安装教程

要求python >= 3.9 , sqlite3 >= 3.38

使用说明

项目克隆下来后,新建python文件,引入jcci项目src目录下的jcci

from path.to.jcci.src.jcci.analyze import JCCI

# 同一分支不同commit分析
commit_analyze = JCCI('[email protected]', 'username1')
commit_analyze.analyze_two_commit('master','commit_id1','commit_id2')

# 分析一个类的方法影响, analyze_class_method方法最后参数为方法所在行数,不同方法行数用逗号分割,不填则分析完整类影响
class_analyze = JCCI('[email protected]', 'username1')
class_analyze.analyze_class_method('master','commit_id1', 'package\src\main\java\ClassA.java', '20,81')

# 不同分支分析
branch_analyze = JCCI('[email protected]', 'username1')
branch_analyze.analyze_two_branch('branch_new','branch_old')

# 多项目联合分析,上述三种方法都支持,以analyze_two_commit方法举例
dependents = [
    {
        'git_url': '[email protected]',
        'branch': 'master',  # default master when empty
        'commit_id': 'HEAD'  # default HEAD when empty
    }
]
commit_analyze = JCCI('[email protected]', 'username1')
commit_analyze.analyze_two_commit('master','commit_id1','commit_id2', dependents=dependents)

参数说明:

  • project_git_url - 项目git地址,代码使用本机git配置clone代码,确保本机git权限或通过用户名密码/token的方式拼接url来clone代码。示例:https://userName:[email protected]/xxx.githttps://[email protected]/xxx.git
  • username1 - 随便输入,为了避免并发分析同一项目导致结果错误,用户1分析项目A时,用户B需要等待,所以设置了该参数

运行时,会将项目克隆到目录中,然后进行分析,生成后缀格式为.cci的文件,其中包含分析结果生成的关系图数据,下载jcci-result.html ,选择分析结果的.cci文件,即可可通过视图显示。

安全性

项目分析都是基于本地环境执行,无任何代码收集和日志上报,源码可查,请放心使用。

开源不易,如本工具对您有帮助,请点一下右上角 star ⭐

沟通交流

扫码加微信,备注:JCCI微信群交流,或者扫码加入钉钉交流群

微信交流群 钉钉交流群

鸣谢

感谢一下同学请作者喝咖啡、提供意见或反馈Bug, 排名不分先后 zouchengli

Star History

Star History Chart

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.