Пример #1
0
 public function load(array $config, $class = 'Composer\\Package\\RootPackage')
 {
     if (!isset($config['name'])) {
         $config['name'] = '__root__';
     }
     $autoVersioned = false;
     if (!isset($config['version'])) {
         // override with env var if available
         if (getenv('COMPOSER_ROOT_VERSION')) {
             $version = getenv('COMPOSER_ROOT_VERSION');
         } else {
             $version = $this->versionGuesser->guessVersion($config, getcwd());
         }
         if (!$version) {
             $version = '1.0.0';
             $autoVersioned = true;
         }
         $config['version'] = $version;
     }
     $realPackage = $package = parent::load($config, $class);
     if ($realPackage instanceof AliasPackage) {
         $realPackage = $package->getAliasOf();
     }
     if ($autoVersioned) {
         $realPackage->replaceVersion($realPackage->getVersion(), 'No version set (parsed as 1.0.0)');
     }
     if (isset($config['minimum-stability'])) {
         $realPackage->setMinimumStability(VersionParser::normalizeStability($config['minimum-stability']));
     }
     $aliases = array();
     $stabilityFlags = array();
     $references = array();
     foreach (array('require', 'require-dev') as $linkType) {
         if (isset($config[$linkType])) {
             $linkInfo = BasePackage::$supportedLinkTypes[$linkType];
             $method = 'get' . ucfirst($linkInfo['method']);
             $links = array();
             foreach ($realPackage->{$method}() as $link) {
                 $links[$link->getTarget()] = $link->getConstraint()->getPrettyString();
             }
             $aliases = $this->extractAliases($links, $aliases);
             $stabilityFlags = $this->extractStabilityFlags($links, $stabilityFlags, $realPackage->getMinimumStability());
             $references = $this->extractReferences($links, $references);
         }
     }
     $realPackage->setAliases($aliases);
     $realPackage->setStabilityFlags($stabilityFlags);
     $realPackage->setReferences($references);
     if (isset($config['prefer-stable'])) {
         $realPackage->setPreferStable((bool) $config['prefer-stable']);
     }
     $repos = Factory::createDefaultRepositories(null, $this->config, $this->manager);
     foreach ($repos as $repo) {
         $this->manager->addRepository($repo);
     }
     $realPackage->setRepositories($this->config->getRepositories());
     return $package;
 }
Пример #2
0
 /**
  * Initializes path repository.
  *
  * This method will basically read the folder and add the found package.
  */
 protected function initialize()
 {
     parent::initialize();
     foreach ($this->getUrlMatches() as $url) {
         $path = realpath($url) . DIRECTORY_SEPARATOR;
         $composerFilePath = $path . 'composer.json';
         if (!file_exists($composerFilePath)) {
             continue;
         }
         $json = file_get_contents($composerFilePath);
         $package = JsonFile::parseJson($json, $composerFilePath);
         $package['dist'] = array('type' => 'path', 'url' => $url, 'reference' => '');
         if (!isset($package['version'])) {
             $package['version'] = $this->versionGuesser->guessVersion($package, $path) ?: 'dev-master';
         }
         $output = '';
         if (is_dir($path . DIRECTORY_SEPARATOR . '.git') && 0 === $this->process->execute('git log -n1 --pretty=%H', $output, $path)) {
             $package['dist']['reference'] = trim($output);
         } else {
             $package['dist']['reference'] = Locker::getContentHash($json);
         }
         $package = $this->loader->load($package);
         $this->addPackage($package);
     }
     if (count($this->getPackages()) == 0) {
         throw new \RuntimeException(sprintf('No `composer.json` file found in any path repository in "%s"', $this->url));
     }
 }
