The attached file 'AntPropertyHelper.patch' contains a patch for this bug. 'basedir' was treated the same way as 'project.xxxx' properties were.
While testing this fix, I found another problem with properties of the following format 'project.xxxx.yyyy'. First AntPropertyHelper would trim this to 'xxxx.yyyy'. After that, ReflectionValueExtractor.evaluate(String, Object) would trim this to 'yyyy' because it delegates to ReflectionValueExtractor.evaluate(String, Object, true). I've modified AntPropertyHelper to always use the three-arg evaluate() method for clarity.
The basedir property is now resolved as 'mavenproject.getBasedir().getPath()'
Please use the attached project-zip 'CustomAntTask-extra-tests.zip' to test. Before applying the patch the result for me is:
C:\work\CustomAntTask>mvn -Dproject.cmdline=commandlineparameter package
[INFO] Scanning for projects...
[INFO] ----------------------------------------------------------------------------
[INFO] Building Unnamed - nl.ohra.test:CustomAntTask:jar:1.0-SNAPSHOT
[INFO] task-segment: [package]
[INFO] ----------------------------------------------------------------------------
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:compile]
[INFO] Nothing to compile - all classes are up to date
[INFO] [resources:testResources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:testCompile]
[INFO] No sources to compile
[INFO] [surefire:test]
[INFO] No tests to run.
[INFO] [jar:jar]
[INFO] Building jar: C:\work\CustomAntTask\target\CustomAntTask-1.0-SNAPSHOT.jar
[INFO] [antrun:run
{execution: testant}
]
[INFO] Executing tasks
[echo] basedir:C:\work\CustomAntTask
[echo] sourceDirectory:src/main/java
sourceDirectory:null
project.cmdline:commandlineparameter
[WARNING] Error evaluating expression 'basedir'
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(String.java:1768)
at java.lang.String.substring(String.java:1735)
at org.apache.maven.plugin.antrun.AntPropertyHelper.getPropertyHook(AntPropertyHelper.java:5
1)
at org.apache.tools.ant.PropertyHelper.getPropertyHook(PropertyHelper.java:184)
at org.apache.tools.ant.PropertyHelper.getProperty(PropertyHelper.java:438)
at org.apache.tools.ant.Project.getProperty(Project.java:474)
at nl.ohra.test.TestTask.execute(TestTask.java:13)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
at org.apache.tools.ant.Task.perform(Task.java:364)
at org.apache.tools.ant.Target.execute(Target.java:341)
at org.apache.maven.plugin.antrun.AbstractAntMojo.executeTasks(AbstractAntMojo.java:103)
at org.apache.maven.plugin.antrun.AntRunMojo.execute(AntRunMojo.java:83)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:432)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor
.java:530)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifec
ycleExecutor.java:472)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.
java:451)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultL
ifecycleExecutor.java:303)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleE
xecutor.java:270)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java
:139)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:322)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:115)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:249)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(String.java:1768)
at java.lang.String.substring(String.java:1735)
at org.apache.maven.plugin.antrun.AntPropertyHelper.getPropertyHook(AntPropertyHelper.java:5
1)
at org.apache.tools.ant.PropertyHelper.getPropertyHook(PropertyHelper.java:184)
at org.apache.tools.ant.PropertyHelper.getProperty(PropertyHelper.java:438)
at org.apache.tools.ant.Project.getProperty(Project.java:474)
at nl.ohra.test.TestTask.execute(TestTask.java:13)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
at org.apache.tools.ant.Task.perform(Task.java:364)
at org.apache.tools.ant.Target.execute(Target.java:341)
at org.apache.maven.plugin.antrun.AbstractAntMojo.executeTasks(AbstractAntMojo.java:103)
at org.apache.maven.plugin.antrun.AntRunMojo.execute(AntRunMojo.java:83)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:432)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor
.java:530)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifec
ycleExecutor.java:472)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.
java:451)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultL
ifecycleExecutor.java:303)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleE
xecutor.java:270)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java
:139)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:322)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:115)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:249)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
basedir:C:\work\CustomAntTask
[INFO] Executed tasks
[INFO] ----------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ----------------------------------------------------------------------------
[INFO] Total time: 4 seconds
[INFO] Finished at: Fri Dec 23 00:19:53 CET 2005
[INFO] Final Memory: 4M/9M
[INFO] ----------------------------------------------------------------------------
C:\work\CustomAntTask>
This is the original exception, but it also shows the result of trying to get 'project.build.sourceDirectory' from within the ant-task.
After applying the patch the result is:
C:\work\CustomAntTask>mvn -Dproject.cmdline=commandlineparameter package
[INFO] Scanning for projects...
[INFO] ----------------------------------------------------------------------------
[INFO] Building Unnamed - nl.ohra.test:CustomAntTask:jar:1.0-SNAPSHOT
[INFO] task-segment: [package]
[INFO] ----------------------------------------------------------------------------
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:compile]
[INFO] Nothing to compile - all classes are up to date
[INFO] [resources:testResources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:testCompile]
[INFO] No sources to compile
[INFO] [surefire:test]
[INFO] No tests to run.
[INFO] [jar:jar]
[INFO] Building jar: C:\work\CustomAntTask\target\CustomAntTask-1.0-SNAPSHOT.jar
[INFO] [antrun:run
{execution: testant}
]
[INFO] Executing tasks
[echo] basedir:C:\work\CustomAntTask
[echo] sourceDirectory:src/main/java
sourceDirectory:C:\work\CustomAntTask\src\main\java
project.cmdline:commandlineparameter
basedir:C:\work\CustomAntTask
[INFO] Executed tasks
[INFO] ----------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ----------------------------------------------------------------------------
[INFO] Total time: 4 seconds
[INFO] Finished at: Fri Dec 23 00:29:40 CET 2005
[INFO] Final Memory: 4M/9M
[INFO] ----------------------------------------------------------------------------
C:\work\CustomAntTask>
The three properties that are read in the ant task are correct now.
The only strange thing is that $
{project.build.sourceDirectory}
when used in pom.xml returns a relative path and getProperty("project.build.sourceDirectory") is absolute. Ideas? anybody?
The attached file 'AntPropertyHelper.patch' contains a patch for this bug. 'basedir' was treated the same way as 'project.xxxx' properties were.
While testing this fix, I found another problem with properties of the following format 'project.xxxx.yyyy'. First AntPropertyHelper would trim this to 'xxxx.yyyy'. After that, ReflectionValueExtractor.evaluate(String, Object) would trim this to 'yyyy' because it delegates to ReflectionValueExtractor.evaluate(String, Object, true). I've modified AntPropertyHelper to always use the three-arg evaluate() method for clarity.
The basedir property is now resolved as 'mavenproject.getBasedir().getPath()'
Please use the attached project-zip 'CustomAntTask-extra-tests.zip' to test. Before applying the patch the result for me is:
C:\work\CustomAntTask>mvn -Dproject.cmdline=commandlineparameter package
{execution: testant}[INFO] Scanning for projects...
[INFO] ----------------------------------------------------------------------------
[INFO] Building Unnamed - nl.ohra.test:CustomAntTask:jar:1.0-SNAPSHOT
[INFO] task-segment: [package]
[INFO] ----------------------------------------------------------------------------
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:compile]
[INFO] Nothing to compile - all classes are up to date
[INFO] [resources:testResources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:testCompile]
[INFO] No sources to compile
[INFO] [surefire:test]
[INFO] No tests to run.
[INFO] [jar:jar]
[INFO] Building jar: C:\work\CustomAntTask\target\CustomAntTask-1.0-SNAPSHOT.jar
[INFO] [antrun:run
]
[INFO] Executing tasks
[echo] basedir:C:\work\CustomAntTask
[echo] sourceDirectory:src/main/java
sourceDirectory:null
project.cmdline:commandlineparameter
[WARNING] Error evaluating expression 'basedir'
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(String.java:1768)
at java.lang.String.substring(String.java:1735)
at org.apache.maven.plugin.antrun.AntPropertyHelper.getPropertyHook(AntPropertyHelper.java:5
1)
at org.apache.tools.ant.PropertyHelper.getPropertyHook(PropertyHelper.java:184)
at org.apache.tools.ant.PropertyHelper.getProperty(PropertyHelper.java:438)
at org.apache.tools.ant.Project.getProperty(Project.java:474)
at nl.ohra.test.TestTask.execute(TestTask.java:13)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
at org.apache.tools.ant.Task.perform(Task.java:364)
at org.apache.tools.ant.Target.execute(Target.java:341)
at org.apache.maven.plugin.antrun.AbstractAntMojo.executeTasks(AbstractAntMojo.java:103)
at org.apache.maven.plugin.antrun.AntRunMojo.execute(AntRunMojo.java:83)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:432)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor
.java:530)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifec
ycleExecutor.java:472)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.
java:451)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultL
ifecycleExecutor.java:303)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleE
xecutor.java:270)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java
:139)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:322)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:115)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:249)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(String.java:1768)
at java.lang.String.substring(String.java:1735)
at org.apache.maven.plugin.antrun.AntPropertyHelper.getPropertyHook(AntPropertyHelper.java:5
1)
at org.apache.tools.ant.PropertyHelper.getPropertyHook(PropertyHelper.java:184)
at org.apache.tools.ant.PropertyHelper.getProperty(PropertyHelper.java:438)
at org.apache.tools.ant.Project.getProperty(Project.java:474)
at nl.ohra.test.TestTask.execute(TestTask.java:13)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
at org.apache.tools.ant.Task.perform(Task.java:364)
at org.apache.tools.ant.Target.execute(Target.java:341)
at org.apache.maven.plugin.antrun.AbstractAntMojo.executeTasks(AbstractAntMojo.java:103)
at org.apache.maven.plugin.antrun.AntRunMojo.execute(AntRunMojo.java:83)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:432)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor
.java:530)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifec
ycleExecutor.java:472)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.
java:451)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultL
ifecycleExecutor.java:303)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleE
xecutor.java:270)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java
:139)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:322)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:115)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:249)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
basedir:C:\work\CustomAntTask
[INFO] Executed tasks
[INFO] ----------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ----------------------------------------------------------------------------
[INFO] Total time: 4 seconds
[INFO] Finished at: Fri Dec 23 00:19:53 CET 2005
[INFO] Final Memory: 4M/9M
[INFO] ----------------------------------------------------------------------------
C:\work\CustomAntTask>
This is the original exception, but it also shows the result of trying to get 'project.build.sourceDirectory' from within the ant-task.
After applying the patch the result is:
C:\work\CustomAntTask>mvn -Dproject.cmdline=commandlineparameter package
{execution: testant}[INFO] Scanning for projects...
[INFO] ----------------------------------------------------------------------------
[INFO] Building Unnamed - nl.ohra.test:CustomAntTask:jar:1.0-SNAPSHOT
[INFO] task-segment: [package]
[INFO] ----------------------------------------------------------------------------
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:compile]
[INFO] Nothing to compile - all classes are up to date
[INFO] [resources:testResources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:testCompile]
[INFO] No sources to compile
[INFO] [surefire:test]
[INFO] No tests to run.
[INFO] [jar:jar]
[INFO] Building jar: C:\work\CustomAntTask\target\CustomAntTask-1.0-SNAPSHOT.jar
[INFO] [antrun:run
]
[INFO] Executing tasks
[echo] basedir:C:\work\CustomAntTask
[echo] sourceDirectory:src/main/java
sourceDirectory:C:\work\CustomAntTask\src\main\java
project.cmdline:commandlineparameter
basedir:C:\work\CustomAntTask
[INFO] Executed tasks
[INFO] ----------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ----------------------------------------------------------------------------
[INFO] Total time: 4 seconds
[INFO] Finished at: Fri Dec 23 00:29:40 CET 2005
[INFO] Final Memory: 4M/9M
[INFO] ----------------------------------------------------------------------------
C:\work\CustomAntTask>
The three properties that are read in the ant task are correct now.
The only strange thing is that $
{project.build.sourceDirectory}when used in pom.xml returns a relative path and getProperty("project.build.sourceDirectory") is absolute. Ideas? anybody?