Java code quality inspection method, device, equipment and storage medium

The open source analysis tool PMD detects the abstract syntax tree of Java code, which solves the problem in the existing technology that code quality inspection relies on manpower and development tool plug-ins, realizes automated code quality inspection, reduces hidden dangers and losses, and improves code standardization. and readability.

CN111258562BActive Publication Date: 2024-09-13CHINA PING AN PROPERTY INSURANCE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202010031768.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-01-13
Publication Date
2024-09-13
Estimated Expiration
2040-01-13

AI Technical Summary

Technical Problem

Existing code quality inspection relies on manual inspection or development tool plug-ins, which is labor-intensive and relies on the active cooperation of developers. It is difficult to ensure the comprehensive elimination of code hazards, leading to possible losses caused by operational problems or technical errors.

Method used

Obtain the abstract syntax tree of Java code through the open source analysis tool PMD, traverse and parse code statements, detect and generate non-compliant information collections according to preset rules, block Git hooks if the rules are not followed, reject code submission, and copy through the Git code management tool The code is transferred to the local database, and visual charts are generated for monitoring and prompting users for modifications.

Benefits of technology

It realizes automated Java code quality inspection, reduces the dependence on manual inspection, ensures that the code complies with specifications, reduces code hidden dangers and operational losses, and improves the standardization and readability of the code.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN111258562B
    Figure CN111258562B
Patent Text Reader

Abstract

The present application relates to the field of computer technology, and in particular to a Java code quality inspection method, device, equipment and storage medium. The method includes: obtaining at least one Java code file to be uploaded; inputting at least one Java code file to be uploaded into an open source analysis tool; traversing the abstract syntax tree, and performing comparative detection on each line of Java code statements in the abstract syntax book through preset rule parsing to obtain a detection result, the detection result includes an array and a regular expression, the array includes at least the granularity function of the Java code to be analyzed and the results in the class in the Java code to be analyzed that do not conform to the preset rules; the granularity function and the results in the class in the Java code to be analyzed that do not conform to the preset rules are saved to a first set; the difference between the first set and the condition set is calculated to obtain a non-compliant information set; if the non-compliant information set is not an empty set, the Git hook is blocked and the results that do not conform to the preset rules are returned to the user. Reduce the quality problems of uploaded code.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a Java code quality inspection method, device, equipment and storage medium. Background Art

[0002] The evaluation of code quality is the key to measure a programmer's ability in the IT field, and it is also one of the foundations of a robust project. If the written code does not have comments and is not in a standardized format, the written code is obscure and difficult to understand. However, the existing code evaluation criteria rely on the existing syntax of the programming language, and predict the results that may appear in the program under high concurrency and multi-user thread test programs. The results of the program may be judged, so that the seemingly normal logic of the code may also hide fatal hidden dangers. Most of the traditional code inspections are done by manually checking code defects, or by checking during the development process of developers through development tool plug-ins provided by open source projects. However, manual inspections require a lot of manpower and cannot eliminate the hidden dangers. The development of plug-ins requires developers to actively cooperate with the company's specification. If developers do not actively accept such plug-ins, they may not follow some development rules, resulting in hidden dangers in the code. At the least, problems will occur during the operation process, and at the worst, the company will suffer losses due to technical errors. Summary of the invention

[0003] The present application provides a method for checking the quality of Java code by configuring it, which can avoid quality problems in uploaded Java code.

[0004] In a first aspect, the present application provides a Java code quality inspection method, comprising:

[0005] Get at least one Java code file to be uploaded;

[0006] Inputting the at least one Java code file to be uploaded into an open source analysis tool, wherein the open source analysis tool is a Java program code checking tool using the Berkeley Software Distribution Agreement;

[0007] Obtaining, by means of the open source analysis tool, an abstract syntax tree of the Java code corresponding to the at least one Java code file to be uploaded;

[0008] Traversing the abstract syntax tree, performing a comparative test on each line of Java code statements in the abstract syntax book through a preset rule analysis, and obtaining a test result, wherein the test result includes an array and a regular expression, wherein the array includes at least a granular function of the Java code to be analyzed and a result in a class in the Java code to be analyzed that does not conform to the preset rule, and the preset rule is a rule for detecting Java code anomalies;

[0009] The granularity function and the results of the classes in the Java code to be analyzed that do not conform to the preset rules are saved in a first set;

[0010] Generate a condition set corresponding to the preset condition according to the preset condition, wherein the preset condition includes ignoring any function in any class when the preset rule check is executed, ignoring any branch when the preset rule check is executed, and ignoring any class when the preset rule check is executed;