Пример #3
0
 /**
  * Initializes path repository.
  *
  * This method will basically read the folder and add the found package.
  */
 protected function initialize()
 {
     parent::initialize();
     foreach ($this->getUrlMatches() as $url) {
         $path = realpath($url) . DIRECTORY_SEPARATOR;
         $composerFilePath = $path . 'composer.json';
         if (!file_exists($composerFilePath)) {
             continue;
         }
         $json = file_get_contents($composerFilePath);
         $package = JsonFile::parseJson($json, $composerFilePath);
         $package['dist'] = array('type' => 'path', 'url' => $url, 'reference' => sha1($json));
         $package['transport-options'] = $this->options;
         if (!isset($package['version'])) {
             $versionData = $this->versionGuesser->guessVersion($package, $path);
             $package['version'] = $versionData['version'] ?: 'dev-master';
         }
         $output = '';
         if (is_dir($path . DIRECTORY_SEPARATOR . '.git') && 0 === $this->process->execute('git log -n1 --pretty=%H', $output, $path)) {
             $package['dist']['reference'] = trim($output);
         }
         $package = $this->loader->load($package);
         $this->addPackage($package);
     }
 }
Пример #4
0
 public function testInvalidTagBecomesVersion()
 {
     $executor = $this->getMockBuilder('\\Composer\\Util\\ProcessExecutor')->setMethods(array('execute'))->disableArgumentCloning()->disableOriginalConstructor()->getMock();
     $self = $this;
     $executor->expects($this->at(0))->method('execute')->willReturnCallback(function ($command, &$output) use($self) {
         $self->assertEquals('git describe --exact-match --tags', $command);
         $output = "foo-bar";
         return 0;
     });
     $executor->expects($this->at(1))->method('execute')->willReturnCallback(function ($command, &$output) use($self) {
         $self->assertEquals('git branch --no-color --no-abbrev -v', $command);
         $output = "* foo 03a15d220da53c52eddd5f32ffca64a7b3801bea Commit message\n";
         return 0;
     });
     $config = new Config();
     $config->merge(array('repositories' => array('packagist' => false)));
     $guesser = new VersionGuesser($config, $executor, new VersionParser());
     $version = $guesser->guessVersion(array(), 'dummy/path');
     $this->assertEquals("dev-foo", $version);
 }
Пример #5
0
 /**
  * Initializes path repository.
  *
  * This method will basically read the folder and add the found package.
  */
 protected function initialize()
 {
     parent::initialize();
     $composerFilePath = $this->path . 'composer.json';
     if (!file_exists($composerFilePath)) {
         throw new \RuntimeException(sprintf('No `composer.json` file found in path repository "%s"', $this->path));
     }
     $json = file_get_contents($composerFilePath);
     $package = JsonFile::parseJson($json, $composerFilePath);
     $package['dist'] = array('type' => 'path', 'url' => $this->path, 'reference' => '');
     if (!isset($package['version'])) {
         $package['version'] = $this->versionGuesser->guessVersion($package, $this->path) ?: 'dev-master';
     }
     if (is_dir($this->path . '/.git') && 0 === $this->process->execute('git log -n1 --pretty=%H', $output, $this->path)) {
         $package['dist']['reference'] = trim($output);
     }
     $package = $this->loader->load($package);
     $this->addPackage($package);
 }
