Skip to content

Commit

Permalink
Merge branch 'main' into SwitchTaskTestRelatedTo1889
Browse files Browse the repository at this point in the history
  • Loading branch information
mrook authored Feb 2, 2025
2 parents d651567 + e7c1fab commit 6aaef16
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 23 deletions.
70 changes: 50 additions & 20 deletions src/Phing/Phing.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ class Phing
* Used by utility function getResourcePath().
*/
private static $importPaths;
/**
* Cache of the Phing version information when it has been loaded.
*/
private static $phingVersion;
/**
* Cache of the short Phing version information when it has been loaded.
*/
private static $phingShortVersion;
/**
* System-wide static properties (moved from System).
*/
Expand Down Expand Up @@ -590,33 +598,56 @@ public static function printVersion()
}

/**
* Gets the current Phing version based on VERSION.TXT file.
* Gets the current Phing version based on VERSION.TXT file. Once the information
* has been loaded once, it's cached and returned from the cache on future
* calls.
*
* @throws ConfigurationException
*/
public static function getPhingVersion(): string
{
$versionPath = self::getResourcePath('phing/etc/VERSION.TXT');
if (null === $versionPath) {
$versionPath = self::getResourcePath('etc/VERSION.TXT');
}
if (null === $versionPath) {
throw new ConfigurationException('No VERSION.TXT file found; try setting phing.home environment variable.');
}
if (self::$phingVersion === null) {
$versionPath = self::getResourcePath('phing/etc/VERSION.TXT');
if (null === $versionPath) {
$versionPath = self::getResourcePath('etc/VERSION.TXT');
}
if (null === $versionPath) {
throw new ConfigurationException('No VERSION.TXT file found; try setting phing.home environment variable.');
}

try { // try to read file
$file = new File($versionPath);
$reader = new FileReader($file);
$phingVersion = trim($reader->read());
} catch (IOException $iox) {
throw new ConfigurationException("Can't read version information file");
}
try { // try to read file
$file = new File($versionPath);
$reader = new FileReader($file);
$phingVersion = trim($reader->read());
} catch (IOException $iox) {
throw new ConfigurationException("Can't read version information file");
}

$basePath = dirname(__DIR__, 2);
$basePath = dirname(__DIR__, 2);

$version = new Version($phingVersion, $basePath);
$version = new Version($phingVersion, $basePath);
self::$phingShortVersion = (method_exists($version, 'asString') ? $version->asString() : $version->getVersion());

return 'Phing ' . (method_exists($version, 'asString') ? $version->asString() : $version->getVersion());
self::$phingVersion = 'Phing ' . self::$phingShortVersion;
}
return self::$phingVersion;
}

/**
* Returns the short Phing version information, if available. Once the information
* has been loaded once, it's cached and returned from the cache on future
* calls.
*
* @return the short Phing version information as a string
*
* @throws ConfigurationException
*/
public static function getPhingShortVersion(): string
{
if (self::$phingShortVersion === null) {
self::getPhingVersion();
}
return self::$phingShortVersion;
}

/**
Expand Down Expand Up @@ -1530,8 +1561,7 @@ private function addInputHandler(Project $project): void
*/
private function comparePhingVersion($version): void
{
$current = strtolower(self::getPhingVersion());
$current = trim(str_replace('phing', '', $current));
$current = self::getPhingShortVersion();

// make sure that version checks are not applied to trunk
if ('dev' === $current) {
Expand Down
2 changes: 1 addition & 1 deletion src/Phing/Type/AbstractFileSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ public function setIncludesfile(File $incl)
*
* @throws BuildException
*/
public function setExcludesfile($excl)
public function setExcludesfile(File $excl)
{
if ($this->isReference()) {
throw $this->tooManyAttributes();
Expand Down
19 changes: 17 additions & 2 deletions tests/Phing/Test/Task/System/CopyTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function setUp(): void
{
$this->configureProject(
PHING_TEST_BASE
. '/etc/tasks/system/CopyTaskTest.xml'
. '/etc/tasks/system/CopyTask/CopyTaskTest.xml'
);
$this->executeTarget('setup');
}
Expand Down Expand Up @@ -90,11 +90,26 @@ public function testOverwriteExistingSymlink(): void
{
$this->executeTarget(__FUNCTION__);
$this->assertInLogs('Copying 1 file to');
$this->assertEquals('tmp/target-a', readlink(PHING_TEST_BASE . '/etc/tasks/system/tmp/link-b'));
$this->assertEquals('tmp/target-a', readlink(PHING_TEST_BASE . '/etc/tasks/system/CopyTask/tmp/link-b'));
}

public function testGranularity(): void
{
$this->expectLogContaining(__FUNCTION__, 'Test omitted, Test is up to date');
}

public function testFilesetFiles(): void
{
$destinationDir = PHING_TEST_BASE . '/etc/tasks/system/CopyTask/tmp/destination';
$this->assertDirectoryDoesNotExist($destinationDir);
$this->executeTarget(__FUNCTION__);
$this->assertFileExists("$destinationDir/Foo/Foo.php");
$this->assertFileExists("$destinationDir/Bar/Bar.php");
$this->assertFileExists("$destinationDir/Baz/Baz.php");
$this->assertFileExists("$destinationDir/Qux/Qux.php");
$this->assertFileDoesNotExist("$destinationDir/Foo/FooTest.php");
$this->assertFileDoesNotExist("$destinationDir/Bar/BarTest.php");
$this->assertFileDoesNotExist("$destinationDir/Baz/BazTest.php");
$this->assertFileDoesNotExist("$destinationDir/Qux/QuxTest.php");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,22 @@
<copy file="${tmp.dir}/copysrcs/Test" todir="${tmp.dir}/copydest" granularity="999999999" overwrite="false"/>
</target>

<target name="testFilesetFiles" description="test fileset include and excludes files">
<touch mkdirs="true" file="${tmp.dir}/source/Foo/Foo.php"/>
<touch mkdirs="true" file="${tmp.dir}/source/Foo/FooTest.php"/>
<touch mkdirs="true" file="${tmp.dir}/source/Bar/Bar.php"/>
<touch mkdirs="true" file="${tmp.dir}/source/Bar/BarTest.php"/>
<touch mkdirs="true" file="${tmp.dir}/source/Baz/Baz.php"/>
<touch mkdirs="true" file="${tmp.dir}/source/Baz/BazTest.php"/>
<touch mkdirs="true" file="${tmp.dir}/source/Qux/Qux.php"/>
<touch mkdirs="true" file="${tmp.dir}/source/Qux/QuxTest.php"/>
<mkdir dir="${tmp.dir}/destination"/>
<copy haltonerror="true" todir="${tmp.dir}/destination">
<fileset dir="${tmp.dir}/source"
includesfile="includes.txt"
excludesfile="excludes.txt"/>
</copy>
</target>

<target name="main"/>
</project>
1 change: 1 addition & 0 deletions tests/etc/tasks/system/CopyTask/excludes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/*Test.php
1 change: 1 addition & 0 deletions tests/etc/tasks/system/CopyTask/includes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/*.php

0 comments on commit 6aaef16

Please sign in to comment.