source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/main/org/apache/tools/ant/types/Description.java@ 14627

Last change on this file since 14627 was 14627, checked in by oranfry, 17 years ago

initial import of the gs3-release-maker

File size: 4.0 KB
Line 
1/*
2 * Copyright 2001-2005 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18package org.apache.tools.ant.types;
19
20import org.apache.tools.ant.Project;
21import org.apache.tools.ant.ProjectHelper;
22import org.apache.tools.ant.Task;
23import org.apache.tools.ant.UnknownElement;
24import org.apache.tools.ant.Target;
25import org.apache.tools.ant.helper.ProjectHelperImpl;
26
27import java.util.Vector;
28
29
30/**
31 * Description is used to provide a project-wide description element
32 * (that is, a description that applies to a buildfile as a whole).
33 * If present, the <description> element is printed out before the
34 * target descriptions.
35 *
36 * Description has no attributes, only text. There can only be one
37 * project description per project. A second description element will
38 * overwrite the first.
39 *
40 *
41 * @ant.datatype ignore="true"
42 */
43public class Description extends DataType {
44
45 /**
46 * Adds descriptive text to the project.
47 *
48 * @param text the descriptive text
49 */
50 public void addText(String text) {
51
52 ProjectHelper ph = ProjectHelper.getProjectHelper();
53 if (!(ph instanceof ProjectHelperImpl)) {
54 // New behavior for delayed task creation. Description
55 // will be evaluated in Project.getDescription()
56 return;
57 }
58 String currentDescription = getProject().getDescription();
59 if (currentDescription == null) {
60 getProject().setDescription(text);
61 } else {
62 getProject().setDescription(currentDescription + text);
63 }
64 }
65
66 /**
67 * Return the descriptions from all the targets of
68 * a project.
69 *
70 * @param project the project to get the descriptions for.
71 * @return a string containing the concatenated descriptions of
72 * the targets.
73 */
74 public static String getDescription(Project project) {
75 Vector targets = (Vector) project.getReference("ant.targets");
76 if (targets == null) {
77 return null;
78 }
79 StringBuffer description = new StringBuffer();
80 for (int i = 0; i < targets.size(); i++) {
81 Target t = (Target) targets.elementAt(i);
82 concatDescriptions(project, t, description);
83 }
84 return description.toString();
85 }
86
87 private static void concatDescriptions(Project project, Target t,
88 StringBuffer description) {
89 if (t == null) {
90 return;
91 }
92 Vector tasks = findElementInTarget(project, t, "description");
93 if (tasks == null) {
94 return;
95 }
96 for (int i = 0; i < tasks.size(); i++) {
97 Task task = (Task) tasks.elementAt(i);
98 if (!(task instanceof UnknownElement)) {
99 continue;
100 }
101 UnknownElement ue = ((UnknownElement) task);
102 StringBuffer descComp = ue.getWrapper().getText();
103 if (descComp != null) {
104 description.append((Object) descComp);
105 }
106 }
107 }
108
109 private static Vector findElementInTarget(Project project,
110 Target t, String name) {
111 Task[] tasks = t.getTasks();
112 Vector elems = new Vector();
113 for (int i = 0; i < tasks.length; i++) {
114 if (name.equals(tasks[i].getTaskName())) {
115 elems.addElement(tasks[i]);
116 }
117 }
118 return elems;
119 }
120
121}
Note: See TracBrowser for help on using the repository browser.