protected function executeUpdate(PhabricatorRepository $repository, $local_path)
 {
     // Run a bunch of sanity checks to detect people checking out repositories
     // inside other repositories, making empty directories, pointing the local
     // path at some random file or path, etc.
     list($err, $stdout) = $repository->execLocalCommand('rev-parse --show-toplevel');
     if ($err) {
         // Try to raise a more tailored error message in the more common case
         // of the user creating an empty directory. (We could try to remove it,
         // but might not be able to, and it's much simpler to raise a good
         // message than try to navigate those waters.)
         if (is_dir($local_path)) {
             $files = Filesystem::listDirectory($local_path, $include_hidden = true);
             if (!$files) {
                 throw new Exception("Expected to find a git repository at '{$local_path}', but there " . "is an empty directory there. Remove the directory: the daemon " . "will run 'git clone' for you.");
             }
         }
         throw new Exception("Expected to find a git repository at '{$local_path}', but there is " . "a non-repository directory (with other stuff in it) there. Move or " . "remove this directory (or reconfigure the repository to use a " . "different directory), and then either clone a repository yourself " . "or let the daemon do it.");
     } else {
         $repo_path = rtrim($stdout, "\n");
         if (empty($repo_path)) {
             throw new Exception("Expected to find a git repository at '{$local_path}', but " . "there was no result from `git rev-parse --show-toplevel`. " . "Something is misconfigured or broken. The git repository " . "may be inside a '.git/' directory.");
         }
         if (!Filesystem::pathsAreEquivalent($repo_path, $local_path)) {
             throw new Exception("Expected to find repo at '{$local_path}', but the actual " . "git repository root for this directory is '{$repo_path}'. " . "Something is misconfigured. The repository's 'Local Path' should " . "be set to some place where the daemon can check out a working " . "copy, and should not be inside another git repository.");
         }
     }
     // This is a local command, but needs credentials.
     $future = $repository->getRemoteCommandFuture('fetch --all --prune');
     $future->setCWD($local_path);
     $future->resolvex();
 }
 public static function loadAllSkinSpecifications()
 {
     static $specs;
     if ($specs === null) {
         $paths = PhabricatorEnv::getEnvConfig('phame.skins');
         $base = dirname(phutil_get_library_root('phabricator'));
         $specs = array();
         foreach ($paths as $path) {
             $path = Filesystem::resolvePath($path, $base);
             foreach (Filesystem::listDirectory($path) as $skin_directory) {
                 $skin_path = $path . DIRECTORY_SEPARATOR . $skin_directory;
                 if (!is_dir($skin_path)) {
                     continue;
                 }
                 $spec = self::loadSkinSpecification($skin_path);
                 if (!$spec) {
                     continue;
                 }
                 $name = trim($skin_directory, DIRECTORY_SEPARATOR);
                 $spec->setName($name);
                 if (isset($specs[$name])) {
                     $that_dir = $specs[$name]->getRootDirectory();
                     $this_dir = $spec->getRootDirectory();
                     throw new Exception(pht("Two skins have the same name ('%s'), in '%s' and '%s'. " . "Rename one or adjust your '%s' configuration.", $name, $this_dir, $that_dir, 'phame.skins'));
                 }
                 $specs[$name] = $spec;
             }
         }
     }
     return $specs;
 }
 public function processRequest()
 {
     $root = dirname(phutil_get_library_root('phabricator'));
     require_once $root . '/support/phame/libskin.php';
     $this->cssResources = array();
     $css = $this->getPath('css/');
     if (Filesystem::pathExists($css)) {
         foreach (Filesystem::listDirectory($css) as $path) {
             if (!preg_match('/.css$/', $path)) {
                 continue;
             }
             $this->cssResources[] = phutil_tag('link', array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => $this->getResourceURI('css/' . $path)));
         }
     }
     $map = CelerityResourceMap::getNamedInstance('phabricator');
     $resource_symbol = 'syntax-highlighting-css';
     $resource_uri = $map->getURIForSymbol($resource_symbol);
     $this->cssResources[] = phutil_tag('link', array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => PhabricatorEnv::getCDNURI($resource_uri)));
     $this->cssResources = phutil_implode_html("\n", $this->cssResources);
     $request = $this->getRequest();
     // Render page parts in order so the templates execute in order, if we're
     // using templates.
     $header = $this->renderHeader();
     $content = $this->renderContent($request);
     $footer = $this->renderFooter();
     if (!$content) {
         $content = $this->render404Page();
     }
     $content = array($header, $content, $footer);
     $response = new AphrontWebpageResponse();
     $response->setContent(phutil_implode_html("\n", $content));
     return $response;
 }
 private function readTestCases($path)
 {
     $files = Filesystem::listDirectory($path, $include_hidden = false);
     $tests = array();
     foreach ($files as $file) {
         $data = Filesystem::readFile($path . $file);
         $parts = preg_split('/^~{5,}$/m', $data);
         if (count($parts) < 2) {
             throw new Exception(pht('Expected test file "%s" to contain an input section in JSON, ' . 'then an expected result section in JSON, with the two sections ' . 'separated by a line of "~~~~~", but the divider is not present ' . 'in the file.', $file));
         } else {
             if (count($parts) > 2) {
                 throw new Exception(pht('Expected test file "%s" to contain exactly two sections, ' . 'but it has more than two sections.'));
             }
         }
         list($input, $expect) = $parts;
         try {
             $input = phutil_json_decode($input);
             $expect = phutil_json_decode($expect);
         } catch (Exception $ex) {
             throw new PhutilProxyException(pht('Exception while decoding test data for test "%s".', $file), $ex);
         }
         $tests[$file] = array('input' => $input, 'expect' => $expect);
     }
     return $tests;
 }
 public function getPatches()
 {
     $patches = array();
     foreach ($this->getOldPatches() as $old_name => $old_patch) {
         if (preg_match('/^db\\./', $old_name)) {
             $old_patch['name'] = substr($old_name, 3);
             $old_patch['type'] = 'db';
         } else {
             if (empty($old_patch['name'])) {
                 $old_patch['name'] = $this->getPatchPath($old_name);
             }
             if (empty($old_patch['type'])) {
                 $matches = null;
                 preg_match('/\\.(sql|php)$/', $old_name, $matches);
                 $old_patch['type'] = $matches[1];
             }
         }
         $patches[$old_name] = $old_patch;
     }
     $root = dirname(phutil_get_library_root('phabricator'));
     $auto_root = $root . '/resources/sql/autopatches/';
     $auto_list = Filesystem::listDirectory($auto_root, $include_hidden = false);
     sort($auto_list);
     foreach ($auto_list as $auto_patch) {
         $matches = null;
         if (!preg_match('/\\.(sql|php)$/', $auto_patch, $matches)) {
             throw new Exception(pht('Unknown patch "%s" in "%s", expected ".php" or ".sql" suffix.', $auto_patch, $auto_root));
         }
         $patches[$auto_patch] = array('type' => $matches[1], 'name' => $auto_root . $auto_patch);
     }
     return $patches;
 }
 public function testParseAll()
 {
     $root = dirname(__FILE__) . '/mercurial/';
     foreach (Filesystem::listDirectory($root, $hidden = false) as $file) {
         $this->parseData(basename($file), Filesystem::readFile($root . '/' . $file));
     }
 }
 public function testDifferentialCommitMessageParser()
 {
     $dir = dirname(__FILE__) . '/messages/';
     $list = Filesystem::listDirectory($dir, $include_hidden = false);
     foreach ($list as $file) {
         if (!preg_match('/.txt$/', $file)) {
             continue;
         }
         $data = Filesystem::readFile($dir . $file);
         $divider = "~~~~~~~~~~\n";
         $parts = explode($divider, $data);
         if (count($parts) !== 4) {
             throw new Exception(pht('Expected test file "%s" to contain four parts (message, fields, ' . 'output, errors) divided by "%s".', $file, '~~~~~~~~~~'));
         }
         list($message, $fields, $output, $errors) = $parts;
         $fields = phutil_json_decode($fields);
         $output = phutil_json_decode($output);
         $errors = phutil_json_decode($errors);
         $parser = id(new DifferentialCommitMessageParser())->setLabelMap($fields)->setTitleKey('title')->setSummaryKey('summary');
         $result_output = $parser->parseCorpus($message);
         $result_errors = $parser->getErrors();
         $this->assertEqual($output, $result_output);
         $this->assertEqual($errors, $result_errors);
     }
 }
 protected function deleteDocumentsByHash(array $hashes)
 {
     $root = $this->getConfig('root');
     $cache = $this->getPublishCache();
     foreach ($hashes as $hash) {
         $paths = $cache->getAtomPathsFromCache($hash);
         foreach ($paths as $path) {
             $abs = $root . DIRECTORY_SEPARATOR . $path;
             Filesystem::remove($abs);
             // If the parent directory is now empty, clean it up.
             $dir = dirname($abs);
             while (true) {
                 if (!Filesystem::isDescendant($dir, $root)) {
                     // Directory is outside of the root.
                     break;
                 }
                 if (Filesystem::listDirectory($dir)) {
                     // Directory is not empty.
                     break;
                 }
                 Filesystem::remove($dir);
                 $dir = dirname($dir);
             }
         }
         $cache->removeAtomPathsFromCache($hash);
         $cache->deleteAtomFromIndex($hash);
     }
 }
 public function testEngine()
 {
     $root = dirname(__FILE__) . '/remarkup/';
     foreach (Filesystem::listDirectory($root, $hidden = false) as $file) {
         $this->markupText($root . $file);
     }
 }
 public function testParseRender()
 {
     $dir = dirname(__FILE__) . '/data/';
     foreach (Filesystem::listDirectory($dir, $show_hidden = false) as $file) {
         if (!preg_match('/\\.diff$/', $file)) {
             continue;
         }
         $data = Filesystem::readFile($dir . $file);
         $opt_file = $dir . $file . '.options';
         if (Filesystem::pathExists($opt_file)) {
             $options = Filesystem::readFile($opt_file);
             $options = json_decode($options, true);
             if (!is_array($options)) {
                 throw new Exception("Invalid options file: {$opt_file}.");
             }
         } else {
             $options = array();
         }
         foreach (array('one', 'two') as $type) {
             $parser = $this->buildChangesetParser($type, $data, $file);
             $actual = $parser->render(null, null, array());
             $expect = Filesystem::readFile($dir . $file . '.' . $type . '.expect');
             $this->assertEqual($expect, (string) $actual, $file . '.' . $type);
         }
     }
 }
 public function testParser()
 {
     $root = dirname(__FILE__) . '/data/';
     foreach (Filesystem::listDirectory($root, $hidden = false) as $file) {
         $this->parseDiff($root . $file);
     }
 }
 public function testParseRender()
 {
     $dir = $this->getTestDataDirectory();
     foreach (Filesystem::listDirectory($dir, $show_hidden = false) as $file) {
         if (!preg_match('/\\.diff$/', $file)) {
             continue;
         }
         $data = Filesystem::readFile($dir . $file);
         $opt_file = $dir . $file . '.options';
         if (Filesystem::pathExists($opt_file)) {
             $options = Filesystem::readFile($opt_file);
             try {
                 $options = phutil_json_decode($options);
             } catch (PhutilJSONParserException $ex) {
                 throw new PhutilProxyException(pht('Invalid options file: %s.', $opt_file), $ex);
             }
         } else {
             $options = array();
         }
         foreach (array('one', 'two') as $type) {
             $this->runParser($type, $data, $file, 'expect');
             $this->runParser($type, $data, $file, 'unshielded');
             $this->runParser($type, $data, $file, 'whitespace');
         }
     }
 }
 public function testPHPFragmentLexer()
 {
     $dir = dirname(__FILE__) . '/php';
     foreach (Filesystem::listDirectory($dir, $hidden = false) as $file) {
         $data = Filesystem::readFile($dir . '/' . $file);
         $this->runLexer($file, $data);
     }
 }
 public function testShellLexer()
 {
     $dir = dirname(__FILE__) . '/shell';
     foreach (Filesystem::listDirectory($dir, $hidden = false) as $file) {
         $data = Filesystem::readFile($dir . '/' . $file);
         $data = rtrim($data, "\n");
         $this->runLexer($file, $data);
     }
 }
 public function testWrap()
 {
     $dir = dirname(__FILE__) . '/wrap/';
     $files = Filesystem::listDirectory($dir);
     foreach ($files as $file) {
         if (preg_match('/.txt$/', $file)) {
             $this->assertEqual(Filesystem::readFile($dir . $file . '.expect'), phutil_console_wrap(Filesystem::readFile($dir . $file)), $file);
         }
     }
 }
 protected final function loadRunningDaemons()
 {
     $daemons = array();
     $pid_dir = $this->getPIDDirectory();
     $pid_files = Filesystem::listDirectory($pid_dir);
     foreach ($pid_files as $pid_file) {
         $daemons[] = PhabricatorDaemonReference::newFromFile($pid_dir . '/' . $pid_file);
     }
     return $daemons;
 }
 private function getAllBuiltinFiles()
 {
     $root = dirname(phutil_get_library_root('phabricator'));
     $root = $root . '/resources/builtin/';
     $map = array();
     $list = Filesystem::listDirectory($root, $include_hidden = false);
     foreach ($list as $file) {
         $map[$file] = $root . $file;
     }
     return $map;
 }
示例#18
0
 public function testParser()
 {
     if (!xhpast_is_available()) {
         $this->assertSkipped(pht('xhpast is not built or not up to date.'));
     }
     $dir = dirname(__FILE__) . '/data/';
     foreach (Filesystem::listDirectory($dir) as $file) {
         if (preg_match('/\\.test$/', $file)) {
             $this->executeParserTest($file, Filesystem::readFile($dir . $file));
         }
     }
 }
 private function hasEmoji($name)
 {
     $files = Filesystem::listDirectory('rsrc/image/emoji', $include_hidden = false);
     foreach ($files as $file) {
         $info = pathinfo($file);
         $file_name = basename($file, '.' . $info['extension']);
         if ($file_name == $name) {
             return true;
         }
     }
     return false;
 }
 public function testLexer()
 {
     $highlighter = id(new PhutilLexerSyntaxHighlighter())->setConfig('language', 'json')->setConfig('lexer', new PhutilJSONFragmentLexer());
     $path = dirname(__FILE__) . '/data/jsonfragment/';
     foreach (Filesystem::listDirectory($path, $include_hidden = false) as $f) {
         if (preg_match('/.test$/', $f)) {
             $expect = preg_replace('/.test$/', '.expect', $f);
             $source = Filesystem::readFile($path . '/' . $f);
             $this->assertEqual(Filesystem::readFile($path . '/' . $expect), (string) $highlighter->getHighlightFuture($source)->resolve(), $f);
         }
     }
 }
 public static function getAllIcons()
 {
     $root = dirname(phutil_get_library_root('phabricator'));
     $root = $root . '/resources/builtin/projects/';
     $quips = self::getIconQuips();
     $map = array();
     $list = Filesystem::listDirectory($root, $include_hidden = false);
     foreach ($list as $file) {
         $short = preg_replace('/\\.png$/', '', $file);
         $map[$short] = array('path' => $root . $file, 'quip' => idx($quips, $short, $short));
     }
     return $map;
 }
 public function testGuessing()
 {
     $dir = dirname(__FILE__) . '/languageguesser/';
     foreach (Filesystem::listDirectory($dir, $hidden = false) as $test) {
         $source = Filesystem::readFile($dir . $test);
         if (strpos($test, '.') !== false) {
             $expect = head(explode('.', $test));
         } else {
             $expect = null;
         }
         $this->assertEqual($expect, PhutilLanguageGuesser::guessLanguage($source), "Guessed language for '{$test}'.");
     }
 }
 public function testMercurialClientWireProtocolParser()
 {
     $data = dirname(__FILE__) . '/hgwiredata/';
     $dir = Filesystem::listDirectory($data, $include_hidden = false);
     foreach ($dir as $file) {
         $raw = Filesystem::readFile($data . $file);
         $raw = explode("\n~~~~~~~~~~\n", $raw, 2);
         $this->assertEqual(2, count($raw));
         $expect = phutil_json_decode($raw[1]);
         $this->assertTrue(is_array($expect), $file);
         $this->assertParserResult($expect, $raw[0], $file);
     }
 }
 public function testStateParsing()
 {
     $dir = dirname(__FILE__) . '/state/';
     $tests = Filesystem::listDirectory($dir, $include_hidden = false);
     foreach ($tests as $test) {
         $fixture = PhutilDirectoryFixture::newFromArchive($dir . '/' . $test);
         $fixture_path = $fixture->getPath();
         $working_copy = ArcanistWorkingCopyIdentity::newFromPath($fixture_path);
         $api = ArcanistRepositoryAPI::newAPIFromWorkingCopyIdentity($working_copy);
         $api->setBaseCommitArgumentRules('arc:this');
         $this->assertCorrectState($test, $api);
     }
 }
 private function getDirectoryList($dir)
 {
     $path = $this->getPath($dir);
     $result = array();
     $images = Filesystem::listDirectory($path, $include_hidden = false);
     foreach ($images as $image) {
         if (!preg_match('/\\.png$/', $image)) {
             throw new Exception(pht("Expected file '%s' in '%s' to be a sprite source ending in '%s'.", $image, $path, '.png'));
         }
         $result[] = substr($image, 0, -4);
     }
     return $result;
 }
 /**
  * Examine a directory for `.php` and `.sql` files and build patch
  * specifications for them.
  */
 protected function buildPatchesFromDirectory($directory)
 {
     $patch_list = Filesystem::listDirectory($directory, $include_hidden = false);
     sort($patch_list);
     $patches = array();
     foreach ($patch_list as $patch) {
         $matches = null;
         if (!preg_match('/\\.(sql|php)$/', $patch, $matches)) {
             throw new Exception(pht('Unknown patch "%s" in "%s", expected ".php" or ".sql" suffix.', $patch, $directory));
         }
         $patches[$patch] = array('type' => $matches[1], 'name' => rtrim($directory, '/') . '/' . $patch);
     }
     return $patches;
 }
 private static function getFigletMap()
 {
     $root = dirname(phutil_get_library_root('phabricator'));
     $dirs = array($root . '/externals/figlet/fonts/', $root . '/externals/pear-figlet/fonts/', $root . '/resources/figlet/custom/');
     $map = array();
     foreach ($dirs as $dir) {
         foreach (Filesystem::listDirectory($dir, false) as $file) {
             if (preg_match('/\\.flf\\z/', $file)) {
                 $name = phutil_utf8_strtolower($file);
                 $name = preg_replace('/\\.flf\\z/', '', $name);
                 $map[$name] = $dir . $file;
             }
         }
     }
     return $map;
 }
 public function testParser()
 {
     if (!PhutilXHPASTBinary::isAvailable()) {
         try {
             PhutilXHPASTBinary::build();
         } catch (Exception $ex) {
             $this->assertSkipped(pht('%s is not built or not up to date.', 'xhpast'));
         }
     }
     $dir = dirname(__FILE__) . '/data/';
     foreach (Filesystem::listDirectory($dir) as $file) {
         if (preg_match('/\\.test$/', $file)) {
             $this->executeParserTest($file, Filesystem::readFile($dir . $file));
         }
     }
 }
 public function testTransformation()
 {
     $files = dirname(__FILE__) . '/transformer/';
     foreach (Filesystem::listDirectory($files) as $file) {
         $name = basename($file);
         $data = Filesystem::readFile($files . '/' . $file);
         $parts = preg_split('/^~~~+\\n/m', $data);
         $parts = array_merge($parts, array(null));
         list($options, $in, $expect) = $parts;
         $options = PhutilSimpleOptions::parse($options) + array('minify' => false, 'name' => $name);
         $xformer = new CelerityResourceTransformer();
         $xformer->setRawResourceMap(array('/rsrc/example.png' => array('uri' => '/res/hash/example.png')));
         $xformer->setMinify($options['minify']);
         $result = $xformer->transformResource($options['name'], $in);
         $this->assertEqual(rtrim($expect), rtrim($result), $file);
     }
 }
 private static function getCowMap()
 {
     $root = dirname(phutil_get_library_root('phabricator'));
     $directories = array($root . '/externals/cowsay/cows/', $root . '/resources/cows/builtin/', $root . '/resources/cows/custom/');
     $map = array();
     foreach ($directories as $directory) {
         foreach (Filesystem::listDirectory($directory, false) as $cow_file) {
             $matches = null;
             if (!preg_match('/^(.*)\\.cow\\z/', $cow_file, $matches)) {
                 continue;
             }
             $cow_name = $matches[1];
             $cow_name = phutil_utf8_strtolower($cow_name);
             $map[$cow_name] = Filesystem::readFile($directory . $cow_file);
         }
     }
     return $map;
 }