Automatic version control of software components

By adding formal comments and static analysis techniques to the source code, API interface changes are automatically identified, and semantic version naming rules are adopted, which solves the problem of non-standard version number management of software components and achieves efficient and accurate automatic version number control.

CN115480815BActive Publication Date: 2026-02-10NO 709 RES INST OF CHINA SHIPBUILDING IND CORP
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211078545.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-09-05
Publication Date
2026-02-10
Estimated Expiration
2042-09-05

AI Technical Summary

Technical Problem

In existing technologies, software component version number iteration and upgrades rely on a manual judgment mechanism, resulting in somewhat arbitrary naming and a failure to strictly adhere to semantic version number naming rules, leading to non-standard version number management.

Method used

Add formally compliant comment lines to the source code, automatically identify API interface changes through static analysis, and generate version numbers using semantic versioning naming rules. This includes a local working module, a version control system, a monitoring module, a static analysis module, and a version number generation module, thereby achieving automated version control.

Benefits of technology

It enables automated, accurate, and efficient management of software component version numbers, reduces the workload of manual analysis, and improves the automated production capability of software component products.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115480815B_ABST
    Figure CN115480815B_ABST
Patent Text Reader

Abstract

The application provides a version automatic control device and method of a software component, belongs to the technical field of software version management, and the control method is specifically as follows: taking the change of an API interface as the main judgment basis for the version upgrade of the software component, after the component source code is submitted to a version control system, the source code is parsed through program static analysis technology to obtain the change of the API interface, then a new version number is automatically generated based on the change of the API interface by using a semantic version naming rule.The application can automatically, efficiently and compliantly update the version number of the software component, reduces the workload of manual analysis, avoids the impreciseness of manually setting the version number, and restricts and standardizes the upgrade iteration of the component version.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application belongs to the technical field of software version management, and more particularly relates to a version automatic control device and method of a software component. BACKGROUND

[0002] The change of the version number of the software component reflects the change range of the software function, and is usually in a semantic version naming manner, in the form of X.Y.Z (for example, 1.2.3, 9.9.5), wherein X is a major version number, indicating that an incompatible API modification is made; Y is a minor version number, indicating that a downward compatible functional addition is made; and Z is a revision number, indicating that a downward compatible problem correction is made.

[0003] Correct maintenance of the version number is of great significance to the establishment of the dependency relationship between components and the automatic release and deployment. At present, the version number iteration and upgrade in engineering practice usually adopts a manual discrimination mechanism, and the developers or integration personnel read the source code and refer to the submission log to determine the update of the version number, and the naming has a certain randomness and does not strictly comply with the semantic version number naming rules. SUMMARY

[0004] In view of the defects of the prior art, the purpose of the present application is to provide a version automatic control device and method of a software component, aiming at solving the problem that the existing version number iteration and upgrade adopts a manual discrimination mechanism, and the developers or integration personnel read the source code and refer to the submission log to determine the update of the version number, and the naming has a certain randomness and does not strictly comply with the semantic version number naming rules.

[0005] To achieve the above purpose, on one hand, the present application provides a version automatic control device of a software component, comprising a local work module, a version control system, a version control monitoring module, a static analysis module, a version number generation module and a version number registration module.

[0006] The local work module is used for adding an annotation line before the declaration code line of an API interface in the source code; wherein the annotation line complies with a set formal specification, and is used for identifying the API interface; the annotation format of identifying the API interface is distinguished from other formal annotation formats in the source code;

[0007] The version control system is used for receiving the source code and generating a new revision number;

[0008] The version control monitoring module is used for perceiving the revision of the source code by means of the hook mechanism provided by the version control system, and sending the revision condition of the source code to the static analysis module by using an event mechanism;

[0009] The static analysis module is used for checking out corresponding source code files from the version control system based on a new revision number, and obtaining code differences between the current revision and the last revision at the same time; performing semantic analysis and context association based on the source code files and the code differences, identifying functions corresponding to the changed code blocks, and generating a changed function set; using a syntax analysis technique to extract the comment lines before the changed function declaration lines from the source code, judging whether the changed functions are API interfaces based on the annotation specification of the API interfaces, and extracting a changed API interface set from the changed function set;

[0010] The version number generation module is used for upgrading the version number of the software component based on the changed API interface set according to the semantic version naming rule;

[0011] The version number registration module is used for registering the mapping relationship between the revision number and the upgraded version number in the version control system.

[0012] Further preferably, the format of the annotation is@@interface.

