From dfdb0bc8095db18284de364b421d320be3c1b6fb Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Tue, 13 Jan 2015 23:24:43 +0100 Subject: [PATCH] Make basedir property (including its default "." value) is a relative path to the project's root. --- classes/phing/parser/ProjectHandler.php | 2 +- .../en/source/chapters/gettingstarted.xml | 10 ++-- .../309/Ticket309RegressionTest.php | 49 +++++++++++++++++++ test/etc/regression/309/basedir-default.xml | 9 ++++ test/etc/regression/309/basedir-dot.xml | 9 ++++ .../etc/regression/309/sub/basedir-dotdot.xml | 9 ++++ 6 files changed, 83 insertions(+), 5 deletions(-) create mode 100644 test/classes/phing/regression/309/Ticket309RegressionTest.php create mode 100644 test/etc/regression/309/basedir-default.xml create mode 100644 test/etc/regression/309/basedir-dot.xml create mode 100644 test/etc/regression/309/sub/basedir-dotdot.xml diff --git a/classes/phing/parser/ProjectHandler.php b/classes/phing/parser/ProjectHandler.php index 0007bae643..f356264b9f 100644 --- a/classes/phing/parser/ProjectHandler.php +++ b/classes/phing/parser/ProjectHandler.php @@ -158,7 +158,7 @@ public function init($tag, $attrs) if ($f->isAbsolute()) { $project->setBasedir($baseDir); } else { - $project->setBaseDir($project->resolveFile($baseDir, new PhingFile(getcwd()))); + $project->setBaseDir($project->resolveFile($baseDir, $buildFileParent)); } } } diff --git a/docs/docbook5/en/source/chapters/gettingstarted.xml b/docs/docbook5/en/source/chapters/gettingstarted.xml index 4d07ff0b3f..70515dbb9e 100644 --- a/docs/docbook5/en/source/chapters/gettingstarted.xml +++ b/docs/docbook5/en/source/chapters/gettingstarted.xml @@ -154,10 +154,12 @@ basedir - The base directory of the project, use "." do denote - the current directory. Note: if - none is specified, the parent directory of the build file is - used! + The base directory of the project. This attribute controls the value of the + ${project.basedir} property which can be used to reference + files with paths relative to the project root folder. Can be a path relative to + the position of the buildfile itself. If omitted, "." will be used, + which means that the build file should be located in the project's root folder. + No diff --git a/test/classes/phing/regression/309/Ticket309RegressionTest.php b/test/classes/phing/regression/309/Ticket309RegressionTest.php new file mode 100644 index 0000000000..29e9f22bbc --- /dev/null +++ b/test/classes/phing/regression/309/Ticket309RegressionTest.php @@ -0,0 +1,49 @@ +. + */ + +require_once 'phing/BuildFileTest.php'; + +class Ticket309RegressionTest extends BuildFileTest +{ + /** + * The project.basedir property denotes the project root directory. + * This root directory can be set by the "basedir" attribute on the + * tag. It denotes the path to the project root, relative to + * the buildfile. + * + * The default is ".", meaning that the build.xml file is locate in the + * project root. + * + * This test uses several buildfiles that reference the /etc/regression/309 + * directory as their project root in various ways. + */ + public function testPhingCallTask() + { + $testBasedir = PHING_TEST_BASE . "/etc/regression/309"; + + foreach (array('basedir-dot.xml', 'basedir-default.xml', 'sub/basedir-dotdot.xml') as $buildfile) { + $this->configureProject("$testBasedir/$buildfile"); + $this->executeTarget("main"); + $this->assertInLogs("project.basedir: $testBasedir"); + } + } +} diff --git a/test/etc/regression/309/basedir-default.xml b/test/etc/regression/309/basedir-default.xml new file mode 100644 index 0000000000..8fc6539031 --- /dev/null +++ b/test/etc/regression/309/basedir-default.xml @@ -0,0 +1,9 @@ + + + + + project.basedir: ${project.basedir} + application.startdir: ${application.startdir} + + + diff --git a/test/etc/regression/309/basedir-dot.xml b/test/etc/regression/309/basedir-dot.xml new file mode 100644 index 0000000000..cdaa518fba --- /dev/null +++ b/test/etc/regression/309/basedir-dot.xml @@ -0,0 +1,9 @@ + + + + + project.basedir: ${project.basedir} + application.startdir: ${application.startdir} + + + diff --git a/test/etc/regression/309/sub/basedir-dotdot.xml b/test/etc/regression/309/sub/basedir-dotdot.xml new file mode 100644 index 0000000000..7a1b7c9d8e --- /dev/null +++ b/test/etc/regression/309/sub/basedir-dotdot.xml @@ -0,0 +1,9 @@ + + + + + project.basedir: ${project.basedir} + application.startdir: ${application.startdir} + + +