Пример #6
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // init repos
     $composer = $this->getComposer();
     $commandEvent = new CommandEvent(PluginEvents::COMMAND, 'status', $input, $output);
     $composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent);
     $installedRepo = $composer->getRepositoryManager()->getLocalRepository();
     $dm = $composer->getDownloadManager();
     $im = $composer->getInstallationManager();
     // Dispatch pre-status-command
     $composer->getEventDispatcher()->dispatchScript(ScriptEvents::PRE_STATUS_CMD, true);
     $errors = array();
     $io = $this->getIO();
     $unpushedChanges = array();
     $vcsVersionChanges = array();
     $parser = new VersionParser();
     $guesser = new VersionGuesser($composer->getConfig(), new ProcessExecutor($io), $parser);
     $dumper = new ArrayDumper();
     // list packages
     foreach ($installedRepo->getCanonicalPackages() as $package) {
         $downloader = $dm->getDownloaderForInstalledPackage($package);
         $targetDir = $im->getInstallPath($package);
         if ($downloader instanceof ChangeReportInterface) {
             if (is_link($targetDir)) {
                 $errors[$targetDir] = $targetDir . ' is a symbolic link.';
             }
             if ($changes = $downloader->getLocalChanges($package, $targetDir, true)) {
                 $errors[$targetDir] = $changes;
             }
         }
         if ($downloader instanceof VcsCapableDownloaderInterface) {
             if ($currentRef = $downloader->getVcsReference($package, $targetDir)) {
                 switch ($package->getInstallationSource()) {
                     case 'source':
                         $previousRef = $package->getSourceReference();
                         break;
                     case 'dist':
                         $previousRef = $package->getDistReference();
                         break;
                     default:
                         $previousRef = null;
                 }
                 $currentVersion = $guesser->guessVersion($dumper->dump($package), $targetDir);
                 if ($previousRef && $currentVersion && $currentVersion['commit'] !== $previousRef) {
                     $vcsVersionChanges[$targetDir] = array('previous' => array('version' => $package->getPrettyVersion(), 'ref' => $previousRef), 'current' => array('version' => $currentVersion['pretty_version'], 'ref' => $currentVersion['commit']));
                 }
             }
         }
         if ($downloader instanceof DvcsDownloaderInterface) {
             if ($unpushed = $downloader->getUnpushedChanges($package, $targetDir)) {
                 $unpushedChanges[$targetDir] = $unpushed;
             }
         }
     }
     // output errors/warnings
     if (!$errors && !$unpushedChanges && !$vcsVersionChanges) {
         $io->writeError('<info>No local changes</info>');
         return 0;
     }
     if ($errors) {
         $io->writeError('<error>You have changes in the following dependencies:</error>');
         foreach ($errors as $path => $changes) {
             if ($input->getOption('verbose')) {
                 $indentedChanges = implode("\n", array_map(function ($line) {
                     return '    ' . ltrim($line);
                 }, explode("\n", $changes)));
                 $io->write('<info>' . $path . '</info>:');
                 $io->write($indentedChanges);
             } else {
                 $io->write($path);
             }
         }
     }
     if ($unpushedChanges) {
         $io->writeError('<warning>You have unpushed changes on the current branch in the following dependencies:</warning>');
         foreach ($unpushedChanges as $path => $changes) {
             if ($input->getOption('verbose')) {
                 $indentedChanges = implode("\n", array_map(function ($line) {
                     return '    ' . ltrim($line);
                 }, explode("\n", $changes)));
                 $io->write('<info>' . $path . '</info>:');
                 $io->write($indentedChanges);
             } else {
                 $io->write($path);
             }
         }
     }
     if ($vcsVersionChanges) {
         $io->writeError('<warning>You have version variations in the following dependencies:</warning>');
         foreach ($vcsVersionChanges as $path => $changes) {
             if ($input->getOption('verbose')) {
                 // If we don't can't find a version, use the ref instead.
                 $currentVersion = $changes['current']['version'] ?: $changes['current']['ref'];
                 $previousVersion = $changes['previous']['version'] ?: $changes['previous']['ref'];
                 if ($io->isVeryVerbose()) {
                     // Output the ref regardless of whether or not it's being used as the version
                     $currentVersion .= sprintf(' (%s)', $changes['current']['ref']);
                     $previousVersion .= sprintf(' (%s)', $changes['previous']['ref']);
                 }
                 $io->write('<info>' . $path . '</info>:');
                 $io->write(sprintf('    From <comment>%s</comment> to <comment>%s</comment>', $previousVersion, $currentVersion));
             } else {
                 $io->write($path);
             }
         }
     }
     if (($errors || $unpushedChanges || $vcsVersionChanges) && !$input->getOption('verbose')) {
         $io->writeError('Use --verbose (-v) to see a list of files');
     }
     // Dispatch post-status-command
     $composer->getEventDispatcher()->dispatchScript(ScriptEvents::POST_STATUS_CMD, true);
     return ($errors ? self::EXIT_CODE_ERRORS : 0) + ($unpushedChanges ? self::EXIT_CODE_UNPUSHED_CHANGES : 0) + ($vcsVersionChanges ? self::EXIT_CODE_VERSION_CHANGES : 0);
 }
Пример #7
0
 /**
  * {@inheritDoc}
  */
 public function getVcsReference(PackageInterface $package, $path)
 {
     $parser = new VersionParser();
     $guesser = new VersionGuesser($this->config, $this->process, $parser);
     $dumper = new ArrayDumper();
     $packageConfig = $dumper->dump($package);
     if ($packageVersion = $guesser->guessVersion($packageConfig, $path)) {
         return $packageVersion['commit'];
     }
 }
Пример #8
0
 /**
  * @param  array                $config package data
  * @param  string               $class  FQCN to be instantiated
  * @param  string               $cwd    cwd of the root package to be used to guess the version if it is not provided
  * @return RootPackageInterface
  */
 public function load(array $config, $class = 'Composer\\Package\\RootPackage', $cwd = null)
 {
     if (!isset($config['name'])) {
         $config['name'] = '__root__';
     }
     $autoVersioned = false;
     if (!isset($config['version'])) {
         // override with env var if available
         if (getenv('COMPOSER_ROOT_VERSION')) {
             $version = getenv('COMPOSER_ROOT_VERSION');
             $commit = null;
         } else {
             $versionData = $this->versionGuesser->guessVersion($config, $cwd ?: getcwd());
             $version = $versionData['version'];
             $commit = $versionData['commit'];
         }
         if (!$version) {
             $version = '1.0.0';
             $autoVersioned = true;
         }
         $config['version'] = $version;
         if ($commit) {
             $config['source'] = array('type' => '', 'url' => '', 'reference' => $commit);
             $config['dist'] = array('type' => '', 'url' => '', 'reference' => $commit);
         }
     }
     $realPackage = $package = parent::load($config, $class);
     if ($realPackage instanceof AliasPackage) {
         $realPackage = $package->getAliasOf();
     }
     if ($autoVersioned) {
         $realPackage->replaceVersion($realPackage->getVersion(), 'No version set (parsed as 1.0.0)');
     }
     if (isset($config['minimum-stability'])) {
         $realPackage->setMinimumStability(VersionParser::normalizeStability($config['minimum-stability']));
     }
     $aliases = array();
     $stabilityFlags = array();
     $references = array();
     foreach (array('require', 'require-dev') as $linkType) {
         if (isset($config[$linkType])) {
             $linkInfo = BasePackage::$supportedLinkTypes[$linkType];
             $method = 'get' . ucfirst($linkInfo['method']);
             $links = array();
             foreach ($realPackage->{$method}() as $link) {
                 $links[$link->getTarget()] = $link->getConstraint()->getPrettyString();
             }
             $aliases = $this->extractAliases($links, $aliases);
             $stabilityFlags = $this->extractStabilityFlags($links, $stabilityFlags, $realPackage->getMinimumStability());
             $references = $this->extractReferences($links, $references);
         }
     }
     if (isset($links[$config['name']])) {
         throw new \InvalidArgumentException(sprintf('Root package \'%s\' cannot require itself in its composer.json' . PHP_EOL . 'Did you accidentally name your root package after an external package?', $config['name']));
     }
     $realPackage->setAliases($aliases);
     $realPackage->setStabilityFlags($stabilityFlags);
     $realPackage->setReferences($references);
     if (isset($config['prefer-stable'])) {
         $realPackage->setPreferStable((bool) $config['prefer-stable']);
     }
     if (isset($config['config'])) {
         $realPackage->setConfig($config['config']);
     }
     $repos = RepositoryFactory::defaultRepos(null, $this->config, $this->manager);
     foreach ($repos as $repo) {
         $this->manager->addRepository($repo);
     }
     $realPackage->setRepositories($this->config->getRepositories());
     return $package;
 }