<commit_before><?php
/* This file is part of the XP framework
 *
 * $Id$ 
 */

  require('lang.base.php');
  xp::sapi('cli');
  uses(
    'io.File',
    'io.FileUtil',
    'io.Folder',
    'net.xp_framework.tophp5.MigrationDoclet',
    'io.collections.FileCollection',
    'io.collections.iterate.FilteredIOCollectionIterator',
    'io.collections.iterate.RegexFilter'
  );
  
  // Params
  $p= &new ParamString();
  
  // Display help
  if ($p->exists('help', 'h')) {
    Console::writeLinef('...');
    exit();
  }
 
  $base= realpath($p->value(1));
  $targetdir= $p->value(2, 2, 'skeleton2');
  $collection= &new FileCollection($base);
  $collection->open();
  
  $iterator= &new FilteredIOCollectionIterator($collection,
    new RegexFilter('#\.class\.php$#'),
    TRUE
  );
  while ($iterator->hasNext()) {
    xp::gc();
    $element= &$iterator->next();
    
    // Construct classname from that
    $relative= substr($element->getURI(), strlen($base)+ 1);
    $fqcn= strtr(substr($relative, 0, -10), DIRECTORY_SEPARATOR, '.');
    
    // Skip existing files
    $folder= &new Folder(dirname($targetdir.DIRECTORY_SEPARATOR.$relative));
    if (!$folder->exists()) {
      Console::write('p');
      $folder->create();
    }
    
    $target= &new File($targetdir.DIRECTORY_SEPARATOR.$relative);
    if ($target->exists()) {
      Console::write('s');
      continue;
    }
    
    try(); {
    
      // Kind of hackish, but RootDoc expects a ParamString
      $param= &new ParamString();
      $param->setParams(array(NULL, $fqcn));
      
      $doclet= &new MigrationDoclet();
      RootDoc::start($doclet, $param);
    } if (catch('Exception', $e)) {
      Console::writeLine('*** Could not convert '.$fqcn.': '.$e->getMessage());
      $e->printStackTrace();
      Console::writeLine();
      xp::gc();
      continue;
    }
    
    FileUtil::setContents($target, $doclet->getOutput());
    Console::write('.');
    xp::gc();
  }
?><commit_msg>- write errors to STDERR<commit_after><?php
/* This file is part of the XP framework
 *
 * $Id$ 
 */

  require('lang.base.php');
  xp::sapi('cli');
  uses(
    'io.File',
    'io.FileUtil',
    'io.Folder',
    'net.xp_framework.tophp5.MigrationDoclet',
    'io.collections.FileCollection',
    'io.collections.iterate.FilteredIOCollectionIterator',
    'io.collections.iterate.RegexFilter'
  );
  
  // Params
  $p= &new ParamString();
  
  // Display help
  if ($p->exists('help', 'h')) {
    Console::writeLinef('...');
    exit();
  }
 
  $base= realpath($p->value(1));
  $targetdir= $p->value(2, 2, 'skeleton2');
  $collection= &new FileCollection($base);
  $collection->open();
  
  $iterator= &new FilteredIOCollectionIterator($collection,
    new RegexFilter('#\.class\.php$#'),
    TRUE
  );
  while ($iterator->hasNext()) {
    xp::gc();
    $element= &$iterator->next();
    
    // Construct classname from that
    $relative= substr($element->getURI(), strlen($base)+ 1);
    $fqcn= strtr(substr($relative, 0, -10), DIRECTORY_SEPARATOR, '.');
    
    // Skip existing files
    $folder= &new Folder(dirname($targetdir.DIRECTORY_SEPARATOR.$relative));
    if (!$folder->exists()) {
      Console::write('p');
      $folder->create();
    }
    
    $target= &new File($targetdir.DIRECTORY_SEPARATOR.$relative);
    if ($target->exists()) {
      Console::write('s');
      continue;
    }
    
    try(); {
    
      // Kind of hackish, but RootDoc expects a ParamString
      $param= &new ParamString();
      $param->setParams(array(NULL, $fqcn));
      
      $doclet= &new MigrationDoclet();
      RootDoc::start($doclet, $param);
    } if (catch('Exception', $e)) {
      fputs(STDERR, '*** Could not convert '.$fqcn.":\n");
      $e->printStackTrace();
      fputs(STDERR, "\n\n");
      Console::write('E');
      xp::gc();
      continue;
    }
    
    FileUtil::setContents($target, $doclet->getOutput());
    Console::write('.');
    xp::gc();
  }
?>
{'fraction_non_alphanumeric': 0.19954245043213015, 'fraction_numerical': 0.004575495678698526, 'mean_word_length': 2.970736629667003, 'pattern_counts': {'":': 1, '<': 5, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1446675', 'n_tokens_mistral': 1355, 'n_tokens_neox': 1328, 'n_words': 241}