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

Reimplemented PR#232, PR#110 #266

Merged
merged 2 commits into from
Nov 20, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 9 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/.settings
/.project
/.buildpath
/satis.phar
/vendor
/phpunit.xml
composer.phar
.php_cs.cache
/.settings
/.project
/.idea
/.buildpath
/satis.phar
/vendor
/phpunit.xml
composer.phar
.php_cs.cache
14 changes: 13 additions & 1 deletion src/Composer/Satis/Command/BuildCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ protected function configure()
new InputArgument('file', InputArgument::OPTIONAL, 'Json file to use', './satis.json'),
new InputArgument('output-dir', InputArgument::OPTIONAL, 'Location where to output built files', null),
new InputArgument('packages', InputArgument::IS_ARRAY | InputArgument::OPTIONAL, 'Packages that should be built, if not provided all packages are.', null),
new InputOption('repository-url', null, InputOption::VALUE_OPTIONAL, 'Only update the repository at given url', null),
new InputOption('no-html-output', null, InputOption::VALUE_NONE, 'Turn off HTML view'),
new InputOption('skip-errors', null, InputOption::VALUE_NONE, 'Skip Download or Archive errors'),
))
Expand Down Expand Up @@ -91,8 +92,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
$verbose = $input->getOption('verbose');
$configFile = $input->getArgument('file');
$packagesFilter = $input->getArgument('packages');
$repositoryUrl = $input->getOption('repository-url');
$skipErrors = (bool) $input->getOption('skip-errors');

if ($repositoryUrl !== null && count($packagesFilter) > 0) {
throw new \InvalidArgumentException('Package and repository-url argument can not be used together.');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change to The arguments "package" and "repository-url" ...

}

// load auth.json authentication information and pass it to the io interface
$io = $this->getIO();
$io->loadConfiguration($this->getConfiguration());
Expand Down Expand Up @@ -124,7 +130,13 @@ protected function execute(InputInterface $input, OutputInterface $output)

$composer = $this->getApplication()->getComposer(true, $config);
$packageSelection = new PackageSelection($output, $outputDir, $config, $skipErrors);
$packageSelection->setPackagesFilter($packagesFilter);

if($repositoryUrl !== null) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space here.

$packageSelection->setRepositoryFilter($repositoryUrl);
} else {
$packageSelection->setPackagesFilter($packagesFilter);
}

$packages = $packageSelection->select($composer, $verbose);

if (isset($config['archive']['directory'])) {
Expand Down
40 changes: 39 additions & 1 deletion src/Composer/Satis/PackageSelection/PackageSelection.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ class PackageSelection
/** @var array The active package filter to merge. */
private $packagesFilter = array();

/** @var string The active repository filter to merge. */
private $repositoryFilter;

/** @var array The selected packages from config */
private $selected = array();

Expand Down Expand Up @@ -89,6 +92,28 @@ private function fetchOptions($config)
$this->minimumStability = isset($config['minimum-stability']) ? $config['minimum-stability'] : 'dev';
}

/**
* Sets the active repository filter to merge
*
* @param string $repositoryFilter The active repository filter to merge
*/
public function setRepositoryFilter($repositoryFilter)
{
$this->repositoryFilter = $repositoryFilter;

return $this;
}

/**
* Tells if repository list should be reduced to single repository
*
* @return bool true if repository filter is set
*/
public function hasRepositoryFilter()
{
return $this->repositoryFilter !== null;
}

/**
* Sets the active package filter to merge
*
Expand Down Expand Up @@ -126,7 +151,16 @@ public function select(Composer $composer, $verbose)

$repos = $composer->getRepositoryManager()->getRepositories();
$pool = new Pool($this->minimumStability);
foreach ($repos as $repo) {
foreach ($repos as $key => $repo) {
if ($this->hasRepositoryFilter()) {
$repoConfig = $repo->getRepoConfig();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not safe to use the 'getRepoConfig()' method. It's not defined in the RepositoryInterface.
E.g.:
I ran into the problem that the Composer\Repository\PearRepository lacks this method.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So does Composer\Repository\ArtifactRepository, I guess. It really lacks of tests ...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to submit more PR's guys. I'll accept anything, as long as it does not look insane. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both Pear and Artifact repository lack this method even though they both accept and work with $repoConfig. @alcohol Could this perhaps be implemented in Composer with a PR? Because at the moment I don't know how to get hold of repository url.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think an additional interface with the method 'getRepoConfig()' would be ideal. In the satis code, it's then possible to check if the repository implements this interface. Meanwhile this could be fixed by checking, if the repo extends the ArrayRepository class.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a sane patch @realshadow if you wanna submit a PR..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dol, @JamesRezo this issue should be resolved after merging of composer/composer#4638. I can add additional check if repository class implements required interface later tonight, if neccessary.

Sorry for delay :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great ! :)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@realshadow Don't worry about the delay. I'm happy that we'll be able to speed up our satis build soon. Thank you for your work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@realshadow don't forget to update the lockfile to depend on the latest version of composer/composer when you submit a new PR (but please limit the update to composer/composer only by running composer update composer/composer). :)

if (isset($repoConfig['url']) && $repoConfig['url'] !== $this->repositoryFilter) {
unset($repos[$key]);

continue;
}
}

try {
$pool->addRepository($repo);
} catch (\Exception $exception) {
Expand All @@ -137,6 +171,10 @@ public function select(Composer $composer, $verbose)
}
}

if($this->hasRepositoryFilter() && count($repos) !== 1) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space here.

throw new \InvalidArgumentException(sprintf('Specified repository url %s does not exist.', $this->repositoryFilter));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use quotes (... url "%s" does ...) to clearly show where the URL starts and ends.

}

$links = $this->requireAll ? $this->getAllLinks($repos, $this->minimumStability, $verbose) : $this->getFilteredLinks($composer);

// process links if any
Expand Down