public function test_abbrev()
 {
     $words = array('start', 'stop', 'queue', 'quit');
     $result = pakeTask::abbrev($words);
     $expected = array('st' => array('start', 'stop'), 's' => array('start', 'stop'), 'sta' => array('start'), 'star' => array('start'), 'start' => array('start'), 'sto' => array('stop'), 'stop' => array('stop'), 'qu' => array('queue', 'quit'), 'q' => array('queue', 'quit'), 'que' => array('queue'), 'queu' => array('queue'), 'queue' => array('queue'), 'qui' => array('quit'), 'quit' => array('quit'));
     $this->assertEqual($expected, $result);
 }
 public static function call_simpletest(pakeTask $task, $type = 'text', $dirs = array())
 {
     if (!class_exists('TestSuite')) {
         throw new pakeException('You must install SimpleTest to use this task.');
     }
     SimpleTest::ignore('UnitTestCase');
     $base_test_dir = 'test';
     $test_dirs = array();
     // run tests only in these subdirectories
     if ($dirs) {
         foreach ($dirs as $dir) {
             $test_dirs[] = $base_test_dir . DIRECTORY_SEPARATOR . $dir;
         }
     } else {
         $test_dirs[] = $base_test_dir;
     }
     $files = pakeFinder::type('file')->name('*Test.php')->in($test_dirs);
     if (count($files) == 0) {
         throw new pakeException('No test to run.');
     }
     $test = new TestSuite('Test suite in (' . implode(', ', $test_dirs) . ')');
     foreach ($files as $file) {
         $test->addFile($file);
     }
     ob_start();
     if ($type == 'html') {
         $result = $test->run(new HtmlReporter());
     } else {
         if ($type == 'xml') {
             $result = $test->run(new XmlReporter());
         } else {
             $result = $test->run(new TextReporter());
         }
     }
     $content = ob_get_contents();
     ob_end_clean();
     if ($task->is_verbose()) {
         echo $content;
     }
 }
function run_help($task = null, $args = array(), $cliopts = array())
{
    /*if ( count( $args ) == 0 )
      {
          // ...
      }*/
    // work around a pake bug
    if (count($args) > 0) {
        $args[0] = pakeTask::get_full_task_name($args[0]);
    }
    $pake = pakeApp::get_instance();
    $pake->run_help($task, $args);
}
Beispiel #4
0
function pake_desc($comment)
{
    pakeTask::define_comment($comment);
}
 private function abbrev($options)
 {
     $abbrevs = array();
     $table = array();
     foreach ($options as $option) {
         $option = pakeTask::get_mini_task_name($option);
         for ($len = strlen($option) - 1; $len > 0; --$len) {
             $abbrev = substr($option, 0, $len);
             if (!array_key_exists($abbrev, $table)) {
                 $table[$abbrev] = 1;
             } else {
                 ++$table[$abbrev];
             }
             $seen = $table[$abbrev];
             if ($seen == 1) {
                 // we're the first word so far to have this abbreviation.
                 $abbrevs[$abbrev] = array($option);
             } else {
                 if ($seen == 2) {
                     // we're the second word to have this abbreviation, so we can't use it.
                     //unset($abbrevs[$abbrev]);
                     $abbrevs[$abbrev][] = $option;
                 } else {
                     // we're the third word to have this abbreviation, so skip to the next word.
                     continue;
                 }
             }
         }
     }
     // Non-abbreviations always get entered, even if they aren't unique
     foreach ($options as $option) {
         $abbrevs[$option] = array($option);
     }
     return $abbrevs;
 }
 public function add_comment()
 {
     if (!pakeTask::$last_comment) {
         return;
     }
     if ($this->comment) {
         $this->comment .= ' / ';
     }
     $this->comment .= pakeTask::$last_comment;
     pakeTask::$last_comment = '';
 }
