A method, tool and computer device for detecting java code dependencies

The method and tool for detecting Java code dependencies automate the detection of customized and standard code dependencies using Java-specific methods, enhancing detection efficiency and reducing product launch risks.

CN114327375BActive Publication Date: 2024-12-27SHANGHAI ZHENYUN INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202111617934.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-27
Publication Date
2024-12-27
Estimated Expiration
2041-12-27

AI Technical Summary

Technical Problem

Existing cloud SAAS services face challenges in determining the dependency between customized and standard code, which can impact business scenario needs and increase the risk of online issues during product iterations.

Method used

A method and tool utilizing Java code characteristics to automatically detect dependencies between customized and standard code, employing API path comparison, annotation analysis, class reflection, and inheritance, packaged as a spring boot dependency, with a one-key search interface for developers to identify code dependencies.

Benefits of technology

The tool achieves a high retrieval coverage rate of 90% and allows developers to quickly locate and address potential issues, reducing the risk of product launch impacts by automating the detection process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114327375B_ABST
    Figure CN114327375B_ABST
Patent Text Reader

Abstract

The present invention discloses a method, tool and computer equipment for detecting java code dependency. The detection tool automatically retrieves code dependency using the characteristics of java code itself, such as API path comparison, annotation analysis, class reflection, JAVA class inheritance, JAVA method rewriting, code comparison, etc., and packages the tool as a spring boot dependency; the scanned service adds dependency on the current tool boot, and a front-end one-key search button is provided to scan out the dependency between all customized codes and standard codes in the service, which greatly reduces the time cost and objective omission of developers manually searching for the dependency of customized codes on standard codes in massive codes, reduces the workload of developers themselves, and also reduces the impact and risk of product release and launch.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of standardized product iteration based on Java, and in particular to a method for detecting the dependency relationship between customized code and standard code. Background Art

[0002] As a cloud SAAS service, the digital procurement platform supports a wide range of standardized business scenarios. The specific needs of 2B products and 2C products are different. Standard product modules alone are difficult to meet the business scenario needs of companies in different industries, so customized customization and scenarios based on standard customization are derived.

[0003] In order to reduce the impact of standardized product iterations on customized code, it is necessary to determine the dependency between customized code and standard code as early as possible and solve the problem before the impact occurs. Summary of the invention

[0004] Based on this, in order to solve the above technical problems, a method, tool and computer equipment for detecting Java code dependencies are provided, which utilize the characteristics of Java itself to automatically retrieve the dependencies between customized code and standard code, thereby reducing the risk of going online.

[0005] In a first aspect, a method for detecting Java code dependencies includes:

[0006] Receive search keywords input by the user;

[0007] Determine the code type of the search keyword; the multiple code types correspond to three situations: based on standard customized API, based on standard customized inheritance rewriting, and customized calling standard;

[0008] According to the code type of the current search keyword, the characteristics of the Java code itself are used to retrieve the dependencies of all customized codes and standard codes in the service, and the data is entered into a table to feedback the search results.

[0009] Furthermore, corresponding to the case of the standard customized API, the specific implementation steps include:

[0010] a1) Get all Controller classes in the bean factory through the @RestController annotation;

[0011] a2) Annotate the API paths of all methods of the Controller class that have been scanned in the past with @GetMaping, @DeleteMaping, @PostMapping, and @PutMapping, and record the correspondence between the paths and the class method collection in the Map;

[0012] a3) Traverse the Map and retrieve the data with class method sets greater than 1 in the Map, one of which is a standard method pointing to the API path, and the rest are customized method pointers;

[0013] a4) Define the current result as a customized type of Controller and store the data in a table.

[0014] Furthermore, corresponding to the case of the standard customized inheritance rewriting, the specific implementation steps include:

[0015] b1) Get the implementation classes of all customized annotations in the bean factory through the @Tenant annotation;

[0016] b2) Get all method objects in the class with customized annotations, and get the parent class and all method objects of the customized class;

