Source code migration adaptation method and device oriented to localized environment
By constructing a data dictionary and optimizing the source code using a large code language model, the complexity of the source code adaptation problem of the Xinchuang project in the localized environment has been solved, the migration efficiency and quality have been improved, and the high performance and reliability of the business system have been ensured. sex.
Patent Information
- Application Number
- CN202410699857.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-31
- Publication Date
- 2024-08-27
- Estimated Expiration
- 2044-05-31
AI Technical Summary
When the Xinchuang project is migrated to a localized environment, the source code and SQL statements need to be adapted and transformed. Existing technologies cannot effectively solve the problems of strong dependencies on operating systems, databases, etc., resulting in complex migration and low efficiency.
Design a source code migration and adaptation method for localized environments. Compatibility judgment is made by building a data dictionary, using a scanner to evaluate evaluation indicators, inputting code blocks into the large code language model for optimization, and providing migration and transformation suggestions and rewritten code. Code, ensuring source code compatibility with operating systems, databases, middleware and third-party software.
It improves the quality and efficiency of localized adaptation and transformation of Xinchuang applications and ensures high-performance and high-reliability operation of business systems during the migration process.
Smart Images

Figure CN118550583A
Abstract
Description
Technical Field
[0001] The invention relates to a source code migration adaptation method and device for a localized environment, belonging to the field of code adaptation. Background Art
[0002] Trusted innovation projects are generally difficult, time-consuming, and technically complex. They require a comprehensive consideration of the complexity of the enterprise's technical architecture, application architecture, and business systems, ensuring high-performance and reliable business operations while ensuring rapid trusted innovation migration. This requires related migration adaptation services to provide full-stack trusted innovation products, full-ecological adaptation capabilities, and systematic service support capabilities to ensure the smooth migration of trusted innovation applications. Trusted innovation project source code is highly dependent on the operating system and database, and the code and SQL statements need to be adapted and modified before migrating to the localized environment.
[0003] The patent "A method, device, equipment and medium for multi-type database compatibility of an ORM framework" with publication number CN114925142A discloses: in the ORM framework, SQL statements supported by multiple types of databases are obtained, and personalized SQL statements that are different from other databases are marked in each type of database; based on the SQL statements supported by the multiple types of databases and the personalized SQL statements, a SQL statement conversion tool for converting SQL statements between the multiple types of databases is created; based on the database type built into the ORM framework, the SQL statement type output by the SQL statement conversion tool is set; based on the SQL statement type, corresponding application functions are developed, and the application functions are applied to the ORM framework to achieve compatibility of the ORM framework with SQL statements of multiple types of databases. Summary of the invention
[0004] In order to overcome the problems existing in the prior art, the present invention designs a source code migration adaptation method and device for a localized environment.
[0005] In order to achieve the above object, the present invention adopts the following technical solution:
[0006] Technical Solution 1
[0007] A source code migration and adaptation method for a localized environment includes the following steps:
[0008] Construct a data dictionary, which contains a list of files with compatibility risks in different environments and contains scanning rules, evaluation indicators, and adaptation and transformation suggestions corresponding to each file;
[0009] The scanner makes compatibility judgments on each file based on the data dictionary, calculates the evaluation index value based on the judgment results, and outputs the value of each evaluation index and the location of the code block with compatibility risks;
[0010] Set the weight of each evaluation index, perform weighted summation on the evaluation index values, and obtain the adaptation evaluation value of the target source code;
[0011] Input code blocks with compatibility risks, code type labels, and code rewriting prompts into the code large language model to optimize the code block structure and format; replace the code block with the output result of the code large language model.
[0012] Furthermore, the evaluation indicators include: SO package dependency compatibility, Jar dependency compatibility, executable file dependency compatibility, database compatibility, syntax compatibility, reserved word dependency compatibility, middleware compatibility, whether the integration method meets the requirements, whether the middleware is compliant, whether the open source software is compliant, whether the third-party component is compliant, and whether the software developer is on the preset list.
[0013] Furthermore, the data dictionary includes an operating system data dictionary, a database data dictionary, a middleware data dictionary, and a third-party software data dictionary.
[0014] Furthermore, the operating system data dictionary has the following fields: dependency package name, dependency package type, dependency package version, CPU architecture, operating system, binding evaluation index, adaptation risk, code reference scanning rule, file scanning rule, POM file scanning rule, and adaptation transformation suggestion.
[0015] Furthermore, the database data dictionary has the following fields: database type, whether it is open source, whether it is commercial, whether it is localized, package reference scanning rules, driver scanning rules, database link scanning rules, and dependency tree scanning rules.
[0016] Furthermore, the middleware data dictionary is provided with the following fields: middleware type, package reference scanning rule, configuration file scanning rule, dependency tree scanning rule, and POM file scanning rule.
[0017] Furthermore, the scanning rules include a number of regular expressions; the scanner performs compatibility judgment and compliance judgment according to the regular expressions to obtain the value of the evaluation index.
[0018] Technical Solution 2
[0019] A source code migration adaptation device for a localized environment, comprising a storage medium, a processor, and a computer program stored on the storage medium and executable on the processor, characterized in that the processor implements the steps described in technical solution one when executing the program.
[0020] Compared with the prior art, the present invention has the following characteristics and beneficial effects:
[0021] The present invention scans and analyzes the source code from four dimensions: operating system adaptation, database adaptation, middleware adaptation, and third-party software, evaluates whether there is a migration risk in the trusted innovation application, gives corresponding migration transformation suggestions and rewritten code, and improves the quality and efficiency of the localization adaptation and transformation of the business system. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] Figure 1-2 It is a flow chart of the present invention;
[0023] Figure 3 It is a schematic diagram of the adaptation evaluation system. DETAILED DESCRIPTION
[0024] The present invention is described in more detail below with reference to the embodiments.
[0025] like Figure 1 As shown, a method for migrating and transforming source code for a localized environment includes the following steps:
[0026] Combined with the requirements for the adaptation and migration evaluation of trusted innovation applications in the localized environment, a trusted innovation application adaptation evaluation system is constructed from four dimensions: operating system adaptation, database adaptation, middleware adaptation, and third-party software adaptation. For example, the first dimension evaluation indicators include SO package dependency compatibility, Jar dependency compatibility, executable file dependency compatibility, etc.; the second dimension evaluation indicators include database compatibility, syntax compatibility, reserved word dependency compatibility, etc.; the third dimension evaluation indicators include middleware compatibility, whether the integration method meets the requirements, whether the middleware is compliant, etc.; the fourth dimension evaluation indicators include whether the open source software is compliant, whether the third-party components are compliant, whether the software developer is on the preset list, etc.
[0027] The user selects the scanner, data dictionary, evaluation indicators, and sets the evaluation indicator weights and other data items through the graphical interface. The data dictionary contains a list of files (such as SO files, dependent packages, open source software) that have compatibility issues in different hardware and software environments (such as different chip + operating system combinations) as well as the file attributes, adaptation risks, corresponding scanning rules, bound evaluation indicators, and adaptation modification suggestions of each file. The scanner performs dependency analysis, compatibility judgment, and compliance assessment of related dependent software on the target trusted innovation application source code (including dynamic libraries, static library files, dependent software packages, executable files, Jar packages, database scripts, etc.) based on the data dictionary, and outputs the values of each evaluation indicator and the location of the code block with compatibility risks.
[0028] Set the weight of each evaluation indicator, take the weighted sum of all evaluation indicator values, and obtain the trusted computing application adaptation evaluation value.
[0029] Input code blocks, code type labels and code rewriting tips to the CodeGeeX2-6B code language model to optimize the code block structure and format; replace the code block with the output result of the code language model.
[0030] In one implementation, the data dictionary is divided into an operating system data dictionary, a database data dictionary, a middleware data dictionary, and a third-party software data dictionary.
[0031] The operating system data dictionary is used to detect whether the source code depends on the characteristics of operating systems such as Windows and Linux, and give suggestions for adaptation and transformation. It mainly targets SO software packages, JAR dependency packages and executable files. The operating system data dictionary construction process is as follows:
[0032] (1) Collect the characteristics and compatibility requirements of operating systems in different heterogeneous environments; (2) Classify and organize the characteristics and compatibility requirements and write them into the operating system data dictionary, and provide adaptation and migration solutions for different heterogeneous environments to provide a basis for subsequent testing and evaluation; (3) Regularly update the characteristics and compatibility requirements to ensure the accuracy and timeliness of the evaluation.
[0033] The scanner identifies and counts the code segments that meet the rules according to the rule fields recorded in the operating system data dictionary, and gives corresponding adaptation and modification suggestions. This dictionary category scans the corresponding operating system adaptation issues in the source code, and a dictionary record is an adaptation scanning solution field for a dependent package. The data dictionary contains the following fields:
[0034] Dependency package name: Scan the corresponding dependency package name
[0035] Dependency package type: The type corresponding to the dependency package result, including three categories: SO file, JAR file, and executable file
[0036] Dependency package version: The dependency package version corresponding to the result, used for statistics
[0037] CPU architecture: The running CPU version corresponding to the result, statistical field
[0038] Operating system: The running operating system corresponding to the result, a field for statistics
[0039] Binding evaluation indicators: This dictionary item is bidirectionally bound to the corresponding data item in indicator management. The optional items are changed according to the data items of the operating system indicators in indicator management.
[0040] Adaptation risk: This result has / has no corresponding adaptation risk
[0041] Code reference scanning rule: Scan the code segment in the source code to see if it matches the regular rule. If it does, it is considered that the problem corresponding to the dictionary item has been scanned.
[0042] File scanning rule: Check whether the file name in the source code matches the regular expression. If it does, the file has a problem with the corresponding dictionary item.
[0043] POM file scanning rules: Scan the POM file, and if there is a matching dependency, record it as the source code referencing the dependency of the corresponding problem
[0044] Adaptation and transformation suggestions: When the scan results are generated, annotate the corresponding scan records and give the corresponding transformation suggestions for the problem
[0045] Examples are shown in the following table:
[0046]
[0047] The database data dictionary construction process is as follows:
[0048] (1) Collect SQL specifications and requirements of different databases from the aspects of syntax compatibility, reserved word compatibility, function compatibility, and other database object compatibility checks; (2) Classify and organize SQL specifications and requirements and write them into the database data dictionary, sort out the conversion differences and precautions between different databases, and provide recommendations for adaptation conversion to facilitate subsequent testing and evaluation; (3) Update SQL specifications and requirements regularly to ensure the accuracy and timeliness of evaluation.
[0049] The scanner uses the database data dictionary to identify and count the databases of methods used or referenced in the source code project to determine whether the project has problems in the database localization adaptation process. The data dictionary contains the following fields:
[0050] Database type: divided into three options: relational database, non-relational database, key-value database, and statistical fields
[0051] Open Source: Whether the database is an open source database, statistical field
[0052] Commercial: Whether the database is a commercial database, statistical fields
[0053] Whether it is localized: whether the database supports localization adaptation, statistical fields
[0054] Package reference scanning rules: Scan the source code segment to detect whether there is a reference code that matches the regular expression of the field. If so, it is considered that the corresponding problem of the dictionary item has been scanned once.
[0055] Driver scanning rules: Perform driver reference scanning on each file in the source code, including code files and configuration files. If there is a code segment or configuration item that matches the regular expression, it is considered that the corresponding problem of the dictionary item has been scanned once.
[0056] Database link scanning rules: Perform database link scanning on each file in the source code, including code files and configuration files. If there is a code segment or configuration item that matches the regular expression, it is considered that the corresponding problem of the dictionary item has been scanned once.
[0057] Dependency tree scanning rules: Scan the POM file or the maven-tree file generated by the maven command line. If there is a matching dependency, it is recorded as a dependency of the corresponding dictionary item referenced by the source code
[0058] Examples are shown in the following table:
[0059]
[0060]
[0061] The middleware data dictionary and third-party software data dictionary are used to detect the source of the component library in the source code and whether there are substitutes. The middleware data dictionary construction process is as follows:
[0062] (1) Sort out the characteristics and compatibility requirements of the middleware, component libraries, and third-party software commonly used in the information and innovation application system in different heterogeneous environments; (2) Classify and organize the software and components and write them into the database data dictionary, sort out the alternative deployment solutions, performance optimization solutions, and migration adaptation solutions for localization in different heterogeneous localization environments, and provide a basis for subsequent testing and evaluation; (3) Regularly update the compatibility and adaptation information of related software and components to ensure the accuracy and timeliness of the evaluation.
[0063] The scanner uses the middleware data dictionary to scan and count the third-party software used or referenced in the source code. The middleware data dictionary contains the following fields:
[0064] Middleware type: includes five categories: application middleware, cache middleware, message middleware, integration middleware, and Web middleware, and statistical fields.
[0065] Package reference scanning rules: Scan the source code segment to detect whether there is a reference code that matches the regular expression of the field. If so, it is considered that the corresponding problem of the dictionary item has been scanned once.
[0066] Configuration file scanning rule: Parse and scan the source code configuration file (including properties files or yml files). If there is a configuration item matching the rule in the code configuration file, it is considered that the dictionary item problem is scanned once.
[0067] Dependency tree scanning rules: Scan the maven-tree file generated by the maven command line. If there is a matching dependency, it is recorded as a dependency of the corresponding dictionary item referenced by the source code.
[0068] POM file scanning rules: Scan the source code POM file. If a matching POM reference is found, it is recorded as a dependency of the source code that references the corresponding dictionary item.
[0069] Here is an example:
[0070]
[0071] In one implementation, after starting the scan, a thread is created for each type of scanner to perform the code scanning process in parallel. The following middleware scanning is taken as an example:
[0072] Step 1: Read the indicators corresponding to the middleware scan from the evaluation indicator library
[0073] Step 2: Read the middleware scanning dictionary items from the dictionary library (i.e., the middleware scanning detection points. For example, redis middleware dependency detection will judge the package references, configuration files, dependency trees, pom import configuration and other detection points. Different types of middleware correspond to different scanning detection indicator information). Process the dictionary items, generate a scanning result statistics class set, and bind the corresponding evaluation indicator items to each dictionary item.
[0074] Step 3: Use grouping regular expressions to process each scan field into the final scan field expression; start traversing the source code files and use the corresponding scan field regular expressions for different file types; whenever a problem is scanned, identify which dictionary item the scanned problem belongs to based on the grouping regular expression, and add statistical data to the scan result of the dictionary item based on the generated scan result statistics class parameters. For example, if the configuration item corresponding to the Redis middleware is scanned in the yml scanning process of the middleware scanning, then read the parameters such as whether it is localized and whether it is open source in the dictionary item, add the corresponding statistical count to the statistical result set that will be returned later, and record the code file path corresponding to the scan result, the number of lines in the file, and other information, and summarize them in the scan result statistics class object; after traversing all files, if the scanner supports maven-tree dependency tree scanning, then scan and count the dependency tree file generated in advance.
[0075] Step 4: After completing the above steps, the middleware scanning results of the source code are obtained, and the statistical results are processed and summarized into the overall statistical results of the source code. For the code that needs to be compatible, source code rewriting and conversion recommendations are made according to the source code compatibility adaptation rules. At the same time, according to the previously bound evaluation indicators, the indicator statistics results are generated.
[0076] Wait for all scanners to complete their work, obtain the final scanning result statistics, and generate a trusted computing application adaptation evaluation report.
[0077] It should be noted that the above-mentioned source code migration and transformation device for the localized environment is also used to achieve the above-mentioned Figure 1 The method steps corresponding to each embodiment of the source code migration and transformation method for a localized environment shown are not repeated in this application.
[0078] It should be noted that each functional unit / module in each embodiment of the present invention may be integrated into one processing unit / module, or each unit / module may exist physically separately, or two or more units / modules may be integrated into one unit / module. The above-mentioned integrated unit / module may be implemented in the form of hardware or in the form of software functional unit / module.
[0079] Through the description of the above implementation mode, it can be clearly understood by those skilled in the art that the embodiments described herein can be implemented in hardware, software, firmware, middleware, code or any appropriate combination thereof. For hardware implementation, the processor can be implemented in one or more of the following units: application specific integrated circuit (ASIC), digital signal processor (DSP), digital signal processing device (DSPD), programmable logic device (PLD), field programmable gate array (FPGA), processor, controller, microcontroller, microprocessor, other electronic units designed to implement the functions described herein or their combination. For software implementation, part or all of the process of the embodiment can be completed by instructing the relevant hardware through a computer program. When implemented, the above program can be stored in a computer-readable medium or transmitted as one or more instructions or codes on a computer-readable medium. Computer-readable media include computer storage media and communication media, wherein the communication medium includes any medium that facilitates the transmission of a computer program from one place to another. The storage medium can be any available medium that can be accessed by a computer. Computer-readable media can include, but are not limited to, RAM, ROM, EEPROM, CD-ROM or other optical disk storage, disk storage media or other magnetic storage devices, or any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer.
[0080] Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present invention, rather than to limit the scope of protection of the present invention. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should analyze that the technical solution of the present invention can be modified or replaced by equivalents without departing from the essence and scope of the technical solution of the present invention.
Claims
1. A source code migration and adaptation method for a localized environment, characterized in that: The following steps are involved: Construct a data dictionary, which contains a list of files with compatibility risks in different environments and contains scanning rules, evaluation indicators, and adaptation and transformation suggestions corresponding to each file; The scanner makes compatibility judgments on each file based on the data dictionary, calculates the evaluation index value based on the judgment results, and outputs the value of each evaluation index and the location of the code block with compatibility risks; Set the weight of each evaluation index, perform weighted summation on the evaluation index values, and obtain the adaptation evaluation value of the target source code; Input code blocks with compatibility risks, code type labels, and code rewriting prompts into the code language model to optimize the structure and format of the code blocks; Replace the code block with the code large language model output.
2. According to the method for source code migration and adaptation for a localized environment according to claim 1, it is characterized in that: The evaluation indicators include: SO package dependency compatibility, Jar dependency compatibility, executable file dependency compatibility, database compatibility, syntax compatibility, reserved word dependency compatibility, middleware compatibility, whether the integration method meets the requirements, whether the middleware is compliant, whether the open source software is compliant, whether the third-party component is compliant, and whether the software developer is on the preset list.
3. According to the method for source code migration and adaptation for a localized environment as described in claim 1, it is characterized in that: The data dictionary includes an operating system data dictionary, a database data dictionary, a middleware data dictionary, and a third-party software data dictionary.
4. According to the method for source code migration and adaptation for a localized environment as described in claim 1, it is characterized in that: The operating system data dictionary has the following fields: dependency package name, dependency package type, dependency package version, CPU architecture, operating system, binding evaluation index, adaptation risk, code reference scanning rule, file scanning rule, POM file scanning rule, and adaptation transformation suggestion.
5. According to the method of claim 1, the source code migration and adaptation method for a localized environment is characterized in that: The database data dictionary has the following fields: database type, whether it is open source, whether it is commercial, whether it is localized, package reference scanning rules, driver scanning rules, database link scanning rules, and dependency tree scanning rules.
6. The method for source code migration and adaptation for a localized environment according to claim 1, characterized in that: The middleware data dictionary has the following fields: middleware type, package reference scanning rule, configuration file scanning rule, dependency tree scanning rule, and POM file scanning rule.
7. The source code migration and adaptation method for a localized environment according to claim 1, characterized in that: The scanning rules include a number of regular expressions; the scanner performs compatibility judgment and compliance judgment according to the regular expressions to obtain the value of the evaluation index.
8. A source code migration and transformation device for a localized environment, comprising a storage medium, a processor, and a computer program stored on the storage medium and executable on the processor, characterized in that: When the processor executes the program, the following steps are implemented: Construct a data dictionary, which contains a list of files with compatibility risks in different environments and contains scanning rules, evaluation indicators, and adaptation and transformation suggestions corresponding to each file; The scanner makes compatibility judgments on each file based on the data dictionary, calculates the evaluation index value based on the judgment results, and outputs the value of each evaluation index and the location of the code block with compatibility risks; Set the weight of each evaluation index, perform weighted summation on the evaluation index values, and obtain the adaptation evaluation value of the target source code; Input code blocks with compatibility risks, code type labels, and code rewriting prompts into the code language model to optimize the structure and format of the code blocks; Replace the code block with the code large language model output.
9. The source code migration adaptation device for a localized environment according to claim 8, characterized in that: The evaluation indicators include: SO package dependency compatibility, Jar dependency compatibility, executable file dependency compatibility, database compatibility, syntax compatibility, reserved word dependency compatibility, middleware compatibility, whether the integration method meets the requirements, whether the middleware is compliant, whether the open source software is compliant, whether the third-party component is compliant, and whether the software developer is on the preset list.
10. The source code migration adaptation device for a localized environment according to claim 8, characterized in that: The data dictionary includes an operating system data dictionary, a database data dictionary, a middleware data dictionary, and a third-party software data dictionary.
Citation Information
Patent Citations
Software package construction method and device
CN115639986A
AI inference task scheduling method and system oriented to multiple heterogeneous environments
CN115756833A
Cloud method and system for credential creation adaptation, storage medium and electronic equipment
CN115827604A
Database migration method and system
CN115934682A
Source code credential migration system and method
CN116450213A
Cited By
Data migration method and device based on multi-dimensional evaluation system
CN119127299A
Database adaptation method based on large language model
CN120295997A
RISC-V-oriented software source code transplantation and deployment method and system
CN120723300A
Domestic application publishing method and system based on quantum weighting dynamic grading
CN121145204A
A method and system for publishing a domestic application based on quantum weighting dynamic grading
CN121145204B
