The automation construction process is divided into several links, each link is a prerequisite. The build framework described in this article encapsulates each link in the build process as a subtask of the Ant script, and is scheduled through the Builds master task. The build Master task, as well as the creation of the scripting framework, has been introduced in part 1th of this series, and this article introduces the construction process of the code in detail. Readers can refer to the code examples in this article to complete the remainder of the code to achieve a complete build framework. When writing a build script, the reader may need to customize some Ant tags, the Java code for these custom tags can be packaged into a jar file and stored in the <build script>/lib directory and passed through <taskdef in build.xml files > Label to declare a custom label. (This article requires readers to read on the basis of a certain Ant scripting knowledge and Java authoring experience.) )
Figure 1. Automate the build process
Extract incremental Code
The first step in building incremental code is to extract the newly added code from the code base, and there are many common code base management tools (SCM) available on the market. The build of incremental code requires that the code management tools have good code http://www.aliyun.com/zixun/aggregation/9591.html "> versioning capabilities and the ability to run the command line, This facilitates automated execution of the entire build process, which can also be done by hand. In the build framework, the reader needs to extract qualified code from the code base and store it in the development directory.
In the build framework described in this article, the incremental code is stored in the Extract directory. To make it easier to differentiate between different versions of the incremental code, you can use a timestamp or build label to mark the time stamp, or construct label, as a parameter to enter as a parameter when you start the construction process. The reader needs to define the corresponding variables in the build script to enable the input variable to be read. For example, the ant command in Listing 1 is to enter the build label as a parameter into the ant script.
Listing 1. Input parameters when starting Ant script
<build scirpt>/ant–buildfile Build.xml–dbuildlabel Buildlabel
For code extraction conditions, the reader can be configured in the Build.properties file, with the following only pseudo code examples. The reader can refer to listing 2 to complete the script for this section and define it as a subtask and add it to the main task.
Listing 2. Code extraction Scripts
<target= "Commone.extract_files"/> <!--1. Obtain version information for the incremental code from the Build.properties file (this information is intended for multiple versions of developed products) 2. Obtain the minimum unit information (such as defect or task) associated with the increment code from the Build.propetties file Note: Any code file that is imported into the code library needs to correspond to a task number or a defect number. This allows the code management tool to differentiate and manage files that import code libraries at different times. 3. Read the build label from the Build.properties file or read it from the input parameters. 4. Determine if there is a directory with the same build readable, delete if present. New if not present. 5. Connect SCM management tools, start command line execution code extraction--> </target >
Your code may be stored in a code base with different paths. In this paper, we need readers to store the extracted code according to the relative path in the project. The specifics of code management are not the focus of this article, so the reader needs to consult the product's configuration management team to complete the section and integrate it into the main task.