CN112748952A - Method, device, equipment and storage medium for detecting ring dependency relationship - Google Patents
Method, device, equipment and storage medium for detecting ring dependency relationship Download PDFInfo
- Publication number
- CN112748952A CN112748952A CN201911047129.7A CN201911047129A CN112748952A CN 112748952 A CN112748952 A CN 112748952A CN 201911047129 A CN201911047129 A CN 201911047129A CN 112748952 A CN112748952 A CN 112748952A
- Authority
- CN
- China
- Prior art keywords
- function module
- module
- dependency
- function
- current
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000000034 method Methods 0.000 title claims abstract description 47
- 238000001514 detection method Methods 0.000 claims abstract description 155
- 230000006870 function Effects 0.000 claims description 376
- 230000001419 dependent effect Effects 0.000 claims description 17
- 230000008030 elimination Effects 0.000 claims description 7
- 238000003379 elimination reaction Methods 0.000 claims description 7
- 238000004590 computer program Methods 0.000 claims description 5
- 238000010586 diagram Methods 0.000 description 4
- 230000003287 optical effect Effects 0.000 description 3
- 230000009286 beneficial effect Effects 0.000 description 2
- 238000013500 data storage Methods 0.000 description 2
- 230000000644 propagated effect Effects 0.000 description 2
- 230000008878 coupling Effects 0.000 description 1
- 238000010168 coupling process Methods 0.000 description 1
- 238000005859 coupling reaction Methods 0.000 description 1
- 238000013523 data management Methods 0.000 description 1
- 238000000354 decomposition reaction Methods 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 239000000835 fiber Substances 0.000 description 1
- 238000010295 mobile communication Methods 0.000 description 1
- 239000003607 modifier Substances 0.000 description 1
- 239000013307 optical fiber Substances 0.000 description 1
- 230000008707 rearrangement Effects 0.000 description 1
- 239000004065 semiconductor Substances 0.000 description 1
- 239000007787 solid Substances 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/70—Software maintenance or management
- G06F8/75—Structural analysis for program understanding
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- General Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Stored Programmes (AREA)
Abstract
The embodiment of the invention discloses a method, a device, equipment and a storage medium for detecting a ring dependency relationship, wherein the method comprises the following steps: acquiring at least two functional modules and a detection protocol object in each functional module, wherein the object type of the detection protocol object is the type of a preset detection interface protocol; calling a dependency detection function in each detection protocol object, and determining a function module dependency set formed by other function modules which are depended on when each function module is initialized; and determining each target function module with an annular dependency relationship according to the function module dependency set corresponding to each function module. By the technical scheme of the embodiment of the invention, the functional module with the annular dependency relationship during initialization can be detected in real time, so that the normal operation of the initialization of the functional module is ensured.
Description
Technical Field
The present invention relates to computer technologies, and in particular, to a method, an apparatus, a device, and a storage medium for detecting a ring dependency relationship.
Background
In order to improve the development efficiency of the application software, software development is generally performed in a functional modularization manner, that is, each function in the application software is divided into corresponding functional modules for software development. For example, a functional module responsible for user login is used as a login module; and the function module for receiving, analyzing, sending and the like the bullet screen message is used as a bullet screen module and the like.
Currently, each functional module in application software developed based on an Android system needs to be initialized one by one before use. However, the inventor has found that in the initialization process, a ring dependency relationship may exist among a plurality of functional modules, for example, when the functional module a is initialized, the functional module B needs to depend on the functional module a to complete the initialization, so that a ring dependency relationship is formed, and the whole initialization logic cannot be completed normally and smoothly.
Disclosure of Invention
The embodiment of the invention provides a method, a device, equipment and a storage medium for detecting an annular dependency relationship, which are used for detecting a functional module with the annular dependency relationship during initialization in real time so as to ensure the normal operation of the initialization of the functional module.
In a first aspect, an embodiment of the present invention provides a method for detecting a ring dependency relationship, including:
acquiring at least two functional modules and a detection protocol object in each functional module, wherein the object type of the detection protocol object is the type of a preset detection interface protocol;
calling a dependency detection function in each detection protocol object, and determining a function module dependency set formed by other function modules which are depended on when each function module is initialized;
and determining each target function module with an annular dependency relationship according to the function module dependency set corresponding to each function module.
In a second aspect, an embodiment of the present invention further provides a device for detecting a ring dependency relationship, including:
the device comprises a detection protocol object acquisition unit, a detection interface protocol acquisition unit and a detection protocol object acquisition unit, wherein the detection protocol object acquisition unit is used for acquiring at least two functional modules and a detection protocol object in each functional module, and the object type of the detection protocol object is the type of a preset detection interface protocol;
a functional module dependency set determination unit to: calling a dependency detection function in each detection protocol object, and determining a function module dependency set formed by other function modules which are depended on when each function module is initialized;
and the target function module determining unit is used for determining each target function module with annular dependency relationship according to the function module dependency set corresponding to each function module.
In a third aspect, an embodiment of the present invention further provides an apparatus, where the apparatus includes:
one or more processors;
a memory for storing one or more programs;
when the one or more programs are executed by the one or more processors, the one or more processors implement the method for detecting a ring dependency as provided by any of the embodiments of the present invention.
In a fourth aspect, the embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the method for detecting a ring dependency provided in any embodiment of the present invention.
The embodiment of the invention creates a detection protocol object with an object type as a preset detection interface protocol type in each function module in advance, so that other function modules depended on by each function module in the initialization process can be automatically determined by calling a dependence detection function in each detection protocol object, the other function modules form a function module dependence set, and each target function module with annular dependence is determined according to the function module dependence set corresponding to each function module, so that each target function module with annular dependence can be exposed, developers can correspondingly adjust the target function modules, the annular dependence is avoided, and the normal operation of the initialization of the function modules can be ensured.
Drawings
Fig. 1 is a flowchart of a method for detecting a ring dependency according to an embodiment of the present invention;
fig. 2 is a flowchart of a method for detecting a ring dependency according to a second embodiment of the present invention;
fig. 3 is a schematic structural diagram of a detection apparatus for detecting a circular dependency relationship according to a third embodiment of the present invention;
fig. 4 is a schematic structural diagram of an apparatus according to a fourth embodiment of the present invention.
Detailed Description
The present invention will be described in further detail with reference to the accompanying drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the invention and are not limiting of the invention. It should be further noted that, for the convenience of description, only some of the structures related to the present invention are shown in the drawings, not all of the structures.
Example one
Fig. 1 is a flowchart of a method for detecting a ring dependency according to an embodiment of the present invention, which is applicable to detecting whether a ring dependency exists when at least two function modules are initialized in application software. The method can be executed by a detection device of the annular dependency relationship, the device can be realized in a software and/or hardware mode, and is integrated in equipment with an Android system, such as an intelligent terminal like a smart phone, a tablet computer, a smart television or a notebook computer. The method specifically comprises the following steps:
s110, acquiring at least two functional modules and a detection protocol object in each functional module, wherein the object type of the detection protocol object is a preset detection interface protocol type.
Functional modules may refer to a collection of program elements such as data descriptions and executable statements. Each functional module may contain a plurality of classes, each class containing a description of data and a set of functions to manipulate data or pass messages, and the corresponding specific function is implemented by initializing the respective class, i.e. initializing the functional module. The detection protocol object can be pre-established in the functional module, and the object type is an object of a preset detection interface protocol type. Each function module comprises a detection protocol object. The preset detection interface protocol type may refer to an object type that is inherited by the preset detection interface protocol in advance.
The preset detection interface protocol may be predefined and is used to detect the protocol of another functional module that is relied on when a certain functional module is initialized. The preset detection interface protocol may include a predefined dependency detection function, so as to automatically detect other function modules depended on during initialization based on the dependency detection function.
Illustratively, a preset detection interface protocol may be predefined, and the preset detection interface protocol includes a predefined dependent detection function that is not implemented by a function. For example, the preset detection interface protocol may be defined as:
Public interface ICheckDependence{
Public int[]dependsOn();
}
the preset detection interface protocol ICheckDependence has an interface type with a public authority modifier, a dependent detection function dependenconn is contained in the preset detection interface protocol ICheckDependence, the dependent detection function is an array with null input parameters and an int integer type return value. It should be noted that the return value of the dependency detection function may be used to represent a functional module dependency set formed by other functional modules that the functional module depends on, and may be an int [ ] array or a string [ ] array of a string type, which may be preset based on the service requirement and the scene.
Exemplarily, before S110, the method may further include: the detection class in each functional module inherits the preset detection interface protocol by calling the interface inheritance key and overwrites the dependent detection function in the preset detection interface protocol so as to enable the dependent detection function to realize the dependent detection function of other functional modules which depend on the detection initialization; and instantiating the detection class inheriting the preset detection interface protocol, and creating a corresponding detection protocol object.
Specifically, for each functional module, a detection class is configured in advance in each functional module, so that the detection class can inherit a preset detection interface protocol by calling an interface to inherit keyword instantiation, and rewrite a dependent detection function dependendson in the preset detection interface protocol by rewriting @ Override in the detection class, and detection logic of other functional modules, on which detection initialization corresponding to the detection class depends, is implemented in the rewrite function dependendson in the detection class, so that the dependent detection function dependendson in a detection protocol object created by instantiation of the detection class can realize a corresponding dependent detection function. And instantiating the detection class inheriting the preset detection interface protocol to enable the object type of the created detection protocol object to be the preset detection interface protocol type.
S120, calling a dependency detection function in each detection protocol object, and determining a function module dependency set formed by other function modules which are depended on when each function module is initialized.
The functional module dependency set may refer to a functional module that is composed of other functional modules except for the functional module itself and is depended upon when the functional module is initialized, and is used for reflecting the dependency condition when the functional module is initialized. Each functional module corresponds to a functional module dependency set. The functional module dependency set may be an empty set or a non-empty set. When the functional module dependency set corresponding to a certain functional module is an empty set, it indicates that the functional module does not need to depend on other functional modules, and can be initialized independently.
Specifically, for each functional module to be detected, a functional module dependency set composed of other functional modules that the functional module depends on when initializing can be quickly obtained by calling a dependency detection function in a detection protocol object in the functional module and according to return data of the dependency detection function. For example, in this embodiment, other function modules depended on for initialization of each function module may be manually detected in advance, and information of the depended other function modules is stored in a configuration file, so that inside the dependency detection function, a function module dependency set corresponding to the function module may be directly obtained in a manner of reading the configuration file, and thus, the detection efficiency may be improved. When determining the function module dependency set corresponding to each function module, the function module or the module identifier corresponding to the function module may be used as key information, and the corresponding function module dependency set may be used as value information, and stored in a preset key value pair type data storage object, so as to facilitate data management and processing.
S130, determining each target function module with annular dependency relationship according to the function module dependency set corresponding to each function module.
The ring dependency relationship may refer to a dependency relationship that is in a closed loop when each functional module is initialized. The ring dependency may include direct dependencies and indirect dependencies. The direct dependency may refer to two functional modules that are mutually dependent when being initialized, for example, the functional module a depends on the functional module B, and the functional module B depends on the functional module a. The indirect dependency may refer to a dependency relationship existing between two or more functional modules, for example, the functional module a depends on the functional module C, the functional module C depends on the functional module B, and the functional module B depends on the functional module a, so that the functional modules A, B and C indirectly depend on each other. It should be noted that, in each functional module to be detected, one or more groups of the functional modules may have an annular dependency relationship, so that each group of the target functional modules having an annular dependency relationship may be determined one by one.
Specifically, in each functional module, whether an annular dependency relationship exists between any at least two functional modules can be detected according to a functional module dependency set corresponding to each functional module, so that each target functional module with the annular dependency relationship can be exposed, developers can modify and debug correspondingly, the existence of the annular dependency relationship is avoided, and the normal operation of the whole initialization logic is ensured.
According to the technical scheme of the embodiment, a detection protocol object with an object type as a preset detection interface protocol type is created in each function module in advance, so that other function modules depended on by each function module in an initialization process can be automatically determined by calling a dependency detection function in each detection protocol object, each function module is formed into a function module dependency set, each target function module with an annular dependency relationship is determined according to the function module dependency set corresponding to each function module, each target function module with the annular dependency relationship can be exposed, developers can correspondingly adjust the function modules, the annular dependency relationship is avoided, and normal operation of initialization of the function modules can be guaranteed.
On the basis of the above technical solution, the dependency detection function may implement the function of determining the function module dependency set composed of other function modules that each function module depends on when initializing by the following steps:
scanning information of each class file which needs to be loaded when a current functional module is initialized, obtaining each package name related to each class file, and generating a package name set, wherein each package name corresponds to one functional module; removing the current package name corresponding to the current functional module from each package name set; and performing packet name duplication elimination processing on each packet name set with the current packet name removed, and generating a function module dependency set corresponding to the current function module according to each packet name obtained after duplication elimination processing.
The Class file, i.e. the Class file, may refer to a file for describing various information of the Class, such as a Class name of the Class, a package name to which the Class belongs, and information of the Class in other function modules used in the initialization process. The packet names and the function modules in the embodiment are in one-to-one correspondence, so that the packet names can be used as unique identifiers of the function modules to distinguish different function modules.
In this embodiment, each function module to be detected may be used as the current function module, and the function module dependency set corresponding to the current function module may be determined in the same manner. Specifically, each required class file is loaded when the current functional module is initialized, so that each package name related to each class file can be determined in an automatic scanning mode for each class file, a package name set composed of each package name is generated, each package name corresponds to one functional module, and each functional module depended on when each class in the current functional module is initialized can be obtained. And removing the current package name corresponding to the current functional module from each package name set so as to obtain other functional modules except the current functional module which are depended on when each class is initialized. And performing packet name duplication elimination on each packet name set without the current packet name, and deleting the same function modules depended on, so that the function module dependence set corresponding to the current function module can be determined based on the duplicated packet names. For example, if the module identifier of the function module is represented by a package name, the package names obtained after deduplication may be directly combined into a function module dependency set corresponding to the current function module.
On the basis of the above technical solution, generating a function module dependency set corresponding to the current function module according to each package name obtained after the deduplication processing may include: calling an identification query function in a preset storage object, and determining a target preset function module identification corresponding to each packet name obtained after duplicate removal; and combining the target preset function module identifications into a function module dependency set corresponding to the current function module.
The preset storage object stores the corresponding relation between the package name and the preset functional module identifier in advance. The preset function module identifier corresponding to each function module may be preset based on the service requirement and the scene. Illustratively, the preset function module identifier may be characterized by at least one of a number and a letter, so as to reduce the memory space occupied by the identifier and improve the efficiency of subsequent data matching. For example, a preset function module identifier corresponding to the function module a is represented by a number "1"; and representing the corresponding preset functional module identification of the functional module B by using a number 2.
Specifically, in this embodiment, a package name packagemame and a preset function module identifier index corresponding to each function module may be stored in the preset storage object myMap in advance by calling a storage function put (packagemame, index) in the preset storage object myMap. And taking each package name packagemame 1 obtained after the deduplication processing as a function input parameter, calling an identification query function mymap.get (packagemame 1) in a preset storage object myMap, and determining a target preset function module identification corresponding to each package name packagemame 1 obtained after the deduplication processing, so that each target preset function module identification can be combined into a function module dependence set corresponding to the current function module.
On the basis of the above technical solution, after determining each target function module having an annular dependency relationship according to the function module dependency set corresponding to each function module, the method may further include: and generating a warning message according to each target function module with the annular dependency relationship, and displaying the warning message to inform a developer to modify the initialization logic of each target function module.
Specifically, when each target function module with the annular dependency relationship is detected, a warning message may be generated in real time based on module information of each target function module, and the warning message is immediately displayed on a display interface of the development end, so as to timely notify a developer to modify the initialization logic of each target function module, for example, in a manner of performing code reconstruction, or performing further function decomposition on the function module, so as to reduce the coupling between each function module during initialization, avoid the condition that the annular dependency relationship exists, and further ensure the normal execution of initialization of each function module.
Example two
Fig. 2 is a flowchart of a method for detecting a ring dependency according to a second embodiment of the present invention, where this embodiment optimizes "determining each target function module having a ring dependency according to a function module dependency set corresponding to each function module" on the basis of the above embodiments, and explanations of terms that are the same as or correspond to the above embodiments are not repeated here.
Referring to fig. 2, the method for detecting a ring dependency provided in this embodiment specifically includes the following steps:
s210, acquiring at least two functional modules and a detection protocol object in each functional module, wherein the object type of the detection protocol object is a preset detection interface protocol type.
S220, calling a dependency detection function in each detection protocol object, and determining a function module dependency set formed by other function modules which are depended on when each function module is initialized.
And S230, taking each function module as the current function module one by one, and taking the first function module in the first function module dependency set corresponding to the current function module as the current first function module.
The first functional module dependency set may refer to a functional module dependency set corresponding to the current functional module. The current first functional module may refer to a functional module in the indicated first functional module dependency set at the current time.
Specifically, the present embodiment may adopt a loop detection manner, and take each functional module one by one as a starting point in a loop to detect whether a loop dependency relationship exists. At the beginning of each loop, the first functional module in the first functional module dependency set may be regarded as the current first functional module, so as to detect whether a ring dependency exists between the current functional module and the current first functional module.
S240, detecting whether a second function module dependent set corresponding to the current first function module is a non-empty set or not; if yes, go to step S250; if not, the process proceeds to step S270.
Specifically, a function module dependency set corresponding to the current first function module is obtained and used as a second function module dependency set, whether the second function module dependency set is a non-empty set or not is detected, if yes, it is indicated that the current first function module needs to depend on other function modules during initialization, and at this time, the operation of S250 can be executed; if not, it indicates that the current first function module does not need to depend on other function modules when being initialized, and can be initialized independently, and at this time, the operation of S270 may be executed.
S250, detecting whether a current functional module exists in the second functional module dependency set; if yes, go to step S260; if not, the process proceeds to step S270.
Specifically, the present embodiment may match, based on the matching manner of the functional module identifiers, the module identifier corresponding to the current functional module with the module identifier corresponding to each functional module in the second functional module dependency set; if the matching is successful, the current functional module exists, and the operation of S260 can be executed at this time; if the matching fails, it indicates that there is no current function module, i.e., there is no ring dependency between the current function module and the first function module of the current module, and at this time, the operation of S270 may be executed.
And S260, determining that the current function module and the current first function module are target function modules with annular dependency relationship.
Specifically, when the current function module exists in the second function module dependency set, it is indicated that the current first function module also needs to be depended on the current function module when the current first function module is initialized, that is, the current function module and the current first function module directly depend on each other, and at this time, the current function module and the current first function module may be determined as a target function module having a ring dependency relationship.
It should be noted that the present embodiment may enter step S270 after S260, so that other target function modules having a ring dependency relationship may be continuously detected. If a plurality of annular dependency relationships are detected, the deduplication processing can be performed on each annular dependency relationship to obtain all the annular dependency relationships existing in each functional module.
S270, taking the next functional module in the first functional module dependency set as the current first functional module, and proceeding to the step S240.
Specifically, the next function module of the current first function module may be regarded as the current first function module based on the function module sorting order in the first function module dependency set to update the current first function module, and the operation of S240 is returned to be executed based on the updated current first function module, so as to determine whether a ring dependency relationship exists between the current function module and the next function module in the first function module dependency set.
According to the technical scheme of the embodiment, each target function module with direct dependency relationship can be quickly detected in a circulating detection mode.
On the basis of the foregoing technical solution, when it is detected that the current functional module does not exist in the second functional module dependency set, that is, before entering S270 in S250, the method may further include:
and S251, taking each functional module in the second functional module dependency set as the current second functional module one by one.
Specifically, when the dependency set of the second function module is a non-empty set and the second function module dependency set does not have a current function module, it indicates that the current first function module does not depend on the current function module, that is, there is no ring dependency relationship between the current first function module and the current dependency module, and at this time, an embedded loop mode may be adopted to take each function module in the dependency set of the second function module as the current second function module one by one, so as to detect whether the current second function module depends on the current function module.
S252, detecting whether a dependency set of a third functional module corresponding to the current second functional module is a non-empty set; if yes, go to step S253; if not, the process proceeds to step S256.
Specifically, a function module dependency set corresponding to the current second function module is obtained and used as a third function module dependency set, whether the third function module dependency set is a non-empty set or not is detected, if yes, it is indicated that the current second function module needs to depend on other function modules during initialization, and at this time, the operation of S253 can be executed; if not, it indicates that the current second function module does not need to depend on other function modules when being initialized, and can be initialized independently, and at this time, the operation of S256 can be executed.
S253, detecting whether a current functional module exists in the third functional module dependence set; if yes, go to step S254; if not, the process proceeds to step S255.
Specifically, it may be detected whether the dependency set of the third functional module corresponding to the current second functional module is a non-empty set based on the above similar module identifier matching manner.
And S254, determining that the current function module, the current first function module and the current second function module are target function modules with annular dependency relationship.
Specifically, when it is detected that the current function module exists in the third function module dependency set, it indicates that the current second function module needs to be depended on the current function module when the current second function module is initialized, at this time, an indirect dependency relationship exists among the current function module, the current first function module, and the current second function module, and at this time, the current function module, the current first function module, and the current second function module may be determined as a target function module having an annular dependency relationship.
And S255, continuing to use each functional module in the dependency set of the third functional module as the current third functional module one by one until the dependency set of the fourth functional module corresponding to the current third functional module is detected to be an empty set.
Specifically, when it is detected that the current functional module does not exist in the third functional module dependency set, a layer of loop may be further embedded based on the similar process, and each functional module in the third functional module dependency set is used as the current third functional module one by one, so as to detect whether there is an indirect dependency relationship among the current functional module, the current first functional module, the current second functional module, and the current third functional module. If the dependency set of the fourth function module corresponding to the current third function module is detected to be an empty set, it indicates that no indirect dependency relationship exists among the current function module, the current first function module, the current second function module and the current third function module, and at this time, the current third function module may be updated to continue the detection.
Illustratively, when a functional module is characterized by a number, such as the current functional module is 1, the dependency set of the corresponding functional module is: {2, 3, 5, 6}, where 2 is taken as the current first functional module, and the functional module dependency set corresponding to functional module 2 is: {4, 6, 7, 8}, where 4 is taken as the current second functional module, and the functional module dependency set corresponding to functional module 4 is: {1, 3, 5, 7}, this loop may determine that there is an indirect ring dependency between functional modules 1, 2, and 4.
And S256, updating the current second function module based on the dependency set of the second function module, and returning to execute the operation of the S252 according to the updated current second function module.
Specifically, the next function module of the current second function module may be regarded as the current second function module based on the function module sorting order in the second function module dependency set to update the current second function module, and the operation of S252 is executed in return based on the updated current second function module, so as to determine whether the loop dependency relationship exists between the current function module and the next function module in the second function module dependency set.
It should be noted that, when it is detected that a plurality of indirect ring dependencies exist, deduplication processing may be performed on each indirect ring dependency, so that all indirect dependencies existing in each functional module may be obtained.
The following is an embodiment of the apparatus for detecting a circular dependency provided in the embodiments of the present invention, which belongs to the same inventive concept as the method for detecting a circular dependency in the foregoing embodiments, and details that are not described in detail in the embodiment of the apparatus for detecting a circular dependency may refer to the embodiment of the method for detecting a circular dependency.
EXAMPLE III
Fig. 3 is a schematic structural diagram of a device for detecting a ring dependency relationship according to a third embodiment of the present invention, where this embodiment is applicable to detecting whether a ring dependency relationship exists when at least two function modules are initialized in application software, and the device specifically includes: a detection protocol object acquisition unit 310, a function module dependence set determination unit 320, and a target function module determination unit 330.
The detection protocol object obtaining unit 310 is configured to obtain at least two functional modules and a detection protocol object in each functional module, where an object type of the detection protocol object is a type of a preset detection interface protocol; a functional module dependency set determination unit 320 for: calling a dependency detection function in each detection protocol object, and determining a function module dependency set formed by other function modules which are depended on when each function module is initialized; the target function module determining unit 330 is configured to determine, according to the function module dependency set corresponding to each function module, each target function module having a ring dependency relationship.
Optionally, the function of determining the function module dependency set formed by other function modules that each function module depends on when initializing is implemented by the dependency detection function in the function module dependency set determining unit 320 through the following sub-units:
the package name set generating subunit is used for scanning the information of each class file which needs to be loaded when the current functional module is initialized, obtaining each package name related to each class file, and generating a package name set, wherein each package name corresponds to one functional module;
the current package name removing unit is used for removing the current package name corresponding to the current functional module from each package name set;
and the functional module dependence set generation subunit is used for carrying out packet name duplication elimination processing on each packet name set with the current packet name eliminated and generating a functional module dependence set corresponding to the current functional module according to each packet name obtained after duplication elimination processing.
Optionally, the functional module dependency set generation subunit is specifically configured to: calling an identification query function in a preset storage object, and determining a target preset function module identification corresponding to each package name obtained after duplicate removal, wherein the preset storage object stores the corresponding relation between the package name and the preset function module identification in advance; and combining the target preset function module identifications into a function module dependency set corresponding to the current function module.
Optionally, the target function module determining unit 330 is specifically configured to:
taking each function module as a current function module one by one, and taking a first function module in a first function module dependency set corresponding to the current function module as a current first function module; if the dependency set of the second function module corresponding to the current first function module is detected to be a non-empty set, detecting whether the current function module exists in the dependency set of the second function module; if yes, determining that the current functional module and the current first functional module are target functional modules with annular dependency relationship; and if not, taking the next functional module in the first functional module dependency set as the current first functional module, and returning to execute the operation of detecting that the current functional module exists in the second functional module dependency set if the second functional module dependency set corresponding to the current first functional module is detected to be a non-empty set.
Optionally, the target function module determining unit 330 is further specifically configured to:
before taking the next functional module in the first functional module dependency set as the current dependent functional module, taking each functional module in the second functional module dependency set as the current second functional module one by one; when detecting that a third function module dependency set corresponding to the current second function module is a non-empty set and a current function module exists in the third function module dependency set, determining that the current function module, the current first function module and the current second function module are target function modules with annular dependency relationship; and when the third function module dependency set corresponding to the current second function module is detected to be a non-empty set and the current function module does not exist in the third function module dependency set, continuously taking each function module in the third function module dependency set as the current third function module one by one until the fourth function module dependency set corresponding to the current third function module is detected to be an empty set.
Optionally, the apparatus further comprises:
the preset detection interface protocol inheritance unit is used for inheriting a preset detection interface protocol by calling an interface inheritance key word by a detection class in each functional module before acquiring at least two functional modules and a detection protocol object in each functional module, and duplicating a dependent detection function in the preset detection interface protocol so as to enable the dependent detection function to realize the dependent detection function of other functional modules which are depended during detection initialization;
and the detection protocol object creating unit is used for instantiating the detection class inheriting the preset detection interface protocol and creating a corresponding detection protocol object.
Optionally, the apparatus further comprises:
and the warning message display unit is used for generating a warning message according to each target function module with the annular dependency relationship after each target function module with the annular dependency relationship is determined according to the function module dependency set corresponding to each function module, and displaying the warning message so as to inform developers to modify the initialization logic of each target function module.
The device for detecting the annular dependency relationship provided by the embodiment of the invention can execute the method for detecting the annular dependency relationship provided by any embodiment of the invention, and has the corresponding functional modules and beneficial effects of the method for detecting the annular dependency relationship.
Example four
Fig. 4 is a schematic structural diagram of an apparatus according to a fourth embodiment of the present invention. Referring to fig. 4, the apparatus includes:
one or more processors 410;
a memory 420 for storing one or more programs;
when the one or more programs are executed by the one or more processors 410, the one or more processors 410 implement the method for detecting a ring dependency provided in any of the embodiments described above, the method comprising:
acquiring at least two functional modules and a detection protocol object in each functional module, wherein the object type of the detection protocol object is a preset detection interface protocol type;
calling a dependency detection function in each detection protocol object, and determining a function module dependency set formed by other function modules which are depended on when each function module is initialized;
and determining each target function module with the annular dependency relationship according to the function module dependency set corresponding to each function module.
In FIG. 4, a processor 410 is illustrated as an example; the processor 410 and the memory 420 in the device may be connected by a bus or other means, as exemplified by the bus connection in fig. 4.
The memory 420 serves as a computer-readable storage medium, and may be used to store software programs, computer-executable programs, and modules, such as program instructions/modules corresponding to the detection method of the ring dependency in the embodiment of the present invention (for example, the detection protocol object obtaining unit 310, the function module dependency set determination unit 320, and the target function module determination unit 330 in the detection apparatus of the ring dependency). The processor 410 executes various functional applications of the device and data processing by executing software programs, instructions and modules stored in the memory 420, namely, the above-mentioned ring dependency detection method is realized.
The memory 420 mainly includes a program storage area and a data storage area, wherein the program storage area can store an operating system and an application program required by at least one function; the storage data area may store data created according to use of the device, and the like. Further, the memory 420 may include high speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other non-volatile solid state storage device. In some examples, memory 420 may further include memory located remotely from processor 410, which may be connected to devices through a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The apparatus proposed in this embodiment belongs to the same inventive concept as the method for detecting circular dependency proposed in the above embodiment, and the technical details that are not described in detail in this embodiment can be referred to the above embodiment, and this embodiment has the same beneficial effects as the method for detecting circular dependency.
EXAMPLE five
The present embodiment provides a computer-readable storage medium, on which a computer program is stored, which when executed by a processor, implements the method steps of detecting a ring dependency provided in any of the embodiments of the present invention, the method including:
acquiring at least two functional modules and a detection protocol object in each functional module, wherein the object type of the detection protocol object is a preset detection interface protocol type;
calling a dependency detection function in each detection protocol object, and determining a function module dependency set formed by other function modules which are depended on when each function module is initialized;
and determining each target function module with the annular dependency relationship according to the function module dependency set corresponding to each function module.
Computer storage media for embodiments of the invention may employ any combination of one or more computer-readable media. The computer readable medium may be a computer readable signal medium or a computer readable storage medium. The computer-readable storage medium may be, for example but not limited to: an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples (a non-exhaustive list) of the computer readable storage medium would include the following: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of this document, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
A computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device.
Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
Computer program code for carrying out operations for aspects of the present invention may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C + + or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
It will be understood by those skilled in the art that the modules or steps of the invention described above may be implemented by a general purpose computing device, they may be centralized on a single computing device or distributed across a network of computing devices, and optionally they may be implemented by program code executable by a computing device, such that it may be stored in a memory device and executed by a computing device, or it may be separately fabricated into various integrated circuit modules, or it may be fabricated by fabricating a plurality of modules or steps thereof into a single integrated circuit module. Thus, the present invention is not limited to any specific combination of hardware and software.
It is to be noted that the foregoing is only illustrative of the preferred embodiments of the present invention and the technical principles employed. It will be understood by those skilled in the art that the present invention is not limited to the particular embodiments described herein, but is capable of various obvious changes, rearrangements and substitutions as will now become apparent to those skilled in the art without departing from the scope of the invention. Therefore, although the present invention has been described in greater detail by the above embodiments, the present invention is not limited to the above embodiments, and may include other equivalent embodiments without departing from the spirit of the present invention, and the scope of the present invention is determined by the scope of the appended claims.
Claims (10)
1. A method for detecting a ring dependency relationship, comprising:
acquiring at least two functional modules and a detection protocol object in each functional module, wherein the object type of the detection protocol object is a preset detection interface protocol type;
calling a dependency detection function in each detection protocol object, and determining a function module dependency set formed by other function modules which are depended on when each function module is initialized;
and determining each target function module with an annular dependency relationship according to the function module dependency set corresponding to each function module.
2. The method according to claim 1, wherein the dependency detection function implements the function of determining the functional module dependency set of the other functional modules that each of the functional modules depends on upon initialization by:
scanning information of each class file which needs to be loaded when a current functional module is initialized, obtaining each package name related to each class file, and generating a package name set, wherein each package name corresponds to one functional module;
removing the current package name corresponding to the current functional module from each package name set;
and performing packet name duplication elimination processing on each packet name set with the current packet name removed, and generating a function module dependency set corresponding to the current function module according to each packet name obtained after duplication elimination processing.
3. The method according to claim 2, wherein generating the function module dependency set corresponding to the current function module according to each package name obtained after the deduplication processing includes:
calling an identification query function in a preset storage object, and determining a target preset function module identification corresponding to each packet name obtained after deduplication processing, wherein the preset storage object stores the corresponding relationship between the packet name and the preset function module identification in advance;
and combining the target preset function module identifications into a function module dependency set corresponding to the current function module.
4. The method according to claim 1, wherein determining each target functional module having a ring dependency relationship according to the functional module dependency set corresponding to each functional module comprises:
taking each function module as a current function module one by one, and taking a first function module in a first function module dependency set corresponding to the current function module as a current first function module;
if the dependency set of a second function module corresponding to the current first function module is detected to be a non-empty set, detecting whether the current function module exists in the dependency set of the second function module;
if yes, determining that the current functional module and the current first functional module are target functional modules with annular dependency relationship;
and if not, taking the next functional module in the first functional module dependency set as the current first functional module, and returning to execute the operation of detecting that the current functional module exists in the second functional module dependency set if the second functional module dependency set corresponding to the current first functional module is detected to be a non-empty set.
5. The method of claim 4, prior to treating a next functional module in the first dependent set of functional modules as a current dependent functional module, comprising:
taking each functional module in the second functional module dependency set as a current second functional module one by one;
when detecting that a third function module dependency set corresponding to a current second function module is a non-empty set and a current function module exists in the third function module dependency set, determining that the current function module, the current first function module and the current second function module are target function modules with annular dependency relationship;
when detecting that the third function module dependency set corresponding to the current second function module is a non-empty set and no current function module exists in the third function module dependency set, continuing to use each function module in the third function module dependency set as the current third function module one by one until detecting that the fourth function module dependency set corresponding to the current third function module is an empty set.
6. The method of claim 1, further comprising, prior to obtaining at least two functional modules and a detection protocol object in each of the functional modules:
the detection class in each functional module inherits a preset detection interface protocol by calling an interface inheritance keyword, and rewrites a dependence detection function in the preset detection interface protocol so as to enable the dependence detection function to realize the dependence detection function of other functional modules depended on during detection initialization;
and instantiating the detection class inheriting the preset detection interface protocol, and creating a corresponding detection protocol object.
7. The method according to claim 1, after determining, according to the functional module dependency set corresponding to each of the functional modules, each target functional module having a ring dependency relationship, further comprising:
and generating a warning message according to each target function module with the annular dependency relationship, and displaying the warning message to inform a developer to modify the initialization logic of each target function module.
8. An apparatus for detecting a loop dependency relationship, comprising:
the device comprises a detection protocol object acquisition unit, a detection interface protocol acquisition unit and a detection protocol object acquisition unit, wherein the detection protocol object acquisition unit is used for acquiring at least two functional modules and a detection protocol object in each functional module, and the object type of the detection protocol object is the type of a preset detection interface protocol;
a functional module dependency set determination unit to: calling a dependency detection function in each detection protocol object, and determining a function module dependency set formed by other function modules which are depended on when each function module is initialized;
and the target function module determining unit is used for determining each target function module with annular dependency relationship according to the function module dependency set corresponding to each function module.
9. An apparatus, characterized in that the apparatus comprises:
one or more processors;
a memory for storing one or more programs;
when executed by the one or more processors, cause the one or more processors to implement a method of detecting a ring dependency as claimed in any one of claims 1 to 7.
10. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out a method for detecting a ring dependency according to any one of claims 1 to 7.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201911047129.7A CN112748952A (en) | 2019-10-30 | 2019-10-30 | Method, device, equipment and storage medium for detecting ring dependency relationship |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201911047129.7A CN112748952A (en) | 2019-10-30 | 2019-10-30 | Method, device, equipment and storage medium for detecting ring dependency relationship |
Publications (1)
Publication Number | Publication Date |
---|---|
CN112748952A true CN112748952A (en) | 2021-05-04 |
Family
ID=75640717
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201911047129.7A Pending CN112748952A (en) | 2019-10-30 | 2019-10-30 | Method, device, equipment and storage medium for detecting ring dependency relationship |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN112748952A (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
WO2023169212A1 (en) * | 2022-03-07 | 2023-09-14 | 华为技术有限公司 | Method for identifying sdk in application, terminal, and server |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102486732A (en) * | 2010-12-02 | 2012-06-06 | 上海可鲁系统软件有限公司 | Distributed type platform and control method for starting priorities of functional modules in platform |
CN104063220A (en) * | 2014-06-25 | 2014-09-24 | 清华大学 | Linux basic software dependency relationship analysis method based on files |
CN109086050A (en) * | 2018-07-04 | 2018-12-25 | 烽火通信科技股份有限公司 | A kind of analysis method and system of module dependencies |
CN109739579A (en) * | 2019-01-11 | 2019-05-10 | 武汉瓯越网视有限公司 | Application starting method, apparatus and storage medium based on feedback protocols |
-
2019
- 2019-10-30 CN CN201911047129.7A patent/CN112748952A/en active Pending
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102486732A (en) * | 2010-12-02 | 2012-06-06 | 上海可鲁系统软件有限公司 | Distributed type platform and control method for starting priorities of functional modules in platform |
CN104063220A (en) * | 2014-06-25 | 2014-09-24 | 清华大学 | Linux basic software dependency relationship analysis method based on files |
CN109086050A (en) * | 2018-07-04 | 2018-12-25 | 烽火通信科技股份有限公司 | A kind of analysis method and system of module dependencies |
CN109739579A (en) * | 2019-01-11 | 2019-05-10 | 武汉瓯越网视有限公司 | Application starting method, apparatus and storage medium based on feedback protocols |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
WO2023169212A1 (en) * | 2022-03-07 | 2023-09-14 | 华为技术有限公司 | Method for identifying sdk in application, terminal, and server |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US7661088B2 (en) | Systems and methods to efficiently and automatically effect population of custom controls onto a visual designer toolbox | |
WO2021137757A1 (en) | Authority management method and apparatus, and electronic device, and storage medium thereof | |
CN110750315B (en) | Class loading method, device, equipment and storage medium in Android system | |
CN109492181B (en) | Page jump method, device, computer equipment and storage medium | |
CN110457132B (en) | Method and device for creating functional object and terminal equipment | |
JP2024061591A (en) | Automatic code reconfiguration based on function and subfunction analysis | |
CN110324722B (en) | Method, device, equipment and storage medium for acquiring data in live broadcast room | |
CN111338716A (en) | Data processing method and device based on rule engine and terminal equipment | |
US20240345834A1 (en) | Configuration properties management for software | |
CN112748952A (en) | Method, device, equipment and storage medium for detecting ring dependency relationship | |
CN113127775B (en) | Page loading method, device, equipment and storage medium | |
US11431795B2 (en) | Method, apparatus and storage medium for resource configuration | |
CN109144520B (en) | Information interaction method, device, equipment and storage medium among different objects in Android | |
CN113342429B (en) | Intelligent contract data processing method, intelligent contract data processing device, computer equipment and storage medium | |
CN110442404B (en) | Object release method, device, equipment and storage medium | |
CN115167822A (en) | Branch code merging method, device, equipment and storage medium | |
CN114968960A (en) | Log processing method and device, computer equipment and storage medium | |
CN111142735B (en) | Software page creating method and device, terminal equipment and storage medium | |
CN109413498B (en) | Bullet screen message distribution method, bullet screen message distribution device, terminal and storage medium | |
CN112506641B (en) | Intelligent object release method and device and terminal equipment | |
CN112988125B (en) | Data bridging method, device, equipment and storage medium | |
CN113010196B (en) | Patch screening method, device, equipment and storage medium | |
CN110032406B (en) | Message-based view loading method, device, equipment and storage medium | |
CN108810644A (en) | Barrage message distributing method, device, equipment and storage medium | |
CN117271424B (en) | Processing device and processing method based on multimode fusion computing framework |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
RJ01 | Rejection of invention patent application after publication |
Application publication date: 20210504 |
|
RJ01 | Rejection of invention patent application after publication |