CN104331316B - A kind of code compaction method and system - Google Patents
A kind of code compaction method and system Download PDFInfo
- Publication number
- CN104331316B CN104331316B CN201410709985.5A CN201410709985A CN104331316B CN 104331316 B CN104331316 B CN 104331316B CN 201410709985 A CN201410709985 A CN 201410709985A CN 104331316 B CN104331316 B CN 104331316B
- Authority
- CN
- China
- Prior art keywords
- code
- bag
- compression
- 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.)
- Active
Links
Abstract
The invention discloses a kind of code compaction method and system, in the compression environment completed applied to advance structure, methods described includes:According to default reduced rule, subpackage is carried out to the exploitation code in exploitation code file, obtains multiple source code bags, each source code bag corresponds to its bag configuration file respectively, and the compress mode of its affiliated source code bag is included in bag configuration file;To quote the code file of each source code bag, switching variable is set;Compressed configuration file is determined according to reduced rule, includes packed attribute in compressed configuration file;Perform compressed configuration file, so as to processing must be compressed to its corresponding source code bag with the compress mode in each bag configuration file respectively, obtain multiple compression code bags, compression code bag forms compression code file, the pressure texture of compression code bag is corresponding with packed attribute in compression code file, and the switching variable of each corresponding source code bag of compression code bag is associated in compression code file.
Description
Technical field
The present invention relates to technical field of software development, more particularly to a kind of code compaction method and system.
Background technology
In software application development, in order to make code file smaller, execution efficiency is higher, and for protection code
Purpose, typically can to enter actually use in code be compressed.
In existing javascript compression schemes, generally exploitation and compression separates, that is to say, that is developing substantially
Cheng Hou, obtains compression code by way of disposably code is compressed, then by repetitious progress source code with
After the Contrast on effect of compression code, to obtain compressing successful compression code, by compressed package renewal to actual application system
In.
Wherein, it is in existing compression scheme, compression code and exploitation code is completely separated, and typically multiple functions
, therefore, can not be accurate when test or effect are compared and gone wrong or the code module of type merges in a code file
The code module to go wrong is navigated to, it is necessary to be detected successively to each module, thus, hence it is evident that reduce code development effect
Rate.
The content of the invention
It is an object of the present invention to provide a kind of code compaction method and system, to solve code of the prior art
Compression scheme, compression code and exploitation code is completely separated, and typically the code module of multiple functions or type merges
In one code file, the code module to go wrong can not be accurately positioned when test or effect are compared and gone wrong, is needed
Each module is detected successively, thus, hence it is evident that reduce the technical problem of code development efficiency.
The invention provides a kind of code compaction method, in the compression environment completed applied to advance structure, methods described
Including:
According to default reduced rule, subpackage is carried out to the exploitation code in exploitation code file, obtains multiple original generations
Code bag, each source code bag correspond to its bag configuration file respectively, include in the bag configuration file original belonging to it
The compress mode of code bag;
To quote the code file of each source code bag, switching variable is set;
Compressed configuration file is determined according to the reduced rule, includes packed attribute in the compressed configuration file;
The compressed configuration file is performed, so that must be right to its with the compress mode in each bag configuration file respectively
The source code bag answered is compressed processing, obtains multiple compression code bags, and the compression code bag forms compression code file,
The pressure texture of compression code bag is corresponding with the packed attribute in the compression code file, in the compression code file
The switching variable of the corresponding source code bag of each compression code bag is associated.
The above method, it is preferred that the reduced rule includes:Code is divided according to default code function classification
Bag;
Accordingly, it is described according to default reduced rule, subpackage is carried out to the exploitation code in exploitation code file, obtained
Multiple source code bags, including:
Exploitation code in exploitation code file is classified according to default code function classification;
Same category of exploitation code will be belonged to and form a source code bag;
According to default packet compression rule, bag supporting paper and each the bag configuration file of the source code bag are generated,
Include the package informatin of each source code bag and its positional information of bag configuration file in the bag supporting paper, it is each described
Include the compress mode of its affiliated source code bag in bag configuration file.
The above method, it is preferred that it is described to perform the compressed configuration file, so that must be respectively with each bag configuration text
Compress mode in part is compressed processing to its corresponding source code bag, obtains multiple compression code bags, including:
The bag supporting paper is read, to obtain the positional information of each bag configuration file in the bag supporting paper;
Each bag configuration file is read with the positional information;
Obtain the compress mode in each bag configuration file;
Code compaction is carried out to its affiliated source code bag with the compress mode, it is each right to obtain each source code bag
The compression code bag answered;
With the packed attribute in the compressed configuration file, all compression code bags are subjected to structure merging, obtained
Compression code file, the switching variable of the corresponding source code bag of each compression code bag is related in the compression code file
Connection.
The above method, it is preferred that after multiple compression code bags are obtained, methods described also includes:
According to the call request received, it is determined that first corresponding to the compression code bag corresponding with the call request
Switching variable;
According to the first switch variable, code is called in generation;
The calling code is performed, to call the compression code bag corresponding with the first switch variable.
The above method, it is preferred that code is called performing described first, it is corresponding with the first switch variable to call
Compression code bag after, methods described also includes:
According to the debugging request received, it is determined that second corresponding to the compression code bag corresponding with the debugging request
Switching variable;
According to the second switch variable, debugging code is generated;
The debugging code is performed, to call the source code bag corresponding with the second switch variable.
Present invention also offers a kind of code compaction system, in the compression environment completed applied to advance structure, the system
System includes:
Code packetized units, for according to default reduced rule, dividing the exploitation code in exploitation code file
Bag, obtains multiple source code bags, and each source code bag corresponds to its bag configuration file respectively, in the bag configuration file
Include the compress mode of its affiliated source code bag;
Setting unit is switched, for setting switching variable to quote the code file of each source code bag;
Determining unit is configured, for determining compressed configuration file according to the reduced rule, in the compressed configuration file
Include packed attribute;
File execution unit, for performing the compressed configuration file, so that must be respectively with each bag configuration file
In compress mode processing is compressed to its corresponding source code bag, obtain multiple compression code bags, the compression code
Wrap and form compression code file, the pressure texture of compression code bag is relative with the packed attribute in the compression code file
Should, the switching variable of the corresponding source code bag of each compression code bag is associated in the compression code file.
Said system, it is preferred that the reduced rule includes:Code is divided according to default code function classification
Bag;
Accordingly, the code packetized units include:
Code classification subelement, for entering to the exploitation code in exploitation code file according to default code function classification
Row classification;
Bag composition subelement, a source code bag is formed for same category of exploitation code will to be belonged to;
File generated subelement, for according to default packet compression rule, generating bag supporting paper and each described original
The bag configuration file of code bag, the package informatin and its bag configuration file of each source code bag are included in the bag supporting paper
Positional information, the compress mode of its affiliated source code bag is included in each bag configuration file.
Said system, it is preferred that the file execution unit includes:
First file reads subelement, each in the bag supporting paper to obtain for reading the bag supporting paper
The positional information of bag configuration file;
Second file reads subelement, for reading each bag configuration file with the positional information;
Compress mode obtains subelement, for obtaining the compress mode in each bag configuration file;
Code compaction subelement, for carrying out code compaction to its affiliated source code bag with the compress mode, obtain
Each self-corresponding compression code bag of each source code bag;
Compressed package merges subelement, for the packed attribute in the compressed configuration file, by all compression generations
Code bag carries out structure merging, obtains compression code file, the corresponding original of each compression code bag in the compression code file
The beginning switching variable of code bag is associated.
Said system, it is preferred that also include:
First variable determination unit, it is multiple to obtain for performing the compressed configuration file in the file execution unit
After compression code bag, according to the call request received, it is determined that the compression code bag institute corresponding with the call request is right
The first switch variable answered;
Code generating unit is called, for calling code according to the first switch variable, generation;
Code execution unit is called, it is corresponding with the first switch variable to call for performing the calling code
Compression code bag.
Said system, it is preferred that also include:
Second variable determination unit, the debugging request received for foundation, it is determined that corresponding with the debugging request
Second switch variable corresponding to compression code bag;
Debugging code generation unit, for according to the second switch variable, generating debugging code;
Debugging code execution unit, for performing the debugging code, with bar with corresponding with the second switch variable
Source code bag.
From such scheme, a kind of code compaction method and system provided by the invention, completed applied to advance structure
Compression environment such as Java context in, when carrying out code compaction, be first according to default reduced rule to exploitation code carry out
Subpackage, to obtain multiple source code bags, these source code bags have a bag containing corresponding compress mode information to configure
File, afterwards, switching variable is respectively provided with to the code file for quoting each source code bag, and according to reduced rule hereinbefore
It is determined that include the compressed configuration file of packed attribute, and then by performing the compressed configuration file, so that must be respectively with each
Compress mode is compressed processing to its corresponding source code bag, obtains multiple compression code bag composition compression code files,
And the pressure texture of compression code bag is corresponding with the packed attribute in compressed configuration file in compression code file now, together
When, each compression code bag is associated by the corresponding source code bag of switching variable respectively, therefore, in subsequent applications
In, developer need to only control the switching variable corresponding to the code file for quoting source code bag to realize compression code with opening
Send out the switching between code, that is, the switching between the calling of compression code and the debugging of exploitation code.In the present invention, pressing
It is not that two kinds of codes are completely separated by setting switching variable to be associated between contracting code and exploitation code, and in generation
Function or different types of code separate during code compression and compress recombinant, therefore, the generation obtained by present invention compression
Code can be accurately positioned code bag (the i.e. code to go wrong when test or effect are compared and gone wrong by switching variable
Module), it is wireless to need again successively to detect each bag, thus, hence it is evident that improve code development efficiency.
Brief description of the drawings
In order to illustrate more clearly about the embodiment of the present invention or technical scheme of the prior art, below will be to embodiment or existing
There is the required accompanying drawing used in technology description to be briefly described, it should be apparent that, drawings in the following description are only this
The embodiment of invention, for those of ordinary skill in the art, on the premise of not paying creative work, can also basis
The accompanying drawing of offer obtains other accompanying drawings.
Fig. 1 is a kind of flow chart of code compaction embodiment of the method one provided by the invention;
Fig. 2 is a kind of partial process view of code compaction embodiment of the method two provided by the invention;
Fig. 3 is the application exemplary plot of the embodiment of the present invention;
Fig. 4 is a kind of partial process view of code compaction embodiment of the method two provided by the invention;
Fig. 5 is a kind of flow chart of code compaction embodiment of the method three provided by the invention;
Fig. 6 is a kind of partial process view 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 a kind of structural representation of code compaction system embodiment six provided by the invention;
Fig. 9 is a kind of part-structure schematic diagram of code compaction system embodiment seven provided by the invention;
Figure 10 is a kind of part-structure schematic diagram of code compaction system embodiment eight provided by the invention;
Figure 11 is a kind of structural representation of code compaction system embodiment nine provided by the invention;
Figure 12 is a kind of structural representation 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, the technical scheme in the embodiment of the present invention is carried out clear, complete
Site preparation describes, it is clear that described embodiment is only part of the embodiment of the present invention, rather than whole embodiments.It is based on
Embodiment in the present invention, those of ordinary skill in the art are obtained every other under the premise of creative work is not made
Embodiment, belong to the scope of protection of the invention.
It is a kind of flow chart of code compaction embodiment of the method one provided by the invention with reference to figure 1, wherein, methods described
In the compression environment completed applied to advance structure, the compression environment can be understood as:In the code of normal development environment
Under structure, the environment required for compressing structure is configured, in the present embodiment, can be with Java to obtain compression environment
Exemplified by environment, that is to say, that in the implementation in carrying out the present embodiment, it is necessary to ensure Java context installation.
In the present embodiment, methods described can realize the compression to code by following steps:
Step 101:According to default reduced rule, subpackage is carried out to the exploitation code in exploitation code file, obtained more
Individual source code bag.
Wherein, each source code bag corresponds to its bag configuration file respectively, includes it in the bag configuration file
The compress mode of affiliated source code bag.
It should be noted that the reduced rule refer to developer be actually needed according to it pre-set to original generation
The rule how code is compressed, the rule being compressed such as reduced overall or splits' positions and using which kind of mode.It is and each
The compress mode to source code in its source code bag, example are included in the source code bag in respective bag configuration file
Such as, which code is compressed and which code carries out the directly compress mode such as duplication to.
Step 102:To quote the code file of each source code bag, switching variable is set.
It should be noted that the switching variable in the present embodiment only has one, but its to be distributed in all references each described
On the position of the code file of source code bag, that is to say, that can by quote code file upper switch variable control,
Redirecting or calling what the switching variable corresponded to that the cited source code of code file wraps to realize.
Step 103:Compressed configuration file is determined according to the reduced rule, includes compression in the compressed configuration file
Attribute.
Wherein, the packed attribute is it is to be understood that the code in each source code bag is carried out after compression
The attributes such as the structure of assembled arrangement and the attribute that all bags are carried out with code compaction using which kind of compress mode, such as a line or multirow
The pressure texture attributes such as arrangement and the attribute how being compressed to codes such as js and css.
Step 104:The compressed configuration file is performed, so that must be respectively with the compression side in each bag configuration file
Formula is compressed processing to its corresponding source code bag, obtains multiple compression code bags.
Wherein, compression code bag composition compression code file, the pressure of compression code bag in the compression code file
Shrinking structure is corresponding with the packed attribute, the corresponding source code bag of each compression code bag in the compression code file
Switching variable be associated.
It should be noted that the compressed configuration file is to perform file, the process of the compressed configuration file is performed i.e.
For:Processing is compressed to its corresponding source code bag with the compress mode in each bag configuration file respectively, obtained
Multiple compression code bags, to cause the compression code bag to form compression code file, and compressed in the compression code file
The pressure texture of code bag is corresponding with the packed attribute.
In the present embodiment, in the compression code file the corresponding source code bag of each compression code bag reference
Switching variable in code file is associated, and developer can quote the switching variable in code file to reach by controlling
Switching between cited source code and compression code.
From such scheme, a kind of code compaction embodiment of the method one provided by the invention, applied to having built in advance
Into compression environment such as Java context in, when carrying out code compaction, be first according to default reduced rule and exploitation code entered
Row subpackage, to obtain multiple source code bags, these source code bags have a bag containing corresponding compress mode information to match somebody with somebody
File is put, afterwards, switching variable is respectively provided with to the code file for quoting each source code bag, and according to compression rule hereinbefore
The compressed configuration file for including packed attribute is then determined, and then by performing the compressed configuration file, so that must be respectively with every
Individual compress mode is compressed processing to its corresponding source code bag, obtains multiple compression code bag composition compression code texts
Part, and the pressure texture of compression code bag is relative with the packed attribute in compressed configuration file in compression code file now
Should, meanwhile, each compression code bag is associated by the corresponding source code bag of switching variable respectively, therefore, follow-up
In, developer need to only control the switching variable quoted in code file to can be achieved to quote the pressure cited in code file
Switching between switching between contracting code and exploitation code, that is, the calling of compression code and the debugging of exploitation code.This
In embodiment, by setting switching variable in the code file for quoting the compression code between compression code and exploitation code
It is associated, it is not that two kinds of codes are completely separated, and divided function or different types of code in code compaction
Compression recombinant is opened, therefore, can be passed through when test or effect are compared and gone wrong by the code that present invention compression obtains
Switching variable is accurately positioned the code bag (i.e. code module) to go wrong, wireless to need again successively to examine each bag
Survey, thus, hence it is evident that improve code development efficiency.
It should be noted that the present embodiment can be realized by Dojo, wherein, Dojo is one and realized with JavaScript
DHTML kits of increasing income.Dojo target be solve DHTML application programs run into those, long-term existence, historical problem with
And DHTML browser-cross problems.
In the above-described embodiments, the reduced rule includes:Subpackage is carried out to code according to default code function classification.
For example, there are three kinds of classification for JavaScript code:The function classifications such as component code, plug-in code, page code:
Component code:Component is typically a body of code with certain durability.Component code can enter according to its purposes
Row classification, finally form the code bag of component.According to the Compression Strategies of the system, the component of function of the same race can be decided to be a work(
Energy component bag, such component bag is interior can be compressed to one " functional layer ", when in use in compression process, it is only necessary to
Corresponding functional layer can is called to find corresponding component;
Plug-in code:The one group of functional module that can be applied to current system that plug-in unit is primarily referred to as third party's exploitation is corresponding
Code.Such code is typically to have the compression requirement of oneself, and configuration needed for compression is added into current compression by its requirement
Configuration;
Page code:Page code refers to the operating function code needed for HTML or JSP.Such code has a page
The corresponding code file in face, therefore, in compression, this category code will not be merged, and simply page code is pressed
Contracting.
In the present embodiment, accordingly, it is in a kind of code compaction embodiment of the method two provided by the invention with reference to figure 2
The implementation process figure of the step 101, wherein, in the step 101, according to default reduced rule, to exploitation code text
Exploitation code in part carries out subpackage, when obtaining multiple source code bags, can be realized by following steps:
Step 111:Exploitation code in exploitation code file is classified according to default code function classification.
Component code, plug-in code and page code as noted above etc..
Step 112:Same category of exploitation code will be belonged to and form a source code bag.
Step 113:According to default packet compression rule, the bag for generating bag supporting paper and each source code bag is matched somebody with somebody
Put file.
Wherein, the package informatin of each source code bag and its position of bag configuration file are included in the bag supporting paper
Information, the compress mode of its affiliated source code bag is each included in the bag configuration file.
It should be noted that include the essential information of each source code bag in the package informatin, such as description letter
Breath, title and code function information etc..
Accordingly, switching variable subsequently is being set to each source code bag and each source code bag is being pressed
, can be by the control to respective switch variable, to reach the purpose that piecemeal quotes some compression code bag after contracting.With above
Exemplified by the splits' positions of middle component code, plug-in code and page code, the logic that corresponding switching variable and the page are quoted is closed
System can be as shown in Figure 3, that is to say, that and after code subpackage, piecemeal is compressed, and forms respective compression code bag,
And then by the switching variable of setting, the page for realizing respective piecemeal by independent calling is quoted.
Based on the implementation in previous embodiment, with reference to figure 4, implement for a kind of code compaction method provided by the invention
104 implementation process figure described in example two, wherein, the step 104 may comprise steps of:
Step 141:The bag supporting paper is read, to obtain the position of each bag configuration file in the bag supporting paper
Information.
Step 142:Each bag configuration file is read with the positional information.
That is, the positional information by reading each bag configuration file in the bag supporting paper, read successively
Corresponding bag configuration file.
Step 143:Obtain the compress mode in each bag configuration file.
Step 144:Code compaction is carried out to its affiliated source code bag with the compress mode, obtains each source code
Wrap each self-corresponding compression code bag.
Wherein, the compress mode refers to, which of source code bag code is compressed, to which code
Directly carry out the mode such as replicating, the packed attribute being different from the compressed configuration file.
Step 145:With the packed attribute in the compressed configuration file, all compression code bags are subjected to structure conjunction
And compression code file is obtained, the switch of the corresponding source code bag of each compression code bag in the compression code file
Variable is associated.
Wherein, the content of the packed attribute may be referred to content described above, be:Each original generation
Code in code bag is combined the attributes such as the structure of arrangement and all bags is carried out using which kind of compress mode after compression
The attribute of code compaction, how being compressed such as the pressure texture such as a line or plurality of rows attribute and to codes such as js and css
Attribute.
It is a kind of flow chart of code compaction embodiment of the method three provided by the invention with reference to figure 5, wherein, in the step
After rapid 104, methods described can also comprise the following steps:
Step 105:According to the call request received, it is determined that the compression code bag institute corresponding with the call request is right
The first switch variable answered.
Wherein, the first switch variable refers to be provided in the reference of the compression code bag corresponding to the call request
Switching variable in code file.
That is, after exploitation code file completes the splits' positions of its code and switching variable is set, Neng Goujin
During the calling of row compression code, by analyzing the position of switching variable in call request, to determine to need the pressure called
Position corresponding to contracting code bag, after subsequent operation, the piecemeal that could complete corresponding independent compression code bag is quoted.
Step 106:According to the first switch variable, code is called in generation.
Wherein, the calling code refers to:The compression code bag corresponding with the call request can be subjected to the page
The execution code of reference.
Step 107:The calling code is performed, to call the compression code bag corresponding with the first switch variable.
Thus, after the step 107 is performed, the compression code bag corresponding with the call request can be quoted
Into corresponding five application page, the purpose that piecemeal is quoted is realized, saves code space, and improve reference efficiency.
It is a kind of partial process view of code compaction embodiment of the method five provided by the invention with reference to figure 6, wherein, in institute
After stating step 107, methods described can also comprise the following steps:
Step 108:According to the debugging request received, it is determined that the compression code bag institute corresponding with the debugging request is right
The second switch variable answered.
Wherein, the second switch variable refers to be provided in the reference of the compression code bag corresponding to the debugging request
Switching variable in code file.
That is, after compression code completes page reference, it is understood that there may be the place to go wrong, or exploit person
Member needs to carry out effect comparison to compression code and its corresponding source code, at this time, it may be necessary to which returning in exploitation code file needs
The position of the source code bag to be debugged, therefore, in the present embodiment, by being quoted to the place of the switching variable in debugging request
The position of code file is analyzed, and the position for the source code bag corresponding to compression code bag debugged with determination needs, is led to
Cross after subsequent operation, the switching of corresponding source code package location could be completed by quoting code file.
Step 109:According to the second switch variable, debugging code is generated;
Wherein, the debugging code refers to:It can be switched to using the second switch variable relative with the debugging request
On the position for the source code bag corresponding to compression code bag answered, source code bag is modified so as to developer or
Effect compares.
Step 110:The debugging code is performed, to call the source code bag corresponding with the second switch variable.
Thus, after the step 110 is performed, the compression environment can be switched to relative with the debugging request
The code position for the source code bag corresponding to compression code bag answered, the purpose of code switching is realized, without carrying out line by line again
Find, hence it is evident that improve debugging efficiency and development efficiency.
In the present embodiment, by the control to switching variable, the code that the page can be controlled to quote.So realization of function
Need, in compression, to carry out special configuration, the file after will compressing carries out corresponding, and institute with the physical address of source file
Some reference address, address can be correctly switched to by the addition and removal of a variable by corresponding code.
As shown in Figure 7, what wherein resourcePath was represented is local resource path variable, buildRelease variables
It is both switching variable.In the explorer schematic diagram in left side, it can be seen that corresponding original " page code " is in scripts
Under path, there is sub-folders such as " home " " sms " " affairs " below, by the pressure that corresponding page code is generated after compression
Page code after contracting, under release paths.
In the page in use, reference statement by adding " switching variable ", such as in Fig. 7, it is desirable to use home mesh
Home.js files under record, then need to introduce by the sentence in figure.Like this, if the page is wanted using the change after compression
Switching variable, can be arranged to " release/ " by amount;If compression code using problematic, it is necessary to be adjusted, can be with
Set by buildRelease, switchback development environment is modified.
Meanwhile when compressing progress, then need according to Compression Strategies, in compressed configuration, the file compressed is carried out
" page code " in corresponding distribution, such as upper figure, then compressed file is distributed under scripts peers catalogue, and by
Release compressed path mark.
It is a kind of structural representation of code compaction system embodiment six provided by the invention with reference to figure 8, wherein, it is described
System is applied in the compression environment that structure is completed in advance, and the compression environment can be understood as:In normal development environment
Under code structure, the environment required for compressing structure is configured, in the present embodiment, can be with to obtain compression environment
Exemplified by Java context, that is to say, that in the implementation in carrying out the present embodiment, it is necessary to ensure that Java context has installed
Into.
In the present embodiment, the system can realize the compression to code by following construction unit:
Code packetized units 801, for according to default reduced rule, being carried out to the exploitation code in exploitation code file
Subpackage, obtain multiple source code bags.
Wherein, each source code bag corresponds to its bag configuration file respectively, includes it in the bag configuration file
The compress mode of affiliated source code bag.
It should be noted that the reduced rule refer to developer be actually needed according to it pre-set to original generation
The rule how code is compressed, the rule being compressed such as reduced overall or splits' positions and using which kind of mode.It is and each
The compress mode to source code in its source code bag, example are included in the source code bag in respective bag configuration file
Such as, which code is compressed and which code carries out the directly compress mode such as duplication to.
Setting unit 802 is switched, for setting switching variable to quote the code file of each source code bag.
It should be noted that the switching variable in the present embodiment only has one, but its to be distributed in all references each described
On the position of the code file of source code bag, that is to say, that can by quote code file upper switch variable control,
Redirecting or calling what the switching variable corresponded to that the cited source code of code file wraps to realize.
Determining unit 803 is configured, for determining compressed configuration file, the compressed configuration file according to the reduced rule
In include packed attribute.
Wherein, the packed attribute is it is to be understood that the code in each source code bag is carried out after compression
The attributes such as the structure of assembled arrangement and the attribute that all bags are carried out with code compaction using which kind of compress mode, such as a line or multirow
The pressure texture attributes such as arrangement and the attribute how being compressed to codes such as js and css.
File execution unit 804, for performing the compressed configuration file, so that must be respectively with each bag configuration text
Compress mode in part is compressed processing to its corresponding source code bag, obtains multiple compression code bags.
Wherein, compression code bag composition compression code file, the pressure of compression code bag in the compression code file
Shrinking structure is corresponding with the packed attribute, the corresponding source code bag of each compression code bag in the compression code file
Switching variable be associated.
It should be noted that the compressed configuration file is to perform file, the process of the compressed configuration file is performed i.e.
For:Processing is compressed to its corresponding source code bag with the compress mode in each bag configuration file respectively, obtained
Multiple compression code bags, to cause the compression code bag to form compression code file, and compressed in the compression code file
The pressure texture of code bag is corresponding with the packed attribute.
In the present embodiment, in the compression code file the corresponding source code bag of each compression code bag reference
Switching variable in code file is associated, and developer can quote the switching variable in code file to reach by controlling
The cited switching between source code and compression code.
From such scheme, a kind of code compaction system embodiment six provided by the invention, applied to having built in advance
Into compression environment such as Java context in, when carrying out code compaction, be first according to default reduced rule and exploitation code entered
Row subpackage, to obtain multiple source code bags, these source code bags have a bag containing corresponding compress mode information to match somebody with somebody
File is put, afterwards, switching variable is respectively provided with to the code file for quoting each source code bag, and according to compression rule hereinbefore
The compressed configuration file for including packed attribute is then determined, and then by performing the compressed configuration file, so that must be respectively with every
Individual compress mode is compressed processing to its corresponding source code bag, obtains multiple compression code bag composition compression code texts
Part, and the pressure texture of compression code bag is relative with the packed attribute in compressed configuration file in compression code file now
Should, meanwhile, each compression code bag is associated by the corresponding source code bag of switching variable respectively, therefore, follow-up
In, developer need to only control the switching variable quoted in code file to can be achieved to quote the pressure that code file lock is quoted
Switching between switching between contracting code and exploitation code, that is, the calling of compression code and the debugging of exploitation code.This
In embodiment, by setting switching variable in the code file for quoting the compression code between compression code and exploitation code
It is associated, it is not that two kinds of codes are completely separated, and divided function or different types of code in code compaction
Compression recombinant is opened, therefore, can be passed through when test or effect are compared and gone wrong by the code that present invention compression obtains
Switching variable is accurately positioned the code bag (i.e. code module) to go wrong, wireless to need again successively to examine each bag
Survey, thus, hence it is evident that improve code development efficiency.
It should be noted that the present embodiment can be realized by Dojo, wherein, Dojo is one and realized with JavaScript
DHTML kits of increasing income.Dojo target be solve DHTML application programs run into those, long-term existence, historical problem with
And DHTML browser-cross problems.
In above-described embodiment, the reduced rule can be:Subpackage is carried out to code according to default code function classification,
Accordingly, it is code packetized units 801 described in a kind of code compaction system embodiment seven provided by the invention with reference to figure 9
Structural representation, wherein, the code packetized units 801 can include following structure and realize:
Code classification subelement 811, for developing the exploitation code in code file according to default code function class
Do not classified.
Component code, plug-in code and page code as noted above etc..
Bag composition subelement 812, a source code bag is formed for same category of exploitation code will to be belonged to.
File generated subelement 813, for according to default packet compression rule, generating bag supporting paper and each original
The bag configuration file of beginning code bag.
Wherein, the package informatin of each source code bag and its position of bag configuration file are included in the bag supporting paper
Information, the compress mode of its affiliated source code bag is each included in the bag configuration file.
It should be noted that include the essential information of each source code bag in the package informatin, such as description letter
Breath, title and code function information etc..
Accordingly, switching variable subsequently is being set to each source code bag and each source code bag is being pressed
, can be by the control to respective switch variable, to reach the purpose that piecemeal quotes some compression code bag after contracting.With above
Exemplified by the splits' positions of middle component code, plug-in code and page code, the logic that corresponding switching variable and the page are quoted is closed
System can be as shown in Figure 3, that is to say, that and after code subpackage, piecemeal is compressed, and forms respective compression code bag,
And then by the switching variable of setting, the page for realizing respective piecemeal by independent calling is quoted.
It is real for a kind of code compaction system provided by the invention with reference to figure 10 based on the implementation in previous embodiment
The structural representation of file execution unit 804 described in example eight is applied, wherein, the file execution unit 804 can be by following
Structure is realized:
First file reads subelement 841, every in the bag supporting paper to obtain for reading the bag supporting paper
The positional information of individual bag configuration file.
Second file reads subelement 842, for reading each bag configuration file with the positional information.
That is, the positional information by reading each bag configuration file in the bag supporting paper, read successively
Corresponding bag configuration file.
Compress mode obtains subelement 843, for obtaining the compress mode in each bag configuration file.
Code compaction subelement 844, for carrying out code compaction to its affiliated source code bag with the compress mode, obtain
To each self-corresponding compression code bag of each source code bag.
Wherein, the compress mode refers to, which of source code bag code is compressed, to which code
Directly carry out the mode such as replicating, the packed attribute being different from the compressed configuration file.
Compressed package merges subelement 845, for the packed attribute in the compressed configuration file, by all compressions
Code bag carries out structure merging, obtains compression code file, and each compression code bag is corresponding in the compression code file
The switching variable of source code bag is associated.
Wherein, the content of the packed attribute may be referred to content described above, be:Each original generation
Code in code bag is combined the attributes such as the structure of arrangement and all bags is carried out using which kind of compress mode after compression
The attribute of code compaction, how being compressed such as the pressure texture such as a line or plurality of rows attribute and to codes such as js and css
Attribute.
It is a kind of structural representation of code compaction system embodiment nine provided by the invention with reference to figure 11, wherein, it is described
System can also include following construction unit:
First variable determination unit 805, for performing the compressed configuration file in the file execution unit 804 to obtain
To after multiple compression code bags, according to the call request received, it is determined that the compression code corresponding with the call request
The corresponding first switch variable of bag.
Wherein, the first switch variable refers to be provided in the reference of the compression code bag corresponding to the call request
Switching variable in code file.
That is, after exploitation code file completes the splits' positions of its code and switching variable is set, Neng Goujin
During the calling of row compression code, by analyzing the position of switching variable in call request, to determine to need the pressure called
Position corresponding to contracting code bag, after subsequent operation, the piecemeal that could complete corresponding independent compression code bag is quoted.
Code generating unit 806 is called, for calling code according to the first switch variable, generation.
Wherein, the calling code refers to:The compression code bag corresponding with the call request can be subjected to the page
The execution code of reference.
Code execution unit 807 is called, it is relative with the first switch variable to call for performing the calling code
The compression code bag answered.
Thus, can be by the pressure corresponding with the call request after the calling code execution unit 807 is run
Contracting code bag is referred in corresponding five application page, realizes the purpose that piecemeal is quoted, and saves code space, and improves reference effect
Rate.
It is a kind of structural representation of code compaction system embodiment ten provided by the invention with reference to figure 12, wherein, it is described
System can also include following structure:
Second variable determination unit 808, the debugging request received for foundation, it is determined that corresponding with the debugging request
Compression code bag corresponding to second switch variable.
Wherein, the second switch variable refers to be provided in the reference of the compression code bag corresponding to the debugging request
Switching variable in code file.
That is, after compression code completes page reference, it is understood that there may be the place to go wrong, or exploit person
Member needs to carry out effect comparison to compression code and its corresponding source code, at this time, it may be necessary to which returning in exploitation code file needs
The position of the source code bag to be debugged, therefore, in the present embodiment, by being quoted to the place of the switching variable in debugging request
The position of code file is analyzed, and the position for the source code bag corresponding to compression code bag debugged with determination needs, is led to
Cross after subsequent operation, the switching of corresponding source code package location could be completed by quoting code file.
Debugging code generation unit 809, for according to the second switch variable, generating debugging code.
Wherein, the debugging code refers to:It can be switched to using the second switch variable relative with the debugging request
On the position for the source code bag corresponding to compression code bag answered, source code bag is modified so as to developer or
Effect compares.
Debugging code execution unit 810, for performing the debugging code, with bar with relative with the second switch variable
The source code bag answered.
Thus, after the debugging code execution unit 810 is run, the compression environment can be switched to it is described
The code position of source code bag corresponding to the corresponding compression code bag of debugging request, realize the purpose of code switching, nothing
Need to be found line by line again, hence it is evident that improve debugging efficiency and development efficiency.
In the present embodiment, by the control to switching variable, the code that the page can be controlled to quote.So realization of function
Need, in compression, to carry out special configuration, the file after will compressing carries out corresponding, and institute with the physical address of source file
Some reference address, address can be correctly switched to by the addition and removal of a variable by corresponding code.
As shown in Figure 7, what wherein resourcePath was represented is local resource path variable, buildRelease variables
It is both switching variable.In the explorer schematic diagram in left side, it can be seen that corresponding original " page code " is in scripts
Under path, there is sub-folders such as " home " " sms " " affairs " below, by the pressure that corresponding page code is generated after compression
Page code after contracting, under release paths.
In the page in use, reference statement by adding " switching variable ", such as in Fig. 7, it is desirable to use home mesh
Home.js files under record, then need to introduce by the sentence in figure.Like this, if the page is wanted using the change after compression
Switching variable, can be arranged to " release/ " by amount;If compression code using problematic, it is necessary to be adjusted, can be with
Set by buildRelease, switchback development environment is modified.
Meanwhile when compressing progress, then need according to Compression Strategies, in compressed configuration, the file compressed is carried out
" page code " in corresponding distribution, such as upper figure, then compressed file is distributed under scripts peers catalogue, and by
Release compressed path mark.
It should be noted that each embodiment in this specification is described by the way of progressive, each embodiment weight
Point explanation is all difference with other embodiment, between each embodiment identical similar part mutually referring to.
Finally, it is to be noted that, herein, such as first and second or the like relational terms be used merely to by
One entity or operation make a distinction with another entity or operation, and not necessarily require or imply these entities or operation
Between any this actual relation or order be present.Moreover, term " comprising ", "comprising" or its any other variant meaning
Covering including for nonexcludability, so that process, method, article or equipment including a series of elements not only include that
A little key elements, but also the other element including being not expressly set out, or also include for this process, method, article or
The intrinsic key element of equipment.In the absence of more restrictions, the key element limited by sentence "including a ...", is not arranged
Except other identical element in the process including the key element, method, article or equipment being also present.
A kind of code compaction method and system provided herein are described in detail above, it is used herein
Specific case is set forth to the principle and embodiment of the application, and the explanation of above example is only intended to help and understands this
The method and its core concept of application;Meanwhile for those of ordinary skill in the art, according to the thought of the application, specific
There will be changes in embodiment and application, in summary, this specification content should not be construed as to the application's
Limitation.
Claims (8)
- A kind of 1. code compaction method, it is characterised in that in the compression environment completed applied to advance structure, methods described bag Include:According to default reduced rule, subpackage is carried out to the exploitation code in exploitation code file, obtains multiple source code bags, Each source code bag corresponds to its bag configuration file respectively, and its affiliated source code bag is included in the bag configuration file Compress mode;To quote the code file of each source code bag, switching variable is set;Determine that compression is matched somebody with somebody according to the reduced rule File is put, includes packed attribute in the compressed configuration file;The compressed configuration file is performed, so that must be respectively with the compress mode in each bag configuration file to corresponding to it Source code bag is compressed processing, obtains multiple compression code bags, the compression code bag forms compression code file, described The pressure texture of compression code bag is corresponding with the packed attribute in compression code file, each in the compression code file The switching variable of the corresponding source code bag of compression code bag is associated;According to the call request received, it is determined that the first switch corresponding to the compression code bag corresponding with the call request Variable;According to the first switch variable, code is called in generation;The calling code is performed, to call the compression code bag corresponding with the first switch variable.
- 2. according to the method for claim 1, it is characterised in that the reduced rule includes:According to default code function Classification carries out subpackage to code;Accordingly, it is described according to default reduced rule, subpackage is carried out to the exploitation code in exploitation code file, obtained multiple Source code bag, including:Exploitation code in exploitation code file is classified according to default code function classification;Same category of exploitation code will be belonged to and form a source code bag;According to default packet compression rule, the bag configuration file of bag supporting paper and each source code bag is generated, it is described Include the package informatin of each source code bag and its positional information of bag configuration file in bag supporting paper, each bag is matched somebody with somebody Put the compress mode for including its affiliated source code bag in file.
- 3. according to the method for claim 2, it is characterised in that it is described to perform the compressed configuration file, so as to must distinguish Processing is compressed to its corresponding source code bag with the compress mode in each bag configuration file, obtains multiple compressions Code bag, including:The bag supporting paper is read, to obtain the positional information of each bag configuration file in the bag supporting paper;Each bag configuration file is read with the positional information;Obtain the compress mode in each bag configuration file;Code compaction is carried out to its affiliated source code bag with the compress mode, it is each self-corresponding to obtain each source code bag Compression code bag;With the packed attribute in the compressed configuration file, all compression code bags are subjected to structure merging, compressed Code file, the switching variable of the corresponding source code bag of each compression code bag is associated in the compression code file.
- 4. according to the method for claim 1, it is characterised in that the calling code is being performed, to call and described first After the corresponding compression code bag of switching variable, methods described also includes:According to the debugging request received, it is determined that the second switch corresponding to the compression code bag corresponding with the debugging request Variable;According to the second switch variable, debugging code is generated;The debugging code is performed, to call the source code bag corresponding with the second switch variable.
- A kind of 5. code compaction system, it is characterised in that in the compression environment completed applied to advance structure, the system bag Include:Code packetized units, for according to default reduced rule, carrying out subpackage to the exploitation code in exploitation code file, obtaining To multiple source code bags, each source code bag corresponds to its bag configuration file, included in the bag configuration file respectively There is the compress mode of its affiliated source code bag;Setting unit is switched, for setting switching variable to quote the code file of each source code bag;Determining unit is configured, for determining compressed configuration file according to the reduced rule, is included in the compressed configuration file There is packed attribute;File execution unit, for performing the compressed configuration file, so that must be respectively with each bag configuration file Compress mode is compressed processing to its corresponding source code bag, obtains multiple compression code bags, the compression code package Into compression code file, the pressure texture of compression code bag is corresponding with the packed attribute in the compression code file, institute Stating the switching variable of each corresponding source code bag of compression code bag in compression code file is associated;First variable determination unit, for performing the compressed configuration file in the file execution unit to obtain multiple compressions After code bag, according to the call request received, it is determined that corresponding to the compression code bag corresponding with the call request First switch variable;Code generating unit is called, for calling code according to the first switch variable, generation;Code execution unit is called, for performing the calling code, to call the pressure corresponding with the first switch variable Contracting code bag.
- 6. system according to claim 5, it is characterised in that the reduced rule includes:According to default code function Classification carries out subpackage to code;Accordingly, the code packetized units include:Code classification subelement, for dividing according to default code function classification the exploitation code in exploitation code file Class;Bag composition subelement, a source code bag is formed for same category of exploitation code will to be belonged to;File generated subelement, for according to default packet compression rule, generating bag supporting paper and each source code The bag configuration file of bag, include the package informatin of each source code bag and its position of bag configuration file in the bag supporting paper Confidence is ceased, and the compress mode of its affiliated source code bag is included in each bag configuration file.
- 7. system according to claim 6, it is characterised in that the file execution unit includes:First file reads subelement, for reading the bag supporting paper, is matched somebody with somebody with obtaining each bag in the bag supporting paper Put the positional information of file;Second file reads subelement, for reading each bag configuration file with the positional information;Compress mode obtains subelement, for obtaining the compress mode in each bag configuration file;Code compaction subelement, for carrying out code compaction to its affiliated source code bag with the compress mode, obtain each Each self-corresponding compression code bag of source code bag;Compressed package merges subelement, for the packed attribute in the compressed configuration file, by all compression code bags Structure merging is carried out, obtains compression code file, each compression code bag corresponding original generation in the compression code file The switching variable of code bag is associated.
- 8. system according to claim 5, it is characterised in that also include:Second variable determination unit, the debugging request received for foundation, it is determined that the compression corresponding with the debugging request Second switch variable corresponding to code bag;Debugging code generation unit, for according to the second switch variable, generating debugging code;Debugging code execution unit, for performing the debugging code, with bar with the original corresponding with the second switch variable Beginning code bag.
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 CN104331316A (en) | 2015-02-04 |
CN104331316B true 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) |
Families Citing this family (2)
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 |
CN107193615B (en) * | 2017-06-29 | 2020-12-04 | 北京全域医疗技术集团有限公司 | Project code information updating and deploying method and device |
Citations (4)
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 |
-
2014
- 2014-11-28 CN CN201410709985.5A patent/CN104331316B/en active Active
Patent Citations (4)
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 |
Also Published As
Publication number | Publication date |
---|---|
CN104331316A (en) | 2015-02-04 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
Alrabaee et al. | Oba2: An onion approach to binary code authorship attribution | |
Kanenobu | Band surgery on knots and links | |
CN104331316B (en) | A kind of code compaction method and system | |
CN103942143A (en) | PC-Lint code inspection result screening method based on version repository comparison | |
CN105164691A (en) | Optimizing test data payload selection for testing computer software applications using computer networks | |
Breier et al. | Feeding two cats with one bowl: On designing a fault and side-channel resistant software encoding scheme | |
CN109683890A (en) | The modular method, apparatus of cascading style sheets, storage medium and equipment | |
CN108197476A (en) | The leak detection method and device of a kind of intelligent terminal | |
CN108733404A (en) | A kind of accurate reverse engineering approach for FPGA firmwares | |
CN104239799A (en) | Android application program privacy stealing detection method and system based on behavior chain | |
Li et al. | The diagnosability and 1-good-neighbor conditional diagnosability of hypercubes with missing links and broken-down nodes | |
CN110442515A (en) | Application testing method, device, equipment and readable storage medium storing program for executing | |
CN110457916A (en) | A kind of electronic contract encryption method, device and terminal device | |
CN106649110A (en) | Software test method and system | |
CN105446752B (en) | Triggering method and device of control in application program and mobile terminal | |
CN104850352A (en) | Quick program starting method and quick program starting system based on touchpad | |
Potestad-Ordóñez et al. | Hardware countermeasures benchmarking against fault attacks | |
Siddall | Bracing for another decade of deception: the promise of Secondary Brooks Parsimony Analysis | |
US10482279B2 (en) | Pattern-less private data detection on data sets | |
CN104461296A (en) | Method and device for sharing mobile terminal at PC (Personal Computer) end | |
JP2021515942A (en) | Security assessment system | |
CN105808429A (en) | Linear constraint code-oriented bounded reachability verification method | |
JPH04167029A (en) | Fault detection and decision device | |
CN108763039B (en) | Service fault simulation method, device and equipment | |
Owen Jr et al. | Node monitoring as a fault detection countermeasure against information leakage within a risc-v microprocessor |
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 |