[zi-cvs] packages/com.zzoss.plugin.lib Plugin.php,1.5,1.6
[email protected] Fri, 05 Mar 2004 06:25:26 -0800
| Newsgroups | gmane.comp.php.zzoss.installer.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/zzossinstaller/packages/com.zzoss.plugin.lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8129/com.zzoss.plugin.lib
Modified Files:
Plugin.php
Log Message:
new plugin architecture in installer
Index: Plugin.php
===================================================================
RCS file: /cvsroot/zzossinstaller/packages/com.zzoss.plugin.lib/Plugin.php,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** Plugin.php 12 Feb 2004 10:36:40 -0000 1.5
--- Plugin.php 5 Mar 2004 14:25:24 -0000 1.6
***************
*** 26,29 ****
--- 26,33 ----
require_once 'ZZOSS_Installer/Utils.php';
+ define('ZZOSS_PLUGIN_STATUS_UNDEFINED', 0);
+ define('ZZOSS_PLUGIN_STATUS_BUILTIN', 1);
+ define('ZZOSS_PLUGIN_STATUS_INCLUDED', 2);
+
/**
* Methods for installer plugins
***************
*** 33,37 ****
var $application_settings = NULL;
! var $builds;
/**
--- 37,41 ----
var $application_settings = NULL;
! var $build;
/**
***************
*** 45,52 ****
var $sources = array();
- var $plugins_params = array();
-
var $output;
function setDestDir($dest_dir)
{
--- 49,64 ----
var $sources = array();
var $output;
+ /**
+ * Data directory where build packages can store data.
+ */
+ var $data_dir;
+
+ /**
+ * Relating file name to its baseinstalldir.
+ */
+ var $file_baseinstalldir = array();
+
function setDestDir($dest_dir)
{
***************
*** 65,68 ****
--- 77,89 ----
}
+ /**
+ * Sources are processed in the order they have been added.
+ * First things first!
+ */
+ function setDataDir($data)
+ {
+ $this->data_dir = $data;
+ }
+
function setQueue($queue)
{
***************
*** 88,93 ****
$queue = $this->queue[$step];
! // First, we register all plugins in this queue
foreach($queue as $key => $val) {
// Pre-processing
--- 109,116 ----
$queue = $this->queue[$step];
+
+ $this->initApplicationPackages();
! // Now we deal with the packages
foreach($queue as $key => $val) {
// Pre-processing
***************
*** 106,149 ****
break;
}
- $this->package = $this->packages[$key];
- $this->log .= "\n[$key]\n\n";
-
- $this->registerPlugins();
- }
-
- if(count($this->plugins_params)){
- $this->registry->setPlugins($this->plugins_params['add'], $this->plugins_params['remove']);
- $this->initPlugins();
- }
-
- $this->initApplicationPackages();
-
- // Now we deal with the packages
- foreach($queue as $key => $val) {
- // Pre-processing
- switch($val) {
- case 'I':
- $this->action = 'install';
- break;
- case 'U':
- $this->action = 'update';
- break;
- case 'R':
- $this->action = 'remove';
- break;
- }
$this->package = $this->packages[$key];
$this->log .= "\n[$key]\n\n";
$this->pkg_root = '';
! if(isset($this->packages_application[$this->package["name"]]["@"]["baseinstalldir"])){
! $this->pkg_root = $this->packages_application[$this->package["name"]]["@"]["baseinstalldir"];
}
$this->pkg_root .= DIRECTORY_SEPARATOR;
!
switch($this->role){
case 'role':
$this->execRole();
break;
case 'build':
--- 129,150 ----
break;
}
$this->package = $this->packages[$key];
$this->log .= "\n[$key]\n\n";
+ $this->log .= "Action: ".$this->action."\n";
+
+ // compose absolute baseinstalldir
$this->pkg_root = '';
! if(isset($this->packages_application[$key]["@"]["baseinstalldir"])){
! $this->pkg_root = ZZOSS_InstallerUtils::fixPath($this->packages_application[$key]["@"]["baseinstalldir"]);
}
$this->pkg_root .= DIRECTORY_SEPARATOR;
! // execute plugins
switch($this->role){
case 'role':
$this->execRole();
+ $this->registerPlugins();
+ $this->registry->setPlugins($this->plugins);
break;
case 'build':
***************
*** 152,155 ****
--- 153,162 ----
}
}
+
+ // register plugins
+ //if(isset($this->plugins_params['add']) && isset($this->plugins_params['remove'])){
+ //$this->registry->setPlugins($this->plugins);
+ //$this->initPlugins();
+ //}
}
***************
*** 177,185 ****
$this->file = $file;
// execute plugins
$this->log .= "* Dealing with role '".$this->file["@"]["role"]."'\n";
//$this->log .= " performing on '".var_export($this->plugins['role']['role'], true)."'\n";
! if(!$this->includePlugins($this->plugins['role']['role'][$this->file["@"]["role"]])){
! $this->log .= "* ERROR: A handler for this role does not exist.\n";
}
}
--- 184,204 ----
$this->file = $file;
+ if(isset($this->file["@"]["baseinstalldir"])){
+ $this->file_baseinstalldir[$this->file["@"]["name"]] = $this->file["@"]["baseinstalldir"];
+ }
+
+ if(!isset($this->file["@"]["role"])){
+ $this->file["@"]["role"] = '';
+ }
+
// execute plugins
$this->log .= "* Dealing with role '".$this->file["@"]["role"]."'\n";
//$this->log .= " performing on '".var_export($this->plugins['role']['role'], true)."'\n";
! if(!isset($this->plugins['role']['role'][$this->file["@"]["role"]])){
! $this->execPluginRole();
! } else {
! if(!$this->includePlugins($this->plugins['role']['role'][$this->file["@"]["role"]])){
! $this->log .= "* ERROR: A handler for this role does not exist.\n";
! }
}
}
***************
*** 189,284 ****
$packages_installed_dir = $this->registry->getApplicationPath().'packages_installed'.DIRECTORY_SEPARATOR.$this->package["name"].'-'.$this->package["release"]["version"].DIRECTORY_SEPARATOR;
!
switch($this->action) {
case 'install':
case 'update':
! if(!isset($this->package["install"]["path"])){
! PEAR::raiseError('Internal Error: Unknow package source path. Seems like the package registry has not been refreshed properly.');
! break;
! }
! // Post-processing
! System::mkDir(array('-p', $packages_installed_dir));
! $this->log .= '* Created directory '.$packages_installed_dir."\n";
! copy(
! $this->package["install"]["path"].'package.xml',
! $packages_installed_dir.'package.xml'
! );
! $this->log .= '* Copied '.$this->package["install"]["path"].'package.xml to '.$packages_installed_dir.'package.xml'."\n";
! // remove the extracted package
! System::rm(array('-rf',$this->package["install"]["path"]));
! $this->log .= '* Removed extracted package ('.$this->package["install"]["path"].')'."\n";
break;
case 'remove':
// remove directory of installed package
! System::rm(array('-rf',$packages_installed_dir));
! $this->log .= '* Removed installed package registry directory ('.$packages_installed_dir.')'."\n";
break;
}
}
! function includePlugins($plugins)
{
! $is_included = true;
! if(!is_array($plugins)){
! return false;
! }
ob_start();
! $this->log .= "* Processing default plugins.\n";
! $is_included = $this->includePluginsIterator($plugins['default']);
! $this->log .= "* Processing other available plugins.\n";
! $is_included = $this->includePluginsIterator($plugins['available']);
$this->output .= ob_get_contents();
ob_end_clean();
! return $is_included;
}
! function includePluginsIterator($plugins)
{
reset($this->sources);
! if(is_array($plugins)){
! foreach($plugins as $name => $params){
// Iterate available sources
if(!count($this->sources)){
PEAR::raiseError('No plugin directory defined.');
! } else {
! $GLOBALS['ZI']['plugin_log'] = '';
foreach($this->sources as $source){
! $this->log .= "* Checking source directory '".$source."'\n";
! $include = $source.$name.DIRECTORY_SEPARATOR.$params['file'];
$this->log .= "* Trying to include '".$include."'\n";
! if(!file_exists($include)){
! $is_included = false;
// Check for development plugin (has no version in its unique name).
! $include = $source.$params['name'].DIRECTORY_SEPARATOR.$params['file'];
$this->log .= "* Trying to include '".$include."'\n";
if(file_exists($include)){
- $this->log .= "* Initializing global plugin variables.\n";
$this->initGlobalVariables();
! $is_included = true;
include($include);
break;
}
! } else {
$this->initGlobalVariables();
include($include);
! $is_included = true;
! break;
}
! }
! if(!$is_included){
! $this->log .= "* Could not find '".$name.DIRECTORY_SEPARATOR.$params['file']."' nor '".$params['name'].DIRECTORY_SEPARATOR.$params['file']."' in specified sources.\n";
! } else {
$this->log .= "* Including $include\n";
! if(strlen($GLOBALS['ZI']['plugin_log'])){
! $this->log .= "--- Plugin Messages ---\n";
! $this->log .= $GLOBALS['ZI']['plugin_log'];
! $this->log .= "-----------------------\n";
! }
}
! }
! }
}
- return $is_included;
}
--- 208,337 ----
$packages_installed_dir = $this->registry->getApplicationPath().'packages_installed'.DIRECTORY_SEPARATOR.$this->package["name"].'-'.$this->package["release"]["version"].DIRECTORY_SEPARATOR;
!
switch($this->action) {
case 'install':
case 'update':
! $this->registry->installPackage($this->package["name"].'-'.$this->package["release"]["version"]);
! $this->log .= $this->registry->getLog();
break;
case 'remove':
// remove directory of installed package
! if(!isset($this->package['_specified'])){
! $this->package['_specified'] = true;
! }
! $this->registry->removePackage($this->package["name"].'-'.$this->package["release"]["version"], $this->package['_specified']);
! $this->log .= $this->registry->getLog();
break;
}
}
! function execPluginRole()
{
! $GLOBALS['ZI']['plugin_log'] = '';
!
! // if we are supposed to process the filelist,
! // but no plugin is available,
! // then we simply copy the file to the specified
! // location.
ob_start();
! $this->log .= "* Using build in plugin to move file\n";
!
! $this->initGlobalVariables();
! $status = ZZOSS_PLUGIN_STATUS_BUILTIN;
!
! switch($GLOBALS['ZI']['package_action']){
! case 'remove':
! unlink($GLOBALS['ZI']['file_dest']);
! $GLOBALS['ZI']['plugin_log'] .= 'deleted '.$GLOBALS['ZI']['file_dest'];
! break;
! case 'update':
! case 'install':
! if(!is_dir(dirname($GLOBALS['ZI']['file_dest']))){
! System::mkDir(array("-p",dirname($GLOBALS['ZI']['file_dest'])));
! $GLOBALS['ZI']['plugin_log'] .= 'Created directory '.dirname($GLOBALS['ZI']['file_dest'])."\n";
! }
! //ZZOSS_InstallerUtils::mkdir($pathinfo["dirname"]);
! //$log .= 'src: '.$src. 'dest: '.$dest."\n";
! //echo 'src: '.$src. 'dest: '.$dest."\n<br>";
! if(!copy($GLOBALS['ZI']['file_src'],$GLOBALS['ZI']['file_dest'])) {
! $GLOBALS['ZI']['plugin_log'] .=
! 'Cannot copy '.$GLOBALS['ZI']['file_src']."\n".
! ' to '.$GLOBALS['ZI']['file_dest']."\n";
! } else {
! $GLOBALS['ZI']['plugin_log'] .=
! 'Copied '.$GLOBALS['ZI']['file_src']."\n".
! ' to '.$GLOBALS['ZI']['file_dest']."\n";
! }
! break;
! }
!
! $this->showPluginMessage();
!
$this->output .= ob_get_contents();
ob_end_clean();
! return $status;
}
! function includePlugins($plugins)
{
+ $status = ZZOSS_PLUGIN_STATUS_UNDEFINED;
+
+ ob_start();
+ $this->log .= "* Processing plugins.\n";
+ /*
reset($this->sources);
! if(is_array($plugins)){*/
! foreach($plugins as $name => $params){/*
// Iterate available sources
if(!count($this->sources)){
PEAR::raiseError('No plugin directory defined.');
! } else {*/
! $GLOBALS['ZI']['plugin_log'] = '';/*
foreach($this->sources as $source){
! $this->log .= "* Checking source directory '".$source."'\n";*/
! $include = ZZOSS_InstallerUtils::fixPath(/*$source.DIRECTORY_SEPARATOR.$name.DIRECTORY_SEPARATOR.*/$params['file']);
$this->log .= "* Trying to include '".$include."'\n";
! if(/*!*/file_exists($include)){
! /*
// Check for development plugin (has no version in its unique name).
! $include = ZZOSS_InstallerUtils::fixPath($source.DIRECTORY_SEPARATOR.$params['name'].DIRECTORY_SEPARATOR.$params['file']);
$this->log .= "* Trying to include '".$include."'\n";
if(file_exists($include)){
$this->initGlobalVariables();
! $status = ZZOSS_PLUGIN_STATUS_INCLUDED;
include($include);
break;
}
! } else {*/
$this->initGlobalVariables();
include($include);
! $status = ZZOSS_PLUGIN_STATUS_INCLUDED;
! //break;
}
! //}
! if($status == ZZOSS_PLUGIN_STATUS_UNDEFINED){
! $this->log .= "* Plugin '$name': Could not find '".$params['file']./*"' nor '".$params['name'].DIRECTORY_SEPARATOR.$params['file'].*/"' in specified sources.\n";
! } elseif($status == ZZOSS_PLUGIN_STATUS_INCLUDED) {
$this->log .= "* Including $include\n";
! $this->showPluginMessage();
}
! /*}
! */}/*
! }*/
!
! $this->output .= ob_get_contents();
! ob_end_clean();
!
! return $status;
! }
!
! function showPluginMessage()
! {
! if(strlen($GLOBALS['ZI']['plugin_log'])){
! $this->log .= "--- Plugin Message ---\n";
! $this->log .= $GLOBALS['ZI']['plugin_log'];
! $this->log .= "-----------------------\n";
}
}
***************
*** 341,369 ****
}
if(count($files)) {
//$plugins_install['default'][$this->package['name'].'-'.$this->package['release']['version']] = strlen($this->package["release"]["plugin"]['@']['default']);
foreach($files as $file) {
! // remember parameters to later register plugin files
! if($this->package["release"]["plugin"]['@']['default'] == 'yes'){
! $type = 'default';
} else {
! $type = 'available';
}
! $plugin_params[$type][$this->package['name'].'-'.$this->package['release']['version']]['file'] = $file["@"]["name"];
! $plugin_params[$type][$this->package['name'].'-'.$this->package['release']['version']]['name'] = $this->package['name'];
! if(!strlen($file['@']['role'])){
! $this->plugins_params[$this->plugin_action]['_undefined'] = $plugin_params;
! } else if(!strlen($file['@']['attr'])){
! $this->plugins_params[$this->plugin_action][$file['@']['role']] = $plugin_params;
} else {
! $this->plugins_params[$this->plugin_action][$file['@']['role']][$file["@"]["attr"]][$file["@"]["val"]] = $plugin_params;
}
// Log info
! $this->log .= "Registered plugin file ".$file["@"]["name"]."\n";
! $this->log .= " Type: $type\n";
! $this->log .= " Action: ".$this->plugin_action."\n";
!
// move files to installer's plugins/ directory
$src = ZZOSS_InstallerUtils::fixPath($this->package["install"]["path"].$file["@"]["name"]);
--- 394,428 ----
}
if(count($files)) {
+ $plugin_param = array();
+ $plugins_params = array();
+ $plugins_params['add'] = NULL;
+ $plugins_params['remove'] = NULL;
//$plugins_install['default'][$this->package['name'].'-'.$this->package['release']['version']] = strlen($this->package["release"]["plugin"]['@']['default']);
foreach($files as $file) {
! if(!isset($this->file_baseinstalldir[$file["@"]["name"]])){
! $file["@"]["baseinstalldir"] = '';
} else {
! $file["@"]["baseinstalldir"] = $this->file_baseinstalldir[$file["@"]["name"]];
}
+ // remember parameters to later register plugin files
+ $file_path = ZZOSS_InstallerUtils::fixPath($this->dest_dir.DIRECTORY_SEPARATOR.$this->pkg_root.$file["@"]["baseinstalldir"].DIRECTORY_SEPARATOR.$file["@"]["name"]);
! $plugin_params[$this->package['name'].'-'.$this->package['release']['version']]['file'] = $file_path;
! $plugin_params[$this->package['name'].'-'.$this->package['release']['version']]['name'] = $this->package['name'];
! if(!isset($file['@']['role'])){
! $role = '';
! $plugins_params[$this->plugin_action]['_undefined'] = $plugin_params;
! } else if(!isset($file['@']['attr'])){
! $role = $file['@']['role'];
! $plugins_params[$this->plugin_action][$file['@']['role']] = $plugin_params;
} else {
! $role = $file['@']['attr'];
! $plugins_params[$this->plugin_action][$file['@']['role']][$file["@"]["attr"]][$file["@"]["val"]] = $plugin_params;
}
// Log info
! $this->log .= $this->plugin_action." plugin file ".$file_path." with role '".$role."'\n";
! /*
// move files to installer's plugins/ directory
$src = ZZOSS_InstallerUtils::fixPath($this->package["install"]["path"].$file["@"]["name"]);
***************
*** 371,379 ****
$dest = ZZOSS_InstallerUtils::fixPath($zi_plugin_dir.$file["@"]["name"]);
! ZZOSS_InstallerUtils::mkdir($zi_plugin_dir);
if(!@copy($src,$dest)) {
$this->log .= 'error writing '.$dest."\n";
}
}
}
}
--- 430,441 ----
$dest = ZZOSS_InstallerUtils::fixPath($zi_plugin_dir.$file["@"]["name"]);
! System::mkdir(array('-p', $zi_plugin_dir));
if(!@copy($src,$dest)) {
$this->log .= 'error writing '.$dest."\n";
}
+ */
}
+
+ $this->plugins = $this->registry->composePlugins($plugins_params['add'], $plugins_params['remove'], $this->plugins);
}
}
***************
*** 381,384 ****
--- 443,447 ----
function initGlobalVariables()
{
+ $this->log .= "* Initializing global plugin variables.\n";
$this->initApplicationSettings();
***************
*** 388,392 ****
$GLOBALS['ZI']['application_baseinstalldir'] =
$this->application_settings['application_root'];
- $GLOBALS['ZI']['application_root'] = $this->application_settings['application_root'];
$GLOBALS['ZI']['application_data_dir'] = $this->registry->getApplicationPath();
--- 451,454 ----
***************
*** 395,399 ****
$GLOBALS['ZI']['application_url_rel'] = $this->application_settings['application_url_rel'];
$GLOBALS['ZI']['application_url'] = $this->application_settings['application_url'];
! $GLOBALS['ZI']['application_demo'] = ($this->application_settings['application_demo'] == 'on');
$GLOBALS['ZI']['application_profile'] = $this->application_settings['application_profile'];
--- 457,461 ----
$GLOBALS['ZI']['application_url_rel'] = $this->application_settings['application_url_rel'];
$GLOBALS['ZI']['application_url'] = $this->application_settings['application_url'];
! $GLOBALS['ZI']['application_demo'] = (isset($this->application_settings['application_demo']) && $this->application_settings['application_demo'] == 'on');
$GLOBALS['ZI']['application_profile'] = $this->application_settings['application_profile'];
***************
*** 402,406 ****
$GLOBALS['ZI']['package_root'] =
$GLOBALS['ZI']['package_baseinstalldir'] =
! ZZOSS_InstallerUtils::fixPath($GLOBALS['ZI']['application_root'].$this->pkg_root);
$GLOBALS['ZI']['package_src'] =
--- 464,468 ----
$GLOBALS['ZI']['package_root'] =
$GLOBALS['ZI']['package_baseinstalldir'] =
! ZZOSS_InstallerUtils::fixPath($this->dest_dir.$this->pkg_root);
$GLOBALS['ZI']['package_src'] =
***************
*** 414,417 ****
--- 476,480 ----
$GLOBALS['ZI']['plugin_mode'] = $this->mode;
+ $GLOBALS['ZI']['plugin_data_dir'] = $this->data_dir.DIRECTORY_SEPARATOR;
// GUI
***************
*** 431,450 ****
function initGlobalVariablesRole()
{
$path = ZZOSS_InstallerUtils::fixPath($GLOBALS['ZI']['package_baseinstalldir'].$this->file['@']["baseinstalldir"].DIRECTORY_SEPARATOR.$this->file['@']["name"]);
$pathinfo = pathinfo($path);
! $GLOBALS['ZI']['file_root'] =
$GLOBALS['ZI']['file_baseinstalldir'] =
! ZZOSS_InstallerUtils::fixPath($pathinfo['dirname']);
$GLOBALS['ZI']['file_src'] = ZZOSS_InstallerUtils::fixPath($GLOBALS['ZI']['package_src'].$this->file['@']['name']);
$GLOBALS['ZI']['file_dest'] = ZZOSS_InstallerUtils::fixPath($GLOBALS['ZI']['package_baseinstalldir'].$this->file['@']["baseinstalldir"].DIRECTORY_SEPARATOR.$this->file['@']["name"]);
}
function initGlobalVariablesBuild()
! {
! $GLOBALS['ZI']['plugin_data_dir'] = $this->registry->getApplicationPath().'data'.DIRECTORY_SEPARATOR.$this->package['name'].DIRECTORY_SEPARATOR;
!
$GLOBALS['ZI']['build_dir'] =
$GLOBALS['ZI']['plugin_root'] =
--- 494,520 ----
function initGlobalVariablesRole()
{
+ if(!isset($this->file['@']["baseinstalldir"])){
+ $this->file['@']["baseinstalldir"] = '';
+ }
$path = ZZOSS_InstallerUtils::fixPath($GLOBALS['ZI']['package_baseinstalldir'].$this->file['@']["baseinstalldir"].DIRECTORY_SEPARATOR.$this->file['@']["name"]);
$pathinfo = pathinfo($path);
! $GLOBALS['ZI']['file_name'] = $this->file['@']["name"];
!
! /*$GLOBALS['ZI']['file_root'] =*/
$GLOBALS['ZI']['file_baseinstalldir'] =
! ZZOSS_InstallerUtils::fixPath($this->file['@']["baseinstalldir"].DIRECTORY_SEPARATOR);
$GLOBALS['ZI']['file_src'] = ZZOSS_InstallerUtils::fixPath($GLOBALS['ZI']['package_src'].$this->file['@']['name']);
$GLOBALS['ZI']['file_dest'] = ZZOSS_InstallerUtils::fixPath($GLOBALS['ZI']['package_baseinstalldir'].$this->file['@']["baseinstalldir"].DIRECTORY_SEPARATOR.$this->file['@']["name"]);
+
+ if(isset($this->file['@']['role'])){
+ $GLOBALS['ZI']['file_role'] = $this->file['@']['role'];
+ }
}
function initGlobalVariablesBuild()
! {
$GLOBALS['ZI']['build_dir'] =
$GLOBALS['ZI']['plugin_root'] =
***************
*** 452,458 ****
$this->package['install']['path'].$this->build["@"]["dir"];
! $GLOBALS['ZI']['build_params'] =
! $GLOBALS['ZI']['plugin_params'] =
! $this->build['params'];
}
}
--- 522,530 ----
$this->package['install']['path'].$this->build["@"]["dir"];
! if(isset($this->build['params'])){
! $GLOBALS['ZI']['build_params'] =
! $GLOBALS['ZI']['plugin_params'] =
! $this->build['params'];
! }
}
}
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click