/**
  * {@inheritDoc}
  */
 public function update(PackageInterface $initial, PackageInterface $target, $path)
 {
     if (!$target->getSourceReference()) {
         throw new \InvalidArgumentException('Package ' . $target->getPrettyName() . ' is missing reference information');
     }
     $name = $target->getName();
     if ($initial->getPrettyVersion() == $target->getPrettyVersion()) {
         $from = $initial->getSourceReference();
         $to = $target->getSourceReference();
         $name .= ' ' . $initial->getPrettyVersion();
     } else {
         $from = $initial->getFullPrettyVersion();
         $to = $target->getFullPrettyVersion();
     }
     $this->io->writeError("  - Updating <info>" . $name . "</info> (<comment>" . $from . "</comment> => <comment>" . $to . "</comment>)");
     $urls = $target->getSourceUrls();
     while ($url = array_shift($urls)) {
         try {
             if (Filesystem::isLocalPath($url)) {
                 $url = realpath($url);
             }
             $this->doUpdate($initial, $target, $path, $url);
             break;
         } catch (\Exception $e) {
             if ($this->io->isDebug()) {
                 $this->io->writeError('Failed: [' . get_class($e) . '] ' . $e->getMessage());
             } elseif (count($urls)) {
                 $this->io->writeError('    Failed, trying the next URL');
             } else {
                 throw $e;
             }
         }
     }
     $this->io->writeError('');
 }
 /**
  * {@inheritDoc}
  */
 public function update(PackageInterface $initial, PackageInterface $target, $path)
 {
     if (!$target->getSourceReference()) {
         throw new \InvalidArgumentException('Package ' . $target->getPrettyName() . ' is missing reference information');
     }
     $name = $target->getName();
     if ($initial->getPrettyVersion() == $target->getPrettyVersion()) {
         if ($target->getSourceType() === 'svn') {
             $from = $initial->getSourceReference();
             $to = $target->getSourceReference();
         } else {
             $from = substr($initial->getSourceReference(), 0, 7);
             $to = substr($target->getSourceReference(), 0, 7);
         }
         $name .= ' ' . $initial->getPrettyVersion();
     } else {
         $from = $initial->getFullPrettyVersion();
         $to = $target->getFullPrettyVersion();
     }
     $this->io->writeError("  - Updating <info>" . $name . "</info> (<comment>" . $from . "</comment> => <comment>" . $to . "</comment>)");
     $this->cleanChanges($initial, $path, true);
     $urls = $target->getSourceUrls();
     $exception = null;
     while ($url = array_shift($urls)) {
         try {
             if (Filesystem::isLocalPath($url)) {
                 $url = realpath($url);
             }
             $this->doUpdate($initial, $target, $path, $url);
             $exception = null;
             break;
         } catch (\Exception $exception) {
             // rethrow phpunit exceptions to avoid hard to debug bug failures
             if ($exception instanceof \PHPUnit_Framework_Exception) {
                 throw $exception;
             }
             if ($this->io->isDebug()) {
                 $this->io->writeError('Failed: [' . get_class($exception) . '] ' . $exception->getMessage());
             } elseif (count($urls)) {
                 $this->io->writeError('    Failed, trying the next URL');
             }
         }
     }
     $this->reapplyChanges($path);
     // print the commit logs if in verbose mode and VCS metadata is present
     // because in case of missing metadata code would trigger another exception
     if (!$exception && $this->io->isVerbose() && $this->hasMetadataRepository($path)) {
         $message = 'Pulling in changes:';
         $logs = $this->getCommitLogs($initial->getSourceReference(), $target->getSourceReference(), $path);
         if (!trim($logs)) {
             $message = 'Rolling back changes:';
             $logs = $this->getCommitLogs($target->getSourceReference(), $initial->getSourceReference(), $path);
         }
         if (trim($logs)) {
             $logs = implode("\n", array_map(function ($line) {
                 return '      ' . $line;
             }, explode("\n", $logs)));
             // escape angle brackets for proper output in the console
             $logs = str_replace('<', '\\<', $logs);
             $this->io->writeError('    ' . $message);
             $this->io->writeError($logs);
         }
     }
     if (!$urls && $exception) {
         throw $exception;
     }
     $this->io->writeError('');
 }
Exemple #3
0
 /**
  * {@inheritdoc}
  */
 public function getSourceUrls()
 {
     return $this->package->getSourceUrls();
 }
 /**
  * {@inheritDoc}
  */
 public function update(PackageInterface $initial, PackageInterface $target, $path)
 {
     if (!$target->getSourceReference()) {
         throw new \InvalidArgumentException('Package ' . $target->getPrettyName() . ' is missing reference information');
     }
     $name = $target->getName();
     if ($initial->getPrettyVersion() == $target->getPrettyVersion()) {
         if ($target->getSourceType() === 'svn') {
             $from = $initial->getSourceReference();
             $to = $target->getSourceReference();
         } else {
             $from = substr($initial->getSourceReference(), 0, 7);
             $to = substr($target->getSourceReference(), 0, 7);
         }
         $name .= ' ' . $initial->getPrettyVersion();
     } else {
         $from = $initial->getFullPrettyVersion();
         $to = $target->getFullPrettyVersion();
     }
     $this->io->writeError("  - Updating <info>" . $name . "</info> (<comment>" . $from . "</comment> => <comment>" . $to . "</comment>)");
     $this->cleanChanges($initial, $path, true);
     $urls = $target->getSourceUrls();
     while ($url = array_shift($urls)) {
         try {
             if (Filesystem::isLocalPath($url)) {
                 $url = realpath($url);
             }
             $this->doUpdate($initial, $target, $path, $url);
             break;
         } catch (\Exception $e) {
             if ($this->io->isDebug()) {
                 $this->io->writeError('Failed: [' . get_class($e) . '] ' . $e->getMessage());
             } elseif (count($urls)) {
                 $this->io->writeError('    Failed, trying the next URL');
             } else {
                 // in case of failed update, try to reapply the changes before aborting
                 $this->reapplyChanges($path);
                 throw $e;
             }
         }
     }
     $this->reapplyChanges($path);
     // print the commit logs if in verbose mode
     if ($this->io->isVerbose()) {
         $message = 'Pulling in changes:';
         $logs = $this->getCommitLogs($initial->getSourceReference(), $target->getSourceReference(), $path);
         if (!trim($logs)) {
             $message = 'Rolling back changes:';
             $logs = $this->getCommitLogs($target->getSourceReference(), $initial->getSourceReference(), $path);
         }
         if (trim($logs)) {
             $logs = implode("\n", array_map(function ($line) {
                 return '      ' . $line;
             }, explode("\n", $logs)));
             // escape angle brackets for proper output in the console
             $logs = str_replace('<', '\\<', $logs);
             $this->io->writeError('    ' . $message);
             $this->io->writeError($logs);
         }
     }
     $this->io->writeError('');
 }
Exemple #5
0
 public function getSourceUrls()
 {
     return $this->aliasOf->getSourceUrls();
 }