Ticket #26 (closed defect: fixed)
Strange behavior with the "dir" property in the PhingTask
| Reported by: | daniel.kobler@… | Owned by: | hans |
|---|---|---|---|
| Priority: | major | Milestone: | 2.2.0 |
| Component: | Version: | 2.2.0RC1 | |
| Keywords: | Cc: |
Description
Hi, I've notice a really strange behavior in the task PhingTask with the dir property.
I've a build.properties with only one property inside :
propel.generator.home = Libraries\propel-1.2.0RC1\generator
And in my build file I try to call an other build like this :
<phing phingfile="build.xml" inheritAll="true" dir="${propel.generator.home}" target="creole">
<property name="project" value="bookstore"/>
<property name="project.dir" value="${propel.generator.home}/projects/bookstore"/>
</phing>
When I run my build I get this error statment :
[phing] Error reading project file [wrapped: Cannot fopen C:\MyProject\Libraries\propel-1.2.0RC1\generator\Libraries\prope l-1.2.0RC1\generator\build.xml. failed to open stream: No such file or directory]
As you can see the propel.generator.home property have been duplicated twice in the final search path. I've browse the source and found that the mistake is located in the PhingTask.php file, line 218. Here is the code :
if ($this->dir !== null) {
$this->newProject->setBasedir($this->dir);
if ($savedDir !== null) { // has been set explicitly
$this->newProject->setInheritedProperty("project.basedir", $this->dir->getAbsolutePath());
}
} else {
$this->dir = $this->getProject()->getBaseDir();
}
After some tests I've seen that the $this->dir value is correct before the $this->newProject->setBaseDir call but wrong right after. I've checked the setBasedir of the project class, but I don't understand the side effect that cause this problem. Temporary I've solved this by changing the code in the like this :
if ($this->dir !== null) {
$this->newProject->setBasedir($this->dir);
// [DK] Correction of a strange bug. I don't understand what's going on, but the dir is changed by the setBasedir call.
$this->dir = $this->newProject->getBasedir();
if ($savedDir !== null) { // has been set explicitly
$this->newProject->setInheritedProperty("project.basedir", $this->dir->getAbsolutePath());
}
} else {
$this->dir = $this->getProject()->getBaseDir();
}
Hope this will help you guys and thanks again for this great product that is phing !
Attachments
Change History
comment:2 Changed 4 years ago by hans
- Status changed from assigned to closed
- Resolution set to fixed
Ok, this should be fixed in branch & trunk as of changeset:78. Please let me know if you still have any errors.
comment:3 Changed 18 months ago by Frank
Peter Griffin: And this is where the Pilgrims landed at Fraggle Rock. cialis carta di credito http://compraviagraitalia.com/ viagra prezzi http://compraviagraitalia.com/
http://headachetreatment.net/fioricet_side_effects.html viagra http://www.compraviagraitalia.com/it/item/viagra.html
http://relievepain.org/tramadol-news/index.php?entry=entry090308-223603

Wow, this was a really tricky one to track down. You were right, the problem is related to Project->setBasedir(). What happens when you call Project->setBasedir() is that is calls chdir() with the new path; this chdir() happens so that you can resolve paths relative to your projects base directory. So, of course, this means that when you call getAbsolutePath() on a dir (PhingFile) object created with a relative path, it is going to call getcwd() to resolve it. So, essentially, the call to Project->setBasedir() changed the filesystem cwd out from under the PhingFile (directory) object.
This probably points to a bigger design flaw, but the short fix is probably just to reset the $this->dir value, after calling Project->setBasedir(). I'll think about this a bit more & see if I can figure out a better solution to this problem. Unfortunately, I think we really need to keep the behavior where it calls chdir(), because that fixed a bunch of quirky behavior when trying to resolve relative paths.