[0011] Calculating the difference between the first set and the condition set to obtain a non-compliant information set;

[0012] If the non-compliant information set is not an empty set, the Git hook is blocked and a result that does not comply with the preset rule is returned to the user.

[0013] In some possible designs, if the non-compliant information set is not an empty set, blocking the Git hook and returning a result that does not comply with the preset rule to the user includes:

[0014] Determining whether the non-compliant information set is an empty set;

[0015] If the non-compliant information set is not an empty set, read the configuration file in the client, obtain the Git sub-warehouse address corresponding to the code name in the configuration file, and send a result return service request to the server corresponding to the Git sub-warehouse address;

[0016] Obtaining the Git sub-warehouse code corresponding to the code name sent by the corresponding server through the Git code management tool;

[0017] The Git sub-warehouse code is copied to the local database of the client through the Git code management tool.

[0018] In some possible designs, before obtaining at least one Java code file to be uploaded, the method further includes:

[0019] Obtain a user upload Java code request, where the user upload Java code request includes user authority information and user information;

[0020] Check the user authority information in the Java code upload request of the user to determine whether the user has the upload authority. If the user does not have the upload authority, uploading the Java code file to be uploaded is prohibited;

[0021] If the user has upload permission, verify whether the user information meets the upload rules;

[0022] If the upload rule is met, the Java code file to be uploaded is obtained.

[0023] In some possible designs, if the non-compliant information set is not an empty set, blocking the Git hook and returning a result that does not comply with the preset rule to the user includes:

[0024] Extracting code information from the non-compliant information set to obtain a code information set, wherein the non-compliant information set includes a class name, a Java function, a line number, and character information of the non-compliant Java code;

[0025] Determining whether the code information set is an empty set;

[0026] If the code information set is not an empty set, arranging the class name, the Java function, the line number and the character information in the non-compliant information set in order;

[0027] Combining the arranged class name, the Java function, the line number and the character information in a fixed format to generate a message to prompt the user;

[0028] The Git hook is blocked and the result that does not conform to the preset rule is returned and the message prompting the user is sent to the user.

[0029] In some possible designs, obtaining, by using the open source analysis tool, an abstract syntax tree of the Java code corresponding to the at least one Java code file to be uploaded includes:

[0030] When the number of the Java code files to be uploaded is greater than a thread pool threshold, a thread pool with the thread pool threshold number is used to obtain an abstract syntax tree of the Java code;

[0031] When the number of Java code files to be uploaded is less than or equal to the thread pool threshold, an abstract syntax tree of the Java code is obtained according to a thread pool of the number of Java code files to be uploaded.

[0032] In some possible designs, after the message prompting the user is generated, the Git hook is blocked and a result that does not conform to the preset rule is returned, and after the message prompting the user is sent to the user, the method further includes:

[0033] Obtain the message prompting the user;

[0034] Uploading the message prompting the user and the set of non-compliant information to a database and summarizing them;

[0035] Generate a corresponding visualization chart from the message prompting the user and the non-compliant information set by data visualization technology, wherein the visualization chart at least includes a bar chart, a line chart, a pie chart, a scatter chart, and a combination chart;

[0036] The visualization chart is summarized by presenting the monitoring log.

[0037] In some possible designs, after presenting the summarized visualization chart through monitoring logs, the method further includes:

[0038] Counting the number of error files of the Java code file to be uploaded through the visual chart;

[0039] Set upper and lower thresholds;

[0040] If the number of error files is greater than or equal to the upper threshold, it is determined to be a high-frequency error code;

[0041] If the number of error files is less than or equal to the lower threshold, it is determined to be a low-frequency error code;

[0042] If the number of error files is greater than the lower threshold and less than the upper threshold, it is determined to be an intermediate frequency error code.

[0043] In a second aspect, the present application provides a Java code quality inspection device having the function of implementing the method corresponding to the Java code quality inspection platform provided in the first aspect. The function can be implemented by hardware, or by hardware executing corresponding software. The hardware or software includes one or more modules corresponding to the above functions, and the modules can be software and / or hardware.

[0044] The Java code quality inspection device comprises:

[0045] An input-output module, used for obtaining at least one Java code file to be uploaded;