[0017] b3) Compare the methods with the same method name and the same method parameters in the subclass and parent class, store the parent class method as the key in a new Map, put the subclass method into a collection with the value of list, record the correspondence between the standard class + method and the customized class + method, and put the data into the table.

[0018] Furthermore, corresponding to the customized calling standard, the specific implementation steps include:

[0019] c1) Traverse the bean factory and obtain all classes related to the business implementation of the digital procurement platform;

[0020] c2) Loop and determine the current class, obtain the current class path, and determine whether the class is a class of the standard service second opening project;

[0021] c3) If the current class is a class of the standard service second-opening project, decompress the jar package that satisfies the class; obtain the class path of the corresponding class after decompression, obtain its file stream and restore it to code text, record the relationship between the current class name and the code text into a Map, and cache the Map locally;

[0022] c4) Get all injected objects of the current class, and select the injected objects as the class of standard services according to the class path; if the injected objects are the class of standard services, search in the code text according to the corresponding keywords (the keyword can be in the form of "injection class name +)"), and the retrieved method is the method for calling the standard by the customized code;

[0023] c5) Obtain all method names of the parent class of the current class, and search for methods whose parent class method names exist in the current class text. The searched methods are the methods that the customized code calls the standard;

[0024] c6) Store the results obtained in step c4) and step c5) in a Map, combine them with the relationship between the class name and the code text recorded in step 3), and finally perform data entry into a table.

[0025] Furthermore, the corresponding keyword in step c4) is in the form of: the injected class attribute name as the start value of the search, and ")" as the end value of the search.

[0026] Furthermore, before the step of receiving the search keyword input by the user, the main program of the method for detecting the dependency of the Java code is packaged as a spring boot dependency; the scanned service adds a dependency on the current tool boot.

[0027] In the second aspect, a tool for detecting Java code dependencies is packaged as a spring boot dependency; the tool includes:

[0028] The search input module is used to generate a search input box and a one-key search button on the human-computer interaction interface to receive the search keywords input by the user;

[0029] A search code type identification module is used to determine the code type of the search keyword; the multiple code types correspond to three situations: based on standard customized API, based on standard customized inheritance rewriting, and customized calling standard;

[0030] The scanning execution module is used to retrieve the dependencies of all customized codes and standard codes in the service based on the code type of the current search keyword by using the characteristics of the Java code itself, and then table the data and feedback the search results.

[0031] In a third aspect, a computer device includes a memory and a processor, wherein the memory stores a computer program, and wherein the processor implements the above-mentioned method for detecting Java code dependencies when executing the computer program.

[0032] The present invention has at least the following beneficial effects:

[0033] The present invention is simple to implement. It can automatically detect the code logic and dependency relationships based on standard customization through the characteristics of the Java code itself, and store the retrieved dependency relationships in a table. With a matching visual front-end, the corresponding class name, method name, and API path can be directly retrieved through keywords in the front-end interface to obtain the corresponding results of the dependency. The test results show that the retrieval coverage rate is as high as 90%, and users can also quickly locate problems through this tool.

[0034] The present invention uses API path comparison, annotation analysis, class reflection, JAVA class inheritance, JAVA method rewriting, and text retrieval as the core logic of this tool, and packages this tool as a spring boot dependency; the scanned service adds a dependency on the current tool boot, and a front-end one-key retrieval button is provided to scan out the dependencies of all customized codes and standard codes in the service, so that developers can check the impact of the current modified code on the dependent code during the development process. BRIEF DESCRIPTION OF THE DRAWINGS

[0035] Figure 1 A schematic diagram of the principle of a tool for detecting Java code dependencies provided by an embodiment of the present invention;

[0036] Figure 2 This is a customized calling standard retrieval logic diagram for the third situation in one embodiment of the present invention. DETAILED DESCRIPTION

