Detailed Description
In order to make those skilled in the art better understand the technical solutions in the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
Fig. 1 is a flowchart of a code processing method in an embodiment of the present application. In this embodiment, the code processing method includes the following steps:
s110: and acquiring a module code corresponding to a module contained in the current service.
The current service is a service which is currently required to be realized by a software developer, and the current service may comprise a plurality of pre-planned modules, and a dependency relationship may exist among the modules. Before a certain service needs to be implemented, a software developer can specify modules included in the current service. For example, for the current service X, the modules included therein may be { a, b, c, d, e }, and then the module codes corresponding to the modules may be obtained according to the modules, respectively.
In this embodiment of the present application, before obtaining a module code corresponding to a module included in a current service, the method further includes:
adding dependency information corresponding to the dependency relationship in the module code of each module according to the dependency relationship among the modules; and mapping and storing the module code of each module and the module identifier of the module.
As mentioned above, there may be dependency relationships between modules, and these dependency relationships may be implemented by adding corresponding dependency information to the module code of each module. Such as:
/*global extend*/
// dependent extension
function ajax(settings){
…
}
In the above exemplary module code, the module "ajax" may then be dependent on the module "extended" by the dependency information "/" global extended/".
According to the method, corresponding dependency information is added to the module codes of the modules with dependency relationship, and different module identification IDs (such as 'ajax' and 'extended') are given to the divided modules, so that the module codes of each module correspond to the module identifications of the module one by one. And finally, mapping the module codes added with the dependency information with the module identification ID of each module respectively, and storing the module codes into a source code database.
As described above, in this embodiment, the step S110 specifically includes:
and receiving a module identification which is input by a user and corresponds to a module contained in the current service.
And inquiring a module code corresponding to the module contained in the current service according to the module identifier.
The user can be a software developer, and the system receives the module identification corresponding to each module included in the current service, which is input by the software developer according to the requirement of the current service. And then, the system queries the source code database according to the received module identification to obtain the prestored module code corresponding to each module. Such as: the inputted module identification comprises: "ajax" and "extended", the system queries the module code mapped with the module id "ajax" and "extended".
S120: and extracting the dependency information contained in the module code.
Specifically, the embodiment of the present application may scan module codes by editing a corresponding Regular Expression (RE) for extracting dependency information to obtain the dependency information.
For example, if the module included in the current service X is { a, b, c, d, e }, the dependency information included in the module code of the module a can be obtained by scanning the module code corresponding to the module: "/" global a/", the dependency information contained in the module code of module b is: "/" global c/", the dependency information contained in the module code of module d is: "/" global b/", the dependency information contained in the module code of module e is: "/" global c/"; then, the dependency relationship corresponding to the dependency information is as follows:
a depends on b, b depends on c, d depends on b, e depends on c.
S130: and determining the sequence of each module in the current service according to the dependency information list, and combining the module codes according to the sequence to obtain a code file corresponding to the current service.
In an embodiment of the present application, after the step S120 and before the step S130, the method further includes:
s140: and determining a dependency information list corresponding to the current service according to the extracted dependency information. And the dependency information list is used for sequencing all modules of the current service according to a certain sequence according to the extracted dependency relationship.
Continuing with the above example, if the current service X includes modules { a, b, c, d, e }, and extracting the dependency information in the codes of the modules, the following dependency relationships can be obtained: a depends on b, b depends on c, d depends on b, e depends on c. Then, the module order in the dependency information list can be obtained as follows: [ a, b, c ], [ d, b ], [ e, c ], then, by combining the module sequences, the module sequence in the dependency information list is obtained as follows: [ a, b, c, d, b, e, c ].
Fig. 2 is a flowchart of a method of determining an order of modules in a current service according to the dependency information in an embodiment of the present application. Based on the above steps, the step S130 specifically includes:
s1301: and judging whether redundant module identifications exist in the dependency information list.
Following the above example, the order of the modules in the dependency information list is obtained as: [ a, b, c, d, b, e, c ], it can be seen that there are redundant module identifications in the dependency information list: b. c, that is, a module identification can only appear once in the dependency information list.
S1302: and if so, deleting the redundant module identification.
In the above example, redundant modules are identified: b. c, deleting, wherein the module sequence in the deleted dependency information list is as follows: [ a, d, b, e, c ].
S1303: and performing reverse order arrangement on the sequence of the module identifications in the dependency information list in which the redundant module identifications are deleted, and determining the sequence of the module identifications after the reverse order arrangement as the sequence of each module in the current service.
In the above example, since the dependent module code in the code file generated by the final merging needs to be placed at the front position in the code file, this embodiment may sequentially: [ a, d, b, e, c ] is arranged in a reverse order, and the sequence of the module identifiers after the reverse order arrangement is as follows: [ c, e, b, d, a ] is determined as the order of the modules in the current service.
Finally, the module codes obtained by query can be combined according to the sequence of each module in the current service, so as to obtain a code file corresponding to the current service.
For example, if the module code of module a is:
/*global b*/
// dependent on b
function a(settings){
…
}
If the module code of module b is:
/*global c*/
// dependent on c
function b(settings){
…
}
If the module code of module c is:
function c(settings){
…
}
if the module code of module d is:
/*global b*/
// dependent on b
function d(settings){
…
}
If the module code of module e is:
/*global c*/
// dependent on c
function e(settings){
…
}
Combining the codes of the modules according to the sequence of the modules in the current service, and obtaining a final code file, wherein the final code file is as follows:
function c(settings){
…
}
/*global c*/
// dependent on c
function e(settings){
…
}
/*global c*/
// dependent on c
function b(settings){
…
}
/*global b*/
// dependent on b
function d(settings){
…
}
/*global b*/
// dependent on b
function a(settings){
…
}
It is worth mentioning that the order of the modules in the current service is not unique, and the order between the modules with no interdependence relationship may be reversed, for example: in [ c, e, b, d, a ], the order of a and e may be interchanged. In addition, in an actual application, there may be a module that does not have any dependency relationship with other modules (the module code of the module does not contain dependency information either), and in the process of finally merging the code files, the module code without dependency relationship may be inserted into any position in the code files obtained by final merging.
In another embodiment of the present application, without the step S140, the step of determining the order of each module in the current service according to the dependency information in the step S130 specifically includes, as shown in fig. 3:
s1304: and determining a first module identification of the depended module and a second module identification of the dependent module according to the dependency information.
Continuing with the above example, if the current service X includes modules { a, b, c, d, e }, and extracting the dependency information in the codes of the modules, the following dependency relationships can be obtained: a depends on b, b depends on c, d depends on b, e depends on c. Wherein the depended module comprises: b. c, the dependency module comprises: a. b, d, e.
S1305: and judging whether the first module identification or the second module identification exists in a preset sequence table.
In this embodiment, the system sets an order table in advance, so as to sequentially insert the determined module identifiers having the dependency relationship into the order table.
S1306: and if the first module identification exists but the second module identification does not exist, placing the second module identification behind the first module identification.
S1307: and if the second module identification exists but the first module identification does not exist, placing the first module identification in front of the second module identification.
Through the above steps 1306 and 1307, the module id in the above sequence table is inserted in the following order:
initially, the order table is empty, the depended module in "a depends on b" is b, the dependent module is a, and then the order table is obtained by inserting the depended module before and the dependent module after the depended module:
[b、a];
subsequently, for "b depends on c", the depended module is c, the dependent module is b, and by judging that b already exists in the above-mentioned order table (which is the case according to step S1307), the module c is inserted before the module b, and the order table is obtained:
[c、b、a];
for "d depends on b", the depended module is b, the dependent module is d, and by judging that b already exists in the order table (which is the case in step S1306), the module d is inserted after the module b to obtain the order table:
[c、b、d、a];
for "e depends on c", the depended module is c, the dependent module is e, and by judging that c already exists in the above-mentioned order table (which is the case in step S1306), the module e is inserted after the module c to obtain the order table:
[c、e、b、d、a]。
so far, the sequence of the module identifiers in the final sequence table can be determined as the sequence of each module corresponding to the current service according to the above process. And then, combining the module codes according to the sequence of the module identifiers contained in the sequence table to obtain a code file corresponding to the current service.
In this embodiment of the application, in order to make a code file obtained by final merging more compact, the method further includes:
and determining and deleting the annotation information contained in the combined module code. The annotation information includes, but is not limited to: comments for describing dependencies, etc., such as: "/dependent extended".
Corresponding to the method flow, the embodiment of the application also provides a device for processing the code. The apparatus may be implemented by software, or by hardware, or by a combination of hardware and software. Taking a software implementation as an example, the logical device is formed by reading a corresponding computer program instruction into a memory through a Central Processing Unit (CPU) of a server to run.
Fig. 4 is a block diagram of a device for processing code according to an embodiment of the present application. The functions of the units in the device are similar to the functions of the steps in the method, so that the device can refer to the details of the embodiment of the method. The device includes:
an obtaining unit 401, configured to obtain a module code corresponding to a module included in a current service;
an extracting unit 402, configured to extract dependency information included in the module code;
a determining unit 403, configured to determine an order of each module in the current service according to the dependency information, and merge the module codes according to the order of the modules to obtain a code file corresponding to the current service.
As shown in fig. 4, in the embodiment of the present application, the apparatus further includes:
the storage unit is used for adding dependency information corresponding to the dependency relationship in the module codes of the modules according to the dependency relationship among the modules; mapping and storing the module code of each module and the module identifier of the module;
then, the obtaining unit 401 is specifically configured to:
receiving a module identification which is input by a user and corresponds to a module contained in the current service;
and inquiring a module code corresponding to the module contained in the current service according to the module identifier.
As shown in fig. 4, in the embodiment of the present application, the apparatus further includes:
the list generating unit is used for determining a dependency information list corresponding to the current service according to the extracted dependency information;
then, the determining unit 403 specifically includes:
the first judgment unit is used for judging whether redundant module identifiers exist in the dependency information list or not;
a deleting unit, configured to delete redundant module identifiers if the redundant module identifiers exist in the dependency information list;
and the order determining unit is used for carrying out reverse order arrangement on the order of the module identifications in the dependency information list for deleting the redundant module identifications, and determining the order of the module identifications after the reverse order arrangement as the order of each module in the current service.
As shown in the apparatus of fig. 4, in the embodiment of the present application, the determining unit 403 specifically includes:
the dependency determining unit is used for determining a first module identifier of the depended module and a second module identifier of the dependent module according to the dependency information;
a second judging unit, configured to judge whether the first module identifier or the second module identifier exists in a preset order table;
a sorting unit, configured to place the second module identifier behind the first module identifier when the first module identifier exists but the second module identifier does not exist in the sorted list; when the second module identification exists but the first module identification does not exist in the sequence table, placing the first module identification in front of the second module identification; and merging the module codes according to the sequence of the module identifiers contained in the sequence table to obtain a code file corresponding to the current service.
As shown in fig. 4, in the embodiment of the present application, the apparatus further includes:
and the comment deleting unit is used for determining and deleting the comment information contained in the combined module code.
According to the technical scheme provided by the embodiment of the application, after the module code corresponding to the module included in the current service is acquired, the dependency information included in the module code is extracted, the order of each module in the current service is determined according to the dependency information, and finally the module code is combined according to the order to obtain the code file corresponding to the current service. In the process, the problem of dependence of each module is solved by introducing a specific code dependence framework is avoided, so that the finally combined code file is more simplified.
The systems, devices, modules or units illustrated in the above embodiments may be implemented by a computer chip or an entity, or by a product with certain functions.
For convenience of description, the above devices are described as being divided into various units by function, and are described separately. Of course, the functionality of the units may be implemented in one or more software and/or hardware when implementing the present application.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, system, or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
In a typical configuration, a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
The memory may include forms of volatile memory in a computer readable medium, Random Access Memory (RAM) and/or non-volatile memory, such as Read Only Memory (ROM) or flash memory (flash RAM). Memory is an example of a computer-readable medium.
Computer-readable media, including both non-transitory and non-transitory, removable and non-removable media, may implement information storage by any method or technology. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), Read Only Memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), Digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information that can be accessed by a computing device. As defined herein, a computer readable medium does not include a transitory computer readable medium such as a modulated data signal and a carrier wave.
It should also be noted that the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
As will be appreciated by one skilled in the art, embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The application may be described in the general context of computer-executable instructions, such as program modules, being executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform particular tasks or implement particular abstract data types. The application may also be practiced in distributed computing environments where tasks are performed by remote processing devices that are linked through a communications network. In a distributed computing environment, program modules may be located in both local and remote computer storage media including memory storage devices.
The embodiments in the present specification are described in a progressive manner, and the same and similar parts among the embodiments are referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, for the system embodiment, since it is substantially similar to the method embodiment, the description is simple, and for the relevant points, reference may be made to the partial description of the method embodiment.
The above description is only an example of the present application and is not intended to limit the present application. Various modifications and changes may occur to those skilled in the art. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the scope of the claims of the present application.