[0046] A processing module is used to input the at least one Java code file to be uploaded into an open source analysis tool, wherein the open source analysis tool is a Java program code inspection tool that adopts the Berkeley Software Distribution Protocol; obtain an abstract syntax tree of the Java code corresponding to the at least one Java code file to be uploaded through the open source analysis tool; traverse the abstract syntax tree, and perform a comparative test on each line of Java code statements in the abstract syntax book through a preset rule analysis to obtain a test result, wherein the test result includes an array and a regular expression, wherein the array includes at least a granularity function of the Java code to be analyzed and a class in the Java code to be analyzed that does not conform to the preset The preset rule is a rule for detecting Java code anomalies; the results of the granular function and the class in the Java code to be analyzed that do not conform to the preset rule are saved in a first set; a condition set corresponding to the preset condition is generated according to the preset condition, and the preset condition includes ignoring any function in any class when the preset rule check is executed, ignoring any branch when the preset rule check is executed, and ignoring any class when the preset rule check is executed; the difference between the first set and the condition set is calculated to obtain a non-compliant information set; if the non-compliant information set is not an empty set, the Git hook is blocked and the results that do not conform to the preset rule are returned to the user.

[0047] In some possible designs, the processing module is further configured to:

[0048] Determining whether the non-compliant information set is an empty set;

[0049] If the non-compliant information set is not an empty set, read the configuration file in the client, obtain the Git sub-warehouse address corresponding to the code name in the configuration file, and send a result return service request to the server corresponding to the Git sub-warehouse address;

[0050] Obtaining the Git sub-warehouse code corresponding to the code name sent by the corresponding server through the Git code management tool;

[0051] The Git sub-warehouse code is copied to the local database of the client through the Git code management tool.

[0052] In some possible designs, the processing module is further configured to:

[0053] Obtain a user upload Java code request, where the user upload Java code request includes user authority information and user information;

[0054] Check the user authority information in the Java code upload request of the user to determine whether the user has the upload authority. If the user does not have the upload authority, uploading the Java code file to be uploaded is prohibited;

[0055] If the user has upload permission, verify whether the user information meets the upload rules;

[0056] If the upload rule is met, the Java code file to be uploaded is obtained.

[0057] In some possible designs, the processing module is further configured to:

[0058] Extracting code information from the non-compliant information set to obtain a code information set, wherein the non-compliant information set includes a class name, a Java function, a line number, and character information of the non-compliant Java code;

[0059] Determining whether the code information set is an empty set;

[0060] If the code information set is not an empty set, arranging the class name, the Java function, the line number and the character information in the non-compliant information set in order;

[0061] Combining the arranged class name, the Java function, the line number and the character information in a fixed format to generate a message to prompt the user;

[0062] The Git hook is blocked and the result that does not conform to the preset rule is returned and the message prompting the user is sent to the user.

[0063] In some possible designs, the processing module is further configured to:

[0064] When the number of the Java code files to be uploaded is greater than a thread pool threshold, a thread pool with the thread pool threshold number is used to obtain an abstract syntax tree of the Java code;

[0065] When the number of Java code files to be uploaded is less than or equal to the thread pool threshold, an abstract syntax tree of the Java code is obtained according to a thread pool of the number of Java code files to be uploaded.

[0066] In some possible designs, the processing module is further configured to:

[0067] Obtain the message prompting the user;

[0068] Uploading the message prompting the user and the set of non-compliant information to a database and summarizing them;

[0069] Generate a corresponding visualization chart from the message prompting the user and the non-compliant information set by data visualization technology, wherein the visualization chart at least includes a bar chart, a line chart, a pie chart, a scatter chart, and a combination chart;

[0070] The visualization chart is summarized by presenting the monitoring log.

[0071] In some possible designs, the processing module is further configured to:

[0072] Counting the number of error files of the Java code file to be uploaded through the visual chart;

[0073] Set upper and lower thresholds;

[0074] If the number of error files is greater than or equal to the upper threshold, it is determined to be a high-frequency error code;

[0075] If the number of error files is less than or equal to the lower threshold, it is determined to be a low-frequency error code;

[0076] If the number of error files is greater than the lower threshold and less than the upper threshold, it is determined to be an intermediate frequency error code.

[0077] On the other hand, the present application provides a Java code quality inspection device, which includes at least one connected processor, memory, and input and output units, wherein the memory is used to store program code, and the processor is used to call the program code in the memory to execute the methods described in the above aspects.

[0078] Yet another aspect of the present application provides a computer storage medium comprising instructions, which, when executed on a computer, enables the computer to execute the methods described in the above aspects.

[0079] This application obtains the abstract syntax tree of Java code through the open source analysis tool PMD, analyzes the abstract syntax tree, and determines whether the Java code complies with the specification based on the analysis results. If the Java code does not comply with the specification, the Java code is rejected from being submitted to Git. Through the combination of open source analysis tools PMD and GIT, the standardization and readability of enterprise codes are constrained, the code quality is controlled, the hidden dangers in the code are reduced, and the losses caused to the enterprise by the code going online are reduced. BRIEF DESCRIPTION OF THE DRAWINGS

