Skip to content

Commit

Permalink
Add option to override the detected version of a package
Browse files Browse the repository at this point in the history
Useful when working with pecl packages that have versions that are not semvar compatible, and when installing from source many packages are detected incorrectly
  • Loading branch information
mcfedr committed Sep 18, 2020
1 parent b071126 commit d004f7c
Show file tree
Hide file tree
Showing 19 changed files with 52 additions and 29 deletions.
6 changes: 4 additions & 2 deletions src/Base/Abstracts/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,12 @@ public function getUniqueNameForFs()
other engines. Lets see if this is needed to be
moved into the Interface so each engines package
is forced to implement it on its own. But so far ... */
public function updateVersion()
public function updateVersion($version = null)
{
/* Be sure package root is set before! */
$version = new Header\Version($this);
if ($version === null) {
$version = new Header\Version($this);
}
$parser = new VersionParser();

$this->version = $parser->normalize($version);
Expand Down
2 changes: 1 addition & 1 deletion src/Base/Abstracts/Package/Convey/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function __construct($path, ConsoleIO $io)

abstract protected function prepare();

abstract public function execute($target, $no_convert);
abstract public function execute($target, $no_convert, $versionOverride);

public function getPath()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Base/Interfaces/Package/Convey/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ interface Command
{
public function __construct($path, ConsoleIO $io);

public function execute($target, $no_convert);
public function execute($target, $no_convert, $versionOverride);

public function getType();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Base/Interfaces/Package/Convey/DefaultExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ interface DefaultExecutor
{
public function __construct(Interfaces\Package\Convey\Command $command);

public function execute($target, $no_convert);
public function execute($target, $no_convert, $versionOverride);
}

/* vim: set tabstop=4 shiftwidth=4 expandtab: fdm=marker */
6 changes: 6 additions & 0 deletions src/Console/Command/ConvertCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ protected function configure()
InputOption::VALUE_REQUIRED,
'path to a custom temp dir',
sys_get_temp_dir()
)
->addOption(
'version-override',
null,
InputOption::VALUE_OPTIONAL,
'Override detected version'
);
}

Expand Down
6 changes: 6 additions & 0 deletions src/Console/Command/InfoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ protected function configure()
InputOption::VALUE_REQUIRED,
'path to a custom temp dir',
sys_get_temp_dir()
)
->addOption(
'version-override',
null,
InputOption::VALUE_OPTIONAL,
'Override detected version'
);
}

Expand Down
6 changes: 6 additions & 0 deletions src/Console/Command/InstallerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ protected function configure()
InputOption::VALUE_REQUIRED,
'path to a custom temp dir',
sys_get_temp_dir()
)
->addOption(
'version-override',
null,
InputOption::VALUE_OPTIONAL,
'Override detected version'
);

if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
Expand Down
3 changes: 2 additions & 1 deletion src/Console/Helper/PackageHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ public function convey(InputInterface $input, OutputInterface $output, $path, $t
$io = new ConsoleIO($input, $output, ($helperSet ? $helperSet : new HelperSet()));

$no_convert = $input->hasOption('no-convert') ? $input->getOption('no-convert') : false;
$versionOverride = $input->hasOption('version-override') ? $input->getOption('version-override') : null;

return (new Convey($path, $io))->deliver($target, $no_convert);
return (new Convey($path, $io))->deliver($target, $no_convert, $versionOverride);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Package/Convey.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ public function __construct($path, ConsoleIO $io)
$this->command = Factory::getCommand($type, $path, $io);
}

public function deliver($target = '', $no_convert = false)
public function deliver($target = '', $no_convert = false, $versionOverride = null)
{
$target = $target ? realpath($target) : Util\TmpDir::get().DIRECTORY_SEPARATOR.$this->command->getName();

return $this->command->execute($target, $no_convert);
return $this->command->execute($target, $no_convert, $versionOverride);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Package/Convey/Command/Any.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected function prepare()
throw new \Exception('Unsupported package type');
}

public function execute($target, $no_convert)
public function execute($target, $no_convert, $versionOverrideOverride)
{
throw new \Exception('Unsupported package type');
}
Expand Down
2 changes: 1 addition & 1 deletion src/Package/Convey/Command/DefaultExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function __construct(Interfaces\Package\Convey\Command $command)
$this->command = $command;
}

public function execute($target, $no_convert)
public function execute($target, $no_convert, $versionOverride)
{
throw new \Exception('Default executor cannot be used without concrete implementation');
}
Expand Down
4 changes: 2 additions & 2 deletions src/Package/Convey/Command/Git.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ protected function fetch($target)
}
}

public function execute($target, $no_convert)
public function execute($target, $no_convert, $versionOverrideOverride)
{
$this->fetch($target);

$exe = DefaultExecutor::factory($this);

return $exe->execute($target, $no_convert);
return $exe->execute($target, $no_convert, $versionOverrideOverride);
}

public function getType()
Expand Down
4 changes: 2 additions & 2 deletions src/Package/Convey/Command/Pickle.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@ protected function fetch($target)
}
}