[0013] Further preferably, the semantic version naming rule based on the API interface change is that the version naming form is X.Y.Z, the major version number X is incremented when the interface declaration is modified or the interface is deleted, the minor version number Y is incremented when the interface is added, the revision number Z is incremented when the interface implementation is modified, the increment times of X, Y and Z are all not more than once, and the revision number Z is incremented if the API interface is not changed.

[0014] Further preferably, when the software system is compiled and released, the mapped revision number is obtained from the version number registration module based on the specified version number of the software component, and the corresponding source code is checked out from the version control system according to the revision number for compilation.

[0015] In another aspect, the present application provides a version automatic control method of a version automatic control device based on a software component, comprising the following steps:

[0016] S1: adding an annotation line before the declaration code line of the API interface in the source code, wherein the annotation line conforms to a set formal specification and is used for identifying the API interface; the annotation format for identifying the API interface is distinguished from other formal annotation formats in the source code;

[0017] S2: if the source code is changed, then generating a new revision number after the changed source code is submitted to the version control system;

[0018] S3: perceiving the revision of the source code based on the hook mechanism provided by the version control system, and obtaining the corresponding revision number;

[0019] S4: Check out the corresponding source code files from the version control system based on the revision number, and obtain the code differences between the current revision and the last revision at the same time; perform semantic analysis and context association on the source code files and the code differences, identify the functions corresponding to the changed code blocks in the source code, and generate a set of changed functions;

[0020] S5: Extract the comment lines before the declaration line of the changed function from the source code using syntax analysis technology, judge whether the changed function is an API interface based on the comment specification of the API interface in S1, and extract a set of changed API interfaces from the set of changed functions, wherein the set of changed API interfaces is a subset of the set of changed functions;

[0021] S6: Based on the set of changed API interfaces, upgrade the version number of the software component using the semantic version naming rule;

[0022] S7: Register the mapping relationship between the new revision number and the upgraded version number in the version control system.

[0023] Further preferably, the format of the comment is @@interface.

[0024] Further preferably, the semantic version naming rule based on the API interface change is: the version naming form is X.Y.Z, the major version X is incremented when the interface declaration is modified or the interface is deleted, the minor version Y is incremented when the interface is added, and the revision Z is incremented when the interface implementation is modified, the increment times of X, Y and Z are not more than once, and if the API interface is not changed, the revision Z is incremented.

[0025] Further preferably, when the software system is compiled and released, the mapped revision number is obtained from the version number registration module based on the specified version number of the software component, and the corresponding source code is checked out from the version control system based on the revision number for compilation.

[0026] Overall, compared with the prior art, the above technical solutions conceived by the present application have the following beneficial effects:

[0027] The present application adds a comment line conforming to a specific formal specification before the declaration code line of the API interface class or interface class function in the source code, for example, the format of the comment is @@interface, the program is semantically labeled by the formal comment method, which does not interfere with the syntax structure of the source code, and is convenient for various types of analysis tools to perform code review.

[0028] After the component source code is submitted to the version control system, the present application can automatically analyze the source code through static program analysis technology, can accurately and efficiently obtain the change of the interface API, and can reduce the workload of manual analysis.

[0029] The application proposes a semantic version naming rule based on API interface change, the version naming form is X.Y.Z, when the interface declaration is changed or the interface is deleted, the major version X is incremented, when the interface is added, the minor version Y is incremented, when the interface method implementation is changed, the revision Z is incremented, the increment times of X, Y and Z are not more than once, if the API interface is not changed, the revision Z is incremented. The software components are automatically named by the rule, the function and state transition of the software components can be efficiently, automatically and compliantly identified, the impreciseness of manual version generation is avoided, and the end-to-end production capacity of the software component product automation is effectively improved. BRIEF DESCRIPTION OF DRAWINGS

[0030] Figure 1 is a principle schematic diagram of a version automatic control method of a software component provided by an embodiment of the application;

[0031] Figure 2 is a flow schematic diagram of a version automatic control method of a software component provided by an embodiment of the application. DETAILED DESCRIPTION

[0032] In order to make the purpose, technical scheme and advantages of the application clearer, the application is further described in detail below with reference to the drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the application, and are not used to limit the application.

[0033] As shown in Figure 1 and Figure 2 , the application provides a flow schematic diagram of a version automatic control method of a software component, specifically including the following steps:

[0034] S1: When a developer implements an API interface in a source code according to a software interface specification, a formal specification based annotation line is added before an API interface declaration code line, used to identify the interface, the format of the annotation specification includes but is not limited to @ @ interface, the annotation specification of the API interface is distinguished from other formal annotation specifications in the code; wherein, the API interface is also called a public interface, which refers to the function or service provided by a software component to other components or external systems based on SOAP, RESTFul, RPC and the like, and the internal implementation form is a function;

[0035] S2: After the developer implements a function baseline, the source code in the local workspace is submitted to a version control system, and the version control system automatically generates a new revision number;

[0036] S3: A version control listening module perceives that the source code is revised based on the hook mechanism provided by the version control system, and an event mechanism is used to send the source code revision to a static analysis module;

[0037] S4: The static analysis module checks out the corresponding source code files from the version control system based on the new revision number, and obtains the code differences between the current revision and the last revision at the same time; wherein the code differences are represented as a set of changed code blocks, and the changed code block is represented in the form of a six-tuple (file name, last revision start line number, last revision consecutive line number, current revision start line number, current revision consecutive line number, change type), and the value domain of the element "change type" is {add, delete, modify}; wherein when the change type is add, the last revision start line number and the last revision consecutive line number are both empty, and when the change type is delete, the current revision start line number and the current revision consecutive line number are both empty;

[0038] S5: The static analysis module performs semantic analysis and context association based on the source code files and the code differences, identifies the functions corresponding to the changed code blocks, and generates a set of changed functions; for the changed functions, the syntax analysis technique is used to extract the comment lines before the changed function declaration line from the source code files, the changed functions are judged to be API interfaces based on the comment specification of the API interfaces in S1, and a subset of changed API interfaces is extracted from the set of changed functions; wherein the changed function is represented in the form of a three-tuple (file name, function name, change type), and the value domain of the element "change type" is {add, delete, modify declaration, modify implementation}; the changed API interface is represented in the form of a three-tuple (file name, API interface name, change type), and the value domain of the element "change type" is {add, delete, modify declaration, modify implementation};

[0039] S6: The version number generation module upgrades the version number of the software component based on the set of changed API interfaces using the semantic version naming rule; more specifically, the set of changed API interfaces is traversed, the major version number X is incremented when the change type is delete or modify declaration, the minor version number Y is incremented when the change type is add, and the revision number Z is incremented when the change type is modify implementation, and the increment times of X, Y and Z are all not more than once; if the set of changed API interfaces is empty, the revision number Z is incremented;

[0040] S7: The version number registration module registers the mapping relationship between the new revision number and the upgraded version number in the version control system, and provides a query service for the mapping relationship;

[0041] S8: The release version of the software system is mapped to the specific version of each software component based on the functional requirements, and when the software system is compiled and released, the mapped revision number is obtained from the version number registration module based on the specified software component version number, and the corresponding source code is checked out from the version control system for compilation according to the revision number.

[0042] Embodiment

[0043] As Figure 2As shown, the software component CompA has 3 functions, 2 of which are marked as API interfaces, and the current version number is 1.0.0. Three code modifications have been made, resulting in the following set of modified code blocks: {(file1,23,1,23,1,modified),(file1,81,1,81,1modified),(file1,156,1,156,1,modified)}. Static analysis reveals the modified function set to be {(file1,func1,modified declaration),(file1,func2,modified implementation),(file1,func3,modified implementation)}. Based on the API interface identifiers, the modified API interface set is extracted as {(file1,func1,modified declaration),(file1,func2,modified implementation)}. Following semantic versioning rules, the major version number X increments when modifying the declaration, and the revision number Z increments when modifying the implementation. The upgraded version number is 2.0.1.

[0044] In summary, compared with the prior art, the present invention has the following advantages:

[0045] This invention adds comment lines conforming to specific formal specifications before the API interface declaration lines in the source code, such as the comment format @@interface. This formal commenting method semantically marks the program without interfering with the syntax structure of the source code, and facilitates code review by various analysis tools.

[0046] This invention automatically analyzes the source code using static program analysis technology after the component source code is submitted to the version control system. This allows for a complete, accurate, and efficient understanding of changes in the interface API, reducing the workload of manual analysis.

[0047] This invention proposes a semantic versioning naming rule based on API interface changes. The versioning format is XYZ. When an interface declaration is changed or an interface is deleted, the major version number X increments; when an interface is added, the minor version number Y increments; and when an interface method implementation is changed, the revision number Z increments. The increments of X, Y, and Z are no more than once. If the API interface remains unchanged, the revision number Z increments. By automating semantic versioning of software components using this rule, the functional and state transitions of software components can be efficiently, automatically, and compliantly identified. This avoids the inaccuracies of manually generated versions and effectively improves the automated end-to-end production capabilities of software component products.