Beispiel #7
0
 public function display_prerequisites()
 {
     foreach (pakeTask::get_tasks() as $name => $task) {
         echo self::$EXEC_NAME . " " . pakeTask::get_mini_task_name($name) . "\n";
         foreach ($task->get_prerequisites() as $prerequisite) {
             echo "    {$prerequisite}\n";
         }
     }
 }
 /**
  * Builds dependent extensions
  *
  * @todo add locking support
  */
 static function run_build_dependencies($task = null, $args = array(), $cliopts = array())
 {
     $opts = self::getOpts(@$args[0], @$args[1], $cliopts);
     $current = $opts['extension']['name'];
     foreach ($opts['dependencies']['extensions'] as $ext => $source) {
         // avoid loops
         if ($ext != $current) {
             // create a temporary config file to drive the init task
             // this could be done better in memory...
             foreach ($source as $type => $def) {
                 break;
             }
             $tempconf = array('extension' => array('name' => $ext), 'version' => array('major' => 0, 'minor' => 0, 'release' => 0), $type => $def);
             $tempconffile = self::getOptionsDir() . "/options-tmp_{$ext}.yaml";
             pakeYaml::emitfile($tempconf, $tempconffile);
             // download remote extension
             // nb: we can not run the init task here via invoke() because of already_invoked status,
             // so we use execute(). NB: this is fine as long as init has no prerequisites
             $task = pakeTask::get('init');
             $task->execute(array("tmp_{$ext}"), array_merge($cliopts, array('skip-init' => false, 'skip-init-fetch' => false, 'skip-init-clean' => true)));
             // copy config file from ext dir to current config dir
             if (is_file(self::getBuildDir($opts) . "/{$ext}/pake/options-{$ext}.yaml")) {
                 pake_copy(self::getBuildDir($opts) . "/{$ext}/pake/options-{$ext}.yaml", self::getOptionsDir() . "/options-{$ext}.yaml");
             } else {
                 throw new pakeException("Missing pake/options.yaml extension in dependent extension {$ext}");
             }
             // finish the init-task
             $task->execute(array("tmp_{$ext}"), array_merge($cliopts, array('skip-init' => false, 'skip-init-fetch' => true, 'skip-init-clean' => false)));
             pake_remove($tempconffile, '');
             // and build it. Here again we cannot use 'invoke', but we know 'build' has prerequisites
             // so we execute them one by one
             $task = pakeTask::get('build');
             foreach ($task->get_prerequisites() as $pretask) {
                 $pretask = pakeTask::get($pretask);
                 $pretask->execute(array($ext), array_merge($opts, array('skip-init' => true)));
             }
             $task->execute(array($ext), array_merge($opts, array('skip-init' => true)));
         }
     }
 }
 public static function define_task($name, $deps = null)
 {
     $task = pakeTask::lookup($name, 'pakeFileTask');
     $task->add_comment();
     $task->enhance($deps);
 }
 /**
  * show documentation; use "pake help taskname" to see detailed documentation on task
  *
  * @param string $task
  * @param string $args
  * @throws pakeException
  * @author Alexey Zakhlestin
  */
 public static function run_help($task, $args)
 {
     if (count($args) == 0) {
         self::get_instance()->help();
         return;
     }
     $victim_name = $args[0];
     $task_name = pakeTask::taskname_from_abbreviation($victim_name);
     $victim = null;
     foreach (pakeTask::get_tasks() as $name => $task) {
         if ($task_name == $name or $task_name == pakeTask::get_mini_task_name($name)) {
             $victim = $task;
             break;
         }
     }
     if (null === $victim) {
         throw new pakeException("Couldn't find documentation for {$task_name}");
     }
     $title = 'Documentation for "' . $task_name . '" task';
     pake_echo($title);
     pake_echo(str_repeat('=', mb_strlen($title)));
     pake_echo($victim->get_comment() . "\n");
     pake_echo($victim->get_help());
 }
Beispiel #11
0
 /**
  * show documentation; use "pake help taskname" to see detailed documentation on task
  *
  * @param string $task 
  * @param string $args 
  * @return bool
  * @author Alexey Zakhlestin
  */
 public static function run_help($task, $args)
 {
     if (count($args) == 0) {
         self::get_instance()->help();
         return;
     }
     $victim_name = $args[0];
     foreach (pakeTask::get_tasks() as $name => $task) {
         if ($victim_name == $name or $victim_name == pakeTask::get_mini_task_name($name)) {
             $victim = $task;
             break;
         }
     }
     $title = 'Documentation for "' . $victim_name . '" task';
     pake_echo($title);
     pake_echo(str_repeat('=', mb_strlen($title)));
     pake_echo($victim->get_comment() . "\n");
     pake_echo($victim->get_help());
 }
Beispiel #12
0
function pake_help($help)
{
    pakeTask::define_help($help);
}
Beispiel #13
0
 public static function abbrev(array $options)
 {
     $abbrevs = array();
     $table = array();
     foreach ($options as $option) {
         $option = pakeTask::get_mini_task_name($option);
         for ($len = strlen($option) - 1; $len > 0; --$len) {
             $abbrev = substr($option, 0, $len);
             if (!array_key_exists($abbrev, $table)) {
                 $table[$abbrev] = 1;
             } else {
                 ++$table[$abbrev];
             }
             $seen = $table[$abbrev];
             if ($seen == 1) {
                 $abbrevs[$abbrev] = array($option);
             } elseif ($seen == 2) {
                 $abbrevs[$abbrev][] = $option;
             } else {
                 continue;
             }
         }
     }
     foreach ($options as $option) {
         $abbrevs[$option] = array($option);
     }
     return $abbrevs;
 }