CN104331316A - Code compression method and system - Google Patents

Code compression method and system Download PDF

Info

Publication number
CN104331316A
CN104331316A CN201410709985.5A CN201410709985A CN104331316A CN 104331316 A CN104331316 A CN 104331316A CN 201410709985 A CN201410709985 A CN 201410709985A CN 104331316 A CN104331316 A CN 104331316A
Authority
CN
China
Prior art keywords
code
bag
compressed
file
configuration file
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.)
Granted
Application number
CN201410709985.5A
Other languages
Chinese (zh)
Other versions
CN104331316B (en
Inventor
李宸
赵佳国
范建刚
王浩远
金鑫
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Agricultural Bank of China
Original Assignee
Agricultural Bank of China
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Agricultural Bank of China filed Critical Agricultural Bank of China
Priority to CN201410709985.5A priority Critical patent/CN104331316B/en
Publication of CN104331316A publication Critical patent/CN104331316A/en
Application granted granted Critical
Publication of CN104331316B publication Critical patent/CN104331316B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
  • Document Processing Apparatus (AREA)

Abstract

The invention discloses a code compression method and a code compression system, applied to a pre-constructed compression environment. The method comprises steps of sub-packaging a development code in a development code file depending on a preset compression rule to obtain a plurality of original code packages, wherein each original code package corresponds to a package configuration file and the package configuration file includes a compression way of the corresponding original code package; setting a switch variable for a code file making quotation of each original code package; confirming a compression configuration file depending on a compression rule, wherein the compression configuration file includes a compression attribute; and executing the compression configuration file so that each original code package is compressed through the compression way in corresponding package configuration document to obtain a plurality of compression code packages, wherein a compression code file is constituted by the compression code packages, the compression structures of the compression code packages in the compression code file correspond to the compression attribute, and each compression code package in the compression code file is associated with the switch variable of the corresponding original code package.

Description

A kind of code compaction method and system
Technical field
The present invention relates to technical field of software development, particularly a kind of code compaction method and system.
Background technology
In software application development, in order to code file can be allowed less, execution efficiency is higher, and for the object of protecting code, generally can compress the code entered in actual use.
In existing javascript compression scheme, usual exploitation separates with compression, that is, after substantially having developed, by disposable, the mode that code carries out compressing is obtained compressed code, again through repetitious carry out the Contrast on effect of source code and compressed code after, to obtain compressing successful compressed code, compressed package is updated in actual application system.
Wherein, in existing compression scheme, compressed code and exploitation code are separated completely, and normally the code module of several functions or type is incorporated in a code file, therefore, cannot accurately navigate to the code module gone wrong when testing or effect comparison goes wrong, needing to detect each module successively, thus, obviously code development efficiency is reduced.
Summary of the invention
The object of the invention is to, a kind of code compaction method and system are provided, in order to solve code compaction scheme of the prior art, compressed code and exploitation code are separated completely, and normally the code module of several functions or type is incorporated in a code file, cannot accurately navigates to the code module gone wrong when testing or effect comparison goes wrong, needing to detect each module successively, thus, the technical matters of code development efficiency is obviously reduced.
The invention provides a kind of code compaction method, be applied in the compression environment built in advance, described method comprises:
According to the reduced rule preset, subpackage is carried out to the exploitation code in exploitation code file, obtain multiple source code bag, each described source code bag is its bag configuration file corresponding respectively, includes the compress mode of source code bag belonging to it in described bag configuration file;
For the code file quoting each described source code bag arranges switching variable;
According to described reduced rule determination compressed configuration file, in described compressed configuration file, include packed attribute;
Perform described compressed configuration file, to make to carry out compression process with the source code bag of compress mode to its correspondence in each described bag configuration file respectively, obtain multiple compressed code bag, described compressed code bag composition compressed code file, in described compressed code file, the pressure texture of compressed code bag is corresponding with described packed attribute, and in described compressed code file, the switching variable of each compressed code bag source code bag corresponding to it is associated.
Said method, preferably, described reduced rule comprises: carry out subpackage according to the code function classification preset to code;
Accordingly, the reduced rule that described foundation is preset, carries out subpackage to the exploitation code in exploitation code file, obtains multiple source code bag, comprising:
Exploitation code in exploitation code file is classified according to the code function classification preset;
Other exploitation code of same class will be belonged to and form a source code bag;
According to the packet compression rule preset, generate the bag configuration file of bag supporting paper and each described source code bag, include the package informatin of each source code bag and the positional information of bag configuration file thereof in described bag supporting paper, in each described bag configuration file, include the compress mode of source code bag belonging to it.
Said method, preferably, the described compressed configuration file of described execution, to make to carry out compression process with the source code bag of compress mode to its correspondence in each described bag configuration file respectively, obtains multiple compressed code bag, comprising:
Read described bag supporting paper, to obtain the positional information of each bag configuration file in described bag supporting paper;
Each described bag configuration file is read with described positional information;
Obtain the compress mode in each described bag configuration file;
With described compress mode, code compaction is carried out to source code bag belonging to it, obtain each self-corresponding compressed code bag of each source code bag;
With the packed attribute in described compressed configuration file, all described compressed code bags are carried out structure merging, obtains compressed code file, in described compressed code file, the switching variable of each compressed code bag source code bag corresponding to it is associated.
Said method, preferably, after obtaining multiple compressed code bag, described method also comprises:
According to the call request received, determine first switching variable compressed code bag corresponding to corresponding with described call request;
According to described first switching variable, generate invoke code;
Perform described invoke code, to call the compressed code bag corresponding with described first switching variable.
Said method, preferably, at described first invoke code of execution, after calling the compressed code bag corresponding with described first switching variable, described method also comprises:
According to the debug request received, determine second switch variable compressed code bag corresponding to corresponding with described debug request;
According to described second switch variable, generating debugging code;
Perform described debugging code, to call the source code bag corresponding with described second switch variable.
Present invention also offers a kind of code compaction system, be applied in the compression environment built in advance, described system comprises:
Code packetized units, for according to the reduced rule preset, subpackage is carried out to the exploitation code in exploitation code file, obtains multiple source code bag, each described source code bag is its bag configuration file corresponding respectively, includes the compress mode of source code bag belonging to it in described bag configuration file;
Switch-linear hybrid unit, arranges switching variable for the code file for quoting each described source code bag;
Configuration determining unit, for according to described reduced rule determination compressed configuration file, includes packed attribute in described compressed configuration file;
File execution unit, for performing described compressed configuration file, to make to carry out compression process with the source code bag of compress mode to its correspondence in each described bag configuration file respectively, obtain multiple compressed code bag, described compressed code bag composition compressed code file, in described compressed code file, the pressure texture of compressed code bag is corresponding with described packed attribute, and in described compressed code file, the switching variable of each compressed code bag source code bag corresponding to it is associated.
Said system, preferably, described reduced rule comprises: carry out subpackage according to the code function classification preset to code;
Accordingly, described code packetized units comprises:
Code classification subelement, for classifying according to the code function classification preset to the exploitation code in exploitation code file;
Bag composition subelement, forms a source code bag for belonging to other exploitation code of same class;
File generated subelement, for regular according to the packet compression preset, generate the bag configuration file of bag supporting paper and each described source code bag, include the package informatin of each source code bag and the positional information of bag configuration file thereof in described bag supporting paper, in each described bag configuration file, include the compress mode of source code bag belonging to it.
Said system, preferably, described file execution unit comprises:
First file reads subelement, for reading described bag supporting paper, to obtain the positional information of each bag configuration file in described bag supporting paper;
Second file reads subelement, for reading each described bag configuration file with described positional information;
Compress mode obtains subelement, for obtaining the compress mode in each described bag configuration file;
Code compaction subelement, for carrying out code compaction with described compress mode to source code bag belonging to it, obtains each self-corresponding compressed code bag of each source code bag;
Compressed package merges subelement, for with the packed attribute in described compressed configuration file, all described compressed code bags are carried out structure merging, obtains compressed code file, in described compressed code file, the switching variable of each compressed code bag source code bag corresponding to it is associated.
Said system, preferably, also comprises:
First variable determination unit, for performing described compressed configuration file in described file execution unit with after obtaining multiple compressed code bag, according to the call request received, determine first switching variable compressed code bag corresponding to corresponding with described call request;
Invoke code generation unit, for according to described first switching variable, generates invoke code;
Invoke code performance element, for performing described invoke code, to call the compressed code bag corresponding with described first switching variable.
Said system, preferably, also comprises:
Second variable determination unit, for according to the debug request received, determines second switch variable compressed code bag corresponding to corresponding with described debug request;
Debugging code generation unit, for according to described second switch variable, generating debugging code;
Debugging code performance element, for performing described debugging code, with the bar source code bag corresponding with described second switch variable.
From such scheme, a kind of code compaction method and system provided by the invention, be applied to the compression environment that built in advance as in Java environment, when carrying out code compaction, first according to the reduced rule preset, subpackage is carried out to exploitation code, to obtain multiple source code bag, these source code bags have a bag configuration file containing corresponding compress mode information, afterwards, all switching variable is arranged to the code file quoting each source code bag, and determine according to the reduced rule above the compressed configuration file including packed attribute, and then by performing this compressed configuration file, to make to carry out compression process with the source code bag of each compress mode to its correspondence respectively, obtain multiple compressed code bag composition compressed code file, and the pressure texture of compressed code bag is corresponding with the packed attribute in compressed configuration file in compressed code file now, simultaneously, each compressed code bag is associated respectively by the source code bag that switching variable is corresponding with it, therefore, in subsequent applications, developer only need control to quote switching variable corresponding to the code file of source code bag to realize the switching between compressed code and exploitation code, namely compressed code call and exploitation code debugging between switching.In the present invention, associate by arranging switching variable between compressed code and exploitation code, not two kinds of codes are separated completely, and when code compaction, function or the different code of type are separately compressed recombinant, therefore, compressed the code obtained by the present invention and can accurately navigate to by switching variable the code packages (code module) gone wrong when testing or effect comparison goes wrong, wireless needs detect each bag more successively, thus, code development efficiency is significantly improved.
Accompanying drawing explanation
In order to be illustrated more clearly in the embodiment of the present invention or technical scheme of the prior art, be briefly described to the accompanying drawing used required in embodiment or description of the prior art below, apparently, accompanying drawing in the following describes is only embodiments of the invention, for those of ordinary skill in the art, under the prerequisite not paying creative work, other accompanying drawing can also be obtained according to the accompanying drawing provided.
Fig. 1 is the process flow diagram of a kind of code compaction embodiment of the method one provided by the invention;
Fig. 2 is the partial process view of a kind of code compaction embodiment of the method two provided by the invention;
Fig. 3 is the application example figure of the embodiment of the present invention;
Fig. 4 is the partial process view of a kind of code compaction embodiment of the method two provided by the invention;
Fig. 5 is the process flow diagram of a kind of code compaction embodiment of the method three provided by the invention;
Fig. 6 is the partial process view of a kind of code compaction embodiment of the method five provided by the invention;
Fig. 7 is the Another Application exemplary plot of the embodiment of the present invention;
Fig. 8 is the structural representation of a kind of code compaction system embodiment six provided by the invention;
Fig. 9 is the part-structure schematic diagram of a kind of code compaction system embodiment seven provided by the invention;
Figure 10 is the part-structure schematic diagram of a kind of code compaction system embodiment eight provided by the invention;
Figure 11 is the structural representation of a kind of code compaction system embodiment nine provided by the invention;
Figure 12 is the structural representation of a kind of code compaction system embodiment ten provided by the invention.
Embodiment
Below in conjunction with the accompanying drawing in the embodiment of the present invention, be clearly and completely described the technical scheme in the embodiment of the present invention, obviously, described embodiment is only the present invention's part embodiment, instead of whole embodiments.Based on the embodiment in the present invention, those of ordinary skill in the art, not making the every other embodiment obtained under creative work prerequisite, belong to the scope of protection of the invention.
With reference to figure 1, for the process flow diagram of a kind of code compaction embodiment of the method one provided by the invention, wherein, described method is applied in the compression environment built in advance, described compression environment can be understood as: under the code structure of normal development environment, environment required for compression being built is configured, to obtain compressing environment, in the present embodiment, can for Java environment, that is, when carrying out the implementation in the present embodiment, need to ensure the installation of Java environment.
In the present embodiment, described method can realize compression to code by following steps:
Step 101: according to the reduced rule preset, carries out subpackage to the exploitation code in exploitation code file, obtains multiple source code bag.
Wherein, each described source code bag is its bag configuration file corresponding respectively, includes the compress mode of source code bag belonging to it in described bag configuration file.
It should be noted that, described reduced rule refers to the rule how compressed source code that developer pre-sets according to its actual needs, as reduced overall or splits' positions and adopt which kind of mode to carry out the rule compressed.And the compress mode comprised in bag configuration file respective in each described source code bag source code in its source code bag, such as, which code is compressed compress modes such as which code directly copy.
Step 102: for the code file quoting each described source code bag arranges switching variable.
It should be noted that, switching variable in the present embodiment only has one, but it is distributed on the position of the code file of each described source code bag of all references, that is, can by the control of quoting switching variable in code file, to realize the redirect of wrapping in the source code of quoting of the corresponding code file of this switching variable or to call.
Step 103: according to described reduced rule determination compressed configuration file, include packed attribute in described compressed configuration file.
Wherein, described packed attribute can be understood as, code in each described source code bag is carried out the attributes such as the structure of assembled arrangement after being compressed and adopts which kind of compress mode to carry out the attribute of code compaction to all bags, as the pressure texture such as a line or plurality of rows attribute and the attribute that how to compress codes such as js and css.
Step 104: perform described compressed configuration file, to make to carry out compression process with the source code bag of compress mode to its correspondence in each described bag configuration file respectively, obtains multiple compressed code bag.
Wherein, described compressed code bag composition compressed code file, in described compressed code file, the pressure texture of compressed code bag is corresponding with described packed attribute, and in described compressed code file, the switching variable of each compressed code bag source code bag corresponding to it is associated.
It should be noted that, described compressed configuration file is execute file, the process performing this compressed configuration file is: carry out compression process with the source code bag of compress mode to its correspondence in each described bag configuration file respectively, obtain multiple compressed code bag, to make described compressed code bag form compressed code file, and in described compressed code file, the pressure texture of compressed code bag is corresponding with described packed attribute.
In the present embodiment, in described compressed code file, the switching variable quoted in code file of each compressed code bag source code bag corresponding to it is associated, and the switching variable that developer can be quoted in code file by control is to reach the switching between quoted source code and compressed code.
From such scheme, a kind of code compaction embodiment of the method one provided by the invention, be applied to the compression environment that built in advance as in Java environment, when carrying out code compaction, first according to the reduced rule preset, subpackage is carried out to exploitation code, to obtain multiple source code bag, these source code bags have a bag configuration file containing corresponding compress mode information, afterwards, all switching variable is arranged to the code file quoting each source code bag, and determine according to the reduced rule above the compressed configuration file including packed attribute, and then by performing this compressed configuration file, to make to carry out compression process with the source code bag of each compress mode to its correspondence respectively, obtain multiple compressed code bag composition compressed code file, and the pressure texture of compressed code bag is corresponding with the packed attribute in compressed configuration file in compressed code file now, simultaneously, each compressed code bag is associated respectively by the source code bag that switching variable is corresponding with it, therefore, in subsequent applications, developer only need control the switching variable quoted in code file can realize quoting the switching between compressed code and exploitation code that code file quotes, namely compressed code call and exploitation code debugging between switching.In the present embodiment, associate by arranging switching variable in the code file quoting this compressed code between compressed code and exploitation code, not two kinds of codes are separated completely, and when code compaction, function or the different code of type are separately compressed recombinant, therefore, compressed the code obtained by the present invention and can accurately navigate to by switching variable the code packages (code module) gone wrong when testing or effect comparison goes wrong, wireless needs detect each bag more successively, thus, code development efficiency is significantly improved.
It should be noted that, the present embodiment can be realized by Dojo, and wherein, Dojo is a DHTML kit of increasing income realized with JavaScript.The target of Dojo is those that solve that DHTML application program runs into, long-term existence, historical problem and DHTML browser-cross problem.
In the above-described embodiments, described reduced rule comprises: carry out subpackage according to the code function classification preset to code.Such as, the code for JavaScript has three kinds of classification: the Function Classifications such as component code, plug-in code, page code:
Component code: assembly is a code body with certain reusability normally.Component code can be classified according to its purposes, finally forms the code packages of assembly.According to the Compression Strategies of native system, the assembly of function of the same race can be decided to be a functional module bag, in compression process, can be able to be compressed to one " functional layer " in such assembly bag, in use, only need to call corresponding functional layer and just can find corresponding assembly;
Plug-in code: plug-in unit mainly refers to the code that one group of functional module that can be applied to current system that third party develops is corresponding.Such code normally has oneself compression requirement, by its requirement, required for compression configuration is added current compressed configuration;
Page code: page code refers to the operating function code needed for HTML or JSP.Such code has the corresponding code file of a page, therefore, when compressing, can not merge this category code, and just page code is compressed.
In the present embodiment, accordingly, with reference to figure 2, for the realization flow figure of step 101 described in a kind of code compaction embodiment of the method two provided by the invention, wherein, in described step 101, at the reduced rule that foundation is preset, subpackage is carried out to the exploitation code in exploitation code file, when obtaining multiple source code bag, can be realized by following steps:
Step 111: the exploitation code in exploitation code file is classified according to the code function classification preset.
As component code, plug-in code and the page code etc. mentioned in above.
Step 112: other exploitation code of same class will be belonged to and form a source code bag.
Step 113: according to the packet compression rule preset, generate the bag configuration file of bag supporting paper and each described source code bag.
Wherein, in described bag supporting paper, include the package informatin of each source code bag and the positional information of bag configuration file thereof, in each described bag configuration file, include the compress mode of source code bag belonging to it.
It should be noted that, include the essential information of each described source code bag in described package informatin, as descriptor, title and code function information etc.
Accordingly, switching variable is arranged to each described source code bag and after each source code bag is compressed follow-up, can by the control to respective switch variable, to reach the object that piecemeal quotes certain compressed code bag.For the splits' positions of component code, plug-in code and page code in above, the logical relation that corresponding switching variable and the page are quoted can be as shown in Figure 3, that is, after code subpackage, piecemeal compresses, form respective compressed code bag, and then the switching variable by arranging, independently called the page realizing respective piecemeal and quoted.
Based on the implementation in previous embodiment, with reference to figure 4, for described in a kind of code compaction embodiment of the method two provided by the invention 104 realization flow figure, wherein, described step 104 can comprise the following steps:
Step 141: read described bag supporting paper, to obtain the positional information of each bag configuration file in described bag supporting paper.
Step 142: read each described bag configuration file with described positional information.
That is, by reading the positional information of each bag configuration file in described bag supporting paper, corresponding bag configuration file is read successively.
Step 143: obtain the compress mode in each described bag configuration file.
Step 144: with described compress mode, code compaction is carried out to source code bag belonging to it, obtain each self-corresponding compressed code bag of each source code bag.
Wherein, described compress mode refers to, to which code in described source code bag compresses, and directly carries out the mode such as copying, be different from the packed attribute in described compressed configuration file to which code.
Step 145: with the packed attribute in described compressed configuration file, carries out structure merging by all described compressed code bags, obtains compressed code file, and in described compressed code file, the switching variable of each compressed code bag source code bag corresponding to it is associated.
Wherein, the content of described packed attribute can with reference to the content described in above, be: the code in each described source code bag is carried out the attributes such as the structure of assembled arrangement after being compressed and adopts which kind of compress mode to carry out the attribute of code compaction to all bags, as the pressure texture such as a line or plurality of rows attribute and the attribute that how to compress codes such as js and css.
With reference to figure 5, be the process flow diagram of a kind of code compaction embodiment of the method three provided by the invention, wherein, after described step 104, described method can also comprise the following steps:
Step 105: according to the call request received, determine first switching variable compressed code bag corresponding to corresponding with described call request.
Wherein, described first switching variable refers to the switching variable quoted in code file arranging the compressed code bag be corresponding to described call request.
That is, after exploitation code file completes the splits' positions of its code and switching variable is arranged, when can carry out the calling of compressed code, by analyzing the position of call request breaker in middle variable, to determine the position corresponding to the compressed code bag that needs to call, after subsequent operation, the piecemeal that just can complete corresponding independent compression code packages is quoted.
Step 106: according to described first switching variable, generates invoke code.
Wherein, described invoke code refers to: the compressed code bag corresponding with described call request can be carried out the run time version that the page is quoted.
Step 107: perform described invoke code, to call the compressed code bag corresponding with described first switching variable.
Thus, after the described step 107 of execution, the compressed code bag corresponding to described call request can be referred in the corresponding application page, realize the object that piecemeal is quoted, save code space, and efficiency is quoted in raising.
With reference to figure 6, be the partial process view of a kind of code compaction embodiment of the method five provided by the invention, wherein, after described step 107, described method can also comprise the following steps:
Step 108: according to the debug request received, determine second switch variable compressed code bag corresponding to corresponding with described debug request.
Wherein, described second switch variable refers to the switching variable quoted in code file arranging the compressed code bag be corresponding to described debug request.
That is, complete after the page quotes at compressed code, the place gone wrong may be there is, or developer needs to carry out effect comparison to compressed code and corresponding source code thereof, now, need to turn back in exploitation code file the position needing the source code bag debugged, therefore, in the present embodiment, analyzed by the position of the place of the switching variable in debug request being quoted to code file, to determine the position of the source code bag needed corresponding to the compressed code bag of debugging, after subsequent operation, code file just can complete the switching of corresponding source code package location by reference.
Step 109: according to described second switch variable, generating debugging code;
Wherein, described debugging code refers to: this second switch variable can be utilized to switch on the position of the source code bag corresponding to compressed code bag corresponding with described debug request, so that developer modifies or effect comparison to source code bag.
Step 110: perform described debugging code, to call the source code bag corresponding with described second switch variable.
Thus, after the described step 110 of execution, described compression environment can be switched to the code position of the source code bag corresponding to the compressed code bag corresponding with described debug request, the object that code switches, without the need to finding line by line again, significantly improve debugging efficiency and development efficiency.
In the present embodiment, by the control to switching variable, the code that the page is quoted can be controlled.The realization of such function needs when compressing, carry out special configuration, the file be about to after compression carries out corresponding with the physical address of source file, and all reference address, all by the interpolation of a variable and removal, correct for address can be switched to corresponding code.
As shown in Figure 7, what wherein resourcePath represented is local resource path variable, and buildRelease variable is switching variable.In the explorer schematic diagram in left side, can find out that corresponding original " page code " is under scripts path, there are the sub-folders such as " home " " sms " " affairs " below, by creating page code after the compression of corresponding page code after compression, under release path.
In the page uses, by adding the reference statement of " switching variable ", such as, in Fig. 7, want the home.js file under use home catalogue, then need to be introduced by the statement in figure.Like this, if the page wants the variable after using compression, switching variable can be set to " release/ "; If compressed code uses problem, need to adjust, then can be arranged by buildRelease, switchback development environment is modified.
Meanwhile, when compression is carried out, then need according to Compression Strategies, when compressed configuration, compressed file is carried out corresponding distribution, such as, " page code " in upper figure, under then compressed file being distributed in scripts catalogue at the same level, and identified by the compressed path of release.
With reference to figure 8, for the structural representation of a kind of code compaction system embodiment six provided by the invention, wherein, described system is applied in the compression environment built in advance, described compression environment can be understood as: under the code structure of normal development environment, environment required for compression being built is configured, to obtain compressing environment, in the present embodiment, can for Java environment, that is, when carrying out the implementation in the present embodiment, need to ensure the installation of Java environment.
In the present embodiment, described system can realize to code by following structural unit compression:
Code packetized units 801, for according to the reduced rule preset, carries out subpackage to the exploitation code in exploitation code file, obtains multiple source code bag.
Wherein, each described source code bag is its bag configuration file corresponding respectively, includes the compress mode of source code bag belonging to it in described bag configuration file.
It should be noted that, described reduced rule refers to the rule how compressed source code that developer pre-sets according to its actual needs, as reduced overall or splits' positions and adopt which kind of mode to carry out the rule compressed.And the compress mode comprised in bag configuration file respective in each described source code bag source code in its source code bag, such as, which code is compressed compress modes such as which code directly copy.
Switch-linear hybrid unit 802, arranges switching variable for the code file for quoting each described source code bag.
It should be noted that, switching variable in the present embodiment only has one, but it is distributed on the position of the code file of each described source code bag of all references, that is, can by the control of quoting switching variable in code file, to realize the redirect of wrapping in the source code of quoting of the corresponding code file of this switching variable or to call.
Configuration determining unit 803, for according to described reduced rule determination compressed configuration file, includes packed attribute in described compressed configuration file.
Wherein, described packed attribute can be understood as, code in each described source code bag is carried out the attributes such as the structure of assembled arrangement after being compressed and adopts which kind of compress mode to carry out the attribute of code compaction to all bags, as the pressure texture such as a line or plurality of rows attribute and the attribute that how to compress codes such as js and css.
File execution unit 804, for performing described compressed configuration file, to make to carry out compression process with the source code bag of compress mode to its correspondence in each described bag configuration file respectively, obtains multiple compressed code bag.
Wherein, described compressed code bag composition compressed code file, in described compressed code file, the pressure texture of compressed code bag is corresponding with described packed attribute, and in described compressed code file, the switching variable of each compressed code bag source code bag corresponding to it is associated.
It should be noted that, described compressed configuration file is execute file, the process performing this compressed configuration file is: carry out compression process with the source code bag of compress mode to its correspondence in each described bag configuration file respectively, obtain multiple compressed code bag, to make described compressed code bag form compressed code file, and in described compressed code file, the pressure texture of compressed code bag is corresponding with described packed attribute.
In the present embodiment, in described compressed code file, the switching variable quoted in code file of each compressed code bag source code bag corresponding to it is associated, and the switching variable that developer can be quoted in code file by control is to reach the quoted switching between source code and compressed code.
From such scheme, a kind of code compaction system embodiment six provided by the invention, be applied to the compression environment that built in advance as in Java environment, when carrying out code compaction, first according to the reduced rule preset, subpackage is carried out to exploitation code, to obtain multiple source code bag, these source code bags have a bag configuration file containing corresponding compress mode information, afterwards, all switching variable is arranged to the code file quoting each source code bag, and determine according to the reduced rule above the compressed configuration file including packed attribute, and then by performing this compressed configuration file, to make to carry out compression process with the source code bag of each compress mode to its correspondence respectively, obtain multiple compressed code bag composition compressed code file, and the pressure texture of compressed code bag is corresponding with the packed attribute in compressed configuration file in compressed code file now, simultaneously, each compressed code bag is associated respectively by the source code bag that switching variable is corresponding with it, therefore, in subsequent applications, developer only need control the switching variable quoted in code file and can realize quoting code file and lock the switching between compressed code and exploitation code of quoting, namely compressed code call and exploitation code debugging between switching.In the present embodiment, associate by arranging switching variable in the code file quoting this compressed code between compressed code and exploitation code, not two kinds of codes are separated completely, and when code compaction, function or the different code of type are separately compressed recombinant, therefore, compressed the code obtained by the present invention and can accurately navigate to by switching variable the code packages (code module) gone wrong when testing or effect comparison goes wrong, wireless needs detect each bag more successively, thus, code development efficiency is significantly improved.
It should be noted that, the present embodiment can be realized by Dojo, and wherein, Dojo is a DHTML kit of increasing income realized with JavaScript.The target of Dojo is those that solve that DHTML application program runs into, long-term existence, historical problem and DHTML browser-cross problem.
In above-described embodiment, described reduced rule can be: carry out subpackage according to the code function classification preset to code, accordingly, with reference to figure 9, for the structural representation of code packetized units 801 described in a kind of code compaction system embodiment seven provided by the invention, wherein, described code packetized units 801 can comprise the realization of following structure:
Code classification subelement 811, for classifying according to the code function classification preset to the exploitation code in exploitation code file.
As component code, plug-in code and the page code etc. mentioned in above.
Bag composition subelement 812, forms a source code bag for belonging to other exploitation code of same class.
File generated subelement 813, for according to the packet compression rule preset, generates the bag configuration file of bag supporting paper and each described source code bag.
Wherein, in described bag supporting paper, include the package informatin of each source code bag and the positional information of bag configuration file thereof, in each described bag configuration file, include the compress mode of source code bag belonging to it.
It should be noted that, include the essential information of each described source code bag in described package informatin, as descriptor, title and code function information etc.
Accordingly, switching variable is arranged to each described source code bag and after each source code bag is compressed follow-up, can by the control to respective switch variable, to reach the object that piecemeal quotes certain compressed code bag.For the splits' positions of component code, plug-in code and page code in above, the logical relation that corresponding switching variable and the page are quoted can be as shown in Figure 3, that is, after code subpackage, piecemeal compresses, form respective compressed code bag, and then the switching variable by arranging, independently called the page realizing respective piecemeal and quoted.
Based on the implementation in previous embodiment, with reference to Figure 10, be the structural representation of file execution unit 804 described in a kind of code compaction system embodiment eight provided by the invention, wherein, described file execution unit 804 can be realized by following structure:
First file reads subelement 841, for reading described bag supporting paper, to obtain the positional information of each bag configuration file in described bag supporting paper.
Second file reads subelement 842, for reading each described bag configuration file with described positional information.
That is, by reading the positional information of each bag configuration file in described bag supporting paper, corresponding bag configuration file is read successively.
Compress mode obtains subelement 843, for obtaining the compress mode in each described bag configuration file.
Code compaction subelement 844, for carrying out code compaction with described compress mode to source code bag belonging to it, obtains each self-corresponding compressed code bag of each source code bag.
Wherein, described compress mode refers to, to which code in described source code bag compresses, and directly carries out the mode such as copying, be different from the packed attribute in described compressed configuration file to which code.
Compressed package merges subelement 845, for with the packed attribute in described compressed configuration file, all described compressed code bags are carried out structure merging, obtains compressed code file, in described compressed code file, the switching variable of each compressed code bag source code bag corresponding to it is associated.
Wherein, the content of described packed attribute can with reference to the content described in above, be: the code in each described source code bag is carried out the attributes such as the structure of assembled arrangement after being compressed and adopts which kind of compress mode to carry out the attribute of code compaction to all bags, as the pressure texture such as a line or plurality of rows attribute and the attribute that how to compress codes such as js and css.
With reference to Figure 11, be the structural representation of a kind of code compaction system embodiment nine provided by the invention, wherein, described system can also comprise following structural unit:
First variable determination unit 805, for performing described compressed configuration file in described file execution unit 804 with after obtaining multiple compressed code bag, according to the call request received, determine first switching variable compressed code bag corresponding to corresponding with described call request.
Wherein, described first switching variable refers to the switching variable quoted in code file arranging the compressed code bag be corresponding to described call request.
That is, after exploitation code file completes the splits' positions of its code and switching variable is arranged, when can carry out the calling of compressed code, by analyzing the position of call request breaker in middle variable, to determine the position corresponding to the compressed code bag that needs to call, after subsequent operation, the piecemeal that just can complete corresponding independent compression code packages is quoted.
Invoke code generation unit 806, for according to described first switching variable, generates invoke code.
Wherein, described invoke code refers to: the compressed code bag corresponding with described call request can be carried out the run time version that the page is quoted.
Invoke code performance element 807, for performing described invoke code, to call the compressed code bag corresponding with described first switching variable.
Thus, after the described invoke code performance element 807 of operation, the compressed code bag corresponding to described call request can be referred in the corresponding application page, realize the object that piecemeal is quoted, save code space, and efficiency is quoted in raising.
With reference to Figure 12, be the structural representation of a kind of code compaction system embodiment ten provided by the invention, wherein, described system can also comprise following structure:
Second variable determination unit 808, for according to the debug request received, determines second switch variable compressed code bag corresponding to corresponding with described debug request.
Wherein, described second switch variable refers to the switching variable quoted in code file arranging the compressed code bag be corresponding to described debug request.
That is, complete after the page quotes at compressed code, the place gone wrong may be there is, or developer needs to carry out effect comparison to compressed code and corresponding source code thereof, now, need to turn back in exploitation code file the position needing the source code bag debugged, therefore, in the present embodiment, analyzed by the position of the place of the switching variable in debug request being quoted to code file, to determine the position of the source code bag needed corresponding to the compressed code bag of debugging, after subsequent operation, code file just can complete the switching of corresponding source code package location by reference.
Debugging code generation unit 809, for according to described second switch variable, generating debugging code.
Wherein, described debugging code refers to: this second switch variable can be utilized to switch on the position of the source code bag corresponding to compressed code bag corresponding with described debug request, so that developer modifies or effect comparison to source code bag.
Debugging code performance element 810, for performing described debugging code, with the bar source code bag corresponding with described second switch variable.
Thus, after the described debugging code performance element 810 of operation, described compression environment can be switched to the code position of the source code bag corresponding to the compressed code bag corresponding with described debug request, the object that code switches, without the need to finding line by line again, significantly improve debugging efficiency and development efficiency.
In the present embodiment, by the control to switching variable, the code that the page is quoted can be controlled.The realization of such function needs when compressing, carry out special configuration, the file be about to after compression carries out corresponding with the physical address of source file, and all reference address, all by the interpolation of a variable and removal, correct for address can be switched to corresponding code.
As shown in Figure 7, what wherein resourcePath represented is local resource path variable, and buildRelease variable is switching variable.In the explorer schematic diagram in left side, can find out that corresponding original " page code " is under scripts path, there are the sub-folders such as " home " " sms " " affairs " below, by creating page code after the compression of corresponding page code after compression, under release path.
In the page uses, by adding the reference statement of " switching variable ", such as, in Fig. 7, want the home.js file under use home catalogue, then need to be introduced by the statement in figure.Like this, if the page wants the variable after using compression, switching variable can be set to " release/ "; If compressed code uses problem, need to adjust, then can be arranged by buildRelease, switchback development environment is modified.
Meanwhile, when compression is carried out, then need according to Compression Strategies, when compressed configuration, compressed file is carried out corresponding distribution, such as, " page code " in upper figure, under then compressed file being distributed in scripts catalogue at the same level, and identified by the compressed path of release.
It should be noted that, each embodiment in this instructions all adopts the mode of going forward one by one to describe, and what each embodiment stressed is the difference with other embodiments, between each embodiment identical similar part mutually see.
Finally, also it should be noted that, in this article, the such as relational terms of first and second grades and so on is only used for an entity or operation to separate with another entity or operational zone, and not necessarily requires or imply the relation that there is any this reality between these entities or operation or sequentially.And, term " comprises ", " comprising " or its any other variant are intended to contain comprising of nonexcludability, thus make to comprise the process of a series of key element, method, article or equipment and not only comprise those key elements, but also comprise other key elements clearly do not listed, or also comprise by the intrinsic key element of this process, method, article or equipment.When not more restrictions, the key element limited by statement " comprising ... ", and be not precluded within process, method, article or the equipment comprising described key element and also there is other identical element.
Above a kind of code compaction method and system that the application provides are described in detail, apply specific case herein to set forth the principle of the application and embodiment, the explanation of above embodiment is just for helping method and the core concept thereof of understanding the application; Meanwhile, for one of ordinary skill in the art, according to the thought of the application, all will change in specific embodiments and applications, in sum, this description should not be construed as the restriction to the application.

Claims (10)

1. a code compaction method, is characterized in that, be applied in the compression environment built in advance, described method comprises:
According to the reduced rule preset, subpackage is carried out to the exploitation code in exploitation code file, obtain multiple source code bag, each described source code bag is its bag configuration file corresponding respectively, includes the compress mode of source code bag belonging to it in described bag configuration file;
For the code file quoting each described source code bag arranges switching variable;
According to described reduced rule determination compressed configuration file, in described compressed configuration file, include packed attribute;
Perform described compressed configuration file, to make to carry out compression process with the source code bag of compress mode to its correspondence in each described bag configuration file respectively, obtain multiple compressed code bag, described compressed code bag composition compressed code file, in described compressed code file, the pressure texture of compressed code bag is corresponding with described packed attribute, and in described compressed code file, the switching variable of each compressed code bag source code bag corresponding to it is associated.
2. method according to claim 1, is characterized in that, described reduced rule comprises: carry out subpackage according to the code function classification preset to code;
Accordingly, the reduced rule that described foundation is preset, carries out subpackage to the exploitation code in exploitation code file, obtains multiple source code bag, comprising:
Exploitation code in exploitation code file is classified according to the code function classification preset;
Other exploitation code of same class will be belonged to and form a source code bag;
According to the packet compression rule preset, generate the bag configuration file of bag supporting paper and each described source code bag, include the package informatin of each source code bag and the positional information of bag configuration file thereof in described bag supporting paper, in each described bag configuration file, include the compress mode of source code bag belonging to it.
3. method according to claim 2, it is characterized in that, the described compressed configuration file of described execution, to make to carry out compression process with the source code bag of compress mode to its correspondence in each described bag configuration file respectively, obtain multiple compressed code bag, comprising:
Read described bag supporting paper, to obtain the positional information of each bag configuration file in described bag supporting paper;
Each described bag configuration file is read with described positional information;
Obtain the compress mode in each described bag configuration file;
With described compress mode, code compaction is carried out to source code bag belonging to it, obtain each self-corresponding compressed code bag of each source code bag;
With the packed attribute in described compressed configuration file, all described compressed code bags are carried out structure merging, obtains compressed code file, in described compressed code file, the switching variable of each compressed code bag source code bag corresponding to it is associated.
4. the method according to claim 1,2 or 3, is characterized in that, after obtaining multiple compressed code bag, described method also comprises:
According to the call request received, determine first switching variable compressed code bag corresponding to corresponding with described call request;
According to described first switching variable, generate invoke code;
Perform described invoke code, to call the compressed code bag corresponding with described first switching variable.
5. method according to claim 4, is characterized in that, at described first invoke code of execution, after calling the compressed code bag corresponding with described first switching variable, described method also comprises:
According to the debug request received, determine second switch variable compressed code bag corresponding to corresponding with described debug request;
According to described second switch variable, generating debugging code;
Perform described debugging code, to call the source code bag corresponding with described second switch variable.
6. a code compaction system, is characterized in that, be applied in the compression environment built in advance, described system comprises:
Code packetized units, for according to the reduced rule preset, subpackage is carried out to the exploitation code in exploitation code file, obtains multiple source code bag, each described source code bag is its bag configuration file corresponding respectively, includes the compress mode of source code bag belonging to it in described bag configuration file;
Switch-linear hybrid unit, arranges switching variable for the code file for quoting each described source code bag;
Configuration determining unit, for according to described reduced rule determination compressed configuration file, includes packed attribute in described compressed configuration file;
File execution unit, for performing described compressed configuration file, to make to carry out compression process with the source code bag of compress mode to its correspondence in each described bag configuration file respectively, obtain multiple compressed code bag, described compressed code bag composition compressed code file, in described compressed code file, the pressure texture of compressed code bag is corresponding with described packed attribute, and in described compressed code file, the switching variable of each compressed code bag source code bag corresponding to it is associated.
7. system according to claim 6, is characterized in that, described reduced rule comprises: carry out subpackage according to the code function classification preset to code;
Accordingly, described code packetized units comprises:
Code classification subelement, for classifying according to the code function classification preset to the exploitation code in exploitation code file;
Bag composition subelement, forms a source code bag for belonging to other exploitation code of same class;
File generated subelement, for regular according to the packet compression preset, generate the bag configuration file of bag supporting paper and each described source code bag, include the package informatin of each source code bag and the positional information of bag configuration file thereof in described bag supporting paper, in each described bag configuration file, include the compress mode of source code bag belonging to it.
8. system according to claim 7, is characterized in that, described file execution unit comprises:
First file reads subelement, for reading described bag supporting paper, to obtain the positional information of each bag configuration file in described bag supporting paper;
Second file reads subelement, for reading each described bag configuration file with described positional information;
Compress mode obtains subelement, for obtaining the compress mode in each described bag configuration file;
Code compaction subelement, for carrying out code compaction with described compress mode to source code bag belonging to it, obtains each self-corresponding compressed code bag of each source code bag;
Compressed package merges subelement, for with the packed attribute in described compressed configuration file, all described compressed code bags are carried out structure merging, obtains compressed code file, in described compressed code file, the switching variable of each compressed code bag source code bag corresponding to it is associated.
9. the system according to claim 6,7 or 8, is characterized in that, also comprise:
First variable determination unit, for performing described compressed configuration file in described file execution unit with after obtaining multiple compressed code bag, according to the call request received, determine first switching variable compressed code bag corresponding to corresponding with described call request;
Invoke code generation unit, for according to described first switching variable, generates invoke code;
Invoke code performance element, for performing described invoke code, to call the compressed code bag corresponding with described first switching variable.
10. system according to claim 9, is characterized in that, also comprises:
Second variable determination unit, for according to the debug request received, determines second switch variable compressed code bag corresponding to corresponding with described debug request;
Debugging code generation unit, for according to described second switch variable, generating debugging code;
Debugging code performance element, for performing described debugging code, with the bar source code bag corresponding with described second switch variable.
CN201410709985.5A 2014-11-28 2014-11-28 A kind of code compaction method and system Active CN104331316B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201410709985.5A CN104331316B (en) 2014-11-28 2014-11-28 A kind of code compaction method and system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201410709985.5A CN104331316B (en) 2014-11-28 2014-11-28 A kind of code compaction method and system

Publications (2)

Publication Number Publication Date
CN104331316A true CN104331316A (en) 2015-02-04
CN104331316B CN104331316B (en) 2017-11-24

Family

ID=52406050

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201410709985.5A Active CN104331316B (en) 2014-11-28 2014-11-28 A kind of code compaction method and system

Country Status (1)

Country Link
CN (1) CN104331316B (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105045598A (en) * 2015-08-07 2015-11-11 北京思特奇信息技术股份有限公司 Java-based web front-end performance optimization and online method and system
CN107193615A (en) * 2017-06-29 2017-09-22 北京全域医疗技术有限公司 The renewal dispositions method and device of item code information

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US4890326A (en) * 1988-03-03 1989-12-26 Rubiyat Software, Inc. Method for compressing data
CN101021812A (en) * 2006-12-21 2007-08-22 华为技术有限公司 Interpreter language debugging method and device
CN101673326A (en) * 2008-09-11 2010-03-17 北京理工大学 Method for detecting web page Trojan horse based on program execution characteristics
CN102419715A (en) * 2011-08-29 2012-04-18 展讯通信(上海)有限公司 Code compression method and device as well as code execution method

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US4890326A (en) * 1988-03-03 1989-12-26 Rubiyat Software, Inc. Method for compressing data
CN101021812A (en) * 2006-12-21 2007-08-22 华为技术有限公司 Interpreter language debugging method and device
CN101673326A (en) * 2008-09-11 2010-03-17 北京理工大学 Method for detecting web page Trojan horse based on program execution characteristics
CN102419715A (en) * 2011-08-29 2012-04-18 展讯通信(上海)有限公司 Code compression method and device as well as code execution method

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105045598A (en) * 2015-08-07 2015-11-11 北京思特奇信息技术股份有限公司 Java-based web front-end performance optimization and online method and system
CN107193615A (en) * 2017-06-29 2017-09-22 北京全域医疗技术有限公司 The renewal dispositions method and device of item code information
CN107193615B (en) * 2017-06-29 2020-12-04 北京全域医疗技术集团有限公司 Project code information updating and deploying method and device

Also Published As

Publication number Publication date
CN104331316B (en) 2017-11-24

Similar Documents

Publication Publication Date Title
CN109614823B (en) Data processing method, device and equipment
KR102107872B1 (en) Compiler based obfuscation
CN107783762B (en) Interface generation method and device, storage medium and computer equipment
WO2021208288A1 (en) Program implementation method and system capable of separating code and configuration data
US20170289730A1 (en) Adaptive audio rendering
CN107580013B (en) Method and device for requesting data in cross-domain mode
CN113079200A (en) Data processing method, device and system
KR101619458B1 (en) Application code obfuscating apparatus and method of obfuscating application code using the same
CN106547580B (en) Method and device for hooking function, mobile terminal and storage medium
CN102799640A (en) Page loading device and page loading method
CN109376316B (en) Method, system and server for dynamically loading route
CN110941779B (en) Page loading method and device, storage medium and electronic equipment
CN103176833A (en) Data transmission method, data receiving method and system based on virtual machine
CN111596920B (en) File compiling method, device, compiling equipment and storage medium
CN110781192B (en) Verification method, device and equipment of block chain data
CN104331316A (en) Code compression method and system
CN105373548A (en) Mobile device and event self-definition method for browser of mobile device
CN110602163B (en) File uploading method and device
CN103324885A (en) Method and system for protecting kernel-level file
CN104346397B (en) Switching method based on the Asynchronous Request page and system
CN105045598A (en) Java-based web front-end performance optimization and online method and system
CN103164492A (en) File copying method between electronic devices and electronic devices
JP2005228183A (en) Program execution method and computer system for executing the program
CN105005497A (en) Method and apparatus for calling local function in Java card virtual machine
CN113467817A (en) Application management method, system, medium and electronic terminal

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant