CN111258562A - Java code quality inspection method, device, equipment and storage medium - Google Patents

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

Info

Publication number
CN111258562A
CN111258562A CN202010031768.0A CN202010031768A CN111258562A CN 111258562 A CN111258562 A CN 111258562A CN 202010031768 A CN202010031768 A CN 202010031768A CN 111258562 A CN111258562 A CN 111258562A
Authority
CN
China
Prior art keywords
java code
java
user
code
uploaded
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202010031768.0A
Other languages
Chinese (zh)
Other versions
CN111258562B (en
Inventor
张汉翼
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ping An Property and Casualty Insurance Company of China Ltd
Original Assignee
Ping An Property and Casualty Insurance Company of China Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Ping An Property and Casualty Insurance Company of China Ltd filed Critical Ping An Property and Casualty Insurance Company of China Ltd
Priority to CN202010031768.0A priority Critical patent/CN111258562B/en
Publication of CN111258562A publication Critical patent/CN111258562A/en
Application granted granted Critical
Publication of CN111258562B publication Critical patent/CN111258562B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms
    • G06F8/315Object-oriented languages
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms
    • G06F8/316Aspect-oriented programming techniques

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computing Systems (AREA)
  • Stored Programmes (AREA)

Abstract

The present application relates to the field of computer technologies, and in particular, to a method, an apparatus, a device, and a storage medium for checking Java code quality. The method comprises the following steps: acquiring at least one Java code file to be uploaded; inputting at least one Java code file to be uploaded to an open source analysis tool; traversing the abstract syntax tree, and performing comparative detection on each line of Java code sentences in the abstract syntax book through preset rule analysis to obtain a detection result, wherein the detection result comprises an array and a regular expression, and the array at least comprises a granularity function of the Java code to be analyzed and a result of the Java code to be analyzed, which is in a class and does not conform to the preset rule; storing the granularity function and the result which does not accord with the preset rule in the class in the Java code to be analyzed into a first set; calculating the difference value between the first set and the condition set to obtain an out-of-compliance information set; and if the non-compliance information set is not an empty set, blocking hooks of Git and returning a result which does not accord with the preset rule to the user. And the quality problem of uploaded codes is reduced.

Description

Java code quality inspection method, device, equipment and storage medium
Technical Field
The present application relates to the field of computer technologies, and in particular, to a method, an apparatus, a device, and a storage medium for checking Java code quality.
Background
The evaluation of code quality is the key to the IT field to measure the ability of a programmer and is one of the bases for the robustness of an item. Written code is obscure if it has no annotations and irregular format. However, the judgment standard of the existing code depends on the existing grammar of the program language, and the judgment is performed according to the result which may appear in the program under the condition of high concurrency and aiming at the result which appears in the multi-user thread test program, so that the logic which seems normal to the code may still have fatal hidden trouble. Most of traditional code inspection is to manually inspect the defects of codes or inspect development tool plug-ins provided by open source projects in the development process of developers, but the manual inspection needs a lot of manpower and cannot be eliminated by exact hidden dangers, the development plug-ins need the developers to actively cooperate with company specifications for use, if the developers do not actively accept the plug-ins, some development rules cannot be followed, so that the hidden dangers of the codes occur, if the developers do not actively accept the plug-ins, problems occur in the operation process, and if the developers do not actively accept the plug-ins, the companies are seriously caused with losses due to technical errors.
Disclosure of Invention
The application provides a method for checking the quality of the uploaded Java code, which can avoid the quality problem of the uploaded Java code.
In a first aspect, the present application provides a Java code quality inspection method, including:
acquiring 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 inspection tool adopting a Berkeley software release protocol;
obtaining 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;
traversing the abstract syntax tree, and performing comparative detection on each line of Java code sentences in the abstract syntax book through preset rule analysis to obtain a detection result, wherein the detection result comprises an array and a regular expression, the array at least comprises a granularity function of the Java code to be analyzed and a result of the Java code to be analyzed, which does not conform to a preset rule in a class, and the preset rule is used for detecting a rule of Java code abnormity;
storing the granularity function and the result which does not accord with the preset rule in the class in the Java code to be analyzed to a first set;
generating a condition set corresponding to a preset condition according to the preset condition, wherein the preset condition comprises that any function in any class is ignored during the execution of the preset rule check, any branch is ignored during the execution of the preset rule check, and any class is ignored during the execution of the preset rule check;
calculating the difference value between the first set and the condition set to obtain an out-of-compliance information set;
and if the non-compliance information set is not an empty set, blocking hooks of Git and returning results which do not conform to the preset rules to the user.
In some possible designs, if the set of non-compliance information is not an empty set, blocking hooks of Git and returning a result that does not comply with the preset rule to the user includes:
judging whether the non-compliance information set is an empty set;
if the non-compliance information set is not an empty set, reading a configuration file in a client, acquiring a Git sub-warehouse address corresponding to the code name in the configuration file, and sending a result return service request to a server corresponding to the Git sub-warehouse address;
acquiring a Git sub-warehouse code corresponding to the code name sent by the corresponding server through the Git code management tool;
copying the Git child repository code into the client's local database through the Git code management tool.
In some possible designs, before the obtaining at least one Java code file to be uploaded, the method further includes:
acquiring a Java code uploading request of a user, wherein the Java code uploading request of the user comprises user permission information and user information;
checking the user permission information in the request for uploading Java code by the user to judge whether the user has uploading permission, and if the user does not have uploading permission, forbidding uploading of the Java code file to be uploaded;
if the user has the uploading authority, checking whether the user information meets the uploading rule;
and if the uploading rule is met, acquiring the Java code file to be uploaded.
In some possible designs, if the set of non-compliance information is not an empty set, blocking hooks of Git and returning a result that does not comply with the preset rule to the user includes:
extracting code information in the non-compliance information set to obtain a code information set, wherein the non-compliance information set comprises class names, Java functions, line numbers and character information of non-compliance Java codes;
judging whether the code information set is an empty set or not;
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-compliance information set in sequence;
filling the arranged class names, the Java functions, the line numbers and the character information in a fixed format to generate a message for prompting a user;
and blocking the hook of the Git, returning a result which does not accord with the preset rule and the message for prompting the user to send to the user.
In some possible designs, the obtaining, by the open source analysis tool, an abstract syntax tree of 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 larger than a thread pool threshold value, acquiring an abstract syntax tree of the Java code by adopting the thread pools with the thread pool threshold value number;
and when the number of the Java code files to be uploaded is less than or equal to the thread pool threshold value, acquiring the abstract syntax tree of the Java code according to the thread pool of the number of the Java code files to be uploaded.
In some possible designs, after generating the message prompting the user, blocking a hook of Git and returning a result that does not conform to the preset rule and after sending the message prompting the user to the user, the method further includes:
acquiring the message for prompting the user;
uploading the message for prompting the user and the non-compliance information set to a database and summarizing;
generating a corresponding visual chart by using the message for prompting the user and the non-compliance information set through a data visualization technology, wherein the visual chart at least comprises a column chart, a line chart, a pie chart, a scatter chart and a combined chart;
and presenting and summarizing the visual chart through the monitoring log.
In some possible designs, after presenting the summary visualization chart through the monitoring log, the method further comprises:
counting the number of error files of the Java code file to be uploaded through the visual chart;
setting an upper limit threshold and a lower limit threshold;
if the number of the error files is larger than or equal to the upper limit threshold value, determining the error files as high-frequency error codes;
if the number of the error files is less than or equal to the lower limit threshold, determining the error files as low-frequency error codes;
and if the number of the error files is larger than the lower limit threshold and smaller than the upper limit threshold, determining that the error files are intermediate-frequency error codes.
In a second aspect, the present application provides a Java code quality inspection apparatus having a function of implementing a method corresponding to the Java code quality inspection platform provided in the first aspect described above. The functions can be realized by hardware, and the functions can also be realized by executing corresponding software by hardware. The hardware or software includes one or more modules corresponding to the above functions, which may be software and/or hardware.
The Java code quality inspection apparatus includes:
the input and output module is used for acquiring at least one Java code file to be uploaded;
the processing module is used for inputting the at least one Java code file to be uploaded into an open source analysis tool, and the open source analysis tool is a Java program code inspection tool adopting a Berkeley software release protocol; obtaining 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; traversing the abstract syntax tree, and performing comparative detection on each line of Java code sentences in the abstract syntax book through preset rule analysis to obtain a detection result, wherein the detection result comprises an array and a regular expression, the array at least comprises a granularity function of the Java code to be analyzed and a result of the Java code to be analyzed, which does not conform to a preset rule in a class, and the preset rule is used for detecting a rule of Java code abnormity; storing the granularity function and the result which does not accord with the preset rule in the class in the Java code to be analyzed to a first set; generating a condition set corresponding to a preset condition according to the preset condition, wherein the preset condition comprises that any function in any class is ignored during the execution of the preset rule check, any branch is ignored during the execution of the preset rule check, and any class is ignored during the execution of the preset rule check; calculating the difference value between the first set and the condition set to obtain an out-of-compliance information set; and if the non-compliance information set is not an empty set, blocking hooks of Git and returning results which do not conform to the preset rules to the user.
In some possible designs, the processing module is further to:
judging whether the non-compliance information set is an empty set;
if the non-compliance information set is not an empty set, reading a configuration file in a client, acquiring a Git sub-warehouse address corresponding to the code name in the configuration file, and sending a result return service request to a server corresponding to the Git sub-warehouse address;
acquiring a Git sub-warehouse code corresponding to the code name sent by the corresponding server through the Git code management tool;
copying the Git child repository code into the client's local database through the Git code management tool.
In some possible designs, the processing module is further to:
acquiring a Java code uploading request of a user, wherein the Java code uploading request of the user comprises user permission information and user information;
checking the user permission information in the request for uploading Java code by the user to judge whether the user has uploading permission, and if the user does not have uploading permission, forbidding uploading of the Java code file to be uploaded;
if the user has the uploading authority, checking whether the user information meets the uploading rule;
and if the uploading rule is met, acquiring the Java code file to be uploaded.
In some possible designs, the processing module is further to:
extracting code information in the non-compliance information set to obtain a code information set, wherein the non-compliance information set comprises class names, Java functions, line numbers and character information of non-compliance Java codes;
judging whether the code information set is an empty set or not;
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-compliance information set in sequence;
filling the arranged class names, the Java functions, the line numbers and the character information in a fixed format to generate a message for prompting a user;
and blocking the hook of the Git, returning a result which does not accord with the preset rule and the message for prompting the user to send to the user.
In some possible designs, the processing module is further to:
when the number of the Java code files to be uploaded is larger than a thread pool threshold value, acquiring an abstract syntax tree of the Java code by adopting the thread pools with the thread pool threshold value number;
and when the number of the Java code files to be uploaded is less than or equal to the thread pool threshold value, acquiring the abstract syntax tree of the Java code according to the thread pool of the number of the Java code files to be uploaded.
In some possible designs, the processing module is further to:
acquiring the message for prompting the user;
uploading the message for prompting the user and the non-compliance information set to a database and summarizing;
generating a corresponding visual chart by using the message for prompting the user and the non-compliance information set through a data visualization technology, wherein the visual chart at least comprises a column chart, a line chart, a pie chart, a scatter chart and a combined chart;
and presenting and summarizing the visual chart through the monitoring log.
In some possible designs, the processing module is further to:
counting the number of error files of the Java code file to be uploaded through the visual chart;
setting an upper limit threshold and a lower limit threshold;
if the number of the error files is larger than or equal to the upper limit threshold value, determining the error files as high-frequency error codes;
if the number of the error files is less than or equal to the lower limit threshold, determining the error files as low-frequency error codes;
and if the number of the error files is larger than the lower limit threshold and smaller than the upper limit threshold, determining that the error files are intermediate-frequency error codes.
Yet another aspect of the present application provides a Java code quality inspection apparatus, which includes at least one connected processor, a memory, and an input-output unit, wherein the memory is used for storing program codes, and the processor is used for calling the program codes in the memory to execute the method of the above aspects.
Yet another aspect of the present application provides a computer storage medium comprising instructions which, when executed on a computer, cause the computer to perform the method of the above-described aspects.
According to the method and the device, an abstract syntax tree of the Java code is obtained through an open source analysis tool PMD, the abstract syntax tree is analyzed, whether the Java code meets the specification or not is judged according to the analysis result, and if the Java code does not meet the specification, the Java code is rejected to be submitted to Git. The standardization and readability of enterprise codes are restricted through the combination of an open source analysis tool PMD and a GIT, the code quality is controlled, hidden dangers in the codes are reduced, and losses caused by the fact that the codes are on line to enterprises are reduced.
Drawings
FIG. 1 is a schematic flow chart of a Java code quality inspection method in an embodiment of the present application;
FIG. 2 is a schematic structural diagram of a Java code quality inspection apparatus in an embodiment of the present application;
fig. 3 is a schematic structural diagram of a Java code quality inspection apparatus in an embodiment of the present application.
The implementation, functional features and advantages of the objectives of the present application will be further explained with reference to the accompanying drawings.
Detailed Description
It should be understood that the specific embodiments described herein are merely illustrative of the present application and are not intended to limit the present application. The terms "first," "second," and the like in the description and in the claims of the present application and in the above-described drawings are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It will be appreciated that the data so used may be interchanged under appropriate circumstances such that the embodiments described herein may be practiced otherwise than as specifically illustrated or described herein. Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or modules is not necessarily limited to those steps or modules explicitly listed, but may include other steps or modules not explicitly listed or inherent to such process, method, article, or apparatus, and such that a division of modules presented in this application is merely a logical division that may be implemented in an actual application in a different manner, such that multiple modules may be combined or integrated into another system, or some features may be omitted, or may not be implemented.
To solve the above technical problems, the present application mainly provides the following technical solutions
According to the method and the device, the abstract syntax tree of the Java code is obtained through the PMD, the abstract syntax tree is analyzed, whether the Java code meets the specification or not is judged according to the analysis result, and if the Java code does not meet the specification, the Java code is rejected to be submitted to the Git. The standardization and readability of enterprise codes are restricted through the combination of an open source analysis tool PMD and a GIT, the code quality is controlled, hidden dangers in the codes are reduced, and losses caused by the fact that the codes are on line to enterprises are reduced.
Referring to fig. 1, the following illustrates a method for checking Java code quality, the method including:
101. and acquiring at least one Java code file to be uploaded.
The file formats of the Java code files to be uploaded at least comprise a Java format and a class format.
102. And inputting at least one Java code file to be uploaded into the open source analysis tool.
The open source analysis tool is a Java program code inspection tool that employs the berkeley software release protocol.
The open source analysis tool also provides integration with various integrated development environments and tools of Java, such as Eclipse, IntelliJ IDEA, NetBean integration.
103. And obtaining at least one abstract syntax tree of the Java code corresponding to the Java code file to be uploaded by an open source analysis tool.
An abstract syntax tree is created by the parser. The parser is a component of a compiler or an interpreter, and is mainly used for performing syntax checking and constructing a data structure (generally, a hierarchical data structure such as a parsing tree or an abstract syntax tree) composed of input words. The abstract syntax tree can be used for conveniently realizing various source program processing tools, such as a source program browser, an intelligent editor, a language translator and the like.
104. Traversing the abstract syntax tree, and performing comparison detection on each line of Java code sentences in the abstract syntax book through preset rule analysis to obtain a detection result, wherein the detection result comprises an array and a regular expression, the array at least comprises a granularity function of the Java code to be analyzed and a result that the class in the Java code to be analyzed does not conform to the preset rule, and the preset rule is used for detecting the rule of the Java code abnormity.
The preset rule is used for detecting the abnormal rule of the Java code. The preset rules at least include: class names must be humped naming, boolean types should not start with is, avoid starting with dollars or underlines, magic rules are undefined, thread pools do not allow creation using actors, creation by thread executor means, classes must add author comments, variable name humped case, abstract class naming digest heading, classes implemented by servers and data access objects need to end with a pulse Impl, and Exception exceptions for Exception classes.
105. And storing the granularity function and the result which does not accord with the preset rule in the class in the Java code to be analyzed into a first set.
The first set holds information of a plurality of Java files. The granularity is the minimum value of the system memory expansion increment. Each class contains a description of the data and a set of functions that operate on the data or pass messages.
106. And generating a condition set corresponding to the preset condition according to the preset condition.
The preset conditions include that any function in any class is ignored during the execution of the preset rule check, any branch is ignored during the execution of the preset rule check, and any class is ignored during the execution of the preset rule check.
107. And calculating the difference value between the first set and the condition set to obtain an out-of-compliance information set.
Or calculating the intersection between the first set and the condition set so as to obtain two different places.
108. And if the non-compliance information set is not an empty set, blocking hooks of Git and returning a result which does not accord with the preset rule to the user.
And obtaining an abstract syntax tree of the Java code through an open source analysis tool PMD, analyzing the abstract syntax tree, judging whether the Java code meets the specification according to an analysis result, and if the Java code does not meet the specification, rejecting the Java code to be submitted to the Git. The standardization and readability of enterprise codes are restricted through the combination of an open source analysis tool PMD and a GIT, the code quality is controlled, hidden dangers in the codes are reduced, and losses caused by the fact that the codes are on line to enterprises are reduced.
In some embodiments, if the non-compliance information set is not an empty set, blocking the hook of Git and returning a result that does not comply with the preset rule to the user includes:
judging whether the non-compliance information set is an empty set or not;
if the non-compliance information set is not an empty set, reading a configuration file in the client, acquiring a Git sub-warehouse address corresponding to a code name in the configuration file, and sending a result return service request to a server corresponding to the Git sub-warehouse address;
acquiring a Git sub-warehouse code corresponding to the code name sent by the corresponding server through the Git code management tool;
the Git child repository code is copied into the client's local database by the Git code management tool.
In some embodiments, before obtaining at least one Java code file to be uploaded, the method further includes:
acquiring a Java code uploading request of a user, wherein the Java code uploading request of the user comprises user permission information and user information;
checking user authority information in a Java code uploading request of a user to judge whether the user has uploading authority, and if the user does not have the uploading authority, forbidding uploading of a Java code file to be uploaded;
if the user has the uploading authority, checking whether the user information meets the uploading rule;
and if the uploading rule is met, acquiring the Java code file to be uploaded.
In the above embodiment, the result that does not conform to the prediction rule is returned to the user by the above method, and the user is prompted to modify the result.
In some embodiments, if the non-compliance information set is not an empty set, blocking the hook of Git and returning a result that does not comply with the preset rule to the user includes:
extracting code information in the non-compliance information set to obtain a code information set, wherein the non-compliance information set comprises class names, Java functions, line numbers and character information of non-compliance Java codes;
judging whether the code information set is an empty set or not;
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-compliance information set in sequence;
the arranged class names, Java functions, line numbers and character information are combined and filled in a fixed format to generate a message for prompting a user;
and blocking hooks of Git, returning results which do not accord with preset rules and prompting the user to send messages to the user.
In the above embodiment, the prompt message indicating the exception code is generated by the above method, for example, the 55 th character a of 153 line in the X function in the class a is a magic value non-compliance.
In some embodiments, obtaining, by an open source analysis tool, an abstract syntax tree of Java code corresponding to at least one Java code file to be uploaded includes:
when the number of Java code files to be uploaded is larger than a thread pool threshold value, acquiring an abstract syntax tree of the Java code by adopting thread pools with the thread pool threshold value number;
and when the number of the Java code files to be uploaded is less than or equal to the thread pool threshold value, acquiring the abstract syntax tree of the Java code according to the thread pool of the number of the Java code files to be uploaded.
In the above embodiment, the thread can be used to put the task in the program with long occupation time into the background for processing, so as to accelerate the processing speed of the task and reduce the waiting time of the user.
In some embodiments, after generating the message prompting the user, blocking the hook of Git and returning the result that does not conform to the preset rule and after sending the message prompting the user to the user, the method further comprises:
acquiring a message for prompting a user;
uploading the information prompting the user and the non-compliance information set to a database and summarizing;
generating a corresponding visual chart by collecting information for prompting a user and non-compliance information through a data visualization technology, wherein the visual chart at least comprises a column chart, a line chart, a pie chart, a scatter chart and a combined chart;
and displaying a summary visual chart through the monitoring log.
In the above embodiment, the code quality of each version is monitored and managed. So as to know the code change between each version and realize the monitoring of the code quality.
In some embodiments, after presenting the summary visualization chart via the monitoring log, the method further comprises:
counting the number of error files of the Java code file to be uploaded through a visual chart;
setting an upper limit threshold and a lower limit threshold;
if the number of the error files is larger than or equal to the upper limit threshold value, determining the error files as high-frequency error codes;
if the number of the error files is less than or equal to the lower limit threshold, determining the error files as low-frequency error codes;
and if the number of the error files is larger than the lower limit threshold and smaller than the upper limit threshold, determining the error files as intermediate-frequency error codes.
In the above embodiment, the code quality is monitored by the above monitoring log.
Fig. 2 is a schematic structural diagram of a Java code quality inspection apparatus 20, which can be applied to Java code quality inspection. The Java code quality inspection apparatus in the embodiment of the present application can implement the steps corresponding to the Java code quality inspection method executed in the embodiment corresponding to fig. 1 described above. The functions implemented by the Java code quality inspection apparatus 20 may be implemented by hardware, or may be implemented by hardware executing corresponding software. The hardware or software includes one or more modules corresponding to the above functions, which may be software and/or hardware. The Java code quality inspection apparatus may include an input/output module 201 and a processing module 202, and the implementation of the functions of the processing module 202 and the input/output module 201 may refer to operations executed in the embodiment corresponding to fig. 1, which are not described herein again. The input-output module 201 may be used to control input, output, and acquisition operations of the input-output module 201.
In some embodiments, the input/output module 201 may be configured to obtain at least one Java code file to be uploaded;
the processing module 202 may be configured to input the at least one Java code file to be uploaded to an open source analysis tool, where the open source analysis tool is a Java program code inspection tool that employs a berkeley software release protocol; obtaining 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; traversing the abstract syntax tree, and performing comparative detection on each line of Java code sentences in the abstract syntax book through preset rule analysis to obtain a detection result, wherein the detection result comprises an array and a regular expression, the array at least comprises a granularity function of the Java code to be analyzed and a result of the Java code to be analyzed, which does not conform to a preset rule in a class, and the preset rule is used for detecting a rule of Java code abnormity; storing the granularity function and the result which does not accord with the preset rule in the class in the Java code to be analyzed to a first set; generating a condition set corresponding to a preset condition according to the preset condition, wherein the preset condition comprises that any function in any class is ignored during the execution of the preset rule check, any branch is ignored during the execution of the preset rule check, and any class is ignored during the execution of the preset rule check; calculating the difference value between the first set and the condition set to obtain an out-of-compliance information set; and if the non-compliance information set is not an empty set, blocking hooks of Git and returning results which do not conform to the preset rules to the user.
In some embodiments, the processing module 202 is further configured to:
judging whether the non-compliance information set is an empty set;
if the non-compliance information set is not an empty set, reading a configuration file in a client, acquiring a Git sub-warehouse address corresponding to the code name in the configuration file, and sending a result return service request to a server corresponding to the Git sub-warehouse address;
acquiring a Git sub-warehouse code corresponding to the code name sent by the corresponding server through the Git code management tool;
copying the Git child repository code into the client's local database through the Git code management tool.
In some embodiments, the processing module 202 is further configured to:
extracting code information in the non-compliance information set to obtain a code information set, wherein the non-compliance information set comprises class names, Java functions, line numbers and character information of non-compliance Java codes;
judging whether the code information set is an empty set or not;
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-compliance information set in sequence;
filling the arranged class names, the Java functions, the line numbers and the character information in a fixed format to generate a message for prompting a user;
and blocking the hook of the Git, returning a result which does not accord with the preset rule and the message for prompting the user to send to the user.
In some embodiments, the processing module 202 is further configured to:
acquiring the non-compliance information set, wherein the non-compliance information set comprises class names, methods, line numbers and character information of non-compliance Java codes;
judging whether the non-compliance information set is an empty set;
if the non-compliance information set is not an empty set, extracting the class name, the method, the line number and the character information in the non-compliance information set;
combining the class name, the method, the line number and the character information through a fixed grid to generate a message for prompting a user;
and after the message for prompting the user is generated, blocking the hook of the Git, returning a result which does not accord with the preset rule and the message for prompting the user to send to the user.
In some embodiments, the processing module 202 is further configured to:
when the number of the Java code files to be uploaded is larger than a thread pool threshold value, acquiring an abstract syntax tree of the Java code by adopting thread pools with the thread pool threshold value number;
and when the number of the Java code files to be uploaded is less than or equal to the thread pool threshold value, acquiring the abstract syntax tree of the Java code according to the thread pool of the number of the Java code files to be uploaded.
In some embodiments, the processing module 202 is further configured to:
acquiring the message for prompting the user;
uploading the message for prompting the user and the non-compliance information set to a database and summarizing;
generating a corresponding visual chart by using the message for prompting the user and the non-compliance information set through a data visualization technology, wherein the visual chart at least comprises a column chart, a line chart, a pie chart, a scatter chart and a combined chart;
and presenting and summarizing the visual chart through the monitoring log.
In some embodiments, the processing module 202 is further configured to:
counting the number of error files of the Java code file to be uploaded through the visual chart;
setting an upper limit threshold and a lower limit threshold;
if the number of the error files is larger than or equal to the upper limit threshold value, determining the error files as high-frequency error codes;
if the number of the error files is less than or equal to the lower limit threshold, determining the error files as low-frequency error codes;
and if the number of the error files is larger than the lower limit threshold and smaller than the upper limit threshold, determining that the error files are intermediate-frequency error codes.
The creating apparatus in the embodiment of the present application is described above from the perspective of the modular functional entity, and the following describes a Java code quality inspection apparatus from the perspective of hardware, as shown in fig. 3, which includes: a processor, a memory, an input-output unit (which may also be a transceiver, not identified in fig. 3), and a computer program stored in the memory and executable on the processor. For example, the computer program may be a program corresponding to the Java code quality inspection method in the embodiment corresponding to fig. 1. For example, when the computer device implements the functions of the Java code quality inspection apparatus 20 shown in fig. 2, the processor executes the computer program to implement the steps in the Java code quality inspection method executed by the Java code quality inspection apparatus 20 in the embodiment corresponding to fig. 2. Alternatively, the processor implements the functions of the modules in the Java code quality inspection apparatus 20 according to the embodiment corresponding to fig. 2 when executing the computer program. For another example, the computer program may be a program corresponding to the Java code quality inspection method in the embodiment corresponding to fig. 1.
The processor may be a Central Processing Unit (CPU), other general purpose processor, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), an off-the-shelf programmable gate array (FPGA) or other programmable logic device, discrete gate or transistor logic, discrete hardware components, etc. The general purpose processor may be a microprocessor or the processor may be any conventional processor or the like which is the control center for the computer device and which connects the various parts of the overall computer device using various interfaces and lines.
The memory may be used to store the computer programs and/or modules, and the processor may implement various functions of the computer device by running or executing the computer programs and/or modules stored in the memory and invoking data stored in the memory. The memory may mainly include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program required by at least one function (such as a sound playing function, an image playing function, etc.), and the like; the storage data area may store data (such as audio data, video data, etc.) created according to the use of the cellular phone, etc. In addition, the memory may include high speed random access memory, and may also include non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a Smart Memory Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), at least one magnetic disk storage device, a Flash memory device, or other volatile solid state storage device.
The input-output unit may also be replaced by a receiver and a transmitter, which may be the same or different physical entities. When they are the same physical entity, they may be collectively referred to as an input-output unit. The input and output may be a transceiver.
The memory may be integrated in the processor or may be provided separately from the processor.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such understanding, the technical solutions of the present application may be embodied in the form of a software product, which is stored in a storage medium (e.g., ROM/RAM), and includes several instructions for enabling a terminal (e.g., a mobile phone, a computer, a server, or a network device) to execute the method according to the embodiments of the present application.
The embodiments of the present application have been described above with reference to the drawings, but the present application is not limited to the above-mentioned embodiments, which are only illustrative and not restrictive, and those skilled in the art can make many changes and modifications without departing from the spirit and scope of the present application and the protection scope of the claims, and all changes and modifications that come within the meaning and range of equivalency of the claims are to be embraced within their scope.

