Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added multiple property file inclusion. #856

Merged
merged 1 commit into from
Jan 20, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 48 additions & 19 deletions classes/phing/Phing.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ class Phing
* @var string
*/
private $searchForThis;
private $propertyFiles = [];

/**
* Entry point allowing for more options from other front ends.
Expand Down Expand Up @@ -501,25 +502,9 @@ public function execute($args)
} else {
$this->inputHandlerClassname = $args[++$i];
}
} elseif ($arg == "-propertyfile") {
if (!isset($args[$i + 1])) {
$msg = "You must specify a filename when using the -propertyfile argument";
throw new ConfigurationException($msg);
} else {
$filename = $args[++$i];
$fileParserFactory = new FileParserFactory();
$fileParser = $fileParserFactory->createParser(pathinfo($filename, PATHINFO_EXTENSION));
$p = new Properties(null, $fileParser);
$p->load(new PhingFile($filename));
foreach ($p->getProperties() as $prop => $value) {
if ($this->propertyFileOverride) {
self::$definedProps->setProperty($prop, $value);
} else {
$this->setProperty($prop, $value);
}
}
}
} elseif ($arg == "-keep-going" || $arg == "-k") {
} elseif ($arg === "-propertyfile") {
$i = $this->handleArgPropertyFile($args, $i);
} elseif ($arg === "-keep-going" || $arg === "-k") {
$this->keepGoingMode = true;
} elseif ($arg == "-longtargets") {
self::$definedProps->setProperty('phing.showlongtargets', 1);
Expand Down Expand Up @@ -574,9 +559,53 @@ public function execute($args)
throw new ConfigurationException("Buildfile: " . $this->buildFile->__toString() . " is not readable!");
}

$this->loadPropertyFiles();

$this->readyToRun = true;
}

/**
* Handle the -propertyfile argument.
*
* @param array $args
* @param int $pos
*
* @return int
*
* @throws ConfigurationException
* @throws IOException
*/
private function handleArgPropertyFile(array $args, int $pos): int
{
if (!isset($args[$pos + 1])) {
throw new ConfigurationException('You must specify a filename when using the -propertyfile argument');
}

$this->propertyFiles[] = $args[++$pos];

return $pos;
}

/**
* @throws IOException
*/
private function loadPropertyFiles()
{
foreach ($this->propertyFiles as $filename) {
$fileParserFactory = new FileParserFactory();
$fileParser = $fileParserFactory->createParser(pathinfo($filename, PATHINFO_EXTENSION));
$p = new Properties(null, $fileParser);
try {
$p->load(new PhingFile($filename));
} catch (IOException $e) {
self::$out->write('Could not load property file ' . $filename . ': ' . $e->getMessage());
}
foreach ($p->getProperties() as $prop => $value) {
self::$definedProps->setProperty($prop, $value);
}
}
}

/**
* Helper to get the parent file for a given file.
*
Expand Down