[0080] Figure 1 This is a flow chart of a Java code quality inspection method in an embodiment of the present application;

[0081] Figure 2 This is a schematic diagram of the structure of a Java code quality inspection device in an embodiment of the present application;

[0082] Figure 3 It is a structural diagram of a Java code quality inspection device in an embodiment of the present application.

[0083] The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION

[0084] 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. The terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments described herein can be implemented in an order other than the content illustrated or described here. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device including a series of steps or modules is not necessarily limited to those steps or modules clearly listed, but may include other steps or modules that are not clearly listed or inherent to these processes, methods, products or devices. The division of the modules that appear in the present application is only a logical division, and there may be other division methods when implemented in practical applications, for example, multiple modules can be combined into or integrated in another system, or some features can be ignored or not executed.

[0085] In order to solve the above technical problems, this application mainly provides the following technical solutions

[0086] This application uses the open source analysis tool PMD to obtain the abstract syntax tree of the Java code, analyzes the abstract syntax tree, and determines whether the Java code complies with the specification based on the analysis results. If the Java code does not comply with the specification, the Java code is rejected from being submitted to Git. Through the combination of the open source analysis tool PMD and GIT, the standardization and readability of the enterprise code are constrained, the code quality is controlled, the hidden dangers in the code are reduced, and the losses caused to the enterprise by the code going online are reduced.

[0087] Please refer to Figure 1 The following is an example of a Java code quality inspection method provided by the present application, the method comprising:

[0088] 101. Obtain at least one Java code file to be uploaded.

[0089] The file formats of the Java code files to be uploaded include at least the java format and the class format.

[0090] 102. Input at least one Java code file to be uploaded into an open source analysis tool.

[0091] The open source analysis tool is a Java program code inspection tool that adopts the Berkeley Software Distribution Agreement.

[0092] Open source analysis tools also provide integration with various Java integrated development environments and tools, such as Eclipse, IntelliJ IDEA, and NetBean integration.

[0093] 103. Obtain an abstract syntax tree of a Java code corresponding to at least one Java code file to be uploaded through an open source analysis tool.

[0094] The abstract syntax tree is created by a syntax analyzer. A syntax analyzer is a component of a compiler or interpreter that is mainly used to perform syntax checking and build a data structure consisting of input words (generally a hierarchical data structure such as a syntax analysis tree or an abstract syntax tree). As an intermediate representation of a program, the abstract syntax tree is widely used in many fields such as program analysis. Using the abstract syntax tree, you can easily implement a variety of source program processing tools, such as source program browsers, smart editors, language translators, etc.

[0095] 104. Traverse the abstract syntax tree, and perform a comparative test on each line of Java code statement in the abstract syntax book through the preset rule parsing to obtain the test result. The test result includes an array and a regular expression. The array includes at least the granular function of the Java code to be analyzed and the results in the class in the Java code to be analyzed that do not meet the preset rules. The preset rules are used to detect Java code anomalies.

[0096] Preset rules are used to detect Java code exceptions. Preset rules include at least: class names must be camel case, Boolean types should not start with is, avoid starting with a dollar or underscore, no magic number rules are defined, thread pools are not allowed to be created using executors, they must be created using thread executors, classes must add author comments, variable names are camel case, abstract class names start with abstract, classes implemented by servers and data access objects need to end with the pulse Impl, and exception classes end with exception Exception.

[0097] 105. Save the granular function and the results that do not meet the preset rules in the class in the Java code to be analyzed to the first set.

[0098] The first set stores information about multiple Java files. The granularity is the minimum value of the system memory expansion increment. Each class contains a data description and a set of functions that operate on the data or pass messages.

[0099] 106. Generate a condition set corresponding to the preset condition according to the preset condition.

[0100] The preset conditions include ignoring any function in any class when the preset rule check is executed, ignoring any branch when the preset rule check is executed, and ignoring any class when the preset rule check is executed.

[0101] 107. Calculate the difference between the first set and the condition set to obtain a non-compliant information set.

[0102] Alternatively, the intersection between the first set and the condition set is calculated to obtain two different places.

[0103] 108. If the non-compliant information set is not an empty set, the Git hook will be blocked and the result that does not comply with the preset rules will be returned to the user.