Claims (10)

1. A Java code quality inspection method, characterized in that the method comprises:
acquiring 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 inspection tool adopting a Berkeley software release protocol;
obtaining 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;
traversing the abstract syntax tree, and performing comparative detection on each line of Java code sentences in the abstract syntax book through preset rule analysis to obtain a detection result, wherein the detection result comprises an array and a regular expression, the array at least comprises a granularity function of the Java code to be analyzed and a result of the Java code to be analyzed, which does not conform to a preset rule in a class, and the preset rule is used for detecting a rule of Java code abnormity;
storing the granularity function and the result which does not accord with the preset rule in the class in the Java code to be analyzed to a first set;
generating a condition set corresponding to a preset condition in a Java code quality inspection algorithm according to the preset condition, wherein the preset condition comprises that any function in any class is ignored during the execution of the preset rule inspection, any branch is ignored during the execution of the preset rule inspection, and any class is ignored during the execution of the preset rule inspection;
calculating the difference value between the first set and the condition set to obtain an out-of-compliance information set;
and if the non-compliance information set is not an empty set, blocking hooks of Git and returning results which do not conform to the preset rules to the user.
2. The method according to claim 1, wherein if the set of non-compliance information is not an empty set, blocking hooks of Git and returning results that do not comply with the preset rules to the user comprises:
judging whether the non-compliance information set is an empty set;
if the non-compliance information set is not an empty set, reading a configuration file in a client, acquiring a Git sub-warehouse address corresponding to the code name in the configuration file, and sending a result return service request to a server corresponding to the Git sub-warehouse address;
acquiring a Git sub-warehouse code corresponding to the code name sent by the corresponding server through the Git code management tool;
copying the Git child repository code into the client's local database through the Git code management tool.
3. The method according to claim 1, wherein before the obtaining of the at least one Java code file to be uploaded, the method further comprises:
acquiring a Java code uploading request of a user, wherein the Java code uploading request of the user comprises user permission information and user information;
checking the user permission information in the request for uploading Java codes by the user to judge whether the user has uploading permission;
if the user does not have the uploading authority, the Java code file to be uploaded is prohibited to be uploaded;
if the user has the uploading authority, checking whether the user information meets the uploading rule;
and if the uploading rule is met, acquiring the Java code file to be uploaded.
4. The method according to claim 1, wherein if the set of non-compliance information is not an empty set, blocking hooks of Git and returning results that do not comply with the preset rules to the user comprises:
extracting code information in the non-compliance information set to obtain a code information set, wherein the non-compliance information set comprises class names, Java functions, line numbers and character information of non-compliance Java codes;
judging whether the code information set is an empty set or not;
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-compliance information set in sequence;
filling the arranged class names, the Java functions, the line numbers and the character information in a fixed format to generate a message for prompting a user;
and blocking the hook of the Git, returning a result which does not accord with the preset rule and the message for prompting the user to send to the user.
5. The method according to any one of claims 1 to 4, wherein the obtaining, by the open source analysis tool, the abstract syntax tree of the Java code corresponding to the at least one Java code file to be uploaded comprises:
when the number of the Java code files to be uploaded is larger than a thread pool threshold value, acquiring an abstract syntax tree of the Java code by adopting the thread pools with the thread pool threshold value number;
and when the number of the Java code files to be uploaded is less than or equal to the thread pool threshold value, acquiring the abstract syntax tree of the Java code according to the thread pool of the number of the Java code files to be uploaded.
6. The method according to claim 4, wherein after generating the message prompting the user, blocking the hook of Git and returning the result that does not conform to the preset rule and after sending the message prompting the user to the user, the method further comprises:
acquiring the message for prompting the user;
uploading the message for prompting the user and the non-compliance information set to a database and summarizing;
generating a corresponding visual chart by using the message for prompting the user and the non-compliance information set through a data visualization technology, wherein the visual chart at least comprises a column chart, a line chart, a pie chart, a scatter chart and a combined chart;
and presenting and summarizing the visual chart through the monitoring log.
7. The method of claim 6, wherein after presenting the aggregated visualization chart via the monitoring log, the method further comprises:
counting the number of error files of the Java code file to be uploaded through the visual chart;
setting an upper limit threshold and a lower limit threshold;
if the number of the error files is larger than or equal to the upper limit threshold value, determining the error files as high-frequency error codes;
if the number of the error files is less than or equal to the lower limit threshold, determining the error files as low-frequency error codes;
and if the number of the error files is larger than the lower limit threshold and smaller than the upper limit threshold, determining that the error files are intermediate-frequency error codes.
8. A Java code quality inspection apparatus, characterized in that the apparatus comprises:
the input and output module is used for acquiring at least one Java code file to be uploaded;
the processing module is used for inputting the at least one Java code file to be uploaded into an open source analysis tool, and the open source analysis tool is a Java program code inspection tool adopting a Berkeley software release protocol; obtaining 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; traversing the abstract syntax tree, and performing comparative detection on each line of Java code sentences in the abstract syntax book through preset rule analysis to obtain a detection result, wherein the detection result comprises an array and a regular expression, the array at least comprises a granularity function of the Java code to be analyzed and a result of the Java code to be analyzed, which does not conform to a preset rule in a class, and the preset rule is used for detecting a rule of Java code abnormity; storing the granularity function and the result which does not accord with the preset rule in the class in the Java code to be analyzed to a first set; generating a condition set corresponding to a preset condition according to the preset condition, wherein the preset condition comprises that any function in any class is ignored during the execution of the preset rule check, any branch is ignored during the execution of the preset rule check, and any class is ignored during the execution of the preset rule check; calculating the difference value between the first set and the condition set to obtain an out-of-compliance information set; and if the non-compliance information set is not an empty set, blocking hooks of Git and returning results which do not conform to the preset rules to the user.
9. A Java code quality inspection apparatus, characterized in that the computer apparatus comprises:
at least one processor, a memory, and an input-output unit;
wherein the memory is configured to store program code and the processor is configured to invoke the program code stored in the memory to perform the method of any of claims 1-7.
10. A computer storage medium comprising instructions which, when run on a computer, cause the computer to perform the method of any one of claims 1-7.
CN202010031768.0A 2020-01-13 2020-01-13 Java code quality inspection method, device, equipment and storage medium Active CN111258562B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010031768.0A CN111258562B (en) 2020-01-13 2020-01-13 Java code quality inspection method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010031768.0A CN111258562B (en) 2020-01-13 2020-01-13 Java code quality inspection method, device, equipment and storage medium

