Browse Source

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.

PR:
Obtained from:
Submitted by:
Reviewed by:


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@273668 13f79535-47bb-0310-9956-ffa450edef68
master
Costin Manolache 22 years ago
parent
commit
4896e42323
1 changed files with 56 additions and 0 deletions
  1. +56
    -0
      src/main/org/apache/tools/ant/types/Description.java

+ 56
- 0
src/main/org/apache/tools/ant/types/Description.java View File

@@ -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 @@ public class Description extends DataType {
* 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 @@ public class Description extends DataType {
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;
}

}

Loading…
Cancel
Save