Skip to content

Commit

Permalink
Fixes #1784 - properties in property file take precedence when they m…
Browse files Browse the repository at this point in the history
…ask existing properties
  • Loading branch information
mrook committed Jan 30, 2024
1 parent d20f817 commit bae7450
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 13 deletions.
21 changes: 12 additions & 9 deletions src/Phing/Task/System/PropertyTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -564,23 +564,26 @@ protected function resolveAllProperties(Properties $props)
throw new BuildException('Property ' . $propertyName . ' was circularly defined.');
}

$fragment = $this->getProject()->getProperty($propertyName);
if (null !== $fragment) {
$sb .= $fragment;

continue;
}

if ($props->containsKey($propertyName)) {
$fragment = $props->getProperty($propertyName);
if (false !== strpos($fragment, '${')) {
$resolveStack[] = $propertyName;
$resolved = false; // parse again (could have been replaced w/ another var)
}
} else {
$fragment = '${' . $propertyName . '}';

$sb .= $fragment;

continue;
}

$fragment = $this->getProject()->getProperty($propertyName);
if (null !== $fragment) {
$sb .= $fragment;

continue;
}

$fragment = '${' . $propertyName . '}';
$sb .= $fragment;
}

Expand Down
17 changes: 15 additions & 2 deletions tests/Phing/Test/Task/System/PropertyTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,22 @@ public function test2(): void
$this->expectLog('test2', 'testprop1=aa, testprop3=xxyy, testprop4=aazz');
}

public function test4(): void
public function testPropertyInFileShouldShadowExistingPropertyWithSameName(): void
{
$this->expectLog('test4', 'http.url is http://localhost:999');
$this->expectLog(__FUNCTION__, 'http.url is http://localhost:80');
$this->assertPropertyEquals('http.port', '999');
}

public function testOverrideExistingPropertyWithNewProperty(): void
{
$this->executeTarget(__FUNCTION__);
$this->assertPropertyEquals('http.port', '80');
}

public function testOverrideExistingPropertyWithNewPropertyFromFile(): void
{
$this->executeTarget(__FUNCTION__);
$this->assertPropertyEquals('http.port', '80');
}

public function testPrefixSuccess(): void
Expand Down
14 changes: 12 additions & 2 deletions tests/etc/tasks/property.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,22 @@
<property file="property2.properties"/>
</target>

<target name="test4">
<property name="http.port" value="999" />
<target name="testPropertyInFileShouldShadowExistingPropertyWithSameName">
<property name="http.port" value="999"/>
<property file="property3.properties"/>
<echo message="http.url is ${http.url}"/>
</target>

<target name="testOverrideExistingPropertyWithNewProperty">
<property name="http.port" value="999"/>
<property name="http.port" value="80" override="true" />
</target>

<target name="testOverrideExistingPropertyWithNewPropertyFromFile">
<property name="http.port" value="999" />
<property file="property3.properties" override="true"/>
</target>

<target name="prefix.success">
<property file="property3.properties" prefix="server1"/>
</target>
Expand Down

0 comments on commit bae7450

Please sign in to comment.