[0104] The abstract syntax tree of the Java code is obtained through the open source analysis tool PMD, and the abstract syntax tree is analyzed. Based on the analysis results, it is determined whether the Java code complies with the specification. If the Java code does not comply with the specification, the Java code is rejected from being submitted to Git. The open source analysis tool PMD and GIT are combined to constrain the standardization and readability of enterprise codes, control code quality, reduce hidden dangers in the code, and reduce the losses caused to the enterprise by the online code.

[0105] In some implementations, if the non-compliant information set is not an empty set, the Git hook is blocked and a result that does not comply with the preset rules is returned to the user, including:

[0106] Determine whether the non-compliant information set is an empty set;

[0107] If the non-compliant information set is not an empty set, read the configuration file in the client, obtain the Git sub-warehouse address corresponding to the code name in the configuration file, and send a result return service request to the server corresponding to the Git sub-warehouse address;

[0108] Obtaining the Git sub-warehouse code corresponding to the code name sent by the corresponding server through the Git code management tool;

[0109] Use the Git code management tool to copy the Git sub-warehouse code to the client's local database.

[0110] In some implementations, before obtaining at least one Java code file to be uploaded, the method further includes:

[0111] Obtain the user's Java code upload request, which includes user authority information and user information;

[0112] Check the user permission information in the Java code upload request to determine whether the user has the upload permission. If the user does not have the upload permission, the Java code file to be uploaded is prohibited from being uploaded.

[0113] If the user has upload permission, check whether the user information meets the upload rules;

[0114] If the upload rules are met, the Java code file to be uploaded is obtained.

[0115] In the above implementation, the results that do not meet the prediction rules are returned to the user through the above method, and the user is prompted to modify them.

[0116] In some implementations, if the non-compliant information set is not an empty set, blocking the Git hook and returning a result that does not comply with the preset rules to the user includes:

[0117] Extracting code information from the non-compliant information set to obtain a code information set, wherein the non-compliant information set includes a class name, a Java function, a line number, and character information of the non-compliant Java code;

[0118] Determine whether the code information set is an empty set;

[0119] If the code information set is not an empty set, the class name, Java function, line number, and character information in the non-compliant information set are arranged in order;

[0120] The arranged class name, Java function, line number and character information are combined in a fixed format to generate a message to prompt the user;

[0121] The Git hook is blocked and the result that does not meet the preset rules is returned, and a message prompting the user is sent to the user.

[0122] In the above implementation, a prompt message for indicating an abnormal code is generated by the above method, for example, the 55th character a in line 153 of the X function in class A is a magic value that is not compliant.

[0123] In some implementations, obtaining an abstract syntax tree of a Java code corresponding to at least one Java code file to be uploaded by using an open source analysis tool includes:

[0124] When the number of Java code files to be uploaded is greater than the thread pool threshold, a thread pool with the thread pool threshold number is used to obtain the abstract syntax tree of the Java code;

[0125] When the number of Java code files to be uploaded is less than or equal to the thread pool threshold, an abstract syntax tree of the Java code is obtained according to the thread pool of the number of Java code files to be uploaded.

[0126] In the above implementation, threads can be used to put tasks in a program that takes a long time to be processed in the background, so as to speed up the processing of tasks and reduce the waiting time of users.

[0127] In some implementations, after the message prompting the user is generated, the Git hook is blocked and a result that does not conform to a preset rule is returned, and after the message prompting the user is sent to the user, the method further includes:

[0128] Get the message to prompt the user;

[0129] Upload and summarize the user's prompt messages and non-compliant information collection to the database;

[0130] Generate corresponding visualization charts from user prompt messages and non-compliant information sets through data visualization technology, and the visualization charts include at least bar charts, line charts, pie charts, scatter charts, and combination charts;

[0131] Displays summary visualization charts from monitoring logs.

[0132] In the above implementation, the code quality of each version is monitored and managed so as to know the code changes between each version and realize the monitoring of code quality.

[0133] In some implementations, after presenting a summary visualization chart through monitoring logs, the method further includes:

[0134] Use visual charts to count the number of error files in the Java code files to be uploaded;

[0135] Set upper and lower thresholds;

[0136] If the number of error files is greater than or equal to the upper threshold, it is determined to be a high-frequency error code;

[0137] If the number of error files is less than or equal to the lower threshold, it is determined to be a low-frequency error code;

[0138] If the number of error files is greater than the lower threshold and less than the upper threshold, it is determined to be an intermediate frequency error code.

[0139] In the above implementation, the code quality is monitored through the above monitoring log.

