1 18 19 package org.apache.tools.ant.types; 20 21 import org.apache.tools.ant.Project; 22 import org.apache.tools.ant.ProjectHelper; 23 import org.apache.tools.ant.Task; 24 import org.apache.tools.ant.UnknownElement; 25 import org.apache.tools.ant.Target; 26 import org.apache.tools.ant.helper.ProjectHelperImpl; 27 28 import java.util.Vector ; 29 30 31 44 public class Description extends DataType { 45 46 51 public void addText(String text) { 52 53 ProjectHelper ph = ProjectHelper.getProjectHelper(); 54 if (!(ph instanceof ProjectHelperImpl)) { 55 return; 58 } 59 String currentDescription = getProject().getDescription(); 60 if (currentDescription == null) { 61 getProject().setDescription(text); 62 } else { 63 getProject().setDescription(currentDescription + text); 64 } 65 } 66 67 75 public static String getDescription(Project project) { 76 Vector targets = (Vector ) project.getReference("ant.targets"); 77 if (targets == null) { 78 return null; 79 } 80 StringBuffer description = new StringBuffer (); 81 for (int i = 0; i < targets.size(); i++) { 82 Target t = (Target) targets.elementAt(i); 83 concatDescriptions(project, t, description); 84 } 85 return description.toString(); 86 } 87 88 private static void concatDescriptions(Project project, Target t, 89 StringBuffer description) { 90 if (t == null) { 91 return; 92 } 93 Vector tasks = findElementInTarget(project, t, "description"); 94 if (tasks == null) { 95 return; 96 } 97 for (int i = 0; i < tasks.size(); i++) { 98 Task task = (Task) tasks.elementAt(i); 99 if (!(task instanceof UnknownElement)) { 100 continue; 101 } 102 UnknownElement ue = ((UnknownElement) task); 103 String descComp = ue.getWrapper().getText().toString(); 104 if (descComp != null) { 105 description.append(project.replaceProperties(descComp)); 106 } 107 } 108 } 109 110 private static Vector findElementInTarget(Project project, 111 Target t, String name) { 112 Task[] tasks = t.getTasks(); 113 Vector elems = new Vector (); 114 for (int i = 0; i < tasks.length; i++) { 115 if (name.equals(tasks[i].getTaskName())) { 116 elems.addElement(tasks[i]); 117 } 118 } 119 return elems; 120 } 121 122 } 123 | Popular Tags |