ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 29052] New: - getProject() method returns null when called from Custom Tasks
Date Tue, 18 May 2004 05:43:58 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=29052>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=29052

getProject() method returns null when called from Custom Tasks

           Summary: getProject() method returns null when called from Custom
                    Tasks
           Product: Ant
           Version: 1.5.3
          Platform: All
        OS/Version: Windows NT/2K
            Status: NEW
          Severity: Blocker
          Priority: Other
         Component: Other
        AssignedTo: dev@ant.apache.org
        ReportedBy: dhananjayan_k@satyam.com


Hi,
I have written custom ant task by extending from Task class. In the execute 
method i call getProject() method, but it returns null.
So i get NullPointerException at the position.
Whenever I try to get Project object by using getProject() from a custom task 
the Project object is null.

Please clarify either its a bug or a behavior.



package anttask;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.Project;

public class JustBuild extends Task

{
public static void main(String[] args)
{
JustBuild justBuild = new JustBuild();
//justBuild.setVersion("01.05.2004");
justBuild.execute();
}
private String myVersion;

public void setVersion(String version) 
{
myVersion = version;
}

public void execute() 
{
System.out.println("In execute");

myVersion = getProject().getProperty("version");
if (myVersion == null) 
{
System.out.println("myVersion is null");
}
else 
{
System.out.println(" myVersion: " + myVersion.toString());
int dot = myVersion.lastIndexOf(".");
System.out.println(" got dot: " + String.valueOf(dot));
String buildnum = myVersion.substring(dot+1);
System.out.println(" got buildnum: " + buildnum);
System.out.println(" project is :");
System.out.println(" project: "+ getProject().toString());
getProject().setProperty("buildnum", buildnum);
}
}
}

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message