[0140] like Figure 2 The Java code quality inspection device 20 shown in FIG. 1 can be applied to Java code quality inspection. The Java code quality inspection device in the embodiment of the present application can achieve the above Figure 1The steps of the Java code quality inspection method executed in the corresponding embodiment. The functions implemented by the Java code quality inspection device 20 can be implemented by hardware, or by hardware executing corresponding software. The hardware or software includes one or more modules corresponding to the above functions, and the modules can be software and / or hardware. The Java code quality inspection device may include an input-output module 201 and a processing module 202. The functions of the processing module 202 and the input-output module 201 can be implemented by reference Figure 1 The operations performed in the corresponding embodiments are not described in detail here. The input-output module 201 can be used to control the input, output and acquisition operations of the input-output module 201 .

[0141] In some implementations, the input-output module 201 may be used to obtain at least one Java code file to be uploaded;

[0142] The processing module 202 can be used to input the at least one Java code file to be uploaded into an open source analysis tool, which is a Java program code inspection tool that adopts the Berkeley Software Distribution Protocol; obtain the abstract syntax tree of the Java code corresponding to the at least one Java code file to be uploaded through the open source analysis tool; traverse the abstract syntax tree, and compare and detect each line of Java code statements in the abstract syntax book through preset rule parsing to obtain a detection result, wherein the detection result includes an array and a regular expression, and the array at least includes the granularity function of the Java code to be analyzed and the class in the Java code to be analyzed that does not conform to The result of the preset rule is consistent with the preset rule, and the preset rule is used to detect the rule of Java code anomalies; the results of the granular function and the class in the Java code to be analyzed that do not comply with the preset rule are saved to a first set; a condition set corresponding to the preset condition is generated according to the preset condition, and the preset condition includes ignoring any function in any class when the preset rule check is executed, ignoring any branch when the preset rule check is executed, and ignoring any class when the preset rule check is executed; the difference between the first set and the condition set is calculated to obtain a non-compliant information set; if the non-compliant information set is not an empty set, the Git hook is blocked and the result that does not comply with the preset rule is returned to the user.

[0143] In some implementations, the processing module 202 is further configured to:

[0144] Determining whether the non-compliant information set is an empty set;

[0145] If the non-compliant information set is not an empty set, read the configuration file in the client, obtain the Git sub-warehouse address corresponding to the code name in the configuration file, and send a result return service request to the server corresponding to the Git sub-warehouse address;

[0146] Obtaining the Git sub-warehouse code corresponding to the code name sent by the corresponding server through the Git code management tool;

[0147] The Git sub-warehouse code is copied to the local database of the client through the Git code management tool.

[0148] In some implementations, the processing module 202 is further configured to:

[0149] Extracting code information from the non-compliant information set to obtain a code information set, wherein the non-compliant information set includes a class name, a Java function, a line number, and character information of the non-compliant Java code;

[0150] Determining whether the code information set is an empty set;

[0151] If the code information set is not an empty set, arranging the class name, the Java function, the line number and the character information in the non-compliant information set in order;

[0152] Combining the arranged class name, the Java function, the line number and the character information in a fixed format to generate a message to prompt the user;

[0153] The Git hook is blocked and the result that does not conform to the preset rule is returned and the message prompting the user is sent to the user.

[0154] In some implementations, the processing module 202 is further configured to:

[0155] Acquire the non-compliant information set, where the non-compliant information set includes the class name, method, line number, and character information of the non-compliant Java code;

[0156] Determining whether the non-compliant information set is an empty set;

[0157] If the non-compliant information set is not an empty set, extracting the class name, the method, the line number, and the character information in the non-compliant information set;

[0158] A message to prompt a user generated by combining the class name, the method, the line number and the character information in a fixed format;

[0159] After the message prompting the user is generated, the Git hook is blocked and the result that does not conform to the preset rule and the message prompting the user are sent to the user.

[0160] In some implementations, the processing module 202 is further configured to:

[0161] When the number of Java code files to be uploaded is greater than a thread pool threshold, an abstract syntax tree of the Java code is acquired using a thread pool with the thread pool threshold number;

[0162] When the number of Java code files to be uploaded is less than or equal to the thread pool threshold, an abstract syntax tree of the Java code is obtained according to a thread pool of the number of Java code files to be uploaded.

[0163] In some implementations, the processing module 202 is further configured to:

[0164] Obtain the message prompting the user;

[0165] Uploading the message prompting the user and the set of non-compliant information to a database and summarizing them;

[0166] Generate a corresponding visualization chart from the message prompting the user and the non-compliant information set by data visualization technology, wherein the visualization chart at least includes a bar chart, a line chart, a pie chart, a scatter chart, and a combination chart;

[0167] The visualization chart is summarized by presenting the monitoring log.

[0168] In some implementations, the processing module 202 is further configured to:

