diff --git a/src/Composer/Package/Package.php b/src/Composer/Package/Package.php index 6dbd78911..2662fd32a 100644 --- a/src/Composer/Package/Package.php +++ b/src/Composer/Package/Package.php @@ -241,7 +241,7 @@ class Package extends BasePackage */ public function getSourceUrls() { - return $this->getUrls($this->sourceUrl, $this->sourceMirrors, $this->sourceReference, $this->sourceType); + return $this->getUrls($this->sourceUrl, $this->sourceMirrors, $this->sourceReference, $this->sourceType, 'source'); } /** @@ -329,7 +329,7 @@ class Package extends BasePackage */ public function getDistUrls() { - return $this->getUrls($this->distUrl, $this->distMirrors, $this->distReference, $this->distType); + return $this->getUrls($this->distUrl, $this->distMirrors, $this->distReference, $this->distType, 'dist'); } /** @@ -580,7 +580,7 @@ class Package extends BasePackage $this->dev = $this->stability === 'dev'; } - protected function getUrls($url, $mirrors, $ref, $type) + protected function getUrls($url, $mirrors, $ref, $type, $urlType) { if (!$url) { return array(); @@ -588,8 +588,14 @@ class Package extends BasePackage $urls = array($url); if ($mirrors) { foreach ($mirrors as $mirror) { - $mirrorUrl = ComposerMirror::processUrl($mirror['url'], $this->name, $this->version, $ref, $type); - if (!in_array($urls, $mirrorUrl)) { + if ($urlType === 'dist') { + $mirrorUrl = ComposerMirror::processUrl($mirror['url'], $this->name, $this->version, $ref, $type); + } elseif ($urlType === 'source' && $type === 'git') { + $mirrorUrl = ComposerMirror::processGitUrl($mirror['url'], $this->name, $url, $type); + } elseif ($urlType === 'source' && $type === 'hg') { + $mirrorUrl = ComposerMirror::processHgUrl($mirror['url'], $this->name, $url, $type); + } + if (!in_array($mirrorUrl, $urls)) { $func = $mirror['preferred'] ? 'array_unshift' : 'array_push'; $func($urls, $mirrorUrl); } diff --git a/src/Composer/Repository/ComposerRepository.php b/src/Composer/Repository/ComposerRepository.php index d1b0f6604..5f5bf445b 100644 --- a/src/Composer/Repository/ComposerRepository.php +++ b/src/Composer/Repository/ComposerRepository.php @@ -443,8 +443,11 @@ class ComposerRepository extends ArrayRepository implements StreamableRepository if (!empty($data['mirrors'])) { foreach ($data['mirrors'] as $mirror) { - if (!empty($mirror['source-url'])) { - $this->sourceMirrors[] = array('url' => $mirror['source-url'], 'preferred' => !empty($mirror['preferred'])); + if (!empty($mirror['git-url'])) { + $this->sourceMirrors['git'][] = array('url' => $mirror['git-url'], 'preferred' => !empty($mirror['preferred'])); + } + if (!empty($mirror['hg-url'])) { + $this->sourceMirrors['hg'][] = array('url' => $mirror['hg-url'], 'preferred' => !empty($mirror['preferred'])); } if (!empty($mirror['dist-url'])) { $this->distMirrors[] = array('url' => $mirror['dist-url'], 'preferred' => !empty($mirror['preferred'])); @@ -452,6 +455,10 @@ class ComposerRepository extends ArrayRepository implements StreamableRepository } } + if (!empty($data['warning'])) { + $this->io->write('Warning from '.$this->url.': '.$data['warning'].''); + } + if (!empty($data['providers-lazy-url'])) { $this->lazyProvidersUrl = $this->canonicalizeUrl($data['providers-lazy-url']); $this->hasProviders = true; @@ -571,7 +578,9 @@ class ComposerRepository extends ArrayRepository implements StreamableRepository } $package = $this->loader->load($data, 'Composer\Package\CompletePackage'); - $package->setSourceMirrors($this->sourceMirrors); + if (isset($this->sourceMirrors[$package->getSourceType()])) { + $package->setSourceMirrors($this->sourceMirrors[$package->getSourceType()]); + } $package->setDistMirrors($this->distMirrors); $this->configurePackageTransportOptions($package); diff --git a/src/Composer/Util/ComposerMirror.php b/src/Composer/Util/ComposerMirror.php index f5c2000db..ce27af21a 100644 --- a/src/Composer/Util/ComposerMirror.php +++ b/src/Composer/Util/ComposerMirror.php @@ -30,4 +30,26 @@ class ComposerMirror $mirrorUrl ); } + + public static function processGitUrl($mirrorUrl, $packageName, $url, $type) + { + if (preg_match('#^(?:(?:https?|git)://github\.com/|git@github\.com:)([^/]+)/(.+?)(?:\.git)?$#', $url, $match)) { + $url = 'gh-'.$match[1].'/'.$match[2]; + } elseif (preg_match('#^https://bitbucket\.org/([^/]+)/(.+?)(?:\.git)?/?$#', $url, $match)) { + $url = 'bb-'.$match[1].'/'.$match[2]; + } else { + $url = preg_replace('{[^a-z0-9_.-]}i', '-', trim($url, '/')); + } + + return str_replace( + array('%package%', '%normalizedUrl%', '%type%'), + array($packageName, $url, $type), + $mirrorUrl + ); + } + + public static function processHgUrl($mirrorUrl, $packageName, $url, $type) + { + return self::processGitUrl($mirrorUrl, $packageName, $url, $type); + } }