[0037] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0038] In one embodiment, Figure 1 As shown, a tool for detecting java code dependencies is provided. The core logic of this tool is to retrieve codes through API path comparison, annotation analysis, class reflection, JAVA class inheritance, JAVA method rewriting, and code comparison. This tool is packaged as a spring boot dependency. The scanned service adds a dependency on the current tool boot, and the front-end one-click search button is provided to scan the dependencies of all customized codes and standard codes in the service, so that developers can check the impact of the current modified code on the dependent code during the development process. The tool uses the characteristics of java itself to automatically retrieve the dependencies between customized code and standard code, reducing the risk of going online.

[0039] The tool includes at least the following program modules:

[0040] The search input module is used to generate a search input box and a one-key search button on the human-computer interaction interface to receive the search keywords input by the user;

[0041] A search code type identification module is used to determine the code type of the search keyword; the multiple code types correspond to three situations: based on standard customized API, based on standard customized inheritance rewriting, and customized calling standard;

[0042] The scanning execution module is used to retrieve the dependencies of all customized codes and standard codes in the service based on the code type of the current search keyword by using the characteristics of the Java code itself, and then table the data and feedback the search results.

[0043] Accordingly, in one embodiment, a method for detecting Java code dependencies is provided, comprising:

[0044] S1: receiving search keywords input by the user;

[0045] S2: Determine the code type of the search keyword; the multiple code types correspond to three situations: based on standard customized API, based on standard customized inheritance rewriting, and customized calling standard;

[0046] S3: For the code type of the current search keyword, use the characteristics of the Java code itself to retrieve the dependencies of all customized codes and standard codes in the service, and then enter the data into a table and feedback the search results.

[0047] The implementation steps of the present invention are different according to the type of the retrieval code, and the specific steps are as follows:

[0048] (1) API path rewriting: There is a customized solution. The API interface paths are consistent in different Controllers. The corresponding scenario is that the front end calls the same API, and different users dynamically enter different Controller execution classes.

[0049] a) Get all Controller classes in the bean factory through the @RestController annotation;

[0050] b) Annotate the API paths of all methods of the Controller class that have been scanned in the past with @GetMaping, @DeleteMaping, @PostMapping, and @PutMapping, and record the correspondence between the paths and the class method collection in the Map;

[0051] c) Traverse the Map and retrieve the data whose value (class method set) is greater than 1. If it is greater than 1, it means that multiple methods are used for one API path. Among the retrieved data, one is the standard method pointing to the API path, and the rest are customized method pointers;

[0052] d) Define the current result as a customized Controller type and store the data in a table.

[0053] (2) Class inheritance method rewriting, there is a customized solution, inheriting the standard service implementation, rewriting some standard methods, customizing user logic, and switching to different subclasses according to different users.

[0054] a) Get the implementation class of all customized annotations in the bean factory through the @Tenant annotation;

[0055] b) Get all method objects in the class with customized annotations, and get the parent class and all method objects of the customized class;

[0056] c) Compare the methods with the same method name and the same method parameters in the subclass and parent class, store the parent class method as the key in a new Map, and put the subclass method into a collection with the value of list, and record the correspondence between the standard class + method and the customized class + method;

[0057] d) Record the corresponding relationship in the table.

[0058] (3) Customized classes call standard methods. There are customized implementations. The methods provided by the standard meet most of the logic. Customized classes only need to call standard methods. Supplementing some customized logic can meet customized business needs. The specific steps are as follows. The process can be referred to Figure 2 .

[0059] a) Traverse all classes in the bean factory that are not Controller, Config, etc. and are related to the business implementation of the digital procurement platform;

[0060] b) Determine and loop the current class, obtain the current class path, and determine whether the class is a class of the standard service second opening project;

[0061] c) Unzip the jar package that meets the above conditions;

[0062] d) Get the class path of the corresponding class after the current decompression, and then get its file stream to restore it to code text, record the relationship between the current class name and the code text into a Map, and cache the Map locally to prevent subsequent repeated decompression and parsing;