[0169] Counting the number of error files of the Java code file to be uploaded through the visual chart;

[0170] Set upper and lower thresholds;

[0171] If the number of error files is greater than or equal to the upper threshold, it is determined to be a high-frequency error code;

[0172] If the number of error files is less than or equal to the lower threshold, it is determined to be a low-frequency error code;

[0173] If the number of error files is greater than the lower threshold and less than the upper threshold, it is determined to be an intermediate frequency error code.

[0174] The above describes the creation device in the embodiment of the present application from the perspective of modular functional entities. The following describes a Java code quality inspection device from the perspective of hardware. Figure 3As shown, it includes: a processor, a memory, an input and output unit (which may also be a transceiver, Figure 3 (not shown) and a computer program stored in the memory and executable on the processor. For example, the computer program may be Figure 1 The corresponding program of the Java code quality inspection method in the corresponding embodiment. For example, when the computer device implements the following Figure 2 When the Java code quality inspection device 20 shown in the figure is used, the processor implements the above-mentioned Figure 2 The steps of the Java code quality inspection method executed by the Java code quality inspection device 20 in the corresponding embodiment. Alternatively, the processor implements the above when executing the computer program Figure 2 The functions of each module in the Java code quality inspection device 20 of the corresponding embodiment. For another example, the computer program can be Figure 1 The program corresponding to the Java code quality inspection method in the corresponding embodiment.

[0175] The processor may be a central processing unit (CPU), other general-purpose processors, digital signal processors (DSP), application specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc. The processor is the control center of the computer device, and uses various interfaces and lines to connect various parts of the entire computer device.

[0176] The memory can be used to store the computer program and / or module, and the processor realizes various functions of the computer device by running or executing the computer program and / or module stored in the memory, and calling the data stored in the memory. The memory can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area can store data created according to the use of the mobile phone (such as audio data, video data, etc.), etc. In addition, the memory can include a high-speed random access memory, and can also include a non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a smart memory card (smart media card, SMC), a secure digital (secure digital, SD) card, a flash card (Flash Card), at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.

[0177] The input-output unit can also be replaced by a receiver and a transmitter, which can be the same or different physical entities. When they are the same physical entities, they can be collectively referred to as input-output units. The input-output can be a transceiver.

[0178] The memory may be integrated into the processor or may be arranged separately from the processor.

[0179] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM) and includes a number of instructions for a terminal (which can be a mobile phone, a computer, a server or a network device, etc.) to execute the methods described in each embodiment of the present application.

[0180] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the inspiration of the present application, ordinary technicians in this field can also make many forms without departing from the purpose of the present application and the scope of protection of the claims. All equivalent structures or equivalent process changes made using the contents of the specification and drawings of this application, or directly or indirectly used in other related technical fields, are protected by the present application.

Claims

1. A Java code quality inspection method, It is characterized in that The method comprises: Get at least one Java code file to be uploaded; Inputting the at least one Java code file to be uploaded into an open source analysis tool, wherein the open source analysis tool is a Java program code checking tool using the Berkeley Software Distribution Agreement; Obtaining, by means of the open source analysis tool, an abstract syntax tree of the Java code corresponding to the at least one Java code file to be uploaded; Traversing the abstract syntax tree, performing a comparative test on each line of Java code statements in the abstract syntax book through a preset rule analysis, and obtaining a test result, wherein the test result includes an array and a regular expression, wherein the array includes at least a granular function of the Java code to be analyzed and a result in a class in the Java code to be analyzed that does not conform to the preset rule, and the preset rule is a rule for detecting Java code anomalies; The granularity function and the results of the classes in the Java code to be analyzed that do not conform to the preset rules are saved in a first set; Generate a condition set corresponding to the preset condition in the Java code quality check algorithm according to the preset condition, wherein the preset condition includes ignoring any function in any class when the preset rule check is executed, ignoring any branch when the preset rule check is executed, and ignoring any class when the preset rule check is executed; Calculating the difference between the first set and the condition set to obtain a non-compliant information set; If the non-compliant information set is not an empty set, the Git hook is blocked and a result that does not comply with the preset rule is returned to the user.

2. The method according to claim 1, It is characterized in that If the non-compliant information set is not an empty set, blocking the Git hook and returning a result that does not comply with the preset rule to the user includes: Determining whether the non-compliant information set is an empty set; If the non-compliant information set is not an empty set, read the configuration file in the client, obtain the Git sub-warehouse address corresponding to the code name in the configuration file, and send a result return service request to the server corresponding to the Git sub-warehouse address; Obtain the Git sub-warehouse code corresponding to the code name sent by the corresponding server through the Git code management tool; The Git sub-warehouse code is copied to the local database of the client through the Git code management tool.

