ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhonda.br...@lynx.co.uk
Subject New Ant Task; Null Pointer Exception
Date Thu, 13 May 2004 10:48:31 GMT
Hi
   

Thanks for your responses, I have still got a problem here.
   

I have since added in some println statements so I can see how far it is getting in the code.
When I call the task from my script, I now get the following feed back:

justbuild:
[justbuild] In execute
[justbuild] myVersion: buildnum
[justbuild] got dot: -1
[justbuild] got buildnum: buildnum
[justbuild] project is :
[justbuild] project: org.apache.tools.ant.Project@8acf6e

>From this it looks like it is not finding buildnumber in the project from some reason.
   

This is the code that I am testing it with at the moment:

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);
}
}
}

Thanks in advance.

Rhonda
   

   

   

>> -----Original Message-----
>
> Then you could also provide a way to specify the property to set.
>
> <justbuild property="foo" version="11.05.2004_1304"/>
>
> String property = "buildnum";
> public void setProperty(...) { ... }
> public void execute() {
> ...
>
> getProject().setProperty(property, buildnum);
>
> }
>
>
>
>Jan
>
> > -----Original Message-----
> From: Peter Reilly [mailto:peter.reilly@corvil.com]
> Sent: Tuesday, May 11, 2004 2:02 PM
> To: Ant Users List
> Subject: Re: New Ant Task; Null Pointer Exception
>
>
> The task works for me.
> However, it does not have error checking,
> so if version is not set, a null pointer exception will
> be thrown.
>
> The execute method should be:
>
>   public void execute()
>   {
>     if (myVersion == null) {
>         throw new BuildException("Missing required attribute
> 'version'");
>     }
>     int dot = myVersion.lastIndexOf(".");
>     String buildnum = myVersion.substring(dot+1);
>     getProject().setProperty("buildnum", buildnum);
>   }
> }
>
> Also as Jan saids,
> you should remove the "main" method as it will not work.
>
> Also ..
> the task sets the buildnum property even if it is already set.
> This goes against normal ant style.
> Peter
>
> rhonda.brown@lynx.co.uk wrote:
>
> >Hi
> >
> >
> >I have written a small Ant Task to amend the format of the
> version number so that it will use the last 4 digits after
> the last period to tag the source files.
> >
> >
> >Example:
> >
> >
> >tag `Ver_release_1.0.5121_resources_120'
> >
> >
> >When I call the task in my build file I get this error message:
> >
> >
> >java.lang.NullPointerException
> >        at anttask.JustBuild.execute(JustBuild.java:23)
> >        at
> org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:193)
> >        at org.apache.tools.ant.Task.perform(Task.java:341)
> >        at org.apache.tools.ant.Target.execute(Target.java:309)
> >        at org.apache.tools.ant.Target.performTasks(Target.java:336)
> >        at
> org.apache.tools.ant.Project.executeTarget(Project.java:1339)
> >        at
> org.apache.tools.ant.Project.executeTargets(Project.java:1255)
> >        at org.apache.tools.ant.Main.runBuild(Main.java:609)
> >        at org.apache.tools.ant.Main.start(Main.java:196)
> >        at org.apache.tools.ant.Main.main(Main.java:235)
> >
> >
> >This is the code that I am using:
> >
> >
> >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()
> >  {
> >    int dot = myVersion.lastIndexOf(".");
> >    String buildnum = myVersion.substring(dot+1);
> >    getProject().setProperty("buildnum", buildnum);
> >    //System.out.println("this is a test");
> >  }
> >}
> >
> >
> >Project has got a Null value, but I can"t see why.
> >
> >
> >Can anyone see where I have gone wrong?
> >
> >
> >Thanks for your answers.
> >
> >
> >Rhonda
> >
> >
> >This message is intended only for the use of the person(s)
> ("The intended
> >Recipient(s)") to whom it is addressed.  It may contain
> information which
> >is privileged and confidential within the meaning of
> applicable law.  If
> >you are not the intended recipient, please contact the
> sender as soon as
> >possible.  The views expressed in this communication are not
> necessarily
> >those held by LYNX Express Limited.
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> >For additional commands, e-mail: user-help@ant.apache.org
> >
> >
> >
> >
> >
>
>


This message is intended only for the use of the person(s) ("The intended
Recipient(s)") to whom it is addressed.  It may contain information which
is privileged and confidential within the meaning of applicable law.  If
you are not the intended recipient, please contact the sender as soon as
possible.  The views expressed in this communication are not necessarily
those held by LYNX Express Limited.

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


Mime
View raw message