[0063] e) Get all injected objects of the current class, and filter the injected objects as standard service classes according to the class path;

[0064] f) The injected class attribute name is used as the start value of the search, and ")" is used as the end value of the search. In the code text search, the retrieved method is the method that the customized code calls the standard method;

[0065] g) Get all method names in the parent class (class belonging to standard services) of the current class, and retrieve the methods whose parent class method names exist in the current class text. The retrieved methods are the methods that the customized code calls the standard methods;

[0066] h) Store the results obtained by f and g in Map and finally put them into the table.

[0067] The above steps will comprehensively scan based on the standard customized API, based on the standard customized inheritance rewrite, and customized calling standard, and finally enter the table to form the final retrieved data.

[0068] The embodiment of the present invention automatically retrieves code dependencies through the characteristics of Java code itself, such as API path comparison, annotation analysis, class reflection, JAVA class inheritance, JAVA method rewriting, code comparison, etc., greatly reducing the time cost and objective omissions of developers manually searching for the dependency of customized code on standard code in massive code, and reducing the workload of developers themselves. At the same time, after the problem is located and solved by the automated tool, the impact and risk of product release and launch will be greatly reduced.

[0069] In one embodiment, a computer device is also provided, which may be a terminal. The computer device may generally include a processor, a memory, a communication interface, a display screen, and an input device connected via a system bus. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. When the computer program is executed by the processor, a method for detecting Java code dependencies in the above embodiment is implemented.

[0070] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0071] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be subject to the attached claims.

Claims

1. A method for detecting Java code dependencies, characterized in that: include: Receive search keywords input by the user; Determine the code type of the search keyword; The various code types correspond to three situations: based on standard customized API, based on standard customized inheritance rewriting, and customized calling standards; based on standard customized API, it means that the front end calls the same API, and different users dynamically switch to different Controller execution classes; based on standard customized inheritance rewriting, it means inheriting the standard service implementation, rewriting some standard methods, customizing user logic, and switching to different subclasses according to different users; the customized calling standard means calling the standard method through the customized class, and then supplementing some customized logic; According to the code type of the current search keyword, the dependency relationship between all customized codes and standard codes in the service is retrieved by using the characteristics of the Java code itself, and the data is entered into a table to feedback the search results; Corresponding to the case of the standard customized API, the specific implementation steps include: a1) Get all Controller classes in the bean factory through the @RestController annotation; a2) Annotate the API paths of all methods of the Controller class that have been scanned in the past with @GetMapping, @DeleteMapping, @PostMapping, and @PutMapping, and record the correspondence between the paths and the class method collection in the Map; a3) Traverse the Map and retrieve the data with class method sets greater than 1 in the Map, one of which is a standard method pointing to the API path, and the rest are customized method pointers; a4) Define the current result as a customized type of Controller and store the data in a table; Corresponding to the above situation of inheritance rewriting based on standard customization, the specific implementation steps include: b1) Get the implementation class of all customized annotations in the bean factory through the @Tenant annotation; b2) Get all method objects in the class with customized annotations, and get the parent class and all method objects of the customized class; b3) Compare the methods with the same method name and the same method parameters in the subclass and the parent class, store the parent class method as the key in newMap, put the subclass method into the collection with the value of list, record the correspondence between the standard class + method and the customized class + method, and put the data into the table; Corresponding to the case of the customized calling standard, the specific implementation steps include: c1) Traverse the bean factory and obtain all classes related to the business implementation of the digital procurement platform; c2) Loop and determine the current class, obtain the current class path, and determine whether the current class is a class of the standard service second opening project; c3) If the current class is a class of the standard service second-opening project, decompress the jar package that satisfies the current class; obtain the class path of the corresponding class after decompression, obtain its file stream and restore it to code text, record the relationship between the current class name and the code text into a Map, and cache the Map locally; c4) Obtain all injected objects of the current class, and select the injected objects as the class of standard services according to the class path; if the injected objects are the class of standard services, search in the code text according to the corresponding keywords, and the retrieved method is the method for calling the standard by the customized code; c5) Obtain all method names of the parent class of the current class, and search for methods whose parent class method names exist in the current class text. The searched methods are the methods that the customized code calls the standard method; c6) The results obtained in step c4) and step c5) are stored in a Map, combined with the relationship between the class name and the code text recorded in step c3), and finally the data is entered into a table.

