Method and device for acquiring code library dependency relationship, electronic equipment and storage medium
Patent Information
- Application Number
- CN202211607799.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-14
- Publication Date
- 2026-09-15
- Estimated Expiration
- 2042-12-14
AI Technical Summary
[0005]本申请实施例提供一种获取代码库依赖关系的方法、装置、电子设备及存储介质,以提高存在依赖关系的代码库的分析效率,能够解决由于项目之间引用不规范导致分层架构无法实施的问题
[0060] The solution provided in this application involves obtaining a dependency list of the codebase corresponding to the target project. Based on the dependency list, depth information of the codebase is obtained. A directed graph indicating the dependencies between the codebases corresponding to the target project is then constructed based on the depth information, allowing the determination of codebase dependencies. This application, by combining the depth information of the codebases in the dependency list to construct a directed graph indicating the dependencies between the codebases corresponding to the target project, can quickly analyze codebases with mutual dependencies, improving the analysis efficiency of codebases with dependencies and solving the problem of layered architecture being unable to be implemented due to non-standard referencing between projects.
Smart Images

Figure CN116185374B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a method, apparatus, electronic device, and storage medium for obtaining code library dependencies. Background Technology
[0002] Layered architecture refers to orthogonally dividing an application system into several layers, each addressing a specific problem. The collaboration of these layers provides an overall solution. Layered structures offer excellent scalability, providing a flexible framework for the evolution and growth of application systems, and are easier to maintain.
[0003] However, in a layered architecture, the underlying codebases have interdependencies. For example, the underlying codebases in the middle layer include codebase A and codebase B. There is an interdependency between codebase A and codebase B. When other projects plan to introduce codebase A, codebase B must be introduced as well, which will bring problems of high coupling, difficulty in reuse, and difficulty in expansion to other projects.
[0004] Currently, to solve the above problems, developers typically need to analyze the codebase dependencies to identify potentially interdependent libraries. This places high demands on developers and is inefficient. Furthermore, human analysis is prone to errors, which can lead to non-standard referencing between projects, making it impossible to implement a layered architecture. Summary of the Invention
[0005] This application provides a method, apparatus, electronic device, and storage medium for obtaining code repository dependencies, thereby improving the analysis efficiency of code repositories with dependencies and solving the problem that layered architecture cannot be implemented due to non-standard referencing between projects. The specific implementation scheme is as follows:
[0006] In a first aspect, embodiments of this application provide a method for obtaining code repository dependencies, including:
[0007] Get the list of dependencies for the code repository corresponding to the target project;
[0008] Based on the dependency list, obtain the depth information of the code repository;
[0009] Based on the depth information, a directed graph is constructed to indicate the dependency relationships between the code libraries corresponding to the target project, so as to obtain the dependency relationships of the code libraries based on the directed graph.
[0010] Optionally, obtaining the dependency list of the code repository corresponding to the target project includes:
[0011] Obtain the initial dependency list corresponding to the target project;
[0012] Filter out invalid information from the initial dependency list to generate the dependency list.
[0013] Optionally, obtaining the depth information of the codebase based on the dependency list includes:
[0014] Obtain the distance information between the first letter of the code library name corresponding to each line of the dependency list and the left boundary;
[0015] Based on the distance information, the depth information corresponding to the code library is obtained.
[0016] Optionally, establishing a directed graph indicating the dependencies between the code repositories corresponding to the target project based on the depth information includes:
[0017] Traverse the dependency list in reverse order;
[0018] Add the names of the code libraries in the dependency list that have been traversed to the code library name set in turn;
[0019] The code library name and the depth information corresponding to the code library name in the traversed dependency list are added to the code library depth information list in sequence;
[0020] The directed graph is constructed based on the set of code repository names and the list of code repository depth information.
[0021] Optionally, the step of adding the code library names of the code libraries in the traversed dependency list to the code library name set in sequence includes:
[0022] After each traversal of a target code library name, determine whether the target code library name exists in the set of code library names;
[0023] If the target code library name exists in the set of code library names, then the target code library name is filtered.
[0024] If the target code library name does not exist in the set of code library names, then the target code library name is added to the set of code library names.
[0025] Optionally, establishing the directed graph based on the set of code repository names and the list of code repository depth information includes:
[0026] Traverse the list of code repository depth information in chronological order.
[0027] Following a first-in-first-out strategy, the dependency relationships corresponding to each code library name are determined sequentially based on the code library name in the code library depth information list and the depth information corresponding to the code library name.
[0028] The directed graph is established based on the code library names in the code library name set, the location information corresponding to each code library name, and the dependency relationships.
[0029] Optionally, establishing the directed graph based on each code repository name in the code repository name set, the location information corresponding to each code repository name, and the dependency relationship includes:
[0030] Based on the code repository name and the location information of the code repository name, an initial adjacency matrix is established with the code repository name as the row and column elements;
[0031] Based on the dependencies, update the dependency values at the corresponding positions in the initial adjacency matrix, generate an adjacency matrix corresponding to the target project that indicates the dependencies between the code libraries, and use the adjacency matrix as the directed graph.
[0032] Secondly, embodiments of this application provide an apparatus for obtaining code library dependencies, comprising:
[0033] The dependency list retrieval module is used to retrieve the dependency list of the code repository corresponding to the target project;
[0034] A depth information acquisition module is used to acquire depth information of the code library based on the dependency list;
[0035] A directed graph building module is used to build a directed graph corresponding to the target project, indicating the dependency relationships between the code libraries, based on the depth information, so as to obtain the dependency relationships of the code libraries based on the directed graph.
[0036] Optionally, the relationship list acquisition module includes:
[0037] The initial list acquisition unit is used to acquire the initial dependency list corresponding to the target project;
[0038] The dependency list generation unit is used to filter invalid information in the initial dependency list and generate the dependency list.
[0039] Optionally, the depth information acquisition module includes:
[0040] The distance information acquisition unit is used to acquire the distance information between the first letter of the code library name corresponding to each line of the dependency list and the left boundary;
[0041] A depth information acquisition unit is used to acquire depth information corresponding to the code library based on the distance information.
[0042] Optionally, the directed graph construction module includes:
[0043] A relation list traversal unit is used to traverse the dependency relation list in a forward-to-back order;
[0044] The code repository name addition unit is used to add the code repository names of the code repositories in the traversed dependency list to the code repository name set in sequence;
[0045] The depth information adding unit is used to add the code library name and the depth information corresponding to the code library name from the traversed dependency list to the code library depth information list in sequence;
[0046] A directed graph building unit is used to build the directed graph based on the set of code library names and the list of code library depth information.
[0047] Optionally, the code repository name addition unit includes:
[0048] The code repository name determination subunit is used to determine whether the target code repository name exists in the set of code repository names after each traversal of a target code repository name;
[0049] The code repository name filtering subunit is used to filter the target code repository name if the target code repository name exists in the set of code repository names;
[0050] The code repository name addition sub-unit is used to add the target code repository name to the code repository name set if the target code repository name does not exist in the code repository name set.
[0051] Optionally, the directed graph building unit includes:
[0052] The depth list traversal sub-unit is used to traverse the code library depth information list in a forward-to-back order.
[0053] The dependency determination subunit is used to determine the dependency relationship corresponding to each code library name in a first-in-first-out (FIFO) strategy, based on the code library name in the code library depth information list and the depth information corresponding to the code library name.
[0054] A directed graph establishment subunit is used to establish the directed graph based on each code library name in the code library name set, the location information corresponding to each code library name, and the dependency relationship.
[0055] Optionally, the directed graph construction subunit includes:
[0056] An initial matrix establishment sub-unit is used to establish an initial adjacency matrix with the code library name as the row and column elements, based on the code library name and the location information of the code library name.
[0057] An adjacency matrix generation subunit is used to update the dependency value at the corresponding position in the initial adjacency matrix according to the dependency relationship, generate an adjacency matrix corresponding to the target project that indicates the dependency relationship between the code libraries, and use the adjacency matrix as the directed graph.
[0058] Thirdly, embodiments of this application provide an electronic device, including: a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the computer program, when executed by the processor, implements the steps of the method for obtaining code library dependencies as described above.
[0059] Fourthly, embodiments of this application provide a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of the method for obtaining code library dependencies as described above.
[0060] The solution provided in this application involves obtaining a dependency list of the codebase corresponding to the target project. Based on the dependency list, depth information of the codebase is obtained. A directed graph indicating the dependencies between the codebases corresponding to the target project is then constructed based on the depth information, allowing the determination of codebase dependencies. This application, by combining the depth information of the codebases in the dependency list to construct a directed graph indicating the dependencies between the codebases corresponding to the target project, can quickly analyze codebases with mutual dependencies, improving the analysis efficiency of codebases with dependencies and solving the problem of layered architecture being unable to be implemented due to non-standard referencing between projects. Attached Figure Description
[0061] Figure 1 A flowchart illustrating the steps of a method for obtaining code library dependencies, provided in an embodiment of this application;
[0062] Figure 2 A flowchart illustrating the steps of a dependency list generation method provided in this application embodiment;
[0063] Figure 3 A flowchart illustrating the steps of a depth information acquisition method provided in this application embodiment;
[0064] Figure 4 A flowchart illustrating the steps of another directed graph construction method provided in this application embodiment;
[0065] Figure 5 A flowchart illustrating the steps of a method for adding a code library name, as provided in this application embodiment;
[0066] Figure 6 A flowchart illustrating the steps of another directed graph construction method provided in this application embodiment;
[0067] Figure 7 A flowchart illustrating the steps of an adjacency matrix generation method provided in this application embodiment;
[0068] Figure 8 This is a schematic diagram of a device for obtaining code library dependencies, provided in an embodiment of this application. Detailed Implementation
[0069] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0070] Reference Figure 1 The flowchart illustrates the steps of a method for obtaining code repository dependencies according to an embodiment of this application. Figure 1 As shown, the method for obtaining code library dependencies may include steps 101, 102, and 103.
[0071] Step 101: Obtain the dependency list of the code repository corresponding to the target project.
[0072] The embodiments of this application can be applied to scenarios where a directed graph is established to indicate the dependency relationships between code libraries corresponding to a target project.
[0073] A dependency list is a list used to indicate the dependencies of a codebase. It contains the names of the codebases used by the target project; each line in the dependency list represents a codebase name.
[0074] When constructing a directed graph representing the dependencies between code repositories corresponding to a target project, a list of code repository dependencies for that target project can be obtained. In a practical implementation within the Android development system, this list can be retrieved using a single Gradle command. In this example, the dependency list obtained via the Gradle command contains many invalid characters, which need to be filtered out to obtain the final dependency list. Specifically, this can be achieved by combining... Figure 2 The implementation process is described in detail.
[0075] Reference Figure 2 The diagram illustrates a flowchart of a dependency list generation method provided in an embodiment of this application. Figure 2 As shown, the dependency list generation method may include steps 201 and 202.
[0076] Step 201: Obtain the initial dependency list corresponding to the target project.
[0077] In this embodiment, when establishing a directed graph of the dependencies between the code libraries corresponding to the target project, an initial dependency list corresponding to the target project can be obtained. The initial dependency list contains information such as the names of all the code libraries used in developing the target project.
[0078] After obtaining the initial dependency list corresponding to the target project, proceed to step 202.
[0079] Step 202: Filter out invalid information in the initial dependency list and generate the dependency list.
[0080] After obtaining the initial dependency list for the target project, invalid information in the initial dependency list can be filtered out to generate the final dependency list. In practice, the initial dependency list may contain invalid information such as "|", "+", "-", and "\", which can be filtered out to obtain the final dependency list for the target project.
[0081] This application embodiment filters out invalid information in the dependency list of the target project, which can prevent invalid information from affecting the identification of the code library name and improve the accuracy of code library name identification.
[0082] After obtaining the dependency list of the code library corresponding to the target project, proceed to step 102.
[0083] Step 102: Based on the dependency list, obtain the depth information of the code library.
[0084] Depth information refers to the information in the dependency list used to indicate the dependencies between code repository names.
[0085] After obtaining the dependency list of the code repository corresponding to the target project, the depth information of the code repository can be obtained based on the dependency list. Specifically, the depth information of the code repository can be obtained by measuring the distance to the left margin of the first letter of the code repository name in each line of the dependency list. This implementation process can be combined with... Figure 3 The following is a detailed description.
[0086] Reference Figure 3 The flowchart illustrates the steps of a depth information acquisition method provided in an embodiment of this application, as follows: Figure 3 As shown, the depth information acquisition method may include steps 301 and 302.
[0087] Step 301: Obtain the distance information between the first letter of the code library name corresponding to each line of the dependency list and the left boundary.
[0088] In this embodiment, after obtaining the dependency list corresponding to the target project, the distance information between the first letter of the code library name corresponding to each line of the dependency list and the left boundary can be obtained.
[0089] After obtaining the distance information between the first letter of the code library name corresponding to each line of the dependency list and the left boundary, proceed to step 302.
[0090] Step 302: Based on the distance information, obtain the depth information corresponding to the code library.
[0091] After obtaining the distance information between the first letter of the code repository name and the left boundary of each line in the dependency list, the depth information of the code repository corresponding to that line can be obtained based on this distance information. In a specific implementation, the dependency list contains the names of the code repositories used by the target project. Each line in the dependency list represents a code repository name, and the distance between the first letter of each line and the left boundary of the list indicates the depth of the code repository corresponding to that line, as shown in the following example of a dependency list:
[0092]
[0093] In the examples above, each line represents the name of a codebase. The first line's codebase name is "com.xxxA.android.main.mainmodule:1017", with a 2-character gap from the left edge of the dependency list. Therefore, the depth information of this first line's codebase name can be defined as 1. The second line's codebase name is "org.jethrains.kotlin:kotlin-andriod-extenssions-runtime:1.4.30", with a 4-character gap from the left edge of the dependency list. Therefore, the depth information of this second line's codebase name can be defined as 2. The third line's codebase name is "com.xxxB.android.commonbusiness:commonbusiness:1017-1.0.0", with a 4-character gap from the left edge of the dependency list. Therefore, the depth information of this third line's codebase name can be defined as 2. The codebase name in the fourth line is "com.xxxC.wmda:1.2.0→1.2.4", and the distance between it and the left boundary of the dependency list is 6 characters. At this point, the depth information of the codebase name in the fourth line can be defined as 3, etc.
[0094] It is understood that the above examples are merely examples listed to better understand the technical solutions of the embodiments of this application, and are not intended to be the only limitation on the embodiments.
[0095] This application embodiment, by combining the depth information corresponding to each line of code library name in the obtained dependency list, can facilitate the subsequent identification of code library dependencies.
[0096] After obtaining the depth information of the codebase based on the dependency list, proceed to step 103.
[0097] Step 103: Based on the depth information, establish a directed graph corresponding to the target project that indicates the dependency relationships between the code libraries.
[0098] After obtaining the depth information of the codebases based on the dependency list, a directed graph indicating the dependencies between the codebases in the target project can be built based on the depth information of each codebase. This directed graph clearly shows whether dependencies exist between codebases, providing guidance to developers when other projects reference these codebases and facilitating the resolution of issues related to other projects calling them.
[0099] In this embodiment, when constructing the directed graph of the target project, the dependency list can be traversed sequentially, and the traversed code library names can be added to the code library name set in turn. Simultaneously, the traversed code library names and their corresponding depth information can be added to the code library depth information list. The directed graph is then constructed by combining the code library name set and the code library depth information list. This implementation process can be combined with... Figure 4 The following is a detailed description.
[0100] Reference Figure 4 The flowchart illustrates another method for constructing a directed graph provided in an embodiment of this application, as follows: Figure 4 As shown, the directed graph construction method may include steps 401, 402, 403 and 404.
[0101] Step 401: Traverse the dependency list in front-to-back order.
[0102] In this embodiment, after obtaining the depth information corresponding to the code library, the dependency list can be traversed in a forward-to-back order. Specifically, the code library names in the dependency list are arranged line by line. During traversal, the list can be traversed line by line starting from the first line until the last line is reached.
[0103] After traversing the dependency list in front-to-back order, execute steps 402 and 403.
[0104] Step 402: Add the library names of the libraries in the dependency list that have been traversed to the library name set in turn.
[0105] In this example, a set of codebase names can be predefined to store the codebase names in the dependency list.
[0106] After traversing the dependency list in chronological order, the library names of the libraries encountered in the dependency list can be added to the library name set sequentially. For example, starting the traversal, after encountering a library name in the first line of the dependency list, that library name is added to the library name set. Continuing the traversal, after encountering a library name in the second line, that library name is added to the library name set, and so on, until the last line is encountered. Understandably, when adding library names to the library name set, they should be added in the order they appear in the dependency list. For example, the library name in the first line of the dependency list should be added to the first position in the library name set, the library name in the second line should be added to the second position, the library name in the third line should be added to the third position, and so on.
[0107] In practical applications, when adding the executed code library names to the code library name set, it can be checked whether the traversed code library name already exists in the code library name set. If it exists, it is not added; otherwise, the traversed code library name is added to the code library name set. This implementation process can be combined with... Figure 5 The following is a detailed description.
[0108] Reference Figure 5 The flowchart illustrates the steps of a code repository name addition method provided in an embodiment of this application, as shown below. Figure 5 As shown, the method for adding the code repository name may include steps 501, 502, and 503.
[0109] Step 501: After each traversal of a target code library name, determine whether the target code library name exists in the set of code library names.
[0110] In this embodiment, after each target code library name is encountered, it can be determined whether the target code library name exists in the code library name set. Specifically, after each target code library name is encountered, it can be matched one by one with the code library names in the code library name set, and the matching results can be used to determine whether there is a code library name in the code library name set that matches the target code library name.
[0111] After confirming that the target code repository name exists in the set of code repository names, proceed to step 502.
[0112] After determining that the target code library name does not exist in the set of code library names, proceed to step 503.
[0113] Step 502: If the target code library name exists in the set of code library names, then filter the target code library name.
[0114] If the target code library name is found in the code library name set, then the target code library name can be filtered out, meaning it will not be added to the code library name set again.
[0115] Step 503: If the target code library name does not exist in the code library name set, then add the target code library name to the code library name set.
[0116] If the target code library name does not exist in the code library name set, the target code library name can be added to the code library name set.
[0117] This application embodiment avoids adding duplicate code library names to the code library name set by checking whether the traversed code library name exists in the code library name set after each traversal of the code library name.
[0118] Step 403: Add the code library name and the corresponding depth information from the traversed dependency list to the code library depth information list in sequence.
[0119] After traversing the dependency list in chronological order, the repository names and their corresponding depth information from the dependency list can be added sequentially to the repository depth information list. That is, the repository names are added to the repository depth information list according to the order they appear in the dependency list. For example, the repository name in the first row of the dependency list should be added to the first row of the repository depth information list, the repository name in the second row should be added to the second row, the repository name in the third row should be added to the third row, and so on.
[0120] Additionally, depth information corresponding to each code repository name can be added to the code repository depth information list. For example, each row in the code repository depth information list can be a code repository name, and the corresponding depth information can be added to the area following each row of the list to indicate the depth of the code repository name.
[0121] Understandably, when adding code repository names to the code repository depth information list, they should be added line by line according to the code repository names in the dependency list. Unlike the code repository name set, if a code repository name encountered during the traversal is the same as a code repository name in the code repository depth information list, it should also be added in order, and the same code repository name should not be filtered out.
[0122] Step 404: Based on the set of code repository names and the list of code repository depth information, establish the directed graph.
[0123] After completing the above traversal operations, a directed graph indicating the code repository dependencies corresponding to the target project can be constructed based on the code repository depth information list in the code repository name set. Specifically, the code repository depth information list can be traversed in reverse order, and following a first-in-first-out strategy, the dependencies corresponding to each code repository name can be determined sequentially based on the code repository name and its corresponding depth information in the code repository depth information list. Then, a directed graph can be constructed based on the dependencies between the code repository names. This implementation process can be combined with... Figure 6 The following is a detailed description.
[0124] Reference Figure 6 This illustrates a flowchart of another directed graph construction method provided in an embodiment of this application, such as... Figure 6 As shown, the directed graph construction method may include steps 601, 602 and 603.
[0125] Step 601: Traverse the code library depth information list in front-to-back order.
[0126] In this embodiment, after adding all the code library names from the dependency list to the code library depth information list, the code library depth information list can be traversed in a forward-to-back order.
[0127] After traversing the list of codebase depth information in reverse order, proceed to step 602.
[0128] Step 602: Following a first-in-first-out strategy, determine the dependency relationships corresponding to each code library name in turn based on the code library name in the code library depth information list and the depth information corresponding to the code library name.
[0129] After traversing the code repository depth information list in chronological order, the dependency relationships corresponding to each code repository name can be determined according to the code repository name and its corresponding depth information in the code repository depth information list, using a first-in-first-out strategy.
[0130] In the specific implementation, a data structure stack can be predefined, along with a dependency set. The data structure stack can be used to store the parent class dependencies of the current codebase name, while the dependency set is used to store the first-level dependencies of the current codebase name, stored in key-value pairs, where the key is the codebase name and the value is the name of the dependent codebase.
[0131] For example, during the traversal, firstly, the code library name in the first row of the code library depth information list is used as the top element of the stack. Then, the depth information of the code library names in the second row of the code library depth information list is compared with the depth information of the top element of the stack. If the depth information of the second row of code library names is greater than the depth information of the top element of the stack, it means that the second row of code library names has a dependency relationship with the top element of the stack, and the second row of code library names can be added to the dependency relationship set corresponding to the top element of the stack. At this time, the first row of code library names can be removed from the top of the data structure stack, and the second row of code library names can be used as the top element of the stack, and the subsequent traversal process can be executed. If the depth information of the second row of code library names is less than or equal to the depth information of the top element of the stack, it means that the second row of code library names has no dependency relationship with the top element of the stack, and the third row of code library names in the code library depth information list is traversed. If the depth information of the third row of code library names is greater than the depth information of the top element of the stack, it means that the third row of code library names has a dependency relationship with the top element of the stack, and the third row of code library names can be added to the dependency relationship set corresponding to the top element of the stack. Then, the library name in the third line of code is used as the top element of the stack, and the subsequent traversal process is executed.
[0132] It is understood that the above examples are merely examples listed to better understand the technical solutions of the embodiments of this application, and are not intended to be the only limitation on the embodiments.
[0133] Following a first-in-first-out strategy, after determining the dependencies of each code repository name based on the code repository name and its corresponding depth information in the code repository depth information list, step 603 is executed.
[0134] Step 603: Based on the code library names in the code library name set, the location information corresponding to each code library name, and the dependency relationships, establish the directed graph.
[0135] Location information refers to the position of a code repository name within the set of code repository names.
[0136] Following a first-in, first-out (FIFO) strategy, after determining the dependencies of each code repository name based on its name and corresponding depth information in the code repository depth information list, a directed graph of the target project can be constructed based on the code repository names in the code repository name set, their corresponding position information, and the dependencies between them. In this example, the directed graph can be represented as an adjacency matrix, with the code repository names as the row and column elements, and the position information as the element's location. The dependency values in the specified rows and columns are then updated according to the dependencies, thus obtaining the adjacency matrix. This implementation process can be combined with... Figure 7 The following is a detailed description.
[0137] Reference Figure 7 The flowchart illustrates the steps of an adjacency matrix generation method provided in an embodiment of this application, as follows: Figure 7 As shown, the adjacency matrix generation method may include steps 701 and 702.
[0138] Step 701: Based on the code library name and the location information of the code library name, establish an initial adjacency matrix with the code library name as the row and column elements.
[0139] After obtaining the set of code repository names, an initial adjacency matrix can be constructed using the code repository names and their position information within the set, with the code repository names as row and column elements. Specifically, the initial adjacency matrix can be constructed using the code repository names as row and column elements and the position information as the element's position in the adjacency matrix. For example, if the code repository names in the set are ordered from beginning to end as V0, V1, V2, V3, then V0, V1, V2, V3 can be used as row and column elements, with their order as the element's position, to construct the initial adjacency matrix as shown in Table 1 below.
[0140] Table 1:
[0141] V0 V1 V2 V3
[0142] As shown in Table 1 above, if V0 is in the first position of the code repository name set, then the code repository name V0 is placed in the first row and first column of the adjacency matrix. If V1 is in the second position of the code repository name set, then the code repository name V1 is placed in the second row and second column of the adjacency matrix. If V2 is in the third position of the code repository name set, then the code repository name V2 is placed in the third row and third column of the adjacency matrix. If V3 is in the fourth position of the code repository name set, then the code repository name V3 is placed in the fourth row and fourth column of the adjacency matrix, and so on, to construct the initial adjacency matrix.
[0143] It is understood that the above examples are merely examples listed to better understand the technical solutions of the embodiments of this application, and are not intended to be the only limitation on the embodiments.
[0144] After establishing an initial adjacency matrix with the code repository name as the row and column element based on the code repository name and its location information, proceed to step 702.
[0145] Step 702: Based on the dependencies, update the dependency values at the corresponding positions in the initial adjacency matrix, generate an adjacency matrix corresponding to the target project that indicates the dependencies between the code libraries, and use the adjacency matrix as the directed graph.
[0146] After establishing an initial adjacency matrix with the code repository names as row and column elements based on the code repository names and their location information, the dependency values at corresponding positions in the initial adjacency matrix can be updated according to the dependencies to generate an adjacency matrix indicating the dependencies between code repositories corresponding to the target project. For example, continuing from the example in step 701 above, among code repository names: V0, V1, V2, V3, V0 and V1 have a mutual dependency relationship. Therefore, corresponding dependency values can be added to the first row, second column, and second row, first column. For example, if a dependency exists, the value is 1; if no dependency exists, the value is 0. The resulting adjacency matrix can be shown in Table 2 below:
[0147] Table 2:
[0148] V0 0 1 1 1 V1 0 0 0 1 V2 1 0 0 V3 0 0 0 0
[0149] As shown in Table 2 above, V0 has an application relationship with V1 and V3, and V0 depends on V1 and V3. V1 has a dependency relationship with V3, and V1 depends on V3. V2 has a mutual dependency relationship with V0, that is, V0 and V2 are mutually dependent.
[0150] It is understood that the above examples are merely examples listed to better understand the technical solutions of the embodiments of this application, and are not intended to be the only limitation on the embodiments.
[0151] This application's embodiments establish an adjacency matrix as a directed graph, which significantly reduces the memory usage of the directed graph and improves memory utilization for large codebases. It also solves the problem of layered architecture being unable to be implemented due to non-standard referencing between projects.
[0152] In this embodiment, the directed graph can also be represented in the form of a graph hierarchy, that is, using code repository names as graph nodes. Based on the dependencies between code repository names, connecting edges are established between graph nodes. These connecting edges have pointing edges, which can be used to indicate the dependencies between code repository names. For example, if the graph nodes are A, B, and C, and A is connected to B with the connecting edge pointing from A to B, it indicates that there is a dependency relationship between A and B, and A depends on B. If B is connected to C with the connecting edge pointing bidirectionally, it indicates that there is a dependency relationship between B and C, and B and C depend on each other, and so on.
[0153] After establishing a directed graph of the dependency relationships between the code libraries corresponding to the target project, this application embodiment can quickly analyze whether there are dependencies between the code library to be called and other code libraries when other projects call a code library under the target project. If there are dependencies, the dependency cycle corresponding to the code library can be printed and sent to the developers of other projects so that the developers can solve the dependency problem based on the dependency cycle and call the code library.
[0154] The method for obtaining code repository dependencies provided in this application involves obtaining a dependency list of the code repository corresponding to the target project. Based on the dependency list, depth information of the code repository is obtained. According to the depth information, a directed graph indicating the dependencies between code repositories corresponding to the target project is established, and the dependencies of the code repositories are obtained from the directed graph. This application embodiment, by combining the depth information of the code repositories in the dependency list to establish a directed graph indicating the dependencies between code repositories corresponding to the target project, can quickly analyze code repositories with mutual dependencies, improving the analysis efficiency of code repositories with dependencies and solving the problem that layered architecture cannot be implemented due to non-standard referencing between projects.
[0155] Reference Figure 8 The diagram illustrates a structural schematic of an apparatus for obtaining code library dependencies according to an embodiment of this application. Figure 8 As shown, the device 800 for obtaining codebase dependencies may include the following modules:
[0156] The dependency list retrieval module 810 is used to retrieve the dependency list of the code library corresponding to the target project;
[0157] The depth information acquisition module 820 is used to acquire the depth information of the code library based on the dependency list;
[0158] The directed graph building module 830 is used to build a directed graph corresponding to the target project that indicates the dependency relationship between the code libraries based on the depth information, so as to obtain the dependency relationship of the code libraries based on the directed graph.
[0159] Optionally, the relationship list acquisition module includes:
[0160] The initial list acquisition unit is used to acquire the initial dependency list corresponding to the target project;
[0161] The dependency list generation unit is used to filter invalid information in the initial dependency list and generate the dependency list.
[0162] Optionally, the depth information acquisition module includes:
[0163] The distance information acquisition unit is used to acquire the distance information between the first letter of the code library name corresponding to each line of the dependency list and the left boundary;
[0164] A depth information acquisition unit is used to acquire depth information corresponding to the code library based on the distance information.
[0165] Optionally, the directed graph construction module includes:
[0166] A relation list traversal unit is used to traverse the dependency relation list in a forward-to-back order;
[0167] The code repository name addition unit is used to add the code repository names of the code repositories in the traversed dependency list to the code repository name set in sequence;
[0168] The depth information adding unit is used to add the code library name and the depth information corresponding to the code library name from the traversed dependency list to the code library depth information list in sequence;
[0169] A directed graph building unit is used to build the directed graph based on the set of code library names and the list of code library depth information.
[0170] Optionally, the code repository name addition unit includes:
[0171] The code repository name determination subunit is used to determine whether the target code repository name exists in the set of code repository names after each traversal of a target code repository name;
[0172] The code repository name filtering subunit is used to filter the target code repository name if the target code repository name exists in the set of code repository names;
[0173] The code repository name addition sub-unit is used to add the target code repository name to the code repository name set if the target code repository name does not exist in the code repository name set.
[0174] Optionally, the directed graph building unit includes:
[0175] The depth list traversal sub-unit is used to traverse the code library depth information list in a forward-to-back order.
[0176] The dependency determination subunit is used to determine the dependency relationship corresponding to each code library name in a first-in-first-out (FIFO) strategy, based on the code library name in the code library depth information list and the depth information corresponding to the code library name.
[0177] A directed graph establishment subunit is used to establish the directed graph based on each code library name in the code library name set, the location information corresponding to each code library name, and the dependency relationship.
[0178] Optionally, the directed graph construction subunit includes:
[0179] An initial matrix establishment sub-unit is used to establish an initial adjacency matrix with the code library name as the row and column elements, based on the code library name and the location information of the code library name.
[0180] An adjacency matrix generation subunit is used to update the dependency value at the corresponding position in the initial adjacency matrix according to the dependency relationship, generate an adjacency matrix corresponding to the target project that indicates the dependency relationship between the code libraries, and use the adjacency matrix as the directed graph.
[0181] The apparatus for obtaining code repository dependencies provided in this application embodiment obtains a dependency list of the code repository corresponding to the target project. Based on the dependency list, it obtains the depth information of the code repository. Based on the depth information, it establishes a directed graph indicating the dependencies between the code repositories corresponding to the target project, and obtains the code repository dependencies based on the directed graph. This application embodiment, by combining the depth information of the code repositories in the dependency list to establish a directed graph indicating the dependencies between the code repositories corresponding to the target project, can quickly analyze code repositories with mutual dependencies, improving the analysis efficiency of code repositories with dependencies and solving the problem that layered architecture cannot be implemented due to non-standard referencing between projects.
[0182] This application also provides an electronic device, including: a processor, a memory, and a computer program stored in the memory and executable on the processor. When the computer program is executed by the processor, it implements the various processes of the above-described method embodiment for obtaining code library dependencies and achieves the same technical effect. To avoid repetition, it will not be described again here.
[0183] This application also provides a computer-readable storage medium storing a computer program. When the computer program is executed by a processor, it implements the various processes of the above-described method embodiment for obtaining code library dependencies and achieves the same technical effect. To avoid repetition, it will not be described again here. The computer-readable storage medium may include a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.
[0184] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.
[0185] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in the various embodiments of this application.
[0186] The embodiments of this application have been described above with reference to the accompanying drawings. However, this application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of this application without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of this application.
[0187] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed in this application can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0188] Those skilled in the art will understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0189] In the embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative. For instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.
[0190] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0191] In addition, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0192] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, ROM, RAM, magnetic disks, or optical disks.
[0193] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A method for obtaining code repository dependencies, characterized in that, include: Get the dependency list of the code repository corresponding to the target project. In the dependency list, each line is a code repository name. Based on the dependency list, obtain the depth information of the code repository; Based on the depth information, a directed graph indicating the dependencies between the code libraries corresponding to the target project is constructed, so as to obtain the dependencies between the code libraries based on the directed graph; The step of obtaining the depth information of the code repository based on the dependency list includes: Obtain the distance information between the first letter of the code library name corresponding to each line of the dependency list and the left boundary; Based on the distance information, obtain the depth information corresponding to the code library; The step of establishing a directed graph indicating the dependency relationships between the code repositories corresponding to the target project based on the depth information includes: Traverse the dependency list in reverse order; Add the names of the code libraries in the dependency list that have been traversed to the code library name set in turn; The code library name and the depth information corresponding to the code library name in the traversed dependency list are added to the code library depth information list in sequence; Based on the set of code repository names and the list of code repository depth information, the directed graph is constructed; The step of establishing the directed graph based on the set of code repository names and the list of code repository depth information includes: Traverse the list of code repository depth information in chronological order. Following a first-in-first-out strategy, the dependency relationships corresponding to each code library name are determined sequentially based on the code library name in the code library depth information list and the depth information corresponding to the code library name. Based on the code library names in the code library name set, the location information corresponding to each code library name, and the dependency relationships, the directed graph is established; The process of determining the dependency relationships corresponding to each code repository name according to a first-in, first-out (FIFO) strategy, based on the code repository name in the code repository depth information list and the depth information corresponding to the code repository name, includes: The code library name in the first row of the code library depth information list is used as the top element of the data structure stack; The depth information of the code library name in the second row of the code library depth information list is compared with the depth information of the top element of the stack. If the depth information of the second line of code library name is greater than the depth information of the top element of the stack, it means that the second line of code library name has a dependency relationship with the top element of the stack. In this case, the second line of code library name is added to the dependency relationship set corresponding to the top element of the stack; the first line of code library name is removed from the top of the data structure stack, and the second line of code library name becomes the top element of the stack. If the depth information of the second line of code library name is less than or equal to the depth information of the top element of the stack, it means that the second line of code library name has no dependency relationship with the top element of the stack. In this case, the code library name of the third line in the code library depth information list is traversed. If the depth information of the third line of code library name is greater than the depth information of the top element of the stack, it means that the third line of code library name has a dependency relationship with the top element of the stack. The third line of code library name is added to the dependency relationship set corresponding to the top element of the stack, and the third line of code library name is used as the top element of the stack. The subsequent traversal process is then executed.
2. The method according to claim 1, characterized in that, The process of obtaining the dependency list of the code repository corresponding to the target project includes: Obtain the initial dependency list corresponding to the target project; Filter out invalid information from the initial dependency list to generate the dependency list.
3. The method according to claim 1, characterized in that, The process of adding the code library names from the dependency list that have been traversed to the code library name set in sequence includes: After each traversal of a target code library name, determine whether the target code library name exists in the set of code library names; If the target code library name exists in the set of code library names, then the target code library name is filtered. If the target code library name does not exist in the set of code library names, then the target code library name is added to the set of code library names.
4. The method according to claim 1, characterized in that, The step of establishing the directed graph based on each code repository name in the code repository name set, the location information corresponding to each code repository name, and the dependency relationships includes: Based on the code repository name and the location information of the code repository name, an initial adjacency matrix is established with the code repository name as the row and column elements; Based on the dependencies, update the dependency values at the corresponding positions in the initial adjacency matrix, generate an adjacency matrix corresponding to the target project that indicates the dependencies between the code libraries, and use the adjacency matrix as the directed graph.
5. An apparatus for obtaining code library dependencies, characterized in that, include: The dependency list retrieval module is used to retrieve the dependency list of the code repository corresponding to the target project. In the dependency list, each line represents a code repository name. A depth information acquisition module is used to acquire depth information of the code library based on the dependency list; A directed graph construction module is used to construct a directed graph corresponding to the target project, indicating the dependency relationships between the code libraries, based on the depth information, so as to obtain the dependency relationships of the code libraries based on the directed graph; The depth information acquisition module includes: The distance information acquisition unit is used to acquire the distance information between the first letter of the code library name corresponding to each line of the dependency list and the left boundary; A depth information acquisition unit is used to acquire depth information corresponding to the code library based on the distance information; The directed graph construction module includes: A relation list traversal unit is used to traverse the dependency relation list in a forward-to-back order; The code repository name addition unit is used to add the code repository names of the code repositories in the traversed dependency list to the code repository name set in sequence; The depth information adding unit is used to add the code library name and the depth information corresponding to the code library name from the traversed dependency list to the code library depth information list in sequence; The directed graph construction unit is used to construct the directed graph based on the set of code repository names and the list of code repository depth information. The directed graph construction unit includes: The depth list traversal sub-unit is used to traverse the code library depth information list in a forward-to-back order. The dependency determination subunit is used to determine the dependency relationship corresponding to each code library name in a first-in-first-out (FIFO) strategy, based on the code library name in the code library depth information list and the depth information corresponding to the code library name. A directed graph construction subunit is used to construct the directed graph based on each code library name in the code library name set, the location information corresponding to each code library name, and the dependency relationship; The dependency determination sub-unit is specifically used to: use the code library name in the first row of the code library depth information list as the top element of the data structure stack; traverse the depth information of the code library names in the second row of the code library depth information list and compare it with the depth information of the top element; if the depth information of the second row of code library names is greater than the depth information of the top element, it indicates that there is a dependency relationship between the second row of code library names and the top element, then add the second row of code library names to the dependency set corresponding to the top element; remove the first row of code library names from the top of the data structure stack, and so on. The second line of code library name is used as the top element of the stack. If the depth information of the second line of code library name is less than or equal to the depth information of the top element of the stack, it means that the second line of code library name has no dependency relationship with the top element of the stack. Then, the third line of code library name in the code library depth information list is traversed. If the depth information of the third line of code library name is greater than the depth information of the top element of the stack, it means that the third line of code library name has a dependency relationship with the top element of the stack. The third line of code library name is added to the dependency relationship set corresponding to the top element of the stack, and the third line of code library name is used as the top element of the stack. The subsequent traversal process is then executed.
6. An electronic device, characterized in that, include: A processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the computer program, when executed by the processor, implements the steps of the method for obtaining code library dependencies as described in any one of claims 1 to 4.
7. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the steps of the method for obtaining code library dependencies as described in any one of claims 1 to 4.
Citation Information
Patent Citations
Data processing method and device, electronic equipment and storage medium
CN113419752A
Method and apparatus for distributed systems management
US20020147764A1