/**
  * Sets PEAR package.xml options, based on class properties.
  *
  * @throws BuildException
  * @return void
  */
 protected function setOptions()
 {
     // 1) first prepare/populate options
     $this->populateOptions();
     // 2) make any final adjustments (this could move into populateOptions() also)
     // default PEAR basedir would be the name of the package (e.g."phing")
     if (!isset($this->preparedOptions['baseinstalldir'])) {
         $this->preparedOptions['baseinstalldir'] = $this->package;
     }
     // unless filelistgenerator has been overridden, we use Phing FileSet generator
     if (!isset($this->preparedOptions['filelistgenerator'])) {
         if (empty($this->filesets)) {
             throw new BuildException("You must use a <fileset> tag to specify the files to include in the package.xml");
         }
         $this->preparedOptions['filelistgenerator'] = 'Fileset';
         $this->preparedOptions['usergeneratordir'] = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'pearpackage';
         // Some PHING-specific options needed by our Fileset reader
         $this->preparedOptions['phing_project'] = $this->project;
         $this->preparedOptions['phing_filesets'] = $this->filesets;
     } elseif ($this->preparedOptions['filelistgenerator'] != 'Fileset' && !empty($this->filesets)) {
         throw new BuildException("You cannot use <fileset> element if you have specified the \"filelistgenerator\" option.");
     }
     // 3) Set the options
     // No need for excessive validation here, since the  PEAR class will do its own
     // validation & return errors
     $e = $this->pkg->setOptions($this->preparedOptions);
     if (PEAR::isError($e)) {
         throw new BuildException("Unable to set options.", new Exception($e->getMessage()));
     }
     // convert roles
     foreach ($this->roles as $role) {
         $this->pkg->addRole($role->getExtension(), $role->getRole());
     }
 }
    echo $e->getMessage();
    exit;
}
// replace @PHP-BIN@ in this file with the path to php executable!  pretty neat
$e = $test->addReplacement('pear-phpdoc', 'pear-config', '@PHP-BIN@', 'php_bin');
if (PEAR::isError($e)) {
    echo $e->getMessage();
    exit;
}
$e = $test->addReplacement('pear-phpdoc.bat', 'pear-config', '@PHP-BIN@', 'php_bin');
if (PEAR::isError($e)) {
    echo $e->getMessage();
    exit;
}
// hack until they get their shit in line with docroot role
$test->addRole('tpl', 'php');
$test->addRole('png', 'php');
$test->addRole('gif', 'php');
$test->addRole('jpg', 'php');
$test->addRole('css', 'php');
$test->addRole('js', 'php');
$test->addRole('ini', 'php');
$test->addRole('inc', 'php');
$test->addRole('afm', 'php');
$test->addRole('pkg', 'doc');
$test->addRole('cls', 'doc');
$test->addRole('proc', 'doc');
$test->addRole('sh', 'script');
if (isset($_GET['make'])) {
    $e = $test->writePackageFile();
} else {
    # -- Contrôle des paramètres obligatoires
    foreach ($mandatory_opts as $short => $long) {
        if (!in_array($short, $opts_h) && !in_array("--{$long}", $opts_h)) {
            die("!! Paramètre obligatoire non renseigné.\n");
        }
    }
}
// Par défaut, on considère que le package se situe dans le réperoire courant
$pkg_dir = isset($opts_h['--packagedir']) ? $opts_h['--packagedir'] : $opts_h['p'];
$pkg_dir = isset($pkg_dir) ? $pkg_dir : getcwd();
echo "Looking for files in {$pkg_dir}...\n";
$pkgxml = new PEAR_PackageFileManager();
# -- Options
$e = $pkgxml->setOptions(array('baseinstalldir' => '/', 'package' => 'Blogmarks', 'version' => '0.1', 'summary' => 'Stop bookmarking, start blogmarking', 'description' => 'Soon to come...', 'license' => 'GPL', 'packagedirectory' => $pkg_dir, 'filelistgenerator' => 'cvs', 'state' => 'beta', 'notes' => 'first try', 'ignore' => array('make_pkg.php'), 'installexceptions' => array(), 'dir_roles' => array('Blogmarks/tutorials' => 'doc'), 'exceptions' => array()));
# -- Roles
$pkgxml->addRole('ini', 'php');
$pkgxml->addRole('dist', 'php');
# -- Maintainers
$pkgxml->addMaintainer('mbertier', 'lead', 'Tristan Rivoallan', '*****@*****.**');
$pkgxml->addMaintainer('benfle', 'developer', 'Benoit Fleury', '*****@*****.**');
# -- Dépendances
$pkgxml->addDependency('DB_DataObject', '1.5.3', 'ge', 'pkg');
$pkgxml->addDependency('HTTP_Request', '1.2', 'ge', 'pkg');
if (PEAR::isError($e)) {
    echo "*** Erreur: " . $e->getMessage() . "\n";
    exit;
}
/*
$e = $pkgxml->debugPackageFile( false );

if ( PEAR::isError($e) ) {
    echo $e->getMessage();
    exit;
}
$e = $test->addReplacement('user/pear-makedocs.ini', 'pear-config', '@PEAR-DIR@', 'php_dir');
if (PEAR::isError($e)) {
    echo $e->getMessage();
    exit;
}
$e = $test->addReplacement('user/pear-makedocs.ini', 'pear-config', '@DOC-DIR@', 'doc_dir');
if (PEAR::isError($e)) {
    echo $e->getMessage();
    exit;
}
$e = $test->addReplacement('user/pear-makedocs.ini', 'package-info', '@VER@', 'version');
if (PEAR::isError($e)) {
    echo $e->getMessage();
    exit;
}
$test->addRole('inc', 'php');
$test->addRole('sh', 'script');
if (isset($_GET['make'])) {
    $e = $test->writePackageFile();
} else {
    $e = $test->debugPackageFile();
}
if (PEAR::isError($e)) {
    echo $e->getMessage();
}
if (!isset($_GET['make'])) {
    echo '<a href="' . $_SERVER['PHP_SELF'] . '?make=1">Make this file</a>';
}