Code quality analysis method and device, equipment and medium
By identifying the code type in the Jenkins server and calling the corresponding command for analysis, combined with the analysis results of the code analysis plug-in in the SonarQube server, the problem of analysis interruption caused by code exceptions in the existing technology is solved, and the fault tolerance rate and efficiency of code quality analysis are improved. .
Patent Information
- Application Number
- CN202310881321.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-07-17
- Publication Date
- 2025-01-21
AI Technical Summary
Existing code quality analysis methods will directly interrupt the analysis process when encountering code exceptions or warnings, resulting in inefficiency.
By identifying the code type in the Jenkins server and calling the corresponding command for analysis, if a negligible error sub-result is encountered, the analysis will continue until completion, and the code analysis plug-in in the SonarQube server will be used to parse the final results and generate a report.
It improves the fault tolerance and efficiency of code quality analysis, allowing analysis to continue when certain ignorable errors are encountered, avoiding interruption of the analysis process.
Smart Images

Figure CN119336612A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of code quality analysis, and in particular to a code quality analysis method, device, equipment and medium. Background Art
[0002] At present, when analyzing code quality, it is usually necessary to hard-code commands in the code analysis plug-in, obtain code running results based on the commands hard-coded in the code analysis plug-in, and analyze the code quality. However, in this method, once the code running results indicate any abnormality or warning in the code, the code quality analysis process will be directly interrupted, which greatly reduces the efficiency of code quality analysis.
[0003] Therefore, there is an urgent need for a technical solution that can quickly and efficiently perform code quality analysis. Summary of the invention
[0004] The present application provides a code quality analysis method, apparatus, device and storage medium for quickly and efficiently performing code quality analysis.
[0005] In a first aspect, the present application provides a code quality analysis method, which is applied to an open source software project Jenkins server, and the method comprises:
[0006] Identify the code type of the code to be quality analyzed, and call and execute a command corresponding to the code type stored in the Jenkins server;
[0007] Based on the command, the quality of the code is analyzed to obtain a real-time analysis result, and when it is identified that the real-time running result contains a sub-result indicating that a code error occurs, if it is determined to ignore the sub-result, the quality of the code is continuously analyzed based on the command until the quality analysis of the code is completed to obtain a machine language analysis result of the code;
[0008] Based on a code analysis plug-in corresponding to the code type pre-configured in a code quality inspection SonarQube server, the machine language analysis result is parsed to generate a quality analysis text report on the code.
[0009] In a second aspect, the present application provides a code quality analysis device, which is applied to an open source software project Jenkins server, and the device includes:
[0010] A command module, used for identifying the code type of the code to be quality analyzed, calling and executing a command corresponding to the code type stored in the Jenkins server;
[0011] an analysis module, configured to analyze the quality of the code based on the command to obtain a real-time analysis result, and when it is identified that the real-time running result contains a sub-result indicating that a code error occurs, if it is determined to ignore the sub-result, continue to analyze the quality of the code based on the command until the quality analysis of the code is completed to obtain a machine language analysis result of the code;
[0012] The plug-in module is used to parse the machine language analysis result based on the code analysis plug-in corresponding to the code type pre-configured in the code quality inspection SonarQube server, and generate a quality analysis text report for the code.
[0013] In a third aspect, the present application provides an electronic device, which includes at least a processor and a memory, and the processor is used to implement the steps of any of the above methods when executing a computer program stored in the memory.
[0014] In a fourth aspect, the present application provides a computer-readable storage medium storing a computer program, which implements the steps of any of the above methods when executed by a processor.
[0015] In a fifth aspect, the present application provides a computer program product, which includes: a computer program code, which, when executed on a computer, enables the computer to execute the steps of any of the above methods.
[0016] In the embodiment of the present application, the open source software project (Jenkins) server can identify the code type of the code to be quality analyzed, call and execute the command corresponding to the code type stored in the Jenkins server itself; based on the command, the quality of the code is analyzed to obtain the real-time analysis result, and when the sub-result containing the code error is identified in the real-time operation result, if it is judged that the sub-result can be ignored, the quality of the code can be analyzed based on the command until the quality analysis of the code is completed, and the machine language analysis result of the code is obtained; the Jenkins server can also parse the machine language analysis result based on the code analysis plug-in corresponding to the code type pre-configured in the code quality check (SonarQube) server, and generate a text report on the quality analysis of the code. Since the present application can decouple the command and the code analysis plug-in, the command is stored in the Jenkins server, and the code analysis plug-in is configured in the SonarQube server, when the sub-result containing the code error in the real-time operation result can be ignored, the sub-result can be ignored, and the quality of the code can be analyzed based on the command, thereby greatly improving the fault tolerance of the code in the code quality analysis process, and greatly improving the efficiency of code quality analysis. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the implementation methods in the embodiments of the present application or the related technologies, the following is a brief introduction to the drawings required for use in the embodiments or the related technology descriptions. Obviously, the drawings described below are some embodiments of the present application, and a person skilled in the art can also obtain other drawings based on these drawings.
[0018] Figure 1 A schematic diagram of a first code quality analysis process provided by some embodiments is shown;
[0019] Figure 2 A schematic diagram of a second code quality analysis process provided by some embodiments is shown;
[0020] Figure 3 A schematic diagram of a third code quality analysis process provided by some embodiments is shown;
[0021] Figure 4 A fourth code quality analysis process schematic diagram provided by some embodiments is shown;
[0022] Figure 5 A fifth code quality analysis process schematic diagram provided by some embodiments is shown;
[0023] Figure 6 A sixth code quality analysis process schematic diagram provided by some embodiments is shown;
[0024] Figure 7 A seventh code quality analysis process schematic diagram provided by some embodiments is shown;
[0025] Figure 8 An eighth code quality analysis process schematic diagram provided by some embodiments is shown;
[0026] Fig. 9 A schematic diagram of a code quality analysis device provided by some embodiments is shown;
[0027] Fig.10 A schematic diagram of the structure of an electronic device provided by some embodiments is shown. DETAILED DESCRIPTION
[0028] In order to make the purpose, technical solutions and advantages of this application clearer, this application will be further described in detail below in conjunction with the accompanying drawings. Obviously, the embodiments described in this application are only part of the embodiments of this application, rather than all the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0029] It should be noted that the brief description of terms in this application is only for the convenience of understanding the embodiments described below, and is not intended to limit the embodiments of this application. Unless otherwise specified, these terms should be understood according to their common and usual meanings.
[0030] The terms "first", "second", "third", etc. in the specification and claims of this application and the above drawings are used to distinguish similar or similar objects or entities, and do not necessarily mean to limit a specific order or sequence, unless otherwise noted. It should be understood that the terms used in this way can be interchangeable under appropriate circumstances.
[0031] The terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover but not exclude inclusion, for example, a product or device comprising a list of components is not necessarily limited to all the components expressly listed but may include other components not expressly listed or inherent to such product or device.
[0032] The term "module" refers to any known or later developed hardware, software, firmware, artificial intelligence, fuzzy logic, or combination of hardware and / or software code that is capable of performing the functions associated with that element.
[0033] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.
[0034] In order to perform code quality analysis quickly and efficiently, the present application provides a code quality analysis method, device, equipment and medium.
[0035] In actual use, the open source software project (Jenkins) server can identify the code type of the code to be analyzed for quality, call and execute the command corresponding to the code type stored in the Jenkins server itself; based on the command, the quality of the code is analyzed to obtain real-time analysis results, and when the sub-result containing the code error is identified in the real-time operation result, if it is determined that the sub-result can be ignored, the quality of the code can be analyzed based on the command until the quality analysis of the code is completed and the machine language analysis result of the code is obtained; the Jenkins server can also parse the machine language analysis result based on the code analysis plug-in corresponding to the code type pre-configured in the code quality check (SonarQube) server, and generate a text report on the quality analysis of the code. Since the present application can decouple the command and the code analysis plug-in, the command is stored in the Jenkins server, and the code analysis plug-in is configured in the SonarQube server, when the sub-result containing the code error in the real-time operation result can be ignored, the sub-result can be ignored, and the quality of the code can be analyzed based on the command, thereby greatly improving the fault tolerance of the code in the code quality analysis process and greatly improving the efficiency of code quality analysis.
[0036] Figure 1 A schematic diagram of a first code quality analysis process provided by some embodiments is shown, such as Figure 1 As shown, the process includes the following steps:
[0037] S101: Identify the code type of the code to be quality analyzed, and call and execute a command corresponding to the code type stored in the Jenkins server.
[0038] The code quality analysis method provided in the embodiment of the present application is applied to an open source software project (Jenkins) server.
[0039] In a possible implementation, after the developer has completed the development of the code, the code to be quality analyzed can be submitted to a code warehouse device (also referred to as a code warehouse). Among them, the present application does not specifically limit the specific type and content of the code. Exemplarily, the code type of the code can be a mobile application development framework (Flutter) code, etc. After the code warehouse device receives the code, it can send a code quality detection instruction to the Jenkins server, and the code quality detection instruction can carry the code identifier of the code. Exemplarily, the code identifier can be a project identifier, etc. The present application does not specifically limit the code identifier and can be flexibly set according to demand. After the Jenkins server receives the code quality detection instruction, it can identify the code identifier carried in the code quality detection instruction and obtain (pull) the code corresponding to the code identifier. Exemplarily, the Jenkins server can obtain the code corresponding to the code identifier from the code warehouse device, etc. The present application does not specifically limit the specific method of obtaining the code corresponding to the code identifier.
[0040] In a possible implementation, when the Jenkins server obtains (pulls) the code to be quality analyzed, the code type of the code can be identified. Optionally, the code type of the code can be identified based on the code type identifier or development language carried by the code, and the specific method of identifying the code type is not specifically limited in this application. After identifying the code type, the Jenkins server can call and execute the command corresponding to the code type stored in the Jenkins server itself. Exemplarily, when the code type is a Flutter code type, the command corresponding to the Flutter code pre-saved in the Jenkins server itself can be called and executed. Among them, the command can be flexibly set according to the needs, and this application does not specifically limit this. Exemplarily, the command corresponding to the Flutter code (Flutter code type) can be the fluttertest>analyser.output command, etc.
[0041] S102: Based on the command, the quality of the code is analyzed to obtain a real-time analysis result, and when it is identified that the real-time running result contains a sub-result indicating a code error, if it is determined to ignore the sub-result, the quality of the code continues to be analyzed based on the command until the quality analysis of the code is completed and a machine language analysis result of the code is obtained.
[0042] In a possible implementation, the Jenkins server can run the code based on the command, and can analyze the quality of the code in real time during the code running process based on the command to obtain a real-time analysis result of the quality of the code. Among them, this application does not specifically limit the specific process of analyzing the quality of the code based on the command.
[0043] In order to improve the efficiency of code quality analysis, when it is identified that the real-time running result contains a sub-result with a code error, it can be determined whether the error in the sub-result can be ignored. If it is determined that the sub-result (the error in the sub-result) can be ignored, the sub-result can be ignored, and the quality of the code can continue to be analyzed based on the command. Compared with the related art in which the command is hard-coded in the code analysis plug-in, once the code running result (real-time analysis result) prompts that there is any abnormality or warning in the code, the quality analysis process of the code will be directly interrupted, and the fault tolerance rate of the code is low, which greatly reduces the efficiency of code quality analysis. In this application, the command and the code analysis plug-in can be decoupled, and the command is saved in the Jenkins server, while the code analysis plug-in is configured in the SonarQube server. When it is determined that the error (sub-result) in the code can be ignored, the corresponding error can be ignored, and the quality of the code can continue to be analyzed based on the command, thereby greatly improving the fault tolerance rate of the code in the code quality analysis process and greatly improving the efficiency of code quality analysis.
[0044] In a possible implementation, in order to quickly and accurately determine whether errors in sub-results can be ignored, a whitelist of errors that can be ignored can be pre-set in the Jenkins server. When a sub-result containing a code error is identified in the real-time running result, it can be determined whether the error in the sub-result is an error in the whitelist. If the error in the sub-result is an error in the preset whitelist, the error in the sub-result can be ignored (ignore the sub-result), and the quality of the code can continue to be analyzed based on the command until the quality analysis of the code is completed and the analysis result of the code is obtained. The analysis result at this time has not been parsed by the code analysis plug-in, and for the convenience of description, it is called a machine language analysis result. Among them, the errors in the preset whitelist can be flexibly set according to demand, for example, format errors in the code can be determined as errors in the whitelist.
[0045] In a possible implementation, in order to quickly and accurately determine whether errors in sub-results can be ignored, the Jenkins server can also output the sub-results, allowing developers and others to determine whether errors in the sub-results can be ignored. If an ignore instruction to ignore the sub-results (errors in the sub-results) input by developers and others is received, the errors appearing in the sub-results can be ignored (ignoring the sub-results), and the quality of the code can continue to be analyzed based on the command until the quality analysis of the code is completed and the machine language analysis results of the code are obtained.
[0046] Optionally, if the Jenkins server identifies that the error in the sub-result is an error that is not in the whitelist (blacklist) such as "forced exit error", or when receiving an instruction from a developer that the error in the sub-result cannot be ignored, the code quality analysis process can be interrupted to prompt the developer to modify the code. After the developer modifies the code and resubmits the code in the code warehouse device, the above-mentioned code quality analysis process can be restarted, which will not be repeated here.
[0047] S103: Based on a code analysis plug-in corresponding to the code type pre-configured in a code quality inspection SonarQube server, the machine language analysis result is parsed to obtain a quality analysis text report on the code.
[0048] In one possible implementation, after obtaining the machine language analysis results of the code, in order to parse the machine language analysis results into analysis results that are easy for developers and the like to view, the machine language analysis results can be parsed based on a code analysis plug-in corresponding to the code type, and the machine language analysis results can be parsed into a quality analysis text report that is easy for developers and the like to view.
[0049] Optionally, the code analysis plug-in can be pre-configured in the code quality check (SonarQube) server, and the machine language analysis results are parsed based on the code analysis plug-in corresponding to the code type pre-configured in the SonarQube server, thereby generating a quality analysis text report for the code. Optionally, when the code type is a Flutter code type, the machine language analysis results can be parsed based on the Flutter code analysis plug-in pre-configured in the SonarQube server. How to configure the Flutter code analysis plug-in will be described in detail in the subsequent embodiments, so I will not go into details here.
[0050] In a possible implementation, when parsing the machine language analysis results based on the code analysis plug-in corresponding to the code type pre-configured in the code quality check SonarQube server, the Jenkins server can pull and run the code analysis plug-in corresponding to the code type from the SonarQube server, and parse the machine language analysis results stored in the Jenkins server based on the code analysis plug-in. Taking the Flutter code type as an example, the Jenkins server can pull and run the Flutter code analysis plug-in from the SonarQube server, and parse the machine language analysis results stored in the Jenkins server based on the Flutter code analysis plug-in, thereby generating a text report on the quality analysis of the code.
[0051] In addition, in a possible implementation, when parsing the machine language analysis results based on the code analysis plug-in corresponding to the code type pre-configured in the code quality check SonarQube server, the Jenkins server can also send the machine language analysis results to the SonarQube server, and the SonarQube server parses the machine language analysis results based on the code analysis plug-in pre-configured in the SonarQube server itself. Taking the code type as the Flutter code type as an example, the Jenkins server can send the machine language analysis results to the SonarQube server, and the SonarQube server parses the machine language analysis results based on the Flutter code analysis plug-in pre-configured in the SonarQube server itself, and generates a quality analysis text report for the code. Optionally, the Jenkins server can obtain the quality analysis text report from the SonarQube server. For example, when the Jenkins server sends the machine language analysis results to the SonarQube server, it can also send the corresponding code identifier to the SonarQube server. After the SonarQube server generates a quality analysis text report on the code, it can send the code identifier and the corresponding quality analysis text report to the Jenkins server. Alternatively, the Jenkins server can send a request to obtain the quality analysis text report to the SonarQube server, and the request can carry the code identifier. The SonarQube server sends the quality analysis text report corresponding to the code identifier to the Jenkins server.
[0052] Among them, the process of the Jenkins server parsing the machine language analysis results based on the code analysis plug-in is similar to the process of the SonarQube server parsing the machine language analysis results based on the code analysis plug-in. For example, both can be based on the code analysis plug-in to obtain each error contained in the machine language analysis results (also referred to as each error contained in the code), and the location information corresponding to the subcode of each error, etc., and the generated quality analysis text report can include each error in the code, and at least one of the location information corresponding to the subcode of each error. In addition, after obtaining each error in the code based on the code analysis plug-in, the error type of each error can be obtained based on the correspondence between the error and the error type saved in advance, and the generated quality analysis report can include each error in the code, the error type of each error, and at least one of the location information corresponding to the subcode of each error. In addition, it is also possible to judge whether the quality of the code is appropriate based on the pre-saved code quality threshold standard and the number of errors, error types, etc. that appear in the code, and the detection results of whether the code quality is appropriate are also saved in the quality analysis text report.
[0053] Optionally, the code quality threshold standard can be flexibly set according to demand. Exemplarily, the code quality threshold standard can be a total error number threshold. Whether the quality of the code is qualified can be judged based on the total number of errors contained in the machine language analysis results and the pre-saved total error number threshold. When the total number of errors contained in the machine language analysis results is not higher than the pre-saved total error number threshold, the quality of the code can be judged to be qualified. Otherwise, when the total number of errors contained in the machine language analysis results is higher than the pre-saved total error number threshold, the quality of the code can be judged to be unqualified. The total error number threshold can be flexibly set according to demand. Exemplarily, the total error number threshold can be 10, etc.
[0054] As another example, the code quality threshold standard can also be an error number threshold of any error type. When the number of errors of the corresponding error type contained in the machine language analysis result is not higher than the error number threshold of the corresponding error type saved in advance, the quality of the code can be judged to be qualified, otherwise, the quality of the code can be judged to be unqualified. Exemplarily, when the number of errors with important errors is higher than the error number threshold of the important error type saved in advance, the quality of the code can be judged to be unqualified, etc., which will not be repeated here. Among them, the error type can be an important error, a minor error, etc., which can be flexibly set according to needs. The position information corresponding to the subcode can be the position information of the subcode in the code (source code), which will not be repeated here.
[0055] In a possible implementation, after the Jenkins server obtains the quality analysis text report, it can send the quality analysis text report to the code warehouse device, and the code warehouse device can display the quality analysis text report for reference by developers.
[0056] For ease of understanding, the code quality analysis process provided by this application is explained below through a specific embodiment. Figure 2 , Figure 2 A schematic diagram of a second code quality analysis process provided by some embodiments is shown, and the process includes the following steps:
[0057] S201: The Jenkins server identifies the code type of the code to be quality analyzed, and calls and executes a command corresponding to the code type stored in the Jenkins server.
[0058] S202: The Jenkins server analyzes the quality of the code based on the command to obtain the real-time analysis result, and when it is identified that the real-time running result contains a sub-result containing a code error, if it is determined that the error in the sub-result is an error in a preset whitelist, the sub-result is ignored, and the code quality analysis continues based on the command until the code quality analysis is completed and the machine language analysis result of the code is obtained.
[0059] S203: The Jenkins server parses the machine language analysis result based on the code analysis plug-in corresponding to the code type pre-configured in the SonarQube server to obtain a text report on the quality analysis of the code.
[0060] For ease of understanding, the code quality analysis process provided by this application is explained below through a specific embodiment. Figure 3 , Figure 3 A schematic diagram of a third code quality analysis process provided by some embodiments is shown, and the process includes the following steps:
[0061] S301: The Jenkins server identifies the code type of the code to be quality analyzed, and calls and executes a command corresponding to the code type stored in the Jenkins server.
[0062] S302: The Jenkins server analyzes the quality of the code based on the command to obtain the real-time analysis result. When it is identified that the real-time running result contains a sub-result with a code error, if an ignore instruction is received to ignore the sub-result, the sub-result is ignored and the code quality analysis is continued based on the command until the code quality analysis is completed and the machine language analysis result of the code is obtained.
[0063] S303: The Jenkins server parses the machine language analysis result based on the code analysis plug-in corresponding to the code type pre-configured in the SonarQube server to obtain a text report on the quality analysis of the code.
[0064] For ease of understanding, the code quality analysis process provided by this application is explained below through a specific embodiment. Figure 4 , Figure 4 A schematic diagram of a fourth code quality analysis process provided by some embodiments is shown, and the process includes the following steps:
[0065] S401: The Jenkins server identifies the code type of the code to be quality analyzed, and calls and executes a command corresponding to the code type stored in the Jenkins server.
[0066] S402: The Jenkins server analyzes the quality of the code based on the command to obtain the real-time analysis result, and when it is identified that the real-time running result contains a sub-result indicating a code error, if it is determined that the sub-result can be ignored, the Jenkins server continues to analyze the quality of the code based on the command until the quality analysis of the code is completed and the machine language analysis result of the code is obtained.
[0067] S403: The Jenkins server pulls and runs the code analysis plug-in from the SonarQube server, and parses the machine language analysis result based on the code analysis plug-in to obtain a text report on the code quality analysis.
[0068] For ease of understanding, the code quality analysis process provided by this application is explained below through a specific embodiment. Figure 5 , Figure 5 A fifth code quality analysis process schematic diagram provided by some embodiments is shown, and the process includes the following steps:
[0069] S501: The Jenkins server identifies the code type of the code to be quality analyzed, and calls and executes a command corresponding to the code type stored in the Jenkins server.
[0070] S502: The Jenkins server analyzes the quality of the code based on the command to obtain the real-time analysis result, and when it is identified that the real-time running result contains a sub-result indicating a code error, if it is determined that the sub-result can be ignored, the Jenkins server continues to analyze the quality of the code based on the command until the quality analysis of the code is completed and the machine language analysis result of the code is obtained.
[0071] S503: The Jenkins server sends the machine language analysis results and the corresponding code identifiers to the SonarQube server. The SonarQube server parses the machine language analysis results based on the code analysis plug-in pre-configured in itself and generates a text report on the code quality analysis.
[0072] S504: The Jenkins server sends a request to obtain a quality analysis text report to the SonarQube server. The request carries a corresponding code identifier. After receiving the request, the SonarQube server sends the quality analysis text report corresponding to the code identifier to the Jenkins server. The Jenkins server obtains the quality analysis text report on the code.
[0073] For ease of understanding, the code quality analysis process provided by this application is explained below through a specific embodiment. Figure 6 , Figure 6A sixth code quality analysis process schematic diagram provided by some embodiments is shown, and the process includes the following steps:
[0074] S601: The developer submits the code to be analyzed for quality to the code warehouse device, and the code warehouse device sends a code quality detection instruction to the Jenkins server.
[0075] S602: The Jenkins server receives the code quality detection instruction sent by the code warehouse device, identifies the code identifier carried in the code quality detection instruction, and obtains the code corresponding to the code identifier. The Jenkins server identifies the code type of the code to be quality analyzed, and calls and executes the command corresponding to the code type stored in the Jenkins server.
[0076] S603: The Jenkins server analyzes the quality of the code based on the command to obtain the real-time analysis result, and when it is identified that the real-time running result contains a sub-result indicating a code error, if it is determined that the sub-result can be ignored, the Jenkins server continues to analyze the quality of the code based on the command until the quality analysis of the code is completed and the machine language analysis result of the code is obtained.
[0077] S604: The Jenkins server sends the machine language analysis results and the corresponding code identifiers to the SonarQube server. The SonarQube server parses the machine language analysis results based on the code analysis plug-in pre-configured in itself and generates a text report on the quality analysis of the code.
[0078] S605: The Jenkins server sends a request to obtain a quality analysis text report to the SonarQube server. The request carries a corresponding code identifier. After receiving the request, the SonarQube server sends the quality analysis text report corresponding to the code identifier to the Jenkins server. The Jenkins server obtains the quality analysis text report on the code.
[0079] S606: The Jenkins server sends the quality analysis text report to the code repository device.
[0080] In a possible implementation, in order to configure the Flutter code analysis plug-in into the SonarQube server, the Flutter code analysis plug-in can be configured with a Sensor data exchange interface, and the SonarQube server can configure the Flutter code analysis plug-in in the SonarQube server based on the Sensor data exchange interface. Exemplarily, the Flutter code analysis plug-in can be compiled and packaged into a flutter-plugin.jar file, and the flutter-plugin.jar file can be configured in the plug-in directory where the SonarQube server installs and runs the plug-in, and the SonarQube server is restarted, thereby configuring the Flutter code analysis plug-in in the SonarQube server, that is, integrating the Flutter code analysis plug-in in the SonarQube server SonarQube platform (SonarQube platform).
[0081] Among them, Flutter is a new open source cross-platform application framework provided by Google. Flutter can help developers build exquisite applications for mobile, World Wide Web (Web), desktop and embedded platforms through a set of code bases. Using Flutter to develop applications can achieve rapid development. It has millimeter-level hot reload, which can quickly develop, debug and modify applications. After the application is modified, the application interface can be updated immediately. The use of rich and fully customizable widgets (Web widgets) can build native interfaces in minutes. Flutter can quickly release functions that focus on native experience, and its layered architecture can be fully customized to achieve incredibly fast rendering and expressive and flexible design. Flutter includes many core widgets, such as scrolling, navigation, icons and fonts, which can achieve native performance on Internetworking Operating System-Cisco (IOS) operating system and Android operating system. At present, more and more companies and developers are using the Flutter development platform to build applications.
[0082] Continuous integration is a software development practice, that is, team members integrate their own developed codes as early and as quickly as possible, and each integration is verified through automated builds (including static code scanning, compilation, automated testing, release, etc.) to find integration errors as early as possible. Among them, code quality analysis is a part of software quality testing, which means that after the developer (developer) completes the source code, the source code is scanned and analyzed to find out the problems in the code.
[0083] At present, when performing code quality analysis (also known as static code quality analysis) during the continuous integration process, it is usually necessary to use the code analysis plug-in in the SonarQube server. However, since Flutter is a new open source cross-platform application framework provided by Google, the SonarQube server has not yet officially provided a code analysis plug-in for the Flutter development platform Dart language. Therefore, how to make the SonarQube server support the quality analysis of the Dart development language code of the Flutter development platform is crucial. Since the present application can produce a code analysis plug-in for the Flutter development platform Dart language: Flutter code analysis plug-in, and the Flutter code analysis plug-in is configured with a Sensor data exchange interface, the Flutter code analysis plug-in can be configured in the SonarQube server based on the Sensor data exchange interface, so that the SonarQube server can support the quality analysis of the Dart development language code of the Flutter development platform.
[0084] In a possible implementation, when making a Flutter code analysis plug-in, the Flutter code analysis plug-in definition can be performed according to the plug-in definition of the SonarQube server, and the prescribed Sensor data exchange interface can be configured in the Flutter code analysis plug-in to realize the integration of the Flutter code analysis plug-in in the SonarQube server (SonarQube platform). In addition, based on the Flutter code analysis plug-in, the Jenkins server can obtain the machine language analysis results (analyzer.output file) of the code saved in the working directory of the Jenkins server, parse the machine language analysis results (analyzer.output file), and save the parsing results (text report on the quality analysis of the code) and the corresponding code identification in a set location, such as saving them in the working directory of the SonarScanner, etc., which will not be repeated here.
[0085] For ease of understanding, the code quality analysis process provided by this application is explained below through a specific embodiment. Figure 7 , Figure 7 A seventh code quality analysis process schematic diagram provided by some embodiments is shown, and the process includes the following steps:
[0086] S701: The Jenkins server recognizes that the code type of the code to be quality analyzed is a Flutter code type, and calls and executes a command corresponding to the Flutter code type stored in the Jenkins server.
[0087] S702: The Jenkins server analyzes the code quality of the Flutter code based on the command corresponding to the Flutter code type to obtain a real-time analysis result. When it is identified that the real-time running result contains a sub-result indicating a code error, if it is determined that the sub-result can be ignored, the Jenkins server continues to analyze the quality of the code based on the command until the quality analysis of the code is completed and a machine language analysis result of the code is obtained.
[0088] S703: The Jenkins server pulls and runs the Flutter code analysis plug-in from the SonarQube server, parses the machine language analysis results based on the Flutter code analysis plug-in, and obtains a text report on the code quality analysis.
[0089] For ease of understanding, the code quality analysis process provided by this application is explained below through a specific embodiment. Figure 8 , Figure 8 An eighth code quality analysis process schematic diagram provided by some embodiments is shown, and the process includes the following steps:
[0090] S801: The developer submits the Flutter code to be analyzed for quality to the code repository device.
[0091] S802: The code warehouse device sends a code quality detection instruction to the Jenkins server, triggering a code quality detection task.
[0092] S803: The Jenkins server receives the code quality detection instruction sent by the code warehouse device, identifies the code identifier carried in the code quality detection instruction, and obtains (pulls) the code corresponding to the code identifier.
[0093] S804: The Jenkins server recognizes that the code type of the code to be quality analyzed is the Flutter code type, and calls and executes a command corresponding to the Flutter code type saved in the Jenkins server: flutter test>analyser.output command.
[0094] S805: The Jenkins server analyzes the quality of the code based on the command and obtains the machine language analysis result of the code: analyzer.output file.
[0095] S806: The Jenkins server pulls and runs the Flutter code analysis plug-in from the SonarQube server, and parses the machine language analysis results based on the Flutter code analysis plug-in to obtain each error contained in the machine language analysis results (also referred to as each error contained in the code), the error type of each error, and the location information corresponding to the sub-code of each error.
[0096] S807: The Jenkins server sends the parsing result and the corresponding code identifier to the SonarQube server.
[0097] S808: The SonarQube server determines whether the quality of the code is appropriate based on the pre-saved code quality threshold standard and the number and type of errors in the code, and saves the code quality detection result, each error contained in the code, the error type of each error, and the location information corresponding to the sub-code of each error in the quality analysis text report.
[0098] The process of judging whether the quality of the code is appropriate based on the pre-saved code quality threshold standard and the number and type of errors in the code is the same as that in the above embodiment and will not be described in detail here.
[0099] S809: The Jenkins server sends a request for obtaining a quality analysis text report to the SonarQube server, and the request carries a corresponding code identifier.
[0100] S810: After receiving the acquisition request, the SonarQube server sends the quality analysis text report corresponding to the code identifier to the Jenkins server.
[0101] S811: The Jenkins server sends the quality analysis text report to the code repository device.
[0102] S812: Code warehouse equipment display quality analysis text report.
[0103] Since the present application can decouple commands and code analysis plug-ins, the commands are saved in the Jenkins server, and the code analysis plug-in is configured in the SonarQube server. When it is identified that the sub-result containing the code errors in the real-time running results can be ignored, the sub-result can be ignored, and the code quality can continue to be analyzed based on the command, thereby greatly improving the fault tolerance of the code during the code quality analysis process and greatly improving the efficiency of code quality analysis.
[0104] Based on the same technical concept, this application provides a code quality analysis device, see Fig. 9 , Fig. 9 A schematic diagram of a code quality analysis device provided in some embodiments is shown, and the device is applied to a Jenkins server of an open source software project, and the device includes:
[0105] A command module 91 is used to identify the code type of the code to be quality analyzed, and call and execute a command corresponding to the code type stored in the Jenkins server;
[0106] The analysis module 92 is used to analyze the quality of the code based on the command to obtain a real-time analysis result, and when it is identified that the real-time running result contains a sub-result indicating that a code error occurs, if it is determined to ignore the sub-result, continue to analyze the quality of the code based on the command until the quality analysis of the code is completed to obtain a machine language analysis result of the code;
[0107] The plug-in module 93 is used to parse the machine language analysis result based on the code analysis plug-in corresponding to the code type pre-configured in the code quality inspection SonarQube server, and generate a quality analysis text report for the code.
[0108] In a possible implementation manner, the analysis module 92 is specifically configured to:
[0109] If the error in the sub-result is an error in the preset whitelist, the sub-result is ignored.
[0110] In a possible implementation manner, the analysis module 92 is specifically configured to:
[0111] If an ignore instruction to ignore the sub-result is received, the sub-result is ignored.
[0112] In a possible implementation manner, the plug-in module 93 is specifically used to:
[0113] Pull and run the code analysis plug-in from the SonarQube server, and parse the machine language analysis result based on the code analysis plug-in.
[0114] In a possible implementation manner, the plug-in module 93 is specifically used to:
[0115] The machine language analysis result is sent to the SonarQube server, so that the SonarQube server analyzes the machine language analysis result based on a code analysis plug-in pre-configured in the SonarQube server.
[0116] In a possible implementation, if the code type is a mobile application development framework Flutter code type, the code analysis plug-in is a Flutter code analysis plug-in.
[0117] In a possible implementation, a Sensor data exchange interface is configured in the Flutter code analysis plug-in, so that the SonarQube server configures the Flutter code analysis plug-in in the SonarQube server based on the Sensor data exchange interface.
[0118] In a possible implementation manner, the command module 91 is further configured to:
[0119] Receive a code quality detection instruction sent by a code warehouse device, identify a code identifier carried in the code quality detection instruction, and obtain a code corresponding to the code identifier;
[0120] The quality analysis text report is sent to the code warehouse device.
[0121] Based on the same technical concept, the present application also provides an electronic device, Fig.10 A schematic diagram of the structure of an electronic device provided by some embodiments is shown. Fig.10 As shown, the electronic device includes: a processor 101, a communication interface 102, a memory 103 and a communication bus 104, wherein the processor 101, the communication interface 102, and the memory 103 communicate with each other through the communication bus 104;
[0122] The memory 610 stores a computer program. When the program is executed by the processor 101, the processor 101 executes the computer program stored in the memory to implement the steps of any of the above methods.
[0123] Since the principle of solving the problem by the above electronic device is similar to the code quality analysis method, the implementation of the above electronic device can refer to the implementation of the method, and the repeated parts will not be repeated.
[0124] The communication bus mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.
[0125] The communication interface 102 is used for communication between the electronic device and other devices.
[0126] The memory may include a random access memory (RAM) or a non-volatile memory (NVM), such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.
[0127] The above-mentioned processor can be a general-purpose processor, including a central processing unit, a network processor (Network Processor, NP), etc.; it can also be a digital signal processing processor (Digital Signal Processing, DSP), an application-specific integrated circuit, a field programmable gate array or other programmable logic device, a discrete gate or transistor logic device, a discrete hardware component, etc.
[0128] Based on the same technical concept, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program that can be executed by an electronic device. When the program runs on the electronic device, the electronic device implements the steps of any of the above methods when executed.
[0129] Since the principle of solving the problem by the above-mentioned computer-readable storage medium is similar to that of the code quality analysis method, the implementation of the above-mentioned computer-readable storage medium can refer to the implementation of the method, and the repeated parts will not be repeated.
[0130] The above-mentioned computer-readable storage medium can be any available medium or data storage device that can be accessed by the processor in the electronic device, including but not limited to magnetic storage such as floppy disks, hard disks, magnetic tapes, magneto-optical disks (MO), etc., optical storage such as CD, DVD, BD, HVD, etc., and semiconductor storage such as ROM, EPROM, EEPROM, non-volatile memory (NANDFLASH), solid-state drive (SSD), etc.
[0131] Based on the same technical concept, the present application provides a computer program product, which includes: computer program code, when the computer program code runs on a computer, the computer implements the steps of the method described in any method embodiment applied to an electronic device.
[0132] In the above embodiments, all or part of the embodiments may be implemented by software, hardware, firmware or any combination thereof, and all or part of the embodiments may be implemented in the form of a computer program product. The computer program product includes one or more computer instructions, and when the computer instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of the present application are generated.
[0133] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0134] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0135] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0136] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0137] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.
Claims
1. A code quality analysis method, characterized in that: The method is applied to the Jenkins server of the open source software project, and the method comprises: Identify the code type of the code to be quality analyzed, and call and execute a command corresponding to the code type stored in the Jenkins server; Based on the command, the quality of the code is analyzed to obtain a real-time analysis result, and when it is identified that the real-time running result contains a sub-result indicating that a code error occurs, if it is determined to ignore the sub-result, the quality of the code is continuously analyzed based on the command until the quality analysis of the code is completed to obtain a machine language analysis result of the code; Based on a code analysis plug-in corresponding to the code type pre-configured in a code quality inspection SonarQube server, the machine language analysis result is parsed to obtain a quality analysis text report on the code.
2. The method according to claim 1, characterized in that The judging step of ignoring the sub-result comprises: If the error in the sub-result is an error in the preset whitelist, the sub-result is ignored.
3. The method according to claim 1, characterized in that The judging step of ignoring the sub-result comprises: If an ignore instruction to ignore the sub-result is received, the sub-result is ignored.
4. The method according to claim 1, characterized in that: The parsing of the machine language analysis result based on a code analysis plug-in corresponding to the code type pre-configured in the code quality inspection SonarQube server includes: Pull and run the code analysis plug-in from the SonarQube server, and parse the machine language analysis result based on the code analysis plug-in.
5. The method according to claim 1, characterized in that: The parsing of the machine language analysis result based on a code analysis plug-in corresponding to the code type pre-configured in the code quality inspection SonarQube server includes: The machine language analysis result is sent to the SonarQube server, so that the SonarQube server analyzes the machine language analysis result based on a code analysis plug-in pre-configured in the SonarQube server.
6. The method according to any one of claims 1 to 5, characterized in that: If the code type is a mobile application development framework Flutter code type, the code analysis plug-in is a Flutter code analysis plug-in.
7. The method according to claim 6, characterized in that The Flutter code analysis plug-in is configured with a Sensor data exchange interface, so that the SonarQube server configures the Flutter code analysis plug-in in the SonarQube server based on the Sensor data exchange interface.
8. The method according to any one of claims 1 to 5, characterized in that: Before identifying the code type to be quality analyzed, the method further includes: Receive a code quality detection instruction sent by a code warehouse device, identify a code identifier carried in the code quality detection instruction, and obtain a code corresponding to the code identifier; The method further comprises: The quality analysis text report is sent to the code warehouse device.
9. A code quality analysis device, characterized in that: The device is applied to the Jenkins server of the open source software project, and the device includes: A command module, used to identify the code type of the code to be quality analyzed, and call and execute a command corresponding to the code type stored in the Jenkins server; an analysis module, configured to analyze the quality of the code based on the command to obtain a real-time analysis result, and when it is identified that the real-time running result contains a sub-result indicating that a code error occurs, if it is determined to ignore the sub-result, continue to analyze the quality of the code based on the command until the quality analysis of the code is completed to obtain a machine language analysis result of the code; The plug-in module is used to parse the machine language analysis result based on the code analysis plug-in corresponding to the code type pre-configured in the code quality inspection SonarQube server, and generate a quality analysis text report for the code.
10. An electronic device, characterized in that: The electronic device comprises at least a processor and a memory, and the processor is configured to implement the steps of any one of the methods of claims 1 to 8 when executing a computer program stored in the memory.
Citation Information
Cited By
File transfer method, quality inspection method and related device
CN121168361A