Publications (2)

Publication Number Publication Date
CN111258562A true CN111258562A (en) 2020-06-09
CN111258562B CN111258562B (en) 2024-09-13

Family

ID=70948731

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010031768.0A Active CN111258562B (en) 2020-01-13 2020-01-13 Java code quality inspection method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN111258562B (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112130862A (en) * 2020-09-28 2020-12-25 平安国际智慧城市科技股份有限公司 Package file generation method, device, equipment and computer readable storage medium
CN112651213A (en) * 2020-12-25 2021-04-13 军工保密资格审查认证中心 Safety examination method and device for numerical control program

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR101051600B1 (en) * 2010-03-29 2011-07-22 주식회사 소프트 포 소프트 Systems for performing code inspection on abap source code
CN109446078A (en) * 2018-10-18 2019-03-08 网易(杭州)网络有限公司 Code test method and device, storage medium, electronic equipment
CN110609693A (en) * 2019-08-15 2019-12-24 平安国际智慧城市科技股份有限公司 Code updating method and device based on data standardization and terminal equipment

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR101051600B1 (en) * 2010-03-29 2011-07-22 주식회사 소프트 포 소프트 Systems for performing code inspection on abap source code
CN109446078A (en) * 2018-10-18 2019-03-08 网易(杭州)网络有限公司 Code test method and device, storage medium, electronic equipment
CN110609693A (en) * 2019-08-15 2019-12-24 平安国际智慧城市科技股份有限公司 Code updating method and device based on data standardization and terminal equipment

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112130862A (en) * 2020-09-28 2020-12-25 平安国际智慧城市科技股份有限公司 Package file generation method, device, equipment and computer readable storage medium
CN112130862B (en) * 2020-09-28 2024-04-05 平安国际智慧城市科技股份有限公司 Method, apparatus, device and computer readable storage medium for generating package file
CN112651213A (en) * 2020-12-25 2021-04-13 军工保密资格审查认证中心 Safety examination method and device for numerical control program

Also Published As

Publication number Publication date
CN111258562B (en) 2024-09-13

Similar Documents

Publication Publication Date Title
US10817271B2 (en) Automated dependency analyzer for heterogeneously programmed data processing system
CN110688307B (en) JavaScript code detection method, device, equipment and storage medium
KR101579493B1 (en) Staging control method for source code, Computer program for the same, Recording medium storing computer program for the same
CN110704306A (en) Assertion processing method, device, equipment and storage medium in test
CN110716866A (en) Code quality scanning method and device, computer equipment and storage medium
EP2199905A1 (en) Lifecycle management and consistency checking of object models using application platform tools
CN111258562B (en) Java code quality inspection method, device, equipment and storage medium
US10459698B2 (en) Framework for generating adapters in an integrated development environment
CN106708897B (en) Data warehouse quality guarantee method, device and system
CN113885876A (en) Parameter checking method, device, storage medium and computer system
CN113688134A (en) Visual variable management method, system and equipment based on multidimensional data
CN112948478A (en) Link-based code analysis method and device, electronic equipment and storage medium
US20110023010A1 (en) Reserved component container-based software development method and apparatus
CN116661758A (en) Method, device, electronic equipment and medium for optimizing log framework configuration
CN114338850B (en) Message checking method, device, terminal equipment and computer readable storage medium
CN113419738A (en) Interface document generation method and device and interface management equipment
CN113935847A (en) Online process risk processing method, device, server and medium
CN112632546A (en) Automatic code analysis method for broadcasting and television industry
Xiao et al. Performing high efficiency source code static analysis with intelligent extensions
CN114780952B (en) Detection method, system and storage medium for sensitive application call scene
Heck et al. LaQuSo software product certification model (LSPCM)
Besson et al. SawjaCard: a static analysis tool for certifying Java Card applications
CN111427769A (en) Code quality detection method, equipment, server and readable storage medium
CN118585451A (en) GitLab-based code auditing method, system, equipment and medium
CN118535454A (en) Method for realizing code detection based on Webpack and related equipment thereof

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant