public function processPermissions(Plugin $plugin, &$log = '', $xml = false)
    {
        if(!$xml)
            $xml = $this->loadXML($plugin->Path);

        if(!$xml)
            throw new Exception('Missing plugin.xml file for plugin ['.$plugin->Slug.']');

        // add permissions
        $perms = $xml->permissions;
        if(!empty($perms))
        foreach ( $perms->permission as $perm_xml ) {
            foreach ( array('slug', 'title') as $required_attribute ) {
                if (!$perm_xml->attributes()->$required_attribute)
                    throw new Exception("Required permission attribute '$required_attribute' was not found.");
            }

            if(!$this->Permissions->permissionExists($perm_xml->attributes()->slug))
            {
                try {
                    $this->Permissions->addPermission($plugin, $perm_xml->attributes()->slug, $perm_xml->attributes()->title);
                } catch(ValidationException $ve) {
                    throw new Exception('Permissions: '.$ve->getMessage());
                }
            }


            $log .= "Permission created...\n";
            $log .= "Slug: " . $perm_xml->attributes()->slug . "\n";
            $log .= "Title: " . $perm_xml->attributes()->title . "\n";
            $log .= "\n";
        }
    }