ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Walter.Heesterm...@toyota-europe.com
Subject RE: New Ant Task; Null Pointer Exception
Date Thu, 13 May 2004 13:44:57 GMT




If I see this :${buildnum} in the echo statement, it means that the
property buildnum is not set. Youa re sure that somewhere you use <property
name="buildnum" value"blablabla"/> ? It seems that you use now a property
name not set.

So you should have for example

<property name="buildnum" value"1.4"/>
<echo> The buildnum value = ${buildnum}</echo>
<justbuild version="${buildnum}"/>
<echo> The result = ${result}</echo>

Walter



                                                                                         
                                              
                                                                                         
                                              
                                                    To:  user@ant.apache.org             
                                              
                                                    cc:                                  
                                              
                                                    bcc:                                 
                                              
                                                    Subject:   RE: New Ant Task; Null Pointer
Exception                                 
              rhonda.brown@lynx.co.uk                                                    
                                              
              13/05/2004 15:47                                                           
                                              
                                                                                         
                                              
                                                                                         
                                              





I have tried with the amendments suggested and received the following
output from the script:

justbuild:
     [echo]  The buildnum value = ${buildnum}
[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
     [echo]  The result = ${buildnum}
[justbuild] In execute
[justbuild] myVersion is null

BUILD SUCCESSFUL



 -----Original Message-----
From: Walter.Heestermans@toyota-euro
[mailto:Walter.Heestermans@toyota-europe.com]
Sent: 13 May 2004 12:55
To: user@ant.apache.org
Subject: RE: New Ant Task; Null Pointer Exception

 --------------------------------------------------------------------------
--




Hi,

Try the following ant task code

package anttask;

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

public class JustBuild extends Task

{

      private String myVersion;

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

      public void execute() {
            System.out.println("In execute");
            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("result", buildnum);
            }
      }
}

In the build XML file

<echo> The buildnum value = ${buildnum}</echo>
<justbuild version="${buildnum}"/>
<echo> The result = ${result}</echo>

Walter











                            To:  Walter.Heestermans@toyota-europe.com



                cc:  user@ant.apache.org



    bcc:



Subject:   RE: New Ant Task; Null Pointer Exception

                        rhonda.brown@lynx.co.uk



            13/05/2004 13:56



















Still no luck.

Have amended the target as follows:

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

When I run the target, I get the following output:

justbuild:
[justbuild] In execute
[justbuild] myVersion is null
[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

BUILD SUCCESSFUL




 -----Original Message-----
From: Walter.Heestermans@toyota-euro
[mailto:Walter.Heestermans@toyota-europe.com]
Sent: 13 May 2004 12:22
To: Rhonda Brown
Subject: RE: New Ant Task; Null Pointer Exception



 --------------------------------------------------------------------------


 --




Oeps, to fast use

  <property name="version" value="${buildnum}"/>
  <justbuild/>











                            To:  rhonda.brown@lynx.co.uk



                cc:



    Subject:   RE: New Ant Task; Null Pointer Exception(Document link:
Walter
Heestermans)

                              Walter Heestermans



                  13/05/2004 13:21

















Hi,

  <!--<justbuild version="${version}"/>-->
  <property name="version" value="buildnum"/>
  <justbuild/>

Change to:

  <justbuild version="${buildnum}"/>

??











                            To:  user@ant.apache.org



                cc:  Walter.Heestermans@toyota-europe.com



    bcc:



Subject:   RE: New Ant Task; Null Pointer Exception

                        rhonda.brown@lynx.co.uk



            13/05/2004 13:21



















Hi Walter

I have copied in the script; the target is called 'justbuild'.


<?xml version="1.0" encoding="windows-1252"?>
<project name="tagrepository" default="tag" basedir=".">
 <!--  The following properties must be set from commandline  bin.outdir
-location of where all deployment files must be   placed  build.properties-
name of build properties file to use  build.type - type of build
integration, production, development, uat  -->
 <!--Version File-->
 <property resource="${version.file}">
  <classpath>
   <pathelement path="${resources.home}"/>
  </classpath>
 </property>
 <!--delete the compile, javadoc, source, repository & resources
directories-->
 <target name="directoryreset" depends="directorydelete,directorycreate"
description="Empties directories by deleting and recreating"/>
 <!--create directories-->
 <target name="directorycreate" description="Create compile, javadoc, jar,
bin, repository, resources and cvscheckout directories">
  <mkdir dir="${repository.home}"/>
  <mkdir dir="${resources.home}"/>
 </target>
 <!--delete the compile, javadoc, source, repository & resources
directories-->
 <target name="directorydelete" description="Delete the compile, javadoc,
source, repository and resources directories">
  <!--Delete output directories-->
  <delete dir="${repository.home}"/>
  <delete dir="${resources.home}"/>
  <delete dir="${cvscheckout.resources.home}"/>
 </target>
 <!--checkout cvs module-->
 <target name="cvscheckout" depends="cvscheckoutrepository"
description="checkout files from cvs"/>
 <!--checkout repository module-->
 <target name="cvscheckoutrepository" description="Checkout all source
from
cvs in the repository module">
  <cvs cvsRoot="${cvs.connection}" package="${cvs.module.repository}"
dest="${cvscheckout.repository.home}"/>
 </target>
 <!--set the source path-->
 <path id="srcpath">
  <pathelement location="${source.home}"/>
 </path>
   <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>
   <!--Commit version file-->
 <target name="cvsversioncommit" description="Commit repositoryversion.txt
into cvs">
  <cvs command="commit -m verinc ${resources.home}/${version.file}"
cvsroot="${cvs.connection}"/>
 </target>
 <!-- Tag source directory with version number from version.txt-->
 <target name="cvstag" depends="cvsversioncommit" description="Tag cvs
source directory with build number">
  <property resource="${version.file}">
   <classpath>
    <pathelement path="${resources.home}"/>
   </classpath>
  </property>
  <echo message="build.number=${build.number}"/>
  <cvs command="tag
${build.type}_release_${buildnum}_repository_${build.number}
${repository.home}" cvsroot="${cvs.connection}"/>
 </target>
 <!--Increment build number in Version File-->
 <target name="incbuild" description="Increment build number in version
file">
  <buildnumber file="${resources.home}/${version.file}"/>
 </target>
 <!--Version repository-->
 <target name="tag"
depends="directorydelete,directorycreate,cvscheckout,incbuild,cvstag"
description="Versions the repository"/>
</project>


 -----Original Message-----
From: Walter.Heestermans@toyota-euro
[mailto:Walter.Heestermans@toyota-europe.com]
Sent: 13 May 2004 11:48
To: user@ant.apache.org
Subject: Re: New Ant Task; Null Pointer Exception





 --------------------------------------------------------------------------






 --




Can you show me the build XML file?

Must include something like <JustBuild version="${buildnum}"/>

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.
>
> <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





 ---------------------------------------------------------------------
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.








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




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