Useless dependency analysis method and device, equipment and storage medium
By building an abstract syntax tree and analytical strategies to identify useless dependencies, the problem of unrecognized useless dependencies in the existing technology is solved, and the useless dependency identification and management of various scenario projects is realized, reducing risks and complexity.
Patent Information
- Application Number
- CN202510653183.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-20
- Publication Date
- 2025-08-15
AI Technical Summary
The existing technology cannot effectively identify and remove useless dependencies in various scenarios, resulting in problems such as intellectual property infringement risks, commercial secret leakage, bloated project dependency lists, and opaque legal liability.
By obtaining the service side of the project to be analyzed, matching the corresponding useless dependency analysis strategy, building an abstract syntax tree, analyzing the useless dependencies of the client, identifying conflicting dependencies and unused dependencies, and integrating them into the CI/CD process for automated detection.
It realizes useless dependence identification for various scenario projects, reduces the risk of intellectual property infringement, simplifies dependency management, improves legal transparency, and reduces the operational complexity of technicians.
Smart Images

Figure CN120492027A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of computer software technology and is applied to the fields of financial technology and medical health, and in particular relates to an analysis method, device, equipment and storage medium for useless dependencies. Background Art
[0002] During project development, there may be many unused dependencies. These dependencies are no longer used by the actual code, but they still remain in the project. The existence of unused dependencies in the project can cause many problems.
[0003] First, useless dependencies may carry strict licensing requirements. Even if the project itself no longer relies on these useless dependencies, these licensing requirements may still affect the project's legitimacy and increase the risk of intellectual property infringement. For example, in the fintech insurance sector, such as internet auto insurance, the risk of intellectual property infringement may cause the insurance company to violate the "Internet Insurance Business Supervision Measures" and be prohibited from conducting innovative business. Open source agreements with useless dependencies may also force projects to open source, leading to the disclosure of trade secrets. Similarly, in the healthcare insurance sector, such as health insurance, the risk of intellectual property infringement may also cause health insurance products to violate the Insurance Law and the Personal Information Protection Law.
[0004] In addition, as useless dependencies accumulate, the dependency list in the project becomes bloated, open source governance becomes more cumbersome, the workload of review and management increases, and omissions are prone to occur.
[0005] Furthermore, the dependency chain of a project is often complex, and useless dependencies may be hidden in multiple layers of dependencies, increasing the opacity of licensing and security, making it difficult for the team to fully grasp all legal responsibilities.
[0006] To this end, related fields often use Maven dependency:analyze, a tool for identifying useless dependencies, to scan for useless dependencies. However, Maven dependency:analyze only supports scanning useless dependencies for Java projects and can only be executed through the command line.
[0007] It is understandable that if you only scan the useless dependencies of Java projects, you will not be able to scan the useless dependencies of projects in other scenarios (such as Vue projects). Summary of the Invention
[0008] The present invention provides a useless dependency analysis method, apparatus, device and storage medium to solve the technical problem in the prior art that useless dependencies of projects in various scenarios cannot be identified.
[0009] In a first aspect, the present invention provides a method for analyzing useless dependencies, comprising:
[0010] Get the project to be analyzed;
[0011] Analyzing the service side of the project to be analyzed;
[0012] For the service side, matching the analysis strategy of useless dependencies corresponding to the service side;
[0013] When the service side is a client, constructing an abstract syntax tree corresponding to the client according to the program file of the client;
[0014] According to the abstract syntax tree, useless dependencies of the project to be analyzed on the client are obtained.
[0015] In a second aspect, the present invention provides an analysis device for useless dependencies, comprising:
[0016] Acquisition module, used to obtain the project to be analyzed;
[0017] A scenario analysis module, configured to analyze the service side of the project to be analyzed, wherein the service side includes a server side and a client side;
[0018] A matching module, configured to match, with respect to the service side, an analysis strategy for useless components corresponding to the service side;
[0019] A construction module, configured to construct an abstract syntax tree corresponding to the client according to the program files of the client when the service side is the client;
[0020] The useless dependency analysis module is used to analyze and obtain useless dependencies of the project to be analyzed on the client side according to the abstract syntax tree.
[0021] In a third aspect, a computer device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above-mentioned useless dependency analysis method when executing the computer program.
[0022] In a fourth aspect, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the above-mentioned useless dependency analysis method are implemented.
[0023] The solution implemented by the above-mentioned useless dependency analysis method, device, equipment and storage medium provides corresponding useless dependency analysis strategies for different service sides, and also provides detailed analysis strategies for useless dependencies of the client, i.e., the front-end. Therefore, it can be understood that the present invention can not only identify useless dependencies of projects in various scenarios, but also, since the Java project is located in the back-end, the present invention can also identify useless dependencies of projects in scenarios that cannot be identified in the prior art. In addition, when analyzing the useless dependencies of the client in the present invention, it is obtained through abstract syntax tree analysis, thereby avoiding the problem that the tools used to identify useless dependencies in the prior art need to be executed through command lines, which requires high technical personnel. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments of the present invention. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0025] Figure 1 1 is a flow chart of a method for analyzing useless dependencies according to an embodiment of the present invention;
[0026] Figure 2 yes Figure 1 A flow chart of step S130;
[0027] Figure 3 yes Figure 1 Another flowchart of step S130;
[0028] Figure 4 yes Figure 3 A flow chart of step S1324;
[0029] Figure 5 yes Figure 1 A flow chart of step S150;
[0030] Figure 6 yes Figure 5 A flow chart of step S1515;
[0031] Figure 7 yes Figure 1 Another flowchart of step S150;
[0032] Figure 8 is a structural schematic diagram of a useless dependency analysis device according to an embodiment of the present invention;
[0033] Figure 9 is a structural diagram of a computer device in one embodiment of the present invention;
[0034] Figure 10 FIG. 2 is another structural diagram of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0035] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of them. All other embodiments obtained by ordinary technicians in this field based on the embodiments of the present invention without making any creative efforts shall fall within the scope of protection of the present invention.
[0036] Figure 1 A flowchart of a useless dependency analysis method provided by an embodiment of the present invention is shown in FIG. Figure 1 As shown, the useless dependency analysis method provided by the embodiment of the present invention includes the following steps.
[0037] Step S110: Obtain the item to be analyzed.
[0038] It should be noted that the project to be analyzed is a project that requires useless dependency analysis.
[0039] As a specific example, in the fintech insurance sector, the project to be analyzed might be an intelligent pricing platform for online auto insurance, which uses complex algorithms to calculate auto insurance premiums in real time based on multi-dimensional information such as vehicle usage data and driver driving habits. During project development, various data analysis toolkits may be introduced for data pre-training and model training. However, as the project progresses, some toolkits are no longer used, and some external interfaces used for testing market data early on become unused dependencies due to not being formally adopted.
[0040] As another specific example, in the healthcare insurance sector, the project to be analyzed might be an intelligent underwriting system for health insurance, which draws on user health data and medical records, combines them with algorithmic models to assess risk, and deliver underwriting results. During the development process, temporary data generation dependencies for testing and machine learning framework plugins that were tried but not adopted in the early stages may be introduced. As the system iterates, these dependencies are no longer used and become unused.
[0041] Step S120, analyzing the service side of the project to be analyzed;
[0042] It should be noted that in this step, the service side of the project to be analyzed refers to the location where the service of the project to be analyzed is provided. For example, the service side of the project to be analyzed can be the client, which can be called the front end. The service side of the project to be analyzed can also be the server, which can also be called the back end.
[0043] Step S130: For the service side, matching the useless dependency analysis strategy corresponding to the service side.
[0044] It should be noted that for different service sides, the useless dependency analysis strategy corresponding to the corresponding service side can be matched according to the characteristics of the service side, so that the useless dependency analysis strategy can be obtained quickly and / or accurately enough.
[0045] In some embodiments of the present invention, Figure 2 As shown, step S130 includes the following steps.
[0046] Step S1311 , when the service side is a client, analyzing the configuration file and lock file of the project to be analyzed.
[0047] It's important to note that the configuration file is a project metadata file manually maintained by the developer for the project being analyzed. It declares the required dependency types, version ranges, and other project information. It determines which dependencies the project requires and how it interacts with them. The lock file is automatically generated and maintained by the package manager. It records the exact versions, hash values, and sub-dependencies of all dependencies actually installed by the analyzed project. This ensures that dependencies are installed consistently across different environments.
[0048] As a specific example, when the service side is a client (front-end), the front-end architecture it depends on may be Vue, then the configuration file of the project to be analyzed is package.json, and the lock file of the project to be analyzed is package-lock.json.
[0049] Step S1312: construct a dependency tree corresponding to the project to be analyzed based on the configuration file and the lock file.
[0050] Specifically, in this step, the direct dependency list can be extracted from the configuration file, and the precise versions and sub-dependencies of all dependencies can be extracted from the lock file. In this way, the direct dependency can be used as the root node, and the sub-dependencies of each dependency can be recursively parsed to eventually form a tree-structured dependency tree containing hierarchy, version, and dependency path. Each node of the dependency tree represents a dependency package, and the edge represents the dependency relationship. It can be understood that when the root node is a direct dependency, the first layer of the dependency tree is the direct dependency, the second layer of the dependency tree is the sub-dependency of the direct dependency, and so on, to obtain the complete structure of the dependency tree. In the dependency tree, different versions of the same dependency can be marked, and the path by which a dependency is introduced can be recorded.
[0051] Step S1313: Analyze the dependency tree to obtain conflicting dependencies.
[0052] It should be noted that conflicting dependencies in this step are dependencies that conflict at runtime. These conflicts may cause errors or redundancy in the project runtime. For example, conflicting dependencies can be version conflicts, which cause different versions of the same dependency to be simultaneously imported by multiple parent dependencies, resulting in version conflicts. Conflicting dependencies can also be duplicate dependencies, which cause the same version of the same dependency to be imported multiple times, resulting in package size bloat.
[0053] Specifically, the method of analyzing the dependency tree to obtain conflicting dependencies can be any feasible method. For example, the dependency tree can be traversed, different version nodes of the same dependency can be compared, conflicting paths and specific version differences can be marked, and the final conflicting dependencies can be obtained.
[0054] Step S1314: Determine useless dependencies based on the conflicting dependencies.
[0055] Finally, the conflicting dependencies can be determined as useless dependencies.
[0056] In some embodiments of the present invention, Figure 3 As shown, step S130 includes the following steps.
[0057] Step S1321: When the service side is a server, source code is obtained and the source code is compiled to obtain bytecode.
[0058] It should be understood that the service side is the server side, that is, the service side is the backend, and the backend source code (java) will be compiled into a bytecode file for execution.
[0059] Step S1322: Analyze the bytecode to obtain the dependencies actually used in the project to be analyzed.
[0060] Furthermore, on the backend, dependencies are statically determined at compile time, and the dependency paths are relatively fixed at runtime. This allows us to analyze the bytecode to obtain the dependencies actually used by the project being analyzed at runtime.
[0061] Step S1323: Obtain pre-declared dependencies in the project to be analyzed.
[0062] It can be understood that, in this step, the dependencies pre-declared by the project to be analyzed may be dependencies declared in a configuration file corresponding to the project to be analyzed.
[0063] Step S1324 : Determine useless dependencies in the pre-declared dependencies based on the pre-declared dependencies and the actually used dependencies.
[0064] In this way, removing the actually used dependencies from the pre-declared dependencies naturally results in unused dependencies, and the unused dependencies are useless dependencies among the pre-declared dependencies.
[0065] In some embodiments of the present invention, Figure 4 As shown, step S1324 includes the following steps.
[0066] Step S13241: Determine candidate useless dependencies among the pre-declared dependencies based on the pre-declared dependencies and the actually used dependencies.
[0067] It can be understood that the candidate unused dependencies in the pre-declared dependencies are dependencies that are not used in the pre-declared dependencies.
[0068] Step S13242, obtaining the preset whitelist dependency in the configuration file.
[0069] It should be noted that some dependencies may not be used in certain situations, but are essential. To avoid these dependencies being excluded as useless dependencies, you can define them as preset whitelist dependencies in the configuration file in advance.
[0070] Step S13243, filtering the preset whitelist dependencies in the candidate useless dependencies to obtain the final useless dependencies.
[0071] In this way, the preset whitelist dependencies in the candidate useless dependencies can be filtered out, which can prevent the preset whitelist dependencies from being excluded as useless dependencies.
[0072] Step S140 : When the service side is a client, construct an abstract syntax tree corresponding to the client according to the program files of the client.
[0073] It's important to note that when the server is a client, that is, when the server is a front-end, there will be dynamic loading syntax or plug-in mechanisms, which complicates the dependency relationship. Abstract syntax tree technology can parse dynamic syntax and track the actual dependency path of the project being analyzed during runtime, thus accurately identifying useless dependencies.
[0074] Step S150: Analyze and obtain useless dependencies of the project to be analyzed on the client side according to the abstract syntax tree.
[0075] It should be noted that in this step, useless dependencies refer to dependencies that will not be used for various reasons. For example, they can be dependencies that are not actually used in the project to be analyzed, or they can be dependencies that are abandoned due to errors, or they can be dependencies that are abandoned due to conflicts with other dependencies.
[0076] In some embodiments of the present invention, Figure 5 As shown, step S150 includes the following steps.
[0077] Step S1511: Obtain the components imported by the client, the registered component mapping table, and the template according to the abstract syntax tree.
[0078] The registered component mapping table is a mapping relationship table between registered component names and imported component names.
[0079] Specifically, in this step, the import and require statements can be analyzed through the abstract syntax tree to extract the component path and name. The component registration logic (such as Vue.use()) can also be analyzed through the abstract syntax tree to obtain the registered component mapping table. The SFC (Single File Component) file can also be parsed. <template>The tag gets the template content.
[0080] Step S1512: determining, based on the registered component mapping table, a first unregistered useless component among the imported components.
[0081] Specifically, in this step, all imported components can be traversed to check whether there is a corresponding entry in the registered component mapping table. If not, it is marked as the first useless component.
[0082] Step S1513: traverse the template to obtain the component tag name used by the template.
[0083] Specifically, in this step, the abstract syntax tree may be used to extract the name of the label node of the corresponding template in the abstract syntax tree to obtain the component label name used by the template.
[0084] Step S1514: Determine, based on the component tag name and the registered component name, a second useless component in the registered components that is not used by the template.
[0085] Step S1515: Analyze and obtain unused useless dependencies based on the first useless component and the second useless component.
[0086] Specifically, the first useless component and the second useless component may be associated with their dependent modules, and the ultimately unused useless dependencies may be screened from these dependent modules.
[0087] In some embodiments of the present invention, Figure 6 As shown, step S1515 includes the following steps.
[0088] Step S15151, obtain the data source.
[0089] Specifically, the data source in this step is all the necessary data for building the dependency tree, including the project's dependency declaration files, module import relationships, and component registration information. For example, dependency declaration files can be obtained from package.json, yarn.lock, and package-lock.json. Module import relationships can be obtained by parsing source code files using an abstract syntax tree, extracting import / require statements or dependency injection annotations. Component registration information can be obtained by parsing component registration information.
[0090] Step S15152: construct a dependency tree based on the data source.
[0091] The dependency tree is a tree structure used to describe the dependencies of a target project and the hierarchical relationships between dependencies.
[0092] Step S15153: recursively detect the dependency tree and analyze that all referenced components are unused dependencies of useless components.
[0093] It is understandable that if all components referenced by a dependency are useless components, then this dependency can be considered an unused dependency.
[0094] In some embodiments of the present invention, Figure 7 As shown, step S150 includes the following steps.
[0095] Step S1521: Analyze the abstract syntax tree to obtain actual usage scenarios of target dependencies.
[0096] It's understandable that in this step, parsing the abstract syntax tree can identify how the target dependency is actually used in the code. Specifically, in this step, all statements that import dependencies in the code can be checked to track whether the imported dependencies are actually called in subsequent code. This can then be used to analyze whether the dependencies are only used under specific conditions, thereby identifying on-demand loading scenarios, i.e., actual usage scenarios.
[0097] Step S1522: Analyze the configuration file of the project to be analyzed to obtain the declared usage scenario of the target dependency.
[0098] It is understandable that in the configuration file of the project to be analyzed, the usage scenarios of the declared dependencies will be configured, that is, the expected usage scenarios of the dependencies.
[0099] Step S1523 : When the declared usage scenario of the target dependency is different from the actual usage scenario, the target dependency is determined as a useless dependency of the project to be analyzed on the client.
[0100] It is understandable that the declared usage scenario of the target dependency is the expected usage scenario of the target dependency based on actual needs. If the scenario in which the target dependency is actually used is different from the expected usage scenario, it may cause problems.
[0101] It is understandable that, through the above-mentioned embodiments of the invention, for different service sides, the corresponding useless dependency analysis strategy is matched and provided, and the analysis strategy of useless dependencies of the client, i.e., the front end, is also provided in detail. Therefore, it can be understood that the present invention can not only identify useless dependencies of projects in various scenarios, but also, since the Java project is located at the back end, the present invention can also identify useless dependencies of projects in scenarios that cannot be identified in the prior art. In addition, when analyzing the useless dependencies of the client in the present invention, it is obtained through abstract syntax tree analysis, thereby avoiding the problem that the tools used to identify useless dependencies in the prior art need to be executed through command lines, which requires high technical personnel.
[0102] In an optional approach, the above useless dependency analysis method can be integrated into the CI (Continuous Integration) and CD (Continuous Deployment) processes, so that useless dependencies can be automatically detected.
[0103] It should be understood that the order of execution of the steps in the above embodiments does not necessarily imply a specific order of execution. The order of execution of each process should be determined by its function and inherent logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention. The software tools or components not provided by our company that appear in the embodiments of this application are merely examples and do not represent actual use.
[0104] In one embodiment, a useless dependency analysis device is provided, which corresponds to the useless dependency analysis method in the above embodiment. Figure 8 As shown, the analysis device includes an acquisition module 810, a scene analysis module 820, a matching module 830, a construction module 840, and a useless dependency analysis module 850. The functional modules are described in detail as follows:
[0105] An acquisition module 810 is used to acquire items to be analyzed;
[0106] A scenario analysis module 820 is configured to analyze the service side of the project to be analyzed;
[0107] A matching module 830 is configured to match, with respect to the service side, an analysis strategy for useless dependencies corresponding to the service side;
[0108] A construction module 840 is configured to construct an abstract syntax tree corresponding to the client according to the client's program files when the service side is the client;
[0109] The useless dependency analysis module 850 is configured to analyze and obtain useless dependencies of the project to be analyzed on the client side according to the abstract syntax tree.
[0110] In one embodiment, the useless dependency analysis module 850 is specifically configured to:
[0111] According to the abstract syntax tree, obtaining the component imported by the client, a registered component mapping table, and a template, wherein the registered component mapping table is a mapping relationship table between registered component names and imported component names;
[0112] Determining, according to the registered component mapping table, a first unregistered useless component among the imported components;
[0113] Traverse the template and get the component tag name used by the template;
[0114] According to the component tag name and the registered component name, determining a second useless component in the registered components that is not used by the template;
[0115] Unused useless dependencies are obtained through analysis based on the first useless component and the second useless component.
[0116] In one embodiment, the useless dependency analysis module 850 is further configured to:
[0117] Get the data source;
[0118] Constructing a dependency tree based on the data source, wherein the dependency tree is a tree structure used to describe the dependencies of the target project and the hierarchical relationships between the dependencies;
[0119] The dependency tree is recursively checked and analyzed to find that the referenced components are all unused dependencies of useless components.
[0120] In one embodiment, the useless dependency analysis module 850 is specifically configured to:
[0121] Analyze the abstract syntax tree to obtain actual usage scenarios of target dependencies;
[0122] Analyze the configuration file of the project to be analyzed to obtain the declared usage scenario of the target dependency;
[0123] When the declared usage scenario of the target dependency is different from the actual usage scenario, the target dependency is determined as a useless dependency of the project to be analyzed on the client.
[0124] In one embodiment, the matching module 830 is specifically configured to:
[0125] When the service side is a client, analyzing the configuration file and the lock file of the project to be analyzed;
[0126] Constructing a dependency tree corresponding to the project to be analyzed according to the configuration file and the lock file;
[0127] Analyze the dependency tree to obtain conflicting dependencies;
[0128] Determine useless dependencies based on the conflicting dependencies.
[0129] In one embodiment, the matching module 830 is specifically configured to:
[0130] When the service side is a server side, obtaining source code, and compiling the source code to obtain bytecode;
[0131] Analyze the bytecode to obtain the dependencies actually used in the project to be analyzed;
[0132] Obtain pre-declared dependencies in the project to be analyzed;
[0133] Determine useless dependencies in the pre-declared dependencies according to the pre-declared dependencies and actually used dependencies.
[0134] In one embodiment, the matching module 830 is further configured to:
[0135] Determining, according to the pre-declared dependencies and the actually used dependencies, candidate useless dependencies among the pre-declared dependencies;
[0136] Get the preset whitelist dependencies in the configuration file;
[0137] Filter the preset whitelist dependencies in the candidate useless dependencies to obtain the final useless dependencies.
[0138] The present invention provides an analysis device for useless dependencies, which matches and provides corresponding analysis strategies for useless dependencies for different service sides, and also provides detailed analysis strategies for useless dependencies of the client, i.e., the front end. Therefore, it can be understood that the present invention can not only identify useless dependencies of projects in various scenarios, but also identify useless dependencies of projects in scenarios that cannot be identified in the prior art because the Java project is located in the back end. In addition, when analyzing useless dependencies of the client, the present invention obtains them through abstract syntax tree analysis, thereby avoiding the problem that the tools used to identify useless dependencies in the prior art need to be executed through command lines, which requires high technical personnel.
[0139] For the specific definition of the useless dependency analysis device, please refer to the definition of the useless dependency analysis method above, which will not be repeated here. The various modules in the above-mentioned useless dependency analysis device can be implemented in whole or in part by software, hardware, and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
[0140] Based on the above useless dependency analysis method, such as Figure 9 As shown, an embodiment of the present invention further provides a schematic structural diagram of a useless dependency analysis device, which includes a processor 91 and a memory 92 coupled to the processor 91. The memory 92 stores a computer program, which, when executed by the processor 91, causes the processor 91 to perform the steps of the service parameter prediction method in the above embodiment.
[0141] For other details about how the processor 91 in the above-mentioned business parameter prediction device implements the above-mentioned technical solution, please refer to the description of the business parameter prediction method provided in the above-mentioned invention embodiment, which will not be repeated here.
[0142] Among them, the processor 91 can also be called a CPU (Central Processing Unit), and the processor 91 may be an integrated circuit chip with signal processing capabilities; the processor 91 can also be a general-purpose processor, DSP (Digital Signal Process), ASIC (Application Specific Integrated Circuit), FPGA (Field Programmable Gate Array) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, among which the general-purpose processor can be a microprocessor or the processor 91 can also be any conventional processor, etc.
[0143] like Figure 10 As shown, an embodiment of the present invention further provides a schematic diagram of the structure of a computer-readable storage medium, on which a readable computer program 101 is stored; wherein, the computer program 101 can be stored in the above-mentioned storage medium in the form of a software product, including a number of instructions for causing a computer device (which can be a personal computer, server, or network device, etc.) or a processor to execute all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: a USB flash drive, a mobile hard disk, a magnetic disk or an optical disk, a ROM (Read-Only Memory), a RAM (Random Access Memory), and other media that can store program code, or a terminal device such as a computer, server, mobile phone, or tablet.
[0144] In the several embodiments provided by the present invention, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of the modules is merely a logical function division. In actual implementation, there may be other division methods, such as multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interface, device or module, which can be electrical, mechanical or other forms.
[0145] The modules described as separate components may or may not be physically separate, and the components shown as modules may or may not be physical modules, that is, they may be located in one place or distributed across multiple network modules. Some or all of the modules may be selected to achieve the purpose of the present embodiment according to actual needs.
[0146] In addition, the functional modules in the various embodiments of the present invention may be integrated into a single processing module, each module may exist physically separately, or two or more modules may be integrated into a single module. The integrated modules may be implemented in the form of hardware or software functional modules. If the integrated modules are implemented in the form of software functional modules and sold or used as independent products, they may be stored in a computer-readable storage medium.
[0147] In the above embodiments, all or part of the embodiments may be implemented by software, hardware, firmware, or any combination thereof. When implemented by software, all or part of the embodiments may be implemented in the form of a computer program product.
[0148] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present invention is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from one website, computer, server or data center to another website, computer, server or data center via a wired (e.g., coaxial cable, optical fiber, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.) method. The computer-readable storage medium can be any available medium that a computer can store or a data storage device such as a server or data center that includes one or more available media integrated. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium), or a semiconductor medium (e.g., an SSD (solid state disk)).
[0149] The technical solution provided by the present invention is introduced in detail above. Specific examples are used in the present invention to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the idea of the present invention, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as limiting the present invention.
[0150] It will be understood by those skilled in the art that embodiments of the present invention may be provided as methods, systems, or computer program products. Thus, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware. Furthermore, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, optical storage, etc.) containing computer-usable program code.
[0151] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to the present invention. It should be understood that each process and / or block in the flowcharts and / or block diagrams, as well as combinations of processes and / or blocks in the flowcharts and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowcharts and / or block diagrams. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0152] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.
[0153] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0154] Obviously, those skilled in the art may make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if such changes and modifications fall within the scope of the claims and their equivalents, the present invention is intended to include such changes and modifications.< / template>
Claims
1. A useless dependency analysis method, characterized in that: include: Get the project to be analyzed; Analyzing the service side of the project to be analyzed; For the service side, matching the analysis strategy of useless dependencies corresponding to the service side; When the service side is a client, constructing an abstract syntax tree corresponding to the client according to the program file of the client; According to the abstract syntax tree, useless dependencies of the project to be analyzed on the client are obtained.
2. The useless dependency analysis method according to claim 1, characterized in that: Analyzing and obtaining useless dependencies of the project to be analyzed on the client according to the abstract syntax tree includes: According to the abstract syntax tree, obtaining the component imported by the client, a registered component mapping table, and a template, wherein the registered component mapping table is a mapping relationship table between registered component names and imported component names; Determining, according to the registered component mapping table, a first unregistered useless component among the imported components; Traverse the template and get the component tag name used by the template; According to the component tag name and the registered component name, determining a second useless component in the registered components that is not used by the template; Unused useless dependencies are obtained through analysis based on the first useless component and the second useless component.
3. The method for analyzing useless dependencies according to claim 2, wherein: The step of analyzing the first useless component and the second useless component to obtain unused useless dependencies includes: Get the data source; Constructing a dependency tree based on the data source, wherein the dependency tree is a tree structure used to describe the dependencies of the target project and the hierarchical relationships between the dependencies; The dependency tree is recursively checked and analyzed to find that the referenced components are all unused dependencies of useless components.
4. The method for analyzing useless dependencies according to claim 1, wherein: Analyzing and obtaining useless dependencies of the project to be analyzed on the client according to the abstract syntax tree includes: Analyze the abstract syntax tree to obtain actual usage scenarios of target dependencies; Analyze the configuration file of the project to be analyzed to obtain the declared usage scenario of the target dependency; When the declared usage scenario of the target dependency is different from the actual usage scenario, the target dependency is determined as a useless dependency of the project to be analyzed on the client.
5. The useless dependency analysis method according to claim 1, characterized in that: The analysis strategy for matching the useless components corresponding to the service side with respect to the service side includes: When the service side is a client, analyzing the configuration file and the lock file of the project to be analyzed; Constructing a dependency tree corresponding to the project to be analyzed according to the configuration file and the lock file; Analyze the dependency tree to obtain conflicting dependencies; Determine useless dependencies based on the conflicting dependencies.
6. The useless dependency analysis method according to claim 1, characterized in that: The analysis strategy for matching the useless components corresponding to the service side with respect to the service side includes: When the service side is a server side, obtaining source code, and compiling the source code to obtain bytecode; Analyze the bytecode to obtain the dependencies actually used in the project to be analyzed; Obtain pre-declared dependencies in the project to be analyzed; Determine useless dependencies in the pre-declared dependencies according to the pre-declared dependencies and actually used dependencies.
7. The useless dependency analysis method according to claim 6, characterized in that: The determining, based on the pre-declared dependencies and the actually used dependencies, of useless dependencies in the pre-declared dependencies includes: Determining, according to the pre-declared dependencies and the actually used dependencies, candidate useless dependencies among the pre-declared dependencies; Get the preset whitelist dependencies in the configuration file; Filter the preset whitelist dependencies in the candidate useless dependencies to obtain the final useless dependencies.
8. A useless dependency analysis device, characterized in that: include: Acquisition module, used to obtain the project to be analyzed; A scenario analysis module, configured to analyze the service side of the project to be analyzed; A matching module, configured to match, with respect to the service side, an analysis strategy for useless dependencies corresponding to the service side; A construction module, configured to construct an abstract syntax tree corresponding to the client according to the program files of the client when the service side is the client; The useless dependency analysis module is used to analyze and obtain useless dependencies of the project to be analyzed on the client side according to the abstract syntax tree.
9. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the processor implements the steps of the useless dependency analysis method according to any one of claims 1 to 7.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the useless dependency analysis method according to any one of claims 1 to 7 are implemented.
Citation Information
Cited By
Authority management method, electronic equipment and computer readable medium
CN121283774A