3. The method according to claim 1, It is characterized in that Before obtaining at least one Java code file to be uploaded, the method further includes: Obtain a user upload Java code request, where the user upload Java code request includes user authority information and user information; Check the user permission information in the Java code upload request of the user to determine whether the user has the upload permission; If the user does not have upload authority, uploading the Java code file to be uploaded is prohibited; If the user has upload permission, verify whether the user information meets the upload rules; If the upload rule is met, the Java code file to be uploaded is obtained.

4. The method according to claim 1, It is characterized in that If the non-compliant information set is not an empty set, blocking the Git hook and returning a result that does not comply with the preset rule to the user includes: Extracting code information from the non-compliant information set to obtain a code information set, wherein the non-compliant information set includes a class name, a Java function, a line number, and character information of the non-compliant Java code; Determining whether the code information set is an empty set; If the code information set is not an empty set, arranging the class name, the Java function, the line number and the character information in the non-compliant information set in order; Combining the arranged class name, the Java function, the line number and the character information in a fixed format to generate a message to prompt the user; The Git hook is blocked and the result that does not conform to the preset rule is returned and the message prompting the user is sent to the user.

5. The method according to any one of claims 1 to 4, It is characterized in that The obtaining, by the open source analysis tool, an abstract syntax tree of the Java code corresponding to the at least one Java code file to be uploaded includes: When the number of the Java code files to be uploaded is greater than a thread pool threshold, a thread pool with the thread pool threshold number is used to obtain an abstract syntax tree of the Java code; When the number of the Java code files to be uploaded is less than or equal to the thread pool threshold, an abstract syntax tree of the Java code is obtained according to the thread pool of the number of the Java code files to be uploaded.

6. The method according to claim 4, It is characterized in that After the message prompting the user is generated, the Git hook is blocked and a result that does not conform to the preset rule is returned, and after the message prompting the user is sent to the user, the method further includes: Obtain the message prompting the user; Uploading the message prompting the user and the set of non-compliant information to a database and summarizing them; Generate a corresponding visualization chart from the message prompting the user and the non-compliant information set by data visualization technology, wherein the visualization chart at least includes a bar chart, a line chart, a pie chart, a scatter chart, and a combination chart; The visualization chart is summarized by presenting the monitoring log.

7. The method according to claim 6, It is characterized in that After summarizing the visualization chart by presenting the monitoring log, the method further includes: Counting the number of error files of the Java code file to be uploaded through the visual chart; Set upper and lower thresholds; If the number of error files is greater than or equal to the upper threshold, it is determined to be a high-frequency error code; If the number of error files is less than or equal to the lower threshold, it is determined to be a low-frequency error code; If the number of error files is greater than the lower threshold and less than the upper threshold, it is determined to be an intermediate frequency error code.

8. A Java code quality inspection device, It is characterized in that The device comprises: An input-output module, used for obtaining at least one Java code file to be uploaded; A processing module is used to input the at least one Java code file to be uploaded into an open source analysis tool, where the open source analysis tool is a Java program code inspection tool that adopts the Berkeley Software Distribution Protocol; obtain an abstract syntax tree of the Java code corresponding to the at least one Java code file to be uploaded through the open source analysis tool; traverse the abstract syntax tree, and perform a comparative test on each line of Java code statements in the abstract syntax book through a preset rule analysis to obtain a test result, where the test result includes an array and a regular expression, where the array includes at least a granular function of the Java code to be analyzed and a result in a class in the Java code to be analyzed that does not conform to the preset rule, and the preset rule is a rule for detecting Java code anomalies; The granular function and the results in the class of the Java code to be analyzed that do not comply with the preset rules are saved to a first set; a condition set corresponding to the preset conditions is generated according to the preset conditions, and the preset conditions include ignoring any function in any class when the preset rule check is executed, ignoring any branch when the preset rule check is executed, and ignoring any class when the preset rule check is executed; the difference between the first set and the condition set is calculated to obtain a non-compliant information set; if the non-compliant information set is not an empty set, the Git hook is blocked and the results that do not comply with the preset rules are returned to the user.

9. A Java code quality inspection device, It is characterized in that The Java code quality inspection device comprises: at least one processor, memory, and input-output unit; The memory is used to store program codes, and the processor is used to call the program codes stored in the memory to execute the method according to any one of claims 1 to 7.

10. A computer storage medium, It is characterized in that The method comprises instructions which, when executed on a computer, cause the computer to execute the method according to any one of claims 1 to 7.