A public code library management method, system, device and medium
By integrating technologies such as AI code generation and automated analysis and optimization, the problem that traditional public code library management methods are difficult to adapt to the software development needs of rapid iteration is solved, and efficient and high-quality management of public code library is achieved, and development efficiency and code quality are improved.
Patent Information
- Application Number
- CN202410971851.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-19
- Publication Date
- 2025-03-14
- Estimated Expiration
- 2044-07-19
AI Technical Summary
Traditional public code base management methods are difficult to adapt to the software development needs of rapid iteration, and there are problems such as uneven code quality, difficulty in sharing knowledge, and incomplete management.
Through the integration of AI code generation, automated analysis and optimization, document generation, sample generation, continuous integration and deployment, efficient and high-quality management of public code bases can be achieved. The specific steps include obtaining development requirements information to generate initial code templates, structuring analysis and optimization through abstract syntax trees, creating a public code base and generating documents and examples, building configuration files and project running environments, and configuring an automated construction process.
It realizes efficient and high-quality management of the public code base, reduces the manual coding work of developers, improves development efficiency, code readability and maintainability, ensures the consistency and stability of the code in different environments, and improves project management efficiency through automated construction processes.
Smart Images

Figure CN118897668B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of public code libraries, and in particular to a public code library management method, system, device and medium. Background Art
[0002] As the complexity of software development continues to increase, developers face problems such as repeated code writing, uneven code quality, and difficulty in knowledge sharing in their daily work. In order to improve development efficiency, ensure code quality, and promote knowledge sharing among teams, public code library management methods are particularly important. However, traditional public code library management often relies on manual writing, review, and maintenance. This process is not only time-consuming and labor-intensive, but also prone to human errors and difficult to adapt to the needs of fast-iteration software development.
[0003] In order to overcome the above shortcomings, AI-based code generation tools have emerged in recent years, such as Copilot launched by GitHub. Copilot uses machine learning technology to automatically generate code snippets based on developer input and contextual information, greatly improving the efficiency of code writing. However, Copilot itself does not directly support the creation of public code repositories or allowing others to call generated code. At the same time, although the code snippets generated by Copilot are convenient, they still have some limitations when directly applied to public code repositories. For example, the generated code snippets need to be further optimized and adjusted according to specific business scenarios to adapt to the standards and specifications of public code repositories. In addition, with the expansion of project scale and the complexity of team structure, the management of public code repositories is not only limited to code writing and storage, but also involves multiple aspects such as code version control, dependency management, build deployment, and security compliance. Traditional public code repository management methods often find it difficult to fully cover these aspects, resulting in inefficient project management and increased risks. Summary of the invention
[0004] The purpose of the present invention is to provide a public code library management method, system, device and medium, which realizes efficient and high-quality management of the public code library by integrating multiple links such as AI code generation, automated analysis and optimization, document generation, example generation, continuous integration and deployment, so as to solve at least one of the above-mentioned prior art problems.
[0005] In a first aspect, the present invention provides a method for managing a public code library, the method specifically comprising:
[0006] Acquire development requirement information, and generate an initial code template based on the development requirement information according to a code generation model;
[0007] By constructing an abstract syntax tree, performing structural analysis on the initial code template to obtain a code analysis result, and optimizing the initial code template according to the code analysis result to obtain a first code template;
[0008] Creating a common code library, inputting the first code template into the common code library, and performing document generation and example generation on the first code template in the common code library;
[0009] Build configuration files and project operating environment according to the directory structure and external dependencies of the public code library, and configure the automated build process through continuous integration tools.
[0010] In a second aspect, the present invention provides a public code library management system, the system specifically comprising:
[0011] A first management module is used to obtain development requirement information and generate an initial code template based on the development requirement information according to a code generation model;
[0012] A second management module is used to perform structural analysis on the initial code template by constructing an abstract syntax tree to obtain a code analysis result, and optimize the initial code template according to the code analysis result to obtain a first code template;
[0013] A third management module is used to create a common code library, input the first code template into the common code library, and perform document generation and example generation on the first code template in the common code library;
[0014] The fourth management module is used to build configuration files and project operating environment according to the directory structure and external dependencies of the public code library, and configure the automated building process through continuous integration tools.
[0015] In a third aspect, the present invention provides a computer device, comprising: a memory and a processor and a computer program stored in the memory, and when the computer program is executed on the processor, a common code library management method as described in any one of the above methods is implemented.
[0016] In a fourth aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the common code library management method as described in any one of the above methods is implemented.
[0017] Compared with the prior art, the present invention has at least one of the following technical effects:
[0018] 1. By integrating AI code generation, automated analysis and optimization, document generation, example generation, continuous integration and deployment, etc., efficient and high-quality management of the public code base is achieved.
[0019] 2. The code generation model automatically generates initial code templates based on development requirement information, greatly reducing the manual coding work of developers and improving development efficiency.
[0020] 3. Automatically generate detailed documentation and usage examples for the first code template in the public code library, so that other developers can easily understand the function, input parameters, output results and usage methods of the code, enhancing the readability and maintainability of the code.
[0021] 4. Through the configuration of automated build processes, configuration files and project operating environments are built according to the directory structure and external dependencies of the public code base to ensure the consistency and stability of the code in different environments and reduce errors and conflicts caused by environmental differences.
[0022] 5. Use the abstract syntax tree (AST) to perform structured analysis on the initial code template, which can accurately identify and fix syntax errors, while optimizing the code logic structure and data flow to ensure code quality.
[0023] 6. Through data mining and collaborative filtering recommendation algorithms, personalized code template recommendations are provided to users, further reducing learning costs and improving code reuse rates.
[0024] 7. Build tasks are automatically executed through continuous integration tools, and the directed acyclic graph scheduling algorithm is used to optimize the task execution order, which improves build efficiency and reliability and ensures rapid iteration and continuous delivery of the project. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0026] Figure 1 It is a flowchart of a public code library management method provided by an embodiment of the present invention;
[0027] Figure 2 It is a structural diagram of a public code library management system provided by an embodiment of the present invention;
[0028] Figure 3 It is a structural schematic diagram of a computer device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0029] In the following description, specific details such as specific system structures, technologies, etc. are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application may also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present application.
[0030] It should be understood that when used in the present specification and the appended claims, the term "comprising" indicates the presence of described features, wholes, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or combinations thereof.
[0031] It should also be understood that the term “and / or” used in the specification and appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes these combinations.
[0032] As used in the specification and appended claims of this application, the term "if" can be interpreted as "when" or "uponce" or "in response to determining" or "in response to detecting", depending on the context. Similarly, the phrase "if it is determined" or "if [described condition or event] is detected" can be interpreted as meaning "uponce it is determined" or "in response to determining" or "uponce [described condition or event] is detected" or "in response to detecting [described condition or event]", depending on the context.
[0033] In addition, in the description of the present application specification and the appended claims, the terms "first", "second", "third", etc. are only used to distinguish the descriptions and cannot be understood as indicating or implying relative importance.
[0034] References to "one embodiment" or "some embodiments" etc. described in the specification of this application mean that one or more embodiments of the present application include specific features, structures or characteristics described in conjunction with the embodiment. Therefore, the statements "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. that appear in different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways.
[0035] In the embodiment of the present application, the execution subject of the process includes a terminal device, which includes but is not limited to: a server, a computer, a smart phone, a tablet computer, and other devices capable of executing the method disclosed in the present application. Figure 1 A schematic diagram of a process flow of a public code library management method disclosed in an embodiment of the present invention is shown, and the details are as follows:
[0036] S101, acquiring development requirement information, and generating an initial code template through the development requirement information according to a code generation model.
[0037] In this embodiment, development requirement information is obtained, including functional requirements, performance requirements, interface requirements and other contents. Based on the acquired development requirement information, the word vector model and long short-term memory network model in natural language processing technology are used to perform semantic understanding and key information extraction on the development requirement information, and obtain structured information such as key functional points, interface information, and performance indicators. Through the constructed code knowledge graph, the extracted structured development requirement information is matched with the code knowledge graph to find the code snippets and templates related to the requirement information. Based on the code snippets and templates obtained by matching the code knowledge graph, the rule-based code generation technology is used to automatically generate the initial code template that meets the development requirements, including the basic class structure, function definition, call relationship, etc.
[0038] In some embodiments, in the above step S101, generating an initial code template according to the development requirement information based on the code generation model specifically includes:
[0039] The development requirement information is segmented and vectorized by a word vector model to obtain a low-dimensional dense vector of the text;
[0040] The TextRank algorithm is used to extract features from the low-dimensional dense vector of the text, and key features are obtained by calculating the similarity and importance between words in the low-dimensional dense vector of the text;
[0041] The key features are input into a code generation model to perform code generation and obtain an initial code template.
[0042] In this embodiment, according to the development requirement information, the word segmentation technology is used to perform word segmentation processing on the text to obtain the word sequence of the text. Through the word vector model training, the word sequence after word segmentation is converted into a low-dimensional dense vector representation to obtain the word vector corresponding to each word. According to the word vector representation, the text vectorization method is used to combine the word vectors of the words to obtain the vectorized representation of the entire text, forming a low-dimensional dense vector of the text.
[0043] According to the low-dimensional dense vector of the text, the TextRank algorithm is used to perform feature extraction processing on the text to obtain the word nodes and edges between words in the text. By calculating the similarity of the word nodes in the low-dimensional dense vector of the text, a similarity matrix between the word nodes is obtained, which represents the semantic relevance of the words. According to the iterative formula in the TextRank algorithm, the similarity matrix of the word nodes is used to iteratively calculate the importance score of each word node until the score converges to obtain the importance weight of each word. According to the importance weight sorting of the words, several words with the largest weights are obtained as candidate keywords, and the final keyword set is determined by setting the weight threshold, which represents the extracted key features of the text.
[0044] The extracted key features are input into a pre-trained code generation model (such as Copilot), and deep learning network structures such as Transformer are used in combination with prior knowledge of a large-scale code corpus to generate initial code templates that meet the project functional requirements.
[0045] For example, first use a pre-trained word vector model such as Word2Vec to segment and vectorize the development requirement information, set the word vector dimension to 300, and obtain a low-dimensional dense vector matrix of the text by vectorizing and mapping each word in the text. Then, based on the TextRank algorithm, extract features from the low-dimensional dense vector of the text, calculate the cosine similarity between words in the vector matrix and construct a word relationship graph, iteratively calculate the centrality and importance score of each word, and select the top 10% of the words as key features. Finally, the extracted key features are input into the code generation model based on the Transformer architecture. The model is pre-trained on a large-scale code corpus and fine-tuned for different programming languages. The initial code template is generated by decoder autoregression. The Beam Search strategy is used for search during the generation process, and the beam width is set to 5 to obtain high-quality code. The entire process automatically realizes the conversion from development requirements to code templates through word vector representation, graph algorithm feature extraction, and deep learning code generation.
[0046] S102, performing structural analysis on the initial code template by constructing an abstract syntax tree to obtain a code analysis result, and optimizing the initial code template according to the code analysis result to obtain a first code template.
[0047] In this embodiment, by constructing an abstract syntax tree, the initial code template is structurally analyzed to obtain the code analysis result. According to the code analysis result, the pattern matching algorithm is used to identify the code structure in the initial code template to obtain the code structure feature. According to the code structure feature, the decision tree algorithm is used to determine the optimization direction of the code template and determine the optimization strategy. If there is redundant code in the code template, the data flow analysis algorithm is used to delete the redundant code; if there is a performance bottleneck in the code template, the dynamic programming algorithm is used to optimize the performance bottleneck code; if there is a code style inconsistency problem in the code template, the code style is unified through the semantic analysis of the abstract syntax tree. According to the optimization strategy, the initial code template is iteratively optimized to obtain an intermediate code template. The control flow graph algorithm is used to perform complexity analysis on the intermediate code template to obtain the complexity analysis result. According to the complexity analysis result, the greedy algorithm is used to reconstruct and optimize the complex code module of the intermediate code template to obtain a simplified code template. According to the simplified code template, the symbolic execution algorithm is used to generate test cases, and the code template is tested through the test cases to obtain the test results. If the test result shows that the code template still has defects, return to the previous step to continue optimization; if the test result shows that the code template has reached the optimization goal, output the optimized first code template.
[0048] In some embodiments, in the above step S102, the constructing of an abstract syntax tree to perform structural analysis on the initial code template to obtain a code analysis result specifically includes:
[0049] Based on an abstract syntax tree algorithm, converting the initial code template into a tree structure;
[0050] Performing structured analysis on the tree structure according to grammatical rules, identifying grammatical errors in the initial code template, and obtaining a first code analysis result;
[0051] Constructing a control flow graph through the tree structure, analyzing the execution path and the logical structure of the initial code template according to the control flow graph, and obtaining a second code analysis result;
[0052] By performing data flow analysis on the tree structure, the variable definition and variable usage of the initial code template are determined to obtain a third code analysis result;
[0053] A target code analysis result is obtained according to the first code analysis result, the second code analysis result and the third code analysis result.
[0054] In this embodiment, first, the initial code template is converted into a tree structure of an abstract syntax tree, and the tree structure is structurally analyzed by grammatical rules to identify syntax errors in the initial code template, such as undefined variables, missing brackets, missing semicolons, etc., to obtain the first code analysis result. Then, a control flow graph is constructed based on the tree structure, and the execution path of the code is analyzed to determine whether there are logical structure problems such as dead loops and unreachable code, and obtain the second code analysis result. Next, a data flow analysis is performed on the tree structure to determine the definition and use of variables, and to check whether there are unused variables, uninitialized variables, etc., to obtain the third code analysis result. The code analysis results of the above three aspects are combined to obtain the comprehensive analysis result of the target code.
[0055] Specifically, by performing a depth-first traversal on the code tree structure, a predefined grammar rule library is used to match the grammar rules for each node of the code tree, and it is determined whether each node has a grammatical error, and the grammatical error mark of the code node is obtained. According to the grammatical error mark of the code node, an error aggregation algorithm is used to cluster adjacent code nodes with the same error type to obtain an aggregated grammatical error area. By performing error type analysis on the code nodes in the grammatical error area, an error repair rule library is used to generate corresponding repair suggestions for each error type to obtain a targeted code repair solution. According to the code repair solution, a code reconstruction algorithm is used to structurally adjust and optimize the code nodes in the error area to obtain an optimized code tree structure after repair. By reversely converting the optimized code tree structure, a code generator is used to regenerate the code tree structure into a repaired code template, and the final code template after structural optimization and grammatical error repair is obtained, which is output as the first code analysis result.
[0056] A control flow graph is constructed through the control flow information, wherein the nodes of the control flow graph represent code blocks, and the edges represent the jump relationship between code blocks; the execution path of the code is analyzed by a graph traversal algorithm according to the control flow graph to obtain all possible execution paths in the initial code template; the conditional statements and iterative statements in the code logic are judged by analyzing the branch structure and loop structure in the execution path to obtain a complete code logic structure; the execution path and the logic structure are combined, and the behavior and results of the code under different inputs are analyzed by symbolic execution technology to obtain a second code analysis result.
[0057] According to the node information of the tree structure, the data flow analysis technology is used to obtain the entry and exit variable sets of each node. Through this analysis, the definition and usage of the variables of each node before and after execution are obtained. Using the variable usage of each node obtained, determine which variables are used without being defined, so as to judge potential coding errors or optimization points. Through this step, a preliminary analysis result on the use of variables is obtained. After obtaining the preliminary analysis results, the dependencies between the nodes and the life cycle of the variables are determined through further algorithm optimization. In this way, more detailed and accurate code behavior analysis results are obtained. Using the detailed code behavior analysis results, the performance of the code under different execution paths is obtained by simulating the execution path. Through this simulation, the robustness and execution efficiency of the code are judged, so as to obtain the third code analysis result.
[0058] Further, optimizing the initial code template according to the code analysis result to obtain the first code template specifically includes:
[0059] According to the target code analysis result, the initial code template is reconstructed and optimized by using a greedy algorithm to obtain a first code template;
[0060] Generate a test case using a symbolic execution algorithm according to the first code template, and test the first code template using the test case to obtain a test result;
[0061] Determine whether the first code template has defects according to the test result. If so, reconstruct and optimize the first code template until the defects no longer exist.
[0062] In this embodiment, according to the target code analysis results, a greedy algorithm is used to reconstruct and optimize the code, such as removing redundant code, optimizing loop structure, merging repeated logic, etc., to generate an optimized first code template. Through the first code template, the execution path and data flow of the key business logic are determined to obtain the optimized execution efficiency and resource occupancy. The obtained execution efficiency data is used to determine the dependencies and performance bottlenecks between the modules, and the improvement direction of the key modules is obtained. According to the structure and functional requirements of the first code template, a symbolic execution algorithm is used to generate test cases. Through these test cases, various possible execution paths can be simulated to ensure the performance of the code under different conditions. The key variables and decision points in the code template are obtained, and all possible paths for code execution are obtained through this information. The first code template is tested using the generated test cases to obtain test results. Through these results, the execution effect and potential problems of the code under various circumstances can be judged. Determine the defects and optimization points in the code, obtain the improved code template, and ensure that it is more robust and efficient.
[0063] S103, creating a common code library, inputting the first code template into the common code library, and performing document generation and example generation on the first code template in the common code library.
[0064] In this embodiment, according to the input first code template, a text analysis algorithm is used to perform semantic analysis on the code template to obtain a semantic feature vector of the code template. Through the semantic feature vector, a support vector machine classification algorithm is used to determine the category of the code template. If the code template belongs to the public code library category, the first code template is input into the public code library. In the public code library, the source code content of the first code template is obtained, and the source code is parsed by an abstract syntax tree analysis algorithm to obtain an abstract syntax tree representation of the code. According to the abstract syntax tree representation, a natural language generation algorithm is used to automatically generate a document description of the code template, and the document description includes the function, input parameters, output results and other contents of the code. According to the source code content of the first code template, a code example generation algorithm is used to automatically generate a usage example of the code, and the usage example includes the calling method of the code, input parameter examples, output result examples and other contents. The generated document description and usage example are associated with the first code template to form a complete code template document. The complexity analysis algorithm is used to perform complexity analysis on the first code template to obtain the complexity index of the code template, and the code template is optimized and reconstructed according to the complexity index to generate an optimized code template version. The optimized code template version is updated to the public code library to replace the original first code template. The code templates in the public code library are indexed and searched using a code search algorithm, and matching code template search results are returned based on the search keywords entered by the user.
[0065] In some embodiments, in the above step S103, the generating of documents and examples for the first code template in the public code library specifically includes:
[0066] Acquire source code content of the first code template, perform syntax analysis on the source code content using an abstract syntax tree analysis algorithm, and obtain an abstract syntax tree representation;
[0067] According to the abstract syntax tree representation, a natural language generation algorithm is used to automatically generate a document description of the first code template, wherein the document description includes code functions, input parameters, and output results;
[0068] According to the source code content, a code usage example is automatically generated by a code example generation algorithm, wherein the code usage example includes a code calling method, an input parameter example, and an output result example;
[0069] The document description and the code usage example are associated with the first code template to form a complete code template.
[0070] In this embodiment, the source code content is obtained according to the first code template. The abstract syntax tree analysis algorithm is used to perform syntax analysis on the obtained source code content. Through syntax analysis, an abstract syntax tree representation corresponding to the source code content is obtained. Based on the obtained abstract syntax tree representation, program elements such as classes, methods, and variables in the source code are determined.
[0071] According to the abstract syntax tree representation, a natural language generation algorithm is used to obtain information such as code functions, input parameters, and output results in the code template, and the overall structure and logic of the code are obtained by analyzing the node types and the relationship between the nodes of the abstract syntax tree. According to the obtained code structure and logic information, a template generation technology is used to obtain a predefined document description template, and a preliminary document description of the code template is generated by filling the code function, input parameters, output results and other information into the corresponding position of the template. According to the generated preliminary document description, natural language processing technology is used to obtain keywords and semantic information in the document, and the organizational structure and expression method of the document description are determined by analyzing the logical relationship between the code function, input parameters and output results. According to the determined document organizational structure and expression method, a language model generation technology is used to obtain a large-scale natural language corpus, and the grammar, semantics and expression habits of natural language are learned by training the language model to obtain a document description generation model that conforms to the expression habits of natural language. According to the obtained document description generation model, a text generation technology is used to obtain the function, input parameters and output result information of the code template, and by inputting it into the document generation model, a fluent, coherent, and natural language expression habit code template document description is automatically generated.
[0072] According to the content of the source code, obtain information such as the class name, method name, parameter list, etc. in the code. By analyzing the source code structure, determine the calling method of the code and obtain a code calling example. Use random data generation technology to obtain a set of representative input parameter example data for the data type of the input parameter. According to the input parameter example, call the method in the source code to obtain the output result. Sort and format the output result to obtain a standardized output result example. Organize the code calling example, input parameter example, and output result example together in a certain format to form a complete code usage example.
[0073] Furthermore, it also includes:
[0074] Obtaining usage records of each complete code template in a public code library, analyzing the usage records by a data mining algorithm, and obtaining statistical information, wherein the statistical information includes usage frequency and usage scenario of each complete code template;
[0075] Obtain user input requirement information, and recommend corresponding complete code templates to the user through a collaborative filtering recommendation algorithm based on the user input requirement information and the statistical information.
[0076] In this embodiment, according to the usage records of each complete code template in the public code library, the usage records are analyzed and processed by a data mining algorithm to obtain statistical information such as the usage frequency and usage scenarios of each complete code template. The demand information input by the user is obtained, and the specific demand characteristics of the user are determined by parsing and extracting the user demand information. The obtained statistical information and the obtained user demand characteristics are used as input, and a collaborative filtering recommendation algorithm is used for calculation and analysis. According to the similarity of the usage frequency, usage scenario and demand characteristics, the complete code template that best matches the user demand is obtained. According to the calculation results, the corresponding complete code template is recommended to the user in order from high to low matching degree for reference and selection by the user. The user's feedback information on the recommendation results is obtained, and the recommendation algorithm is optimized and adjusted by analyzing the user's selection and evaluation, so as to continuously improve the accuracy of the recommendation and user satisfaction. The optimized recommendation algorithm is applied to the subsequent code template recommendation process, and the recommendation results are dynamically updated according to the user's latest needs and feedback, so as to provide users with personalized code template recommendation services. For example, when a user enters a specific programming requirement through the interface, the system uses collaborative filtering recommendation algorithms, such as user- and task-based recommendation systems, combined with statistical information obtained from previous analysis, to recommend code templates that best suit their needs. If a user needs a data cleaning function, the system may recommend efficient string processing functions that are frequently used in similar scenarios. In this way, the system can provide personalized programming support to help users quickly find and apply the most appropriate code solutions.
[0077] S104, building a configuration file and a project operating environment according to the directory structure and external dependencies of the public code library, and configuring an automated building process through a continuous integration tool.
[0078] In this embodiment, according to the directory structure and external dependencies of the public code library, a recursive descent analysis method is used to build a configuration file and a project operating environment. By analyzing the directory structure of the public code library, the file organization structure and module division information of the project are obtained. According to the external dependencies, the third-party libraries and tools required for the project operation are determined. Based on the above analysis results, a build configuration file of the project is generated, such as Maven's pom.xml or Gradle's build.gradle file, and the project operating environment, such as JDK version, environment variables, etc., is configured. In a continuous integration tool, such as Jenkins or GitLabCI, an automated build and test process is configured. By parsing the build configuration file, the build steps and dependencies of the project are obtained. According to the build steps, corresponding build tasks are created in the continuous integration tool, such as compilation, packaging, unit testing, etc. A directed acyclic graph scheduling algorithm is used to determine the execution order of tasks based on the dependencies between tasks to form a complete build pipeline. During the build process, the code quality is checked by static code analysis tools, such as SonarQube or CheckStyle. According to predefined code specifications and quality indicators, the code is scanned and analyzed to identify potential defects and non-compliance. Output the analysis results in the form of a report, and set quality gates in the build process. If the code quality does not meet the standard, the build fails and the developer needs to fix it. For the test process, adopt the test pyramid strategy to reasonably divide the proportion of unit testing, integration testing, and end-to-end testing. Use test coverage analysis tools such as JaCoCo or Cobertura to measure test coverage and ensure that the test is comprehensive enough. In the continuous integration process, configure automated test tasks to run unit tests, integration tests, etc. If the test fails, the build fails and the developer needs to fix it. Use automated deployment tools such as Ansible or Kubernetes to deploy the build products to different environments, such as development environment, test environment, and production environment. Define the deployment process and required resources based on deployment configuration files such as Dockerfile or HelmChart. Use strategies such as blue-green deployment or canary release to achieve smooth version upgrades and rollbacks. Throughout the continuous integration and deployment process, use log aggregation and monitoring tools such as ELK or Prometheus to collect and analyze log and indicator data for build, test, and deployment in real time. According to the preset thresholds and rules, anomaly detection and alarm are performed to ensure the stability and reliability of the process. At the same time, through visual dashboards such as Grafana or Kibana, the running status and key indicators of the process are intuitively displayed, which facilitates the team to monitor and optimize. Through version control systems such as Git or SVN, the version evolution of the code base is managed.Adopt branch management strategies such as GitFlow or Trunk-Based Development to standardize the code submission, branch creation and merging processes. In the continuous integration process, trigger the corresponding build and test tasks according to the branch creation and merging events to ensure the reliability and stability of the code. Finally, continuously optimize the continuous integration and deployment process through feedback mechanisms and continuous improvement. According to the build and test results, identify bottlenecks and problems in the process and develop optimization plans. Through automated scripts and tools such as JenkinsPipeline or GitLabCI / CD, automate and standardize the process to reduce manual intervention and errors. At the same time, through team collaboration and knowledge sharing, promote the construction of continuous integration and deployment culture and improve the team's delivery efficiency and quality.
[0079] In some embodiments, in the above step S104, the configuration file and the project operating environment are constructed according to the directory structure and external dependencies of the public code library, and the automated construction process is configured through a continuous integration tool, specifically including:
[0080] By analyzing the directory structure of the public code library, the project file organization structure and project module division information are obtained to form a first analysis result;
[0081] According to the analysis of the external dependencies of the common code library, third-party libraries and tools required for the project operation are determined to form a second analysis result;
[0082] According to the first analysis result and the second analysis result, a configuration file is constructed and a project operating environment is configured;
[0083] By parsing the configuration file, the project building steps and project dependencies are obtained, a continuous integration tool is used to create corresponding building tasks through the project building steps, and a directed acyclic graph scheduling algorithm is used to determine the execution order of characters through the project dependencies.
[0084] In this embodiment, based on the common code library, a directory structure analysis method is used to obtain the organizational structure information of the project files, and by analyzing the hierarchical relationship of the project folders, the module division information of the project is obtained, it is determined which main modules the project is composed of, the dependency relationship between the modules is judged, and the first analysis result of the project module organizational structure is obtained.
[0085] According to the analysis of the external dependencies of the public code library, the dependency analysis tool is used to obtain the information of the third-party libraries and tools referenced in the project. By analyzing the functions and roles of these third-party libraries and tools, their application scenarios in the project are obtained. According to the application scenarios of third-party libraries and tools, the function mapping method is used to obtain the specific functions provided by each third-party library and tool. By classifying and summarizing these functions, the functional categories required for the project operation are obtained. According to the functional categories, the version comparison method is used to obtain the latest stable version number of each third-party library and tool. By comparing the version number used in the current project with the latest stable version number, it is determined whether a version upgrade is required. According to the results of the version comparison, the compatibility analysis method is used to obtain the compatibility information between different versions. By analyzing the compatibility information, it is determined whether upgrading a third-party library or tool version will have an impact on the project. According to the results of the compatibility analysis, the dependency adjustment method is used to obtain the dependencies of the third-party libraries and tools that need to be adjusted. By adjusting the dependencies, a third-party library and tool combination solution with minimized compatibility issues is obtained. According to the third-party library and tool combination solution, the environment configuration method is used to obtain the system environment and parameter settings required for the project operation. By configuring the environment and parameters, the conditions required for the project to run normally are determined. Based on the results of the environment configuration, the test verification method is used to obtain the operation status of the project under the new third-party library and tool combination solution. Through comprehensive testing of the project, it is determined whether the new solution can meet the functional and performance requirements of the project. Based on the results of the test verification, the solution optimization method is used to obtain measures to further optimize the third-party library and tool combination solution. Through continuous optimization and adjustment, a stable, efficient, and easy-to-maintain third-party library and tool combination solution is finally obtained to form the final analysis result.
[0086] Based on the first analysis result and the second analysis result, a configuration file construction algorithm is used to obtain the business attributes and operating environment parameters of the project, and the optimal configuration solution is obtained by analyzing the business requirements and system architecture. According to the configuration solution, an automated deployment tool is used to obtain the project code and dependent libraries, and the services and components required for the project operation are deployed in the target environment by executing the build script and configuration file, and necessary initialization and data preparation are performed, and finally the project operating environment configuration is determined to be complete.
[0087] According to the provided project configuration file, file parsing technology is used to obtain the project's build steps and dependency information. Based on the obtained project build steps, continuous integration tools such as Jenkins are used to create corresponding build tasks and convert the build steps into executable automated tasks. According to the parsed project dependencies, a directed acyclic graph (DAG) scheduling algorithm is used to abstract the project's dependencies into a directed acyclic graph data structure. Through the dependencies between the nodes in the directed acyclic graph, graph traversal algorithms such as depth-first search are used to determine the optimal execution order of the build tasks, thereby solving the task scheduling problem. According to the determined task execution order, the task orchestration function provided by the continuous integration tool is used to orchestrate the build tasks in the optimal order to form a complete build pipeline. Through the task triggering mechanism of the continuous integration tool, such as timed triggering, code submission triggering, etc., the build pipeline is automatically executed to achieve automated construction and deployment of the project. During the build process, log collection and analysis technology is used to obtain the real-time execution status and results of the build tasks, and quality judgment and alarm are performed according to preset rules. Based on the build results and quality judgments, continuous deployment technology is used to automatically deploy the build products to the target environment, such as the test environment, pre-release environment, etc., to achieve continuous delivery of the project. By collecting the operation data and feedback of the project in different environments, the build process and task scheduling strategy are continuously optimized, and the optimization results are fed back to the configuration file to form a closed-loop improvement mechanism for project construction. Finally, through the application of automation technologies such as continuous integration and continuous deployment, as well as task scheduling optimization based on the directed acyclic graph scheduling algorithm, a set of efficient, reliable, and sustainably optimized project build and deployment solutions are obtained, which effectively support the rapid iteration and delivery of the project.
[0088] When analyzing a public code base, we first automatically scan the directory structure of the project through a script. For example, we find that the project contains ten modules, with an average of twenty files in each module, and a total of two hundred source code files. Then, we use static analysis tools such as SonarQube to conduct an in-depth analysis of the code base, identify the relationship between core modules and auxiliary modules, and form a detailed report on the project file organization structure and module division. Subsequently, by analyzing the build file in the project (such as Maven's pom.xml), all external dependencies are automatically extracted, including but not limited to SpringFramework2, MySQLJDBCDriver19, etc. This dependency information is used to determine the third-party libraries and tools required for the project to run and ensure the integrity of the environment configuration.
[0089] When building the configuration file, the above analysis results are integrated into Dockerfile and docker-compose.yml to configure the project running environment, such as setting up database services, application servers and their versions. For example, the configuration file specifies the use of MySQL0 and Tomcat0 to ensure compatibility with project dependencies. By parsing these configuration files, CI (continuous integration) tools such as Jenkins automatically obtain project build steps, such as compilation, unit testing, and packaging, and use the directed acyclic graph (DAG) scheduling algorithm to determine the order of task execution based on the dependencies defined in the configuration file.
[0090] This embodiment ensures the efficiency and stability of the construction process. Through this embodiment, each construction step is precisely defined and automatically executed, thereby greatly improving development efficiency and project maintainability. The entire process does not require manual intervention and is completely managed by automated tools and scripts, ensuring the consistency and accuracy of project construction.
[0091] Reference Figure 2 An embodiment of the present invention provides a public code library management system 2, and the system 2 specifically includes:
[0092] The first management module 201 is used to obtain development requirement information and generate an initial code template based on the development requirement information according to the code generation model;
[0093] The second management module 202 is used to perform structural analysis on the initial code template by constructing an abstract syntax tree to obtain a code analysis result, and optimize the initial code template according to the code analysis result to obtain a first code template;
[0094] The third management module 203 is used to create a common code library, input the first code template into the common code library, and perform document generation and example generation on the first code template in the common code library;
[0095] The fourth management module 204 is used to build configuration files and project operating environment according to the directory structure and external dependencies of the public code library, and configure the automated building process through continuous integration tools.
[0096] It is understandable that if Figure 1 The contents of the public code library management method embodiment shown in the figure are applicable to the public code library management system embodiment. The functions specifically implemented by the public code library management system embodiment are similar to those in the example shown in the figure. Figure 1 The common code library management method embodiment shown is the same as that shown in FIG. Figure 1 The beneficial effects achieved by the common code library management method embodiment shown are also the same.
[0097] It should be noted that the information interaction, execution process and other contents between the above-mentioned systems are based on the same concept as the embodiment of the method of the present invention. Their specific functions and technical effects can be found in the method embodiment part and will not be repeated here.
[0098] Those skilled in the art can clearly understand that, for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In practical applications, the above-mentioned function allocation can be completed by different functional units and modules as needed, that is, the internal structure of the system can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.
[0099] Reference Figure 3 The embodiment of the present invention further provides a computer device 3, comprising: a memory 302 and a processor 301 and a computer program 303 stored in the memory 302. When the computer program 303 is executed on the processor 301, a common code library management method as described in any one of the above methods is implemented.
[0100] The computer device 3 may be a computing device such as a desktop computer, a notebook, a PDA, or a cloud server. The computer device 3 may include, but is not limited to, a processor 301 and a memory 302. Those skilled in the art will appreciate that Figure 3 It is only an example of computer device 3 and does not constitute a limitation on computer device 3. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components, for example, it may also include input and output devices, network access devices, etc.
[0101] The processor 301 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.
[0102] In some embodiments, the memory 302 may be an internal storage unit of the computer device 3, such as a hard disk or memory of the computer device 3. In other embodiments, the memory 302 may also be an external storage device of the computer device 3, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped on the computer device 3. Further, the memory 302 may also include both an internal storage unit of the computer device 3 and an external storage device. The memory 302 is used to store an operating system, an application program, a boot loader (Boot Loader), data, and other programs, such as the program code of the computer program, etc. The memory 302 may also be used to temporarily store data that has been output or is to be output.
[0103] An embodiment of the present invention further provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the common code library management method as described in any one of the above methods is implemented.
[0104] In this embodiment, if the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the processes in the above-mentioned embodiment method, which can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a computer-readable storage medium. When the computer program is executed by the processor, the steps of the above-mentioned various method embodiments can be implemented. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium can at least include: any entity or device that can carry the computer program code to the camera / terminal device, recording medium, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electric carrier signal, telecommunication signal and software distribution medium. For example, a USB flash drive, a mobile hard disk, a disk or an optical disk. In some jurisdictions, according to legislation and patent practice, computer-readable media cannot be electric carrier signals and telecommunication signals.
[0105] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0106] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0107] In the embodiments disclosed in the present application, it should be understood that the disclosed devices / terminal equipment and methods can be implemented in other ways. For example, the device / terminal equipment embodiments described above are only schematic. For example, the division of the modules or units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0108] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
Claims
1. A method for managing a public code base, characterized in that: The method specifically comprises: Acquire development requirement information, and generate an initial code template based on the development requirement information according to a code generation model; By constructing an abstract syntax tree, performing structural analysis on the initial code template to obtain a code analysis result, and optimizing the initial code template according to the code analysis result to obtain a first code template; Creating a common code library, inputting the first code template into the common code library, and performing document generation and example generation on the first code template in the common code library; Build configuration files and project operating environment according to the directory structure and external dependencies of the public code library, and configure the automated build process through continuous integration tools; The steps of building a configuration file and a project operating environment according to the directory structure and external dependencies of the public code library and configuring an automated building process through a continuous integration tool include: By analyzing the directory structure of the public code library, the project file organization structure and project module division information are obtained to form a first analysis result; According to the analysis of the external dependencies of the common code library, third-party libraries and tools required for the project operation are determined to form a second analysis result; According to the first analysis result and the second analysis result, a configuration file is constructed and a project operating environment is configured; By parsing the configuration file, the project building steps and project dependencies are obtained, a continuous integration tool is used to create corresponding building tasks through the project building steps, and a directed acyclic graph scheduling algorithm is used to determine the task execution order through the project dependencies.
2. The method according to claim 1, characterized in that The generating of the initial code template according to the development requirement information based on the code generation model specifically includes: The development requirement information is segmented and vectorized by a word vector model to obtain a low-dimensional dense vector of the text; The TextRank algorithm is used to extract features from the low-dimensional dense vector of the text, and key features are obtained by calculating the similarity and importance between words in the low-dimensional dense vector of the text; The key features are input into a code generation model to perform code generation and obtain an initial code template.
3. The method according to claim 1, characterized in that The process of constructing an abstract syntax tree and performing structural analysis on the initial code template to obtain a code analysis result specifically includes: Based on an abstract syntax tree algorithm, converting the initial code template into a tree structure; Performing structured analysis on the tree structure according to grammatical rules, identifying grammatical errors in the initial code template, and obtaining a first code analysis result; Constructing a control flow graph through the tree structure, analyzing the execution path and the logical structure of the initial code template according to the control flow graph, and obtaining a second code analysis result; By performing data flow analysis on the tree structure, the variable definition and variable usage of the initial code template are determined to obtain a third code analysis result; A target code analysis result is obtained according to the first code analysis result, the second code analysis result and the third code analysis result.
4. The method according to claim 3, characterized in that The optimizing the initial code template by using the code analysis result to obtain the first code template specifically includes: According to the target code analysis result, the initial code template is reconstructed and optimized by using a greedy algorithm to obtain a first code template; Generate a test case using a symbolic execution algorithm according to the first code template, and test the first code template using the test case to obtain a test result; Determine whether the first code template has defects according to the test result. If so, reconstruct and optimize the first code template until the defects no longer exist.
5. The method according to claim 1, characterized in that Generating a document and an example for the first code template in the public code library specifically includes: Acquire source code content of the first code template, perform syntax analysis on the source code content using an abstract syntax tree analysis algorithm, and obtain an abstract syntax tree representation; According to the abstract syntax tree representation, a natural language generation algorithm is used to automatically generate a document description of the first code template, wherein the document description includes code functions, input parameters, and output results; According to the source code content, a code usage example is automatically generated by a code example generation algorithm, wherein the code usage example includes a code calling method, an input parameter example, and an output result example; The document description and the code usage example are associated with the first code template to form a complete code template.
6. The method according to claim 5, characterized in that The method further comprises: Obtaining usage records of each complete code template in a public code library, analyzing the usage records by a data mining algorithm, and obtaining statistical information, wherein the statistical information includes usage frequency and usage scenario of each complete code template; Obtain user input requirement information, and recommend corresponding complete code templates to the user through a collaborative filtering recommendation algorithm based on the user input requirement information and the statistical information.
7. A public code library management system, characterized in that: The system specifically comprises: A first management module is used to obtain development requirement information and generate an initial code template based on the development requirement information according to a code generation model; A second management module is used to perform structural analysis on the initial code template by constructing an abstract syntax tree to obtain a code analysis result, and optimize the initial code template according to the code analysis result to obtain a first code template; A third management module is used to create a common code library, input the first code template into the common code library, and perform document generation and example generation on the first code template in the common code library; A fourth management module is used to build configuration files and project operating environment according to the directory structure and external dependencies of the public code library, and configure an automated build process through a continuous integration tool; The steps of building a configuration file and a project operating environment according to the directory structure and external dependencies of the public code library and configuring an automated building process through a continuous integration tool include: By analyzing the directory structure of the public code library, the project file organization structure and project module division information are obtained to form a first analysis result; According to the analysis of the external dependencies of the common code library, third-party libraries and tools required for the project operation are determined to form a second analysis result; According to the first analysis result and the second analysis result, a configuration file is constructed and a project operating environment is configured; By parsing the configuration file, the project building steps and project dependencies are obtained, a continuous integration tool is used to create corresponding building tasks through the project building steps, and a directed acyclic graph scheduling algorithm is used to determine the task execution order through the project dependencies.
8. A computer device, characterized in that: include: A memory, a processor, and a computer program stored in the memory, when the computer program is executed on the processor, implements the public code library management method according to any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that: A computer program is stored thereon, and when the computer program is executed by a processor, the public code library management method according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Public module library calling method, system, equipment and medium
CN114661285A
Automatic interface code generation method and system based on AI and modular framework
CN117111916A