public function execute($target, $no_convert)
public function execute($target, $no_convert, $versionOverrideOverride)
{
$this->fetch($target);

$exe = DefaultExecutor::factory($this);

return $exe->execute($target, $no_convert);
return $exe->execute($target, $no_convert, $versionOverrideOverride);
}

public function getType()
Expand Down
4 changes: 2 additions & 2 deletions src/Package/Convey/Command/SrcDir.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ protected function prepare()
$this->url = $this->path;
}

public function execute($target, $no_convert)
public function execute($target, $no_convert, $versionOverrideOverride)
{
/* Override target, otherwise we'd need to copy ext root each time */
$target = realpath($this->path);

$exe = DefaultExecutor::factory($this);

return $exe->execute($target, $no_convert);
return $exe->execute($target, $no_convert, $versionOverrideOverride);
}

public function getType()
Expand Down
4 changes: 2 additions & 2 deletions src/Package/Convey/Command/Tgz.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ protected function fetch($target)
}
}

public function execute($target, $no_convert)
public function execute($target, $no_convert, $versionOverrideOverride)
{
$this->fetch($target);

$exe = DefaultExecutor::factory($this);

return $exe->execute($target, $no_convert);
return $exe->execute($target, $no_convert, $versionOverrideOverride);
}

public function getType()
Expand Down
6 changes: 3 additions & 3 deletions src/Package/PHP/Convey/Command/DefaultExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function __construct(Interfaces\Package\Convey\Command $command)
{
}

public function execute($target, $no_convert)
public function execute($target, $no_convert, $versionOverride)
{
$jsonLoader = new \Pickle\Package\Util\JSON\Loader(new \Pickle\Package\Util\Loader());
$pickle_json = $target.DIRECTORY_SEPARATOR.'composer.json';
Expand All @@ -61,7 +61,7 @@ public function execute($target, $no_convert)
}

if (null === $package) {
$pkgXml = new PackageXml($target);
$pkgXml = new PackageXml($target, $versionOverride);
$pkgXml->dump();

$jsonPath = $pkgXml->getJsonPath();
Expand All @@ -71,7 +71,7 @@ public function execute($target, $no_convert)
}

$package->setRootDir($target);
$package->updateVersion();
$package->updateVersion($versionOverride);

return $package;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Package/PHP/Convey/Command/Pecl.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ protected function fetch($target)
unset($package, $downloader);
}

public function execute($target, $no_convert)
public function execute($target, $no_convert, $versionOverrideOverride)
{
$this->fetch($target);

$exe = new DefaultExecutor($this);

return $exe->execute($target, $no_convert);
return $exe->execute($target, $no_convert, $versionOverrideOverride);
}

public function getType()
Expand Down
8 changes: 5 additions & 3 deletions src/Package/PHP/Util/PackageXml.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ class PackageXml
protected $xmlPath = null;
protected $jsonPath = null;
protected $package = null;
protected $versionOverride = null;

public function __construct($path)
public function __construct($path, $versionOverride)
{
$names = ['package2.xml', 'package.xml' ];

Expand All @@ -63,12 +64,13 @@ public function __construct($path)
}

$this->jsonPath = $path.DIRECTORY_SEPARATOR.'composer.json';
$this->versionOverride = $versionOverride;
}

public function load()
{
$loader = new Package\PHP\Util\XML\Loader(new Package\Util\Loader());
$this->package = $loader->load($this->xmlPath);
$this->package = $loader->load($this->xmlPath, $this->versionOverride);

if (!$this->package) {
throw new \Exception("Failed to load '{$this->xmlPath}'");
Expand Down Expand Up @@ -98,7 +100,7 @@ public function dump($fname = null)
$this->jsonPath = $fname;
}

$version = new Header\Version($this->package);
$version = $this->versionOverride ?? new Header\Version($this->package);
if ($version != $this->package->getPrettyVersion()) {
throw new \Exception("Version mismatch - '".$version."' != '".$this->package->getVersion().'. in source vs JSON');
}
Expand Down
6 changes: 3 additions & 3 deletions src/Package/PHP/Util/XML/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function __construct(LoaderInterface $loader)
*
* @return Pickle\Base\Interfaces\Package
*/
public function load($path)
public function load($path, $versionOverride)
{
if (false === is_file($path)) {
throw new \InvalidArgumentException('File not found: '.$path);
Expand All @@ -77,7 +77,7 @@ public function load($path)

$package = [
'name' => (string) $xml->name,
'version' => (string) $xml->version->release,
'version' => $versionOverride ?? (string) $xml->version->release,
'stability' => (string) $xml->stability->release,
'description' => (string) $xml->summary,
];
Expand Down Expand Up @@ -136,7 +136,7 @@ public function load($path)
}
$ret_pkg->setRootDir(dirname($path));

$src_ver = new Header\Version($ret_pkg);
$src_ver = $versionOverride ?? new Header\Version($ret_pkg);
if ($src_ver != $ret_pkg->getPrettyVersion()) {
throw new \Exception("Version mismatch - '".$src_ver."' != '".$ret_pkg->getPrettyVersion()."' in source vs. XML");
}
Expand Down

0 comments on commit d004f7c

Please sign in to comment.