2. The method for detecting Java code dependencies according to claim 1, characterized in that: The corresponding keywords in step c4) are in the form of: the injected class attribute name as the start value of the search, and ")" as the end value of the search.

3. The method for detecting Java code dependencies according to claim 1, characterized in that: Before the step of receiving the search keyword input by the user, the main program of the method for detecting the dependency of the Java code is packaged as a spring boot dependency; the scanned service adds a dependency on the current tool boot.

4. A tool for detecting Java code dependencies, characterized in that: Packaged as a spring boot dependency; the tool includes: The search input module is used to generate a search input box and a one-key search button on the human-computer interaction interface to receive the search keywords input by the user; The retrieval code type identification module is used to determine the code type of the search keyword; the multiple code types correspond to three situations: based on standard customized API, based on standard customized inheritance rewriting, and customized calling standard; the based on standard customized API means that the front end calls the same API, and different users dynamically switch to different Controller execution classes; the based on standard customized inheritance rewriting means inheriting the standard service implementation, rewriting some standard methods, customizing user logic, and switching to different subclasses according to different users; the customized calling standard means calling the standard method through the customized class, and then supplementing some customized logic; The scanning execution module is used to retrieve the dependencies between all customized codes and standard codes in the service based on the code type of the current search keyword by using the characteristics of the Java code itself, and then table the data and feedback the search results. Corresponding to the case of the standard customized API, the specific implementation steps include: a1) Get all Controller classes in the bean factory through the @RestController annotation; a2) Annotate the API paths of all methods of the Controller class that have been scanned in the past with @GetMapping, @DeleteMapping, @PostMapping, and @PutMapping, and record the correspondence between the paths and the class method collection in the Map; a3) Traverse the Map and retrieve the data with class method sets greater than 1 in the Map, one of which is a standard method pointing to the API path, and the rest are customized method pointers; a4) Define the current result as a customized type of Controller and store the data in a table; Corresponding to the above situation of inheritance rewriting based on standard customization, the specific implementation steps include: b1) Get the implementation class of all customized annotations in the bean factory through the @Tenant annotation; b2) Get all method objects in the class with customized annotations, and get the parent class and all method objects of the customized class; b3) Compare the methods with the same method name and the same method parameters in the subclass and the parent class, store the parent class method as the key in newMap, put the subclass method into the collection with the value of list, record the correspondence between the standard class + method and the customized class + method, and put the data into the table; Corresponding to the case of the customized calling standard, the specific implementation steps include: c1) Traverse the bean factory and obtain all classes related to the business implementation of the digital procurement platform; c2) Loop and determine the current class, obtain the current class path, and determine whether the current class is a class of the standard service second opening project; c3) If the current class is a class of the standard service second-opening project, decompress the jar package that satisfies the current class; obtain the class path of the corresponding class after decompression, obtain its file stream and restore it to code text, record the relationship between the current class name and the code text into a Map, and cache the Map locally; c4) Obtain all injected objects of the current class, and select the injected objects as the class of standard services according to the class path; if the injected objects are the class of standard services, search in the code text according to the corresponding keywords, and the retrieved method is the method for calling the standard by the customized code; c5) Obtain all method names of the parent class of the current class, and search for methods whose parent class method names exist in the current class text. The searched methods are the methods that the customized code calls the standard method; c6) The results obtained in step c4) and step c5) are stored in a Map, combined with the relationship between the class name and the code text recorded in step c3), and finally the data is entered into a table.

5. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the method for detecting Java code dependencies according to any one of claims 1 to 3 is implemented.