Return-Path: Delivered-To: apmail-ant-user-archive@www.apache.org Received: (qmail 51397 invoked from network); 13 May 2004 10:47:19 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 13 May 2004 10:47:19 -0000 Received: (qmail 18888 invoked by uid 500); 13 May 2004 10:47:05 -0000 Delivered-To: apmail-ant-user-archive@ant.apache.org Received: (qmail 18820 invoked by uid 500); 13 May 2004 10:47:05 -0000 Mailing-List: contact user-help@ant.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Ant Users List" Reply-To: "Ant Users List" Delivered-To: mailing list user@ant.apache.org Received: (qmail 18690 invoked by uid 98); 13 May 2004 10:47:04 -0000 Received: from Walter.Heestermans@toyota-europe.com by hermes.apache.org by uid 82 with qmail-scanner-1.20 (clamuko: 0.70. Clear:RC:0(195.177.81.6):. Processed in 2.12655 secs); 13 May 2004 10:47:03 -0000 X-Qmail-Scanner-Mail-From: Walter.Heestermans@toyota-europe.com via hermes.apache.org X-Qmail-Scanner: 1.20 (Clear:RC:0(195.177.81.6):. Processed in 2.12655 secs) Received: from unknown (HELO smtp2.toyota-europe.com) (195.177.81.6) by hermes.apache.org with SMTP; 13 May 2004 10:47:01 -0000 Received: (qmail 18203 invoked from network); 13 May 2004 13:39:29 -0000 Received: from unknown (HELO smtp2.toyota-europe.com) (127.0.0.1) by a with SMTP; 13 May 2004 13:39:29 -0000 Received: (qmail 18198 invoked from network); 13 May 2004 13:39:29 -0000 Received: from unknown (HELO tmmebxlxnts04.be.tmme.com) (150.45.94.4) by 0 with SMTP; 13 May 2004 13:39:29 -0000 Subject: Re: New Ant Task; Null Pointer Exception To: "Ant Users List" X-Mailer: Lotus Notes Release 5.0.8 June 18, 2001 Message-ID: From: Walter.Heestermans@toyota-europe.com Date: Thu, 13 May 2004 12:49:01 +0200 X-MIMETrack: Serialize by Router on BXLNOTES04/TMME(Release 6.5|September 26, 2003) at 13/05/2004 12:46:59 MIME-Version: 1.0 Content-type: text/plain; charset=US-ASCII X-Spam-Rating: hermes.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Can you show me the build XML file? Must include something like Walter To: user@ant.apache.org cc: bcc: Subject: New Ant Task; Null Pointer Exception rhonda.brown@lynx.co.uk 13/05/2004 12:48 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. > > > > 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 --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For additional commands, e-mail: user-help@ant.apache.org