ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Reilly <peter.rei...@corvil.com>
Subject Re: New Ant Task; Null Pointer Exception
Date Thu, 13 May 2004 12:23:51 GMT
rhonda.brown@lynx.co.uk wrote:

>No I haven't.  Version is a property that has already been defined by Ant as follows:
>  
>
Not in the build file you have shown:

The justbuild target is:   
<target name="justbuild" description="format version number">
  <taskdef name="justbuild" classname="anttask.JustBuild" classpath="${tasks.outdir}"/>
  <!--<justbuild version="${version}"/>-->
  <property name="version" value="buildnum"/>
  <justbuild/>
 </target>


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

Peter


>${version} property is made up of <prefix> <buildNo> and <postfix> from
which I just want to extract the buildNo property to tag certain source files
>
>I have used the property ${version} to tag the files as seen below in a previous version
of my build file:
>
><cvs command="tag
>${build.type}_release_${version}_repository_${build.number}
>${repository.home}" cvsroot="${cvs.connection}"/>
>
>The build is successful, except it is not tagging any of the files as
>expected.  I have checked the build log and found the following message:
>
>
>cvstag:
>     [echo] build.number=120
>      [cvs] cvs [tag aborted]: tag `Ver_release_1.0.4187_resources_120'
>must not contain the characters `$,.:;@'
>
>
>Because it does not allow any of the above symbols I have tried to write an Ant Task just
to use the last 4 numbers after the last dot.
>
>
> -----Original Message-----
>From: Jan.Materne@rzf.fin-nrw.de [mailto:Jan.Materne@rzf.fin-nrw.de]
>Sent: 13 May 2004 11:47
>To: user@ant.apache.org
>Subject: RE: New Ant Task; Null Pointer Exception
>
> --------------------------------------------------------------------------  --
>Do you have a
>  <property name="version" value="1.4"/>
>in your script?
>
>Jan
>
>  
>
>>-----Original Message-----
>>From: rhonda.brown@lynx.co.uk [mailto:rhonda.brown@lynx.co.uk]
>>Sent: Thursday, May 13, 2004 12:49 PM
>>To: user@ant.apache.org
>>Subject: New Ant Task; Null Pointer Exception
>>    
>>
>>>>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
>>
>>    
>>
>
>
>
>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


Mime
View raw message