[0048] Those skilled in the art will readily understand that the above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.

Claims

1. A software component version automatic control device, characterized in that, include: Local working module, version control system, version control monitoring module, static analysis module, version number generation module, and version number registration module; The local working module is used to add comment lines before the declaration lines of API interfaces in the source code; the comment lines conform to the defined formal specifications and are used to identify the API interface; the comment format that identifies the API interface is distinguished from other formal comment formats in the source code; Version control systems are used to receive source code and generate new revision numbers; The version control monitoring module is used to detect source code revisions by means of the hook mechanism provided by the version control system, and sends the source code revision information to the static analysis module through an event mechanism. The static analysis module is used to retrieve the corresponding source code file from the version control system based on the new revision number, and simultaneously obtain the code differences between the current revision and the previous revision; based on the source code file and code differences, it performs semantic analysis and context association to identify the functions corresponding to the changed code blocks and generate a set of changed functions; using syntax analysis technology, it extracts the comment lines before the declaration lines of the changed functions from the source code, determines whether the changed functions are API interfaces based on the API interface comment specifications, and extracts the set of changed API interfaces from the set of changed functions; The version number generation module is used to upgrade the version number of software components based on semantic version naming rules and the set of changed API interfaces; The version number registration module is used to register the mapping relationship between revision numbers and upgraded version numbers in the version control system.

2. The version automatic control device according to claim 1, characterized in that, The annotation format is @@interface.

3. The version automatic control device according to claim 1 or 2, characterized in that, The semantic versioning naming rule based on API interface changes is as follows: the version naming format is XYZ. When an interface declaration is modified or an interface is deleted, the major version number X increments. When an interface is added, the minor version number Y increments. When an interface implementation is modified, the revision number Z increments. The increment count of X, Y, and Z is no more than once. If the API interface has not changed, the revision number Z increments.

4. The automatic control device according to claim 1 or 2, characterized in that, When compiling and releasing a software system, the version number is obtained from the version number registration module based on the version number of the specified software component, and the corresponding source code is retrieved from the version control system for compilation based on the revision number.

5. A method for automatic version control of a software component, characterized in that, Includes the following steps: S1: Add a comment line before the declaration line of the API interface in the source code. The comment line conforms to the set formal specifications and is used to identify the API interface. The comment format that identifies the API interface is different from other formal comments in the source code. S2: If the source code is changed, the changed source code will be submitted to the version control system to generate a new revision number; S3: Based on the hook mechanism provided by the version control system, it detects the revisions made to the source code and obtains the corresponding revision number; S4: Based on the revision number, retrieve the corresponding source code file from the version control system and simultaneously obtain the code differences between the current revision and the previous revision; perform semantic analysis and context association on the source code file and code differences to identify the functions corresponding to the changed code blocks in the source code and generate a set of changed functions; S5: Using syntax analysis technology, extract the comment lines before the declaration lines of the modified functions from the source code, determine whether the modified function is an API interface based on the comment specifications of the API interface in S1, and extract the set of modified API interfaces from the set of modified functions. The set of modified API interfaces is a subset of the set of modified functions. S6: Based on the change of API interface set, the version number of software components is upgraded using semantic version naming rules; S7: Register the mapping relationship between the new revision number and the upgraded version number in the version control system.

6. The version automatic control method according to claim 5, characterized in that, The annotation format is @@interface.

7. The version automatic control method according to claim 5 or 6, characterized in that, The semantic versioning naming rule based on API interface changes is as follows: the version naming format is XYZ. When an interface declaration is modified or an interface is deleted, the major version number X increments. When an interface is added, the minor version number Y increments. When an interface implementation is modified, the revision number Z increments. The increment count of X, Y, and Z is no more than once. If the API interface has not changed, the revision number Z increments.

8. The version automatic control method according to claim 5 or 6, characterized in that, When compiling and releasing a software system, the version number is obtained from the version number registration module based on the version number of the specified software component, and the corresponding source code is retrieved from the version control system for compilation based on the revision number.

Citation Information

Patent Citations

  • Software version number automatic generation method

    CN107766074A

  • Processing method and device for code update, storage medium, processor and servers

    CN107894895A