costin 2002/12/13 13:58:23
Modified: src/main/org/apache/tools/ant/types Description.java
Log:
Initial fix for description problems.
If the original ProjectHelperImpl will be used, things will
work as before.
If not - Description will look into each target and do
whatever it is supposed to do.
Revision Changes Path
1.9 +57 -1
jakarta-ant/src/main/org/apache/tools/ant/types/Description.java
Index: Description.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/types/Description.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- Description.java 23 Jul 2002 07:54:56 -0000 1.8
+++ Description.java 13 Dec 2002 21:58:23 -0000 1.9
@@ -54,6 +54,12 @@
package org.apache.tools.ant.types;
+import org.apache.tools.ant.*;
+import org.apache.tools.ant.helper.ProjectHelperImpl;
+
+import java.util.Hashtable;
+import java.util.Enumeration;
+import java.util.Vector;
/**
@@ -77,6 +83,13 @@
* Adds descriptive text to the project.
*/
public void addText(String text) {
+
+ ProjectHelper ph=ProjectHelper.getProjectHelper();
+ if( ! ( ph instanceof ProjectHelperImpl )) {
+ // New behavior for delayed task creation. Description
+ // will be evaluated in Project.getDescription()
+ return;
+ }
String currentDescription = getProject().getDescription();
if (currentDescription == null) {
getProject().setDescription(text);
@@ -84,4 +97,47 @@
getProject().setDescription(currentDescription + text);
}
}
+
+ public static String getDescription(Project project) {
+ StringBuffer description=new StringBuffer();
+ Vector targets=(Vector)project.getReference( "ant.targets");
+ for( int i=0; i<targets.size(); i++ ) {
+ Target t=(Target)targets.elementAt(i);
+ concatDescriptions(project, t, description);
+ }
+ return description.toString();
+ }
+
+ private static void concatDescriptions(Project project, Target t,
+ StringBuffer description)
+ {
+ if( t==null ) return;
+ Vector tasks= findElementInTarget(project, t, "description");
+ if( tasks==null ) return;
+ for( int i=0; i<tasks.size(); i++ ) {
+ Task task=(Task)tasks.elementAt(i);
+ if( ! ( task instanceof UnknownElement)) {
+ continue;
+ }
+ UnknownElement ue=((UnknownElement)task);
+ StringBuffer descComp=ue.getWrapper().getText();
+ if( descComp != null ) {
+ description.append( descComp );
+ }
+ }
+ }
+
+ private static Vector findElementInTarget(Project project,
+ Target t, String name )
+ {
+ Task tasks[]=t.getTasks();
+ Vector elems=new Vector();
+ for( int i=0; i<tasks.length; i++ ) {
+ if( name.equals( tasks[i].getTaskName()) ) {
+ elems.addElement(tasks[i]);
+ }
+ }
+ return elems;
+ }
+
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>