Apache Jakarta and Beyond: A Java Programmeramp;#039;s Introduction [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Apache Jakarta and Beyond: A Java Programmeramp;#039;s Introduction [Electronic resources] - نسخه متنی

Larne Pekowsky

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید







2.2. Dependencies


Stringing together tasks within a target solves part of the problem of a complex build process. A target could run one task to generate any needed Java files, then another to compile them, another to collect the resulting class files into an archive, and so on.

Ant provides a much more powerful and hence more commonly used mechanism for connecting tasks, called

dependencies. Task B is said to depend on task A if A must complete successfully in order for B to run. One task may depend on many others and may be depended on by many others. Dependencies are represented within a build file by adding the depends attribute to a target, as in


<target name="B" depends="A">
...
</target>

If one target depends on multiple other targets, their names appear separated by commas in the depends attribute.

A hierarchy of dependencies implies an order in which tasks will be executed, but it is a logical ordering rather than the explicit one given by placing multiple tasks in a target. Conceptually the programmer specifies what each individual target needs in order to do its job, and Ant figures out an ordering in which to execute the targets such that these requirements are met.

To illustrate the idea of dependencies, consider a set of abstract targets designated A, B, C, and D with the relationships illustrated in Figure 2.1. In this figure an arrow between two tasks indicates that the task at the tail depends on the task at the headfor example

A

B means that A depends on B.


Figure 2.1. Task dependencies.

By having each of these tasks echo its name it is possible to see how Ant arranges execution to satisfy dependencies. The build file is shown in Listing 2.1.


Listing 2.1. Dependencies between tasks


<?xml version="1.0"?>
<project default="sampleA">
<target name="sampleA" depends="sampleB,sampleC">
<echo message="This is a simple target A"/>
</target>
<target name="sampleB">
<echo message="This is a simple target B"/>
</target>
<target name="sampleC" depends="sampleD">
<echo message="This is a simple target C"/>
</target>
<target name="sampleD">
<echo message="This is a simple target D"/>
</target>
</project>

When this build file is run, Ant will produce the following output:


Buildfile: build.xml
sampleB:
[echo] This is a simple target B
sampleD:
[echo] This is a simple target D
sampleC:
[echo] This is a simple target C
sampleA:
[echo] This is a simple target A
BUILD SUCCESSFUL
Total time: 9 seconds

This shows that B was run first, then D, then C, and finally A. Ant has some flexibility in the precise order in which it executed the targets, as long as B and C happened before A and D happened before C. If B also depended on D, this order would be further constrained. By changing the target definition for B to <target name="sampleB" depends="sampleD"> the order would be restricted to either DBCA or DCBA.


/ 207