Application package generation method and apparatus, electronic device, and storage medium
By analyzing the application's source code, identifying external dependencies, and generating target package files, the problem of large package size was solved, network transmission bandwidth and time consumption were reduced, and transmission costs were lowered.
Patent Information
- Application Number
- CN202111632387.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-29
- Publication Date
- 2025-10-24
- Estimated Expiration
- 2041-12-29
AI Technical Summary
Existing technologies generate large program packages, occupy a lot of disk space, increase hardware costs, and consume more bandwidth and time in network transmission, thus increasing network transmission costs.
By analyzing the application's source code, the source code class files of external dependencies and their location information in external toolkits are determined, target package files of target reference class files are generated, and a program package is generated based on these files and the target program.
This reduces the bandwidth usage and transmission time of the program package during network transmission, thereby lowering transmission costs.
Smart Images

Figure CN114296705B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] Embodiments of the present application relate to the technical field of software, and particularly relate to an application package generation method and device, electronic equipment and storage medium. BACKGROUND
[0002] In the Java web project, the source code is compiled to generate a target program, a program package is generated based on the target program, and the program package is transmitted to a target server to start running. However, the program package generated in the prior art has a large file size, occupies a large space on the disk, increases the hardware cost, occupies more bandwidth and transmission time in the network transmission process, and increases the network transmission cost. SUMMARY
[0003] The present application provides an application package generation method and device, electronic equipment and storage medium to solve the problem of generating a large program package, reduce the bandwidth and transmission time occupied in the network transmission process, and thus reduce the transmission cost of the application program package in the network transmission process.
[0004] In a first aspect, an embodiment of the present application provides an application package generation method, which comprises:
[0005] Obtaining the source code of an application program, and determining at least one source code class file having an external dependency relationship in the source code;
[0006] For any source code class file, determining a target reference class file depended by the current source code class file, and determining the location information of the target class file in an external tool package; wherein the target reference class file is a class file without an external dependency relationship;
[0007] Determining a target package file of each target reference class file based on the target reference class file identifier and the location information corresponding to each source code class file;
[0008] Obtaining a target program of the source code, and generating a program package of the application program based on the target package file and the target program.
[0009] Optionally, before determining at least one source code class file having an external dependency relationship in the source code, the method comprises:
[0010] Performing logical analysis on the source code to determine the code logic in the source code; wherein the logical analysis comprises lexical analysis, syntax analysis and semantic analysis.
[0011] Optionally, the determination of at least one source code class file having an external dependency relationship in the source code comprises:
[0012] Obtaining a preset annotation identifier, performing reference identification on the code logic based on the annotation identifier, and determining a source code class file with external dependency relationship in the source code.
[0013] Optionally, for any source code class file, the target reference class file depended by the current source code class file is determined, including:
[0014] Obtaining a source code header file in the source code class file, and determining at least one reference class file stored in the source code header file;
[0015] Obtaining a reference header file of each reference class file, and determining at least one external reference class file in the reference class file based on the file type of the header file;
[0016] For any external reference class file, if the reference header file no longer includes an external reference class file, the current external reference class file is determined as the target reference class file.
[0017] Optionally, before determining the target package file of each target reference class file based on the target reference class file identifier and the position information corresponding to each source code class file, the method further includes:
[0018] Performing verification processing on the target class file corresponding to each source code class file to obtain each target class file after verification; wherein the verification processing includes de-duplication verification and legality verification.
[0019] Optionally, the target package file of each target reference class file is determined based on the target reference class file identifier and the position information corresponding to each source code class file, including:
[0020] Obtaining each position information, and determining the parent package file in which each target reference class file after the verification processing is located based on each position information;
[0021] Extracting the class file data corresponding to each target reference class file identifier in the parent package file to generate the target package file corresponding to each target reference class file.
[0022] Optionally, the target program of the source code is obtained, and the program package of the application program is generated based on the target package file and the target program, including:
[0023] Performing code compilation processing on the source code after logical analysis to generate the target program of the source code;
[0024] Packing the target program and the target package file to obtain the program package.
[0025] In a second aspect, an application program package generation device is also provided, and the device includes:
[0026] a source code class file determination module, configured to obtain source code of an application program, and determine at least one source code class file having external dependency in the source code;
[0027] a position information determination module, configured to, for any source code class file, determine a target reference class file depended by the current source code class file, and determine position information of the target class file in an external tool package; wherein the target reference class file is a class file without external dependency;
[0028] a target package file generation module, configured to determine a target package file of each target reference class file based on the target reference class file identifier and the position information corresponding to each source code class file;
[0029] a program package generation module, configured to obtain a target program of the source code, and generate a program package of the application program based on the target package file and the target program.
[0030] In a third aspect, an electronic device is provided, and the electronic device includes:
[0031] one or more processors;
[0032] a memory configured to store one or more programs,
[0033] when the one or more programs are executed by the one or more processors, the one or more processors implement the application program package generation method provided by any of the embodiments of the present application.
[0034] In a fourth aspect, a computer readable storage medium is provided, and the computer readable storage medium stores a computer program, and the program is executed by a processor to implement the application program package generation method provided by any of the embodiments of the present application.
[0035] The technical scheme of the embodiment is specifically that source code of an application program is acquired, and at least one source code class file with external dependency relationship in the source code is determined; for any source code class file, a target reference class file on which the current source code class file depends is determined, and position information of the target class file in an external tool package is determined; the target reference class file is a class file without external dependency relationship; target package files of the target reference class files are determined based on the target reference class file identifiers and the position information of the target reference class files corresponding to the source code class files respectively; a target program of the source code is acquired, and a program package of the application program is generated based on the target package files and the target program. Through the above technical scheme, the dependent code of the current application program which needs to depend on external class files is analyzed, the positions of the external class files on which all the dependent codes depend are listed, and a temporary sub-package is generated based on all the dependent external class files, the sub-package and the target program are used for packaging, and a program package is generated, thereby solving the problem of large size of the generated program package, reducing the bandwidth occupied and the transmission time in the network transmission process, and thereby reducing the transmission cost of the program package of the application program in the network transmission process. BRIEF DESCRIPTION OF DRAWINGS
[0036] In order to more clearly illustrate the technical scheme of the example embodiments of the present application, the drawings needed in the description of the embodiments are briefly introduced as follows. Obviously, the drawings introduced are only the drawings of a part of the embodiments of the present application, and not all the drawings, and other drawings can be obtained by those skilled in the art without creative effort on the basis of the drawings.
[0037] Figure 1 is a flow diagram of the application program package generation method provided by the first embodiment of the present application;
[0038] Figure 2 is a structure diagram of a class file provided by the first embodiment of the present application;
[0039] Figure 3 is a structure diagram of an application program package generation device provided by the second embodiment of the present application;
[0040] Figure 4 is a structure diagram of an electronic device provided by the third embodiment of the present application. DETAILED DESCRIPTION
[0041] The present application will be further described in detail below in combination with the drawings and embodiments. It can be understood that the specific embodiments described herein are only used to explain the present application, and not to limit the present application. In addition, it should be noted that, in order to facilitate the description, only the parts related to the present application are shown in the drawings, and not all the structures.
[0042] Embodiment one
[0043] Figure 1 This is a flowchart of a method for generating an application package provided in the first embodiment of the present invention. This embodiment is applicable to packaging application packages. The method can be executed by an application package generation device, which can be implemented in software and / or hardware.
[0044] Before introducing the technical solutions of the embodiments of the present invention, we will first provide an illustrative introduction to the application scenarios for implementing the technical solutions of this embodiment. Of course, the following application scenarios are merely optional, and this embodiment can also be implemented in other application scenarios. This embodiment does not limit the application scenarios of the technical methods implemented. Specifically, the application scenarios include: deploying an application in a Java web project, which requires compiling source code to generate a target program, generating a program package based on the target program, and transferring the program package to a target server for startup. Current packaging implementation methods include: Java application source code -> lexical analysis -> syntax analysis -> semantic analysis -> intermediate code generation -> code optimization program -> target code generator -> project object model dependency analysis -> copying dependent packages and target code to a temporary directory -> packaging to generate a program package. During the application packaging process, after dependency analysis, the dependent code packages are directly copied to a temporary directory to generate the package. This results in a large package file, occupying more disk space and increasing network bandwidth and transmission time. Currently, it is common for generated packages to be over 100MB in size.
[0045] Furthermore, in the above prior art, the Maven project object model is used to analyze the coordinate position of the dependency package (i.e., the file directory path where the dependency package is located) during the dependency analysis phase, the required dependency package is copied to a temporary directory, and a program package is generated. There are two drawbacks to this. First, as long as the dependency package is configured in the project object model, regardless of whether the dependency package is actually used by the application, it will eventually be packaged into the generated program package. Second, the dependency package is actually used by the application, but only a part or a small part of the code in the dependency package is used. The dependency package cannot be split and will eventually be packaged into the generated program package. Both of these drawbacks will result in some code in the final program package being unable to be used but occupying server disk space, increasing hardware costs, and occupying more bandwidth and transmission time during network transmission, increasing network transmission costs.
[0046] In order to solve the problem of large volume of the generated program package in the prior art, the technical scheme of the embodiment specifically comprises the following steps: obtaining source code of an application program, and determining at least one source code class file with external dependency relationship in the source code; for any source code class file, determining a target reference class file depended by the current source code class file, and determining position information of the target class file in an external tool package; wherein the target reference class file is a class file without external dependency relationship; determining a target package file of each target reference class file based on the target reference class file identifier and the position information corresponding to each source code class file; obtaining a target program of the source code, and generating a program package of the application program based on the target package file and the target program. Through the above technical scheme, the dependent code of the current application program which needs to depend on external class files is analyzed, the positions of the external class files depended by all the dependent codes are listed, and temporary sub-packages are generated based on all the dependent external class files, the sub-packages and the target program are used for packaging, and a program package is generated, thereby solving the problem of large volume of the generated program package, reducing the occupied bandwidth and transmission time in the network transmission process, and thereby reducing the transmission cost of the program package of the application program in the network transmission process.
[0047] As shown in Figure 1 the method specifically comprises the following steps:
[0048] S110, obtaining source code of an application program, and determining at least one source code class file with external dependency relationship in the source code.
[0049] In the embodiment of the application, the application program can be a computer program for completing one or more specific tasks, which runs in a user mode, can interact with a user, has a visual user interface, and corresponds to different system platforms. The application program can be constructed by different programming languages. For example, for an Android platform, the application program can be written by Java language, and the source code thereof can be JavaScript code.
[0050] Specifically, the method for obtaining the source code of the application program can comprise directly reading from the development document of the application program, or can comprise obtaining the source code of the application program by disassembling the application program after decompression. The method for obtaining the source code of the application program is not limited in the embodiment.
[0051] Optionally, in order to facilitate the determination of the source code class file in the obtained source code, the technical scheme of the embodiment can perform logical analysis on the source code to determine the code logic in the source code. The logical analysis comprises lexical analysis, syntax analysis and semantic analysis.
[0052] It should be noted that the code logic in the embodiment can be a reference relationship or a calling relationship between the codes.
[0053] Specifically, the process of lexical analysis on the source code can include: converting the character sequence in the code into a word sequence, scanning the source program from left to right, identifying various types of words according to the lexical rules of the language, and generating attribute words of the words. Further, the process of syntax analysis on the source code after lexical analysis can include: on the basis of lexical analysis, combining the word sequence into various types of syntax phrases such as "program", "statement", "expression" and the like, identifying the corresponding syntax categories from the results of syntax analysis according to the syntax rules of the source language, and performing syntax checking. Further, the process of semantic analysis on the source code after syntax analysis can include: reviewing the context-related properties of the source code, performing type review, semantic error review, and collecting type information of the source code to facilitate subsequent generation of target programs.
[0054] Of course, the above explanation of the logical analysis process of the source code is only an exemplary explanation, and the logical analysis can also be based on other methods. The logical analysis method of the source code in the present embodiment is not limited.
[0055] Further, after determining the code logic of the source code, at least one source code class file with external dependency relationship in the source code is determined.
[0056] The dependency relationship can be that one piece of code can call the data or function or attribute of another piece of code, for example, in a shopping application, when the shopping cart needs to display the product details, the code corresponding to the shopping cart needs to call the code data of the product detail page corresponding code, which forms the dependency relationship between the codes, that is, one piece of code is dependent on another piece of code, or one piece of code depends on another piece of code. The dependency relationship between the codes has been determined during project development and written into the source code of the application. By analyzing the code, the dependency relationship between the codes can be obtained. In the present embodiment, the external dependency relationship can be understood as that one piece of code depends on another piece of code in other application. In the above analysis, one piece of code can be understood as a class file for implementing a business function. In the present embodiment, the source code class file can be understood as a piece of code in the source code of the current application that depends on the code in other application.
[0057] For example, Figure 2As shown, the source code includes code segment 1, code segment 2 and code segment 3. Specifically, code segment 1 depends on code segment 2, in other words, it can be understood that code segment 1 has a dependency relationship with code segment 2, but since code 2 is within the source code, that is, the dependency relationship between code segment 1 and code segment 2 does not belong to external dependency relationship, so code segment 1 is not a source code class file in the source code; on the contrary, code segment 3 depends on code segment b and code segment c, and code segment b and code segment c are both code segments in the external tool package other than the source code, that is, the dependency relationship between code segment 3 and code segment b and code segment c belongs to external dependency relationship, so code segment 3 is a source code class file in the source code.
[0058] It should be noted that each source code class file in the source code can be determined based on the reference relationship between each code segment. Of course, other source code class files in the source code can also be determined based on other logical relationships, which are not enumerated one by one in this embodiment.
[0059] Further, after determining the code logic in the source code, the dependency relationship between each code segment in the source code is determined based on the code logic, so as to determine the source code class file in the source code.
[0060] Optionally, the method for determining the source code class file in the source code can include: obtaining a preset annotation identifier, identifying the code logic based on the annotation identifier, and determining the source code class file having external dependency relationship in the source code.
[0061] Specifically, in a Java web application, the application includes an interactive program that needs human-computer interaction and a timing task that does not need human-computer interaction. Specifically, the task architecture of the interactive task is a layered architecture, so all application business entrances are converged in the control layer of the task. Further, the annotation identifier is set in the startup class of the program in advance, specifically including adding @PackageScope to the startup class of the program main entrance, so as to determine the source code class file having external dependency relationship in the source code.
[0062] S120, for any source code class file, determining the target reference class file depended by the current source code class file, and determining the position information of the target class file in the external tool package.
[0063] In the embodiment of the application, the target reference class file is a class file without external dependency relationship, that is, it can be understood that the target class file does not depend on other class files except the class files in the tool package where the target class file is located.
[0064] The example continues as follows Figure 2As shown, the external dependency class files of code segment 3 include code segment b and code segment c. Specifically, code segment b depends on code segment a, and since code segment a and code segment b are both code segments in external toolkit 1, the dependency relationship between code segment b and code segment a is not an external dependency relationship, so code segment b is a target reference class file of code segment 3; on the contrary, code segment c depends on code segment C, and since code segment C and code segment belong to code segments in different external toolkits, the dependency relationship between code segment c and code segment C is an external dependency relationship, that is, code segment c is not a target reference class file of code segment 3.
[0065] Specifically, based on the above technical solution, a plurality of source code class files in the source code can be determined; in order to facilitate the introduction of the technical solution in the embodiment, in this embodiment, any source code class file in the source code is taken as an example to introduce how to determine the target reference class file that the source code class file depends on. It should be noted that one code segment can depend on a plurality of other code segments, so one source code class file can include a plurality of target reference class files.
[0066] Optionally, for the current source code class file, the method of determining the target reference class file of the current source code class file can include: obtaining a source code header file in the source code class file, determining at least one reference class file stored in the source code header file; obtaining a reference header file of each reference class file, and determining at least one external reference class file in the reference class file based on the file type of the header file; for any external reference class file, if the external reference class file is no longer included in the reference header file, the current external reference class file is determined as the target reference class file.
[0067] It should be noted that the source code header file can be understood as the header part area of the source code class file. The source code header file includes each reference class file that the source code class file depends on. The type of the reference class file includes an external reference class file and an internal reference class file. The reference header file can be understood as the header file of the reference class file.
[0068] Specifically, the header part import of the source code class file is analyzed to determine the external reference class files in the reference class files relied on by the source code class file. For example, during the analysis, the classes using the JRE environment and other internal reference class files in the application scope can be excluded first, and then the other classes relied on by the source code class file are external reference class files. Further, the reference header file of each external reference class file is obtained. If it is determined that the current reference header file does not include other external reference class files, the external reference class file corresponding to the current reference header file is determined as the target reference class file of the current source code class file; on the contrary, if the current reference header file includes other external reference class files, the reference header file of the external reference class file is further determined, and it is determined whether the reference header file further stores external reference class files, until the external reference class file corresponding to the reference header file without storing external reference class files is determined as the target reference class file of the current source code class file.
[0069] Of course, on the basis of the above embodiment, there is a circular reference between some class files, that is, a mutual dependence relationship. For example, in any segment of source code, the source code class file A relies on the source code class file B, and at the same time, the source code class file B relies on the source code class file A. During the analysis process of the target reference class, it is found that the source code class file A relies on the source code class file B; further, it is found that the source code class file B relies on the source code class file A when analyzing the dependence of the source code class file B, but the current source code class file A has not been analyzed, so the analysis process of the source code class file B skips the source code class file A and continues to analyze other source code class files. Until all the source code class files in the @PackageScope range are analyzed, the target reference class files of the source code class files in the source code are determined.
[0070] Further, after determining the target reference class files of the source code class files in the source code, the position information of each target reference class file is determined, so that the target package file of the source code can be generated.
[0071] Optionally, the position information of each target reference class is obtained, and each position information and the corresponding target reference class file are stored in a preset file, such as a preset Map collection. Further, the position information is used as the key of the collection, the target class files are de-duplicated, and the de-duplicated target class files are used as the values corresponding to each key in the collection. Specifically, the representation of the target class files and the position information in the collection includes but is not limited to: Map<position information, Set<class information>>.
[0072] Further, in order to avoid the dependency failure between the generated target package file and the source code class files, the technical solution of the embodiment further comprises: performing a check processing on the target class files corresponding to the source code class files respectively to obtain the checked target class files before determining the target package file of the target reference class files based on the target reference class file identifier and the location information corresponding to the source code class files respectively; wherein the check processing comprises a de-duplication check and a legality check.
[0073] Specifically, the target reference class analysis result temporary file is loaded into the memory, and meanwhile, the preset project object dependency model is subjected to integrity information check, de-duplication check, legality check whether in the range of the project object dependency, and file check.
[0074] S130, determining the target package file of the target reference class files based on the target reference class file identifier and the location information corresponding to the source code class files respectively.
[0075] In the embodiment, the target reference class file identifier can be the file name of the class file, that is, the class file data corresponding to the target reference class file can be obtained based on the target reference class file identifier. The target package file can be understood as a file comprising only the file data of the target reference class file.
[0076] Optionally, the method for generating the target package file can comprise: obtaining the location information, determining the parent package file in which the target reference class files after the check processing are located based on the location information; extracting the class file data corresponding to the target reference class file identifier in the parent package file to generate the target package file corresponding to the target reference class file. The parent package can be understood as an external tool package comprising the target reference class file and other reference class files.
[0077] Specifically, the location information is taken as the key in the Map, the location of the target reference class file in the external tool package is determined based on the key, the class file data of the target reference class file is determined according to the target reference class file identifier, the class file data is extracted and copied into the preset file, and further, the target package file is generated based on the class file data of the target reference class file.
[0078] S140, obtaining the target program of the source code, and generating the program package of the application program based on the target package file and the target program.
[0079] In the embodiment of the present application, the target program can be understood as the code generated after the compiler processes the source code. Alternatively, the method for obtaining the target program of the source code can comprise: obtaining the source code after logical analysis, and performing code compilation processing on the source code after logical analysis to generate the target program of the source code. Specifically, the compilation processing comprises generating intermediate code, performing code optimization processing on the intermediate code, and performing specific compilation on the optimized code to obtain the target program of the source code. Specifically, the generation of the intermediate code based on the source code can immediately be the equivalent internal representation code of the source program for translating the source code into the target program, that is, the intermediate code is a code between the source program and the target language. The optimization processing on the code can make the program code perform equivalent transformation without changing the program running result, so that the time and space efficiency of the finally generated target code is higher.
[0080] The program package can be understood as the Jar package or War package of the application program. Specifically, the JAR package can be understood as a compression document specific to Java, which can be understood as a.zip package. Of course, there are also differences, and the JAR package has a META-INF\MANIFEST.MF file. The JAR package is generated by the JDK installation directory\bin\jar.exe command. The JAR package contains various files. The WAR package can be understood as a packaging format, and various resource files and codes required by the program in the Java web project are packaged into the WAR package for publication.
[0081] Alternatively, the method for generating the program package of the application program can comprise: packaging the target program and the target package file to obtain the program package.
[0082] Specifically, the target package file and the target program are copied into a temporary directory, and the temporary directory and the contents in the directory are packaged to generate the program package of the application program, that is, the Jar or War package.
[0083] It should be noted that the generation of the program package can be the packaging processing performed autonomously after the target package file and the target program are detected, so as to generate the package file, or the packaging processing can be performed after the packaging is detected, and the present embodiment does not limit this.
[0084] On the basis of the above-mentioned embodiments, the embodiments of the present application further provide a specific embodiment which introduces the specific steps from the source code of the application program to the generation of the program package. The specific steps include: Java application program source code -> lexical analysis -> syntax analysis -> semantic analysis -> business application reference analysis -> referenced class circular reference analysis -> intermediate code generation -> code optimization program -> target code generation program -> referenced class and project object model dependency analysis collection -> sub-package generation -> copy sub-package and target code to temporary directory -> package generation Jar package or War package.
[0085] The technical scheme of the embodiments specifically comprises: obtaining the source code of the application program and determining at least one source code class file having external dependency relationship in the source code; for any source code class file, determining the target reference class file on which the current source code class file depends and the position information of the target class file in the external tool package; wherein the target reference class file is a class file without external dependency relationship; determining the target package file of each target reference class file based on the target reference class file identifier and the position information corresponding to each source code class file; obtaining the target program of the source code and generating the program package of the application program based on the target package file and the target program. Through the above technical scheme, the dependent code in the current application program which needs to depend on external class files is analyzed, the positions of the external class files on which all the dependent codes depend are listed, and temporary sub-packages are generated based on all the dependent external class files, the sub-packages and the target program are used for packaging, and the program package is generated, thereby solving the problem of large size of the generated program package, reducing the bandwidth occupation and transmission time in the network transmission process, and thereby reducing the transmission cost of the program package of the application program in the network transmission process.
[0086] The following is an embodiment of the application program package generation device provided by the embodiments of the present application. The device and the application program package generation method of the above-mentioned embodiments belong to the same inventive concept. The details not described in the embodiments of the application program package generation device can be referred to the embodiments of the application program package generation method.
[0087] Embodiment two
[0088] Figure 3 The structure diagram of the application program package generation device provided for the second embodiment of the present application. The present embodiment can be applied to the case of packaging the program package of the application program. Referring to Figure 3 The specific structure of the application program package generation device includes: a source code class file determination module 210, a position information determination module 220, a target package file generation module 230 and a program package generation module 240; wherein,
[0089] The source code class file determination module 210 is configured to obtain source code of an application program, and determine at least one source code class file with external dependency in the source code.
[0090] The position information determination module 220 is configured to, for any source code class file, determine a target reference class file depended by the current source code class file, and determine position information of the target class file in an external tool package; wherein the target reference class file is a class file without external dependency.
[0091] The target package file generation module 230 is configured to determine a target package file of each target reference class file based on the target reference class file identifier and the position information corresponding to each source code class file.
[0092] The program package generation module 240 is configured to obtain a target program of the source code, and generate a program package of the application program based on the target package file and the target program.
[0093] The technical scheme of the embodiment is specifically configured to obtain source code of an application program, and determine at least one source code class file with external dependency in the source code; for any source code class file, determine a target reference class file depended by the current source code class file, and determine position information of the target class file in an external tool package; wherein the target reference class file is a class file without external dependency; determine a target package file of each target reference class file based on the target reference class file identifier and the position information corresponding to each source code class file; obtain a target program of the source code, and generate a program package of the application program based on the target package file and the target program. Through the above technical scheme, the dependent code of the current application program that needs to depend on external class files is analyzed, the positions of all external class files depended by the dependent code are listed, and a temporary sub-package is generated based on all dependent external class files. The sub-package and the target program are used for packaging to generate a program package, which solves the problem of large program package size, reduces the bandwidth occupied and transmission time in the network transmission process, and thus reduces the transmission cost of the program package of the application program in the network transmission process.
[0094] On the basis of each of the above embodiments, the device further comprises:
[0095] The code logic determination module is configured to, before determining at least one source code class file with external dependency in the source code, perform logical analysis on the source code to determine code logic in the source code; wherein the logical analysis includes lexical analysis, syntax analysis and semantic analysis.
[0096] On the basis of each of the above embodiments, the source code class file determination module 210 comprises:
[0097] The source code class file determination unit is used to obtain a preset annotation identifier, reference and identify the code logic based on the annotation identifier, and determine the source code class files with external dependencies in the source code.
[0098] Based on the above embodiments, the location information determination module 220 includes:
[0099] a reference class file determining unit, configured to obtain a source class file in the source class file and determine at least one reference class file stored in the source class file;
[0100] an external reference class file determining unit, configured to obtain a reference header file of each of the reference class files, and determine at least one external reference class file among the reference class files based on a file type of the header file;
[0101] The target reference class file determination unit is used for determining, for any external reference class file, if the reference header file no longer includes the external reference class file, the current external reference class file as the target reference class file.
[0102] Based on the above embodiments, the device further includes:
[0103] The verification processing module is used to verify the target class files corresponding to each source code class file to obtain the verified target class files; wherein, the verification processing includes deduplication verification and legal verification.
[0104] Based on the above embodiments, the target package file generation module 230 includes:
[0105] a parent package file determining unit, configured to obtain each piece of location information and determine, based on each piece of location information, the parent package file where each target reference class file after verification is located;
[0106] The target package file generating unit is configured to extract class file data corresponding to each target reference class file identifier in the parent package file, and generate a target package file corresponding to each target reference class file.
[0107] Based on the above embodiments, the program package generation module 240 includes:
[0108] A target program generating unit is used to compile the source code after the logic analysis to generate a target program of the source code;
[0109] The program package generating unit is configured to package the target program and the target package file to obtain a program package.
[0110] The application package generation apparatus provided by the embodiments of the present application can execute the application package generation method provided by any of the embodiments of the present application, and has the function modules and beneficial effects corresponding to the execution method.
[0111] It is worth noting that, in the embodiments of the application program package generation apparatus, each unit and module included is only divided according to the function logic, but is not limited to the above division, as long as the corresponding function can be realized; in addition, the specific name of each function unit is only for the convenience of mutual differentiation, and does not serve to limit the protection scope of the present application.
[0112] Embodiment three
[0113] Figure 4 A structural schematic diagram of an electronic device provided for the third embodiment of the present application. Figure 4 A block diagram of an exemplary electronic device 12 suitable for implementing embodiments of the present application is shown. Figure 4 The electronic device 12 shown is merely an example and should not impose any limitation on the function and use range of the embodiments of the present application.
[0114] As shown in Figure 4 The electronic device 12 is shown in the form of a general computing electronic device. The components of the electronic device 12 can include, but are not limited to, one or more processors or processing units 16, system memory 28, and a bus 18 that couples various system components including the system memory 28 and the processing unit 16.
[0115] The bus 18 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, a graphics bus (e.g., AGP or Accelerated Graphics Port), and a processor or local bus using any of a variety of bus architectures. By way of example, these architectures include Industry Standard Architecture (ISA) bus, Micro Channel Architecture (MCA) bus, Enhanced ISA (EISA) bus, Video Electronics Standards Association (VESA) local bus, and Peripheral Component Interconnect (PCI) bus.
[0116] The electronic device 12 typically includes a variety of computer system readable media. Such media can be any available media that is accessible by the electronic device 12 and includes both volatile and non-volatile media, removable and non-removable media.
[0117] The system memory 28 can include computer system readable media in the form of volatile memory, such as random access memory (RAM) 30 and / or cache memory 32. The electronic device 12 can further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, a storage system 34 can be provided for reading from and writing to non-removable, non-volatile magnetic media (e.g., a hard disk drive). Figure 4not shown, is typically referred to as a "hard disk drive"). Although Figure 4 not shown, a magnetic disk drive (for example, a floppy disk drive) for reading from or writing to a removable, nonvolatile magnetic disk (e.g., a "floppy disk"), and an optical disk drive for reading from or writing to a removable, nonvolatile optical disk (e.g., a CD-ROM, DVD-ROM, or other optical media) can be provided. In such instances, each drive can be connected to the system bus 18 by one or more data media interfaces. The system memory 28 can include at least one program product having a set (e.g., at least one) of program modules that are configured to carry out the functions of embodiments of the application.
[0118] Program / utility 40 having a set (at least one) of program modules 42 can be stored in system memory 28 by way of example, without limitation, including an operating system, one or more application programs, other program modules, and program data, each or some combination thereof, which may
[0119] The electronic device 12 can also communicate with one or more external devices 14 such as a keyboard or a pointing device, displays 24, etc.; other devices such as devices that enable a user to interact with the electronic device 12; and / or any devices (e.g., network card, modem, etc.) that enable the electronic device 12 to communicate with one or more other computing devices. Such communication can occur via the input / output (I / O) interface(s) 22. Still yet, the electronic device 12 can communicate with one or more networks (such as a local area network (LAN), a wide area network (WAN), and / or the Internet) through a network adapter 20. As Figure 4 illustrated, the network adapter 20 can communicate with the other components of the electronic device 12 through the bus 18. It should be understood that although not shown, other hardware and / or software modules can be used in conjunction with the electronic device 12. Such hardware would include, but is not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data archival storage systems, etc.
[0120] The processing unit 16 executes various functional applications and sample data acquisition by running programs stored in the system memory 28, such as implementing a method for generating an application package, the method for generating an application package comprising:
[0121] obtaining source code of an application, and determining at least one source code class file having external dependency in the source code;
[0122] For any source code class file, determine the target reference class file on which the current source code class file depends, and determine the location information of the target class file in the external tool package; wherein the target reference class file is a class file without external dependency relationship;
[0123] Based on the target reference class file identifier corresponding to each of the source code class files and the location information, determine the target package file of each of the target reference class files;
[0124] Obtain the target program of the source code, and generate the program package of the application program based on the target package file and the target program.
[0125] Of course, those skilled in the art can understand that the processor can also implement the technical solutions of the sample data acquisition method provided by any embodiment of the application.
[0126] Embodiment four
[0127] The embodiment four provides a computer readable storage medium, and a computer program is stored on the computer readable storage medium. The program is executed by a processor to implement, for example, a kind of application program package generation method provided by the embodiment of the present application. Application program package generation method includes:
[0128] Obtain the source code of the application program, and determine at least one source code class file with external dependency relationship in the source code;
[0129] For any source code class file, determine the target reference class file on which the current source code class file depends, and determine the location information of the target class file in the external tool package; wherein the target reference class file is a class file without external dependency relationship;
[0130] Based on the target reference class file identifier corresponding to each of the source code class files and the location information, determine the target package file of each of the target reference class files;
[0131] Obtain the target program of the source code, and generate the program package of the application program based on the target package file and the target program.
[0132] The computer storage medium of the embodiments of the present application can adopt any combination of one or more computer readable media. The computer readable medium can be a computer readable signal medium or a computer readable storage medium. The computer readable storage medium may, for example, but is not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or apparatus, or any combination thereof. More specific examples (non-exhaustive list) of the computer readable storage medium include an electrical connection having one or more wires, a portable computer diskette, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this document, the computer readable storage medium can be any tangible medium that contains or stores a program that can be used by or in connection with an instruction execution system, apparatus or device.
[0133] The computer readable signal medium can include a data signal propagated in baseband or propagated as a carrier wave, in which computer readable program code is embodied. Such propagated data signals can take a wide variety of forms, including but not limited to electro-magnetic signals, optical signals, or any suitable combination thereof. Computer readable signal medium can also be any computer readable medium that is not a storage medium, that is capable of storing the program for use by or in connection with the instruction execution system, apparatus or device.
[0134] The program code contained on the computer readable medium can be transmitted using any suitable medium, including but not limited to wireless, wire line, optical fiber cable, RF, etc., or any suitable combination of the above.
[0135] Computer program code for carrying out operations of the present application can be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C++ or the like, and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code can execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the latter scenario, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or the connection can be made to an external computer (for example, through the Internet using an Internet Service Provider). In some embodiments of the present application, electronic mail (email) can be utilized as the
[0136] Those skilled in the art should understand that the modules or steps of the present application described above can be realized by general computing devices, which can be centralized on a single computing device or distributed on a network composed of multiple computing devices, and optionally, they can be realized by program codes executable by the computing devices, so that they can be stored in storage devices and executed by the computing devices, or they can be respectively manufactured into individual integrated circuit modules, or multiple modules or steps among them can be manufactured into a single integrated circuit module to realize. Thus, the present application is not limited to any specific combination of hardware and software.
[0137] It is noted that the above merely describes the preferred embodiments of the present application and the principles of the applied technology. Those skilled in the art will understand that the present application is not limited to the specific embodiments described herein, and various obvious changes, re-adjustments and substitutions can be made by those skilled in the art without departing from the scope of the present application. Therefore, although the present application has been described in detail through the above embodiments, the present application is not limited to the above embodiments, and more other equivalent embodiments can be included without departing from the concept of the present application, and the scope of the present application is determined by the appended claims.
Claims
1. An application package generation method characterized by comprising: The application comprises the following steps: acquire the source code of the application and determine at least one source code class file with external dependencies in the source code; for any source code class file, determine the target reference class file that the current source code class file depends on, and determine the location information of the target reference class file in the external tool package; wherein the target reference class file is a class file without external dependencies; determine the target package file of each target reference class file based on the target reference class file identifier and the location information corresponding to each source code class file; wherein the target package file is a file containing only the file data of the target reference class file; acquire the target program of the source code and generate the program package of the application based on the target package file and the target program; the determination of the target reference class file that the current source code class file depends on includes: acquire the source code header file in the source code class file, and determine at least one reference class file stored in the source code header file; acquire the reference header file of each reference class file, and determine at least one external reference class file in the reference class file based on the file type of the header file; for any external reference class file, if the reference header file no longer includes the external reference class file, the current external reference class file is determined as the target reference class file; if the reference header file includes the external reference class file, determine the reference header file corresponding to the external reference class file, and if the reference header file does not store the external reference class file, determine the external reference class file corresponding to the reference header file as the target reference class file of the current source code class file.
2. The method of claim 1, wherein, Before determining at least one source code class file with external dependencies in the source code, the application comprises the following steps: perform logical analysis on the source code to determine the code logic in the source code; wherein the logical analysis includes lexical analysis, syntax analysis and semantic analysis.
3. The method of claim 2, wherein, The determination of at least one source code class file with external dependencies in the source code comprises the following steps: acquire a preset annotation identifier, perform reference identification on the code logic based on the annotation identifier, and determine the source code class file with external dependencies.
4. The method of claim 1, wherein, Before determining the target package file of each target reference class file based on the target reference class file identifier and the location information corresponding to each source code class file, the application further comprises the following steps: perform verification processing on the target class file corresponding to each source code class file to obtain the verified target class file; wherein the verification processing includes de-duplication verification and legality verification.
5. The method of claim 4, wherein, The determination of the target package file of each target reference class file based on the target reference class file identifier and the location information corresponding to each source code class file comprises the following steps: acquire each location information, determine the parent package file where each target reference class file after the verification processing is located based on each location information; extract the class file data corresponding to each target reference class file identifier in the parent package file to generate the target package file corresponding to each target reference class file.
6. The method of claim 1, wherein, The target program of the source code is acquired, and a program package of the application program is generated based on the target package file and the target program, including: The source code after logical analysis is subjected to code compilation processing to generate a target program of the source code; The target program and the target package file are packaged to obtain a program package.
7. An application package generation apparatus characterized by comprising: Comprise: A source code class file determination module is configured to acquire source code of an application program and determine at least one source code class file having external dependency relationship in the source code; A position information determination module is configured to determine, for any source code class file, a target reference class file on which the current source code class file depends and position information of the target reference class file in an external tool package; wherein the target reference class file is a class file without external dependency relationship; A target package file generation module is configured to determine a target package file of each target reference class file based on target reference class file identification and the position information corresponding to each source code class file, wherein the target package file is a file including only file data of a target reference class file; A program package generation module is configured to acquire a target program of the source code and generate a program package of the application program based on the target package file and the target program; The position information determination module comprises: A reference class file determination unit is configured to acquire a source code header file in the source code class file and determine at least one reference class file stored in the source code header file; An external reference class file determination unit is configured to acquire a reference header file of each reference class file and determine at least one external reference class file in the reference class file based on the file type of the header file; A target reference class file determination unit is configured to, for any external reference class file, determine the current external reference class file as a target reference class file if the reference header file no longer includes an external reference class file; If the reference header file includes an external reference class file, determine a reference header file corresponding to the external reference class file, and in the case that the reference header file does not store an external reference class file, determine the external reference class file corresponding to the reference header file as the target reference class file of the current source code class file.
8. An electronic device, comprising: Comprise: One or more processors; A storage device configured to store one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the application program package generation method of any one of claims 1-6.
9. A computer readable storage medium having stored thereon a computer program, characterized in that, The program is executed by the processor to implement the application program package generation method of any one of claims 1-6.
Citation Information
Patent Citations
Data processing method and device
CN106227668A
Java file dependency analysis method and module for distributed static detection system
CN109033843A
Dependence analysis and program compiling method and device and storage medium
CN113296777A