aspose file tools
The moose likes Ant, Maven and Other Build Tools and the fly likes New Ant Task Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Practical Unit Testing with TestNG and Mockito this week in the Testing forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Reply Bookmark "New Ant Task Problem" Watch "New Ant Task Problem" New topic
Author

New Ant Task Problem

Rhonda Brown
Greenhorn

Joined: May 13, 2004
Posts: 1
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 called the task in my build file I was getting 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)

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, 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.
Can anyone see where I have gone wrong?

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

[ May 13, 2004: Message edited by: Rhonda Brown ]
[ May 13, 2004: Message edited by: Rhonda Brown ]
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 12512

It would require more looking to solve THAT problem, but if all you want is an automatic-incrementing build number, there's an ant task to handle that, at least since Ant 1.6. It's called something like "buildversion".


One of the most odious afflictions that Business has inflicted on the modern English language is "pro-active". Most of the time it's simply redundantly used in place of the simple old word "active". And a good deal of the rest of the time it means "You're not overworked enough yet, so go out and find more!"
 
 
subject: New Ant Task Problem
 
Threads others viewed
Wrapping an existing core Ant task
Adding an attribute to an ANT task
Getting the free disk space
Help with Ant -FTP Task
[WEBSPHERE][MIGRATION] migrate-user-groups-ac error!
IntelliJ Java IDE