$value) { $this->{$key} = $value; } $this->downloadClass = DrushMakeDownload::factory($this); if (!$this->downloadClass) { drush_make_error('BUILD_ERROR', dt('Could not find download type %type', array('%type' => $this->download['type']))); } } /** * Build a project. */ function make() { if (empty($this->made)) { $directory = $this->queue->addItem(array($this->downloadClass, 'download')); $full_path = $this->queue->addItem(array($this, 'makePath'), array(), $directory); $move = $this->queue->addItem(array($this, 'move'), array(), array($directory, $full_path)); $this->queue->addItem(array($this, 'applyPatches'), array(), array($move)); $this->queue->addItem(array($this, 'recurse'), array(), array($move, $directory)); $this->made = TRUE; } return FALSE; } function makePath($directory) { $this->path = $this->generatePath(); drush_shell_exec('mkdir -p %s', $this->path); if (is_dir($this->path . '/' . $directory)) { drush_set_error(dt('Directory not empty: %directory', array('%directory' => $directory))); drush_shell_exec('rm -r %s', $directory); } return $this->path; } /** * Retrieve and apply any patches specified by the makefile to this project. */ function applyPatches($project_directory) { if (!empty($this->patch)) { $patches_txt = ''; foreach ($this->patch as $url) { // Download the patch. list($filename) = array_reverse(explode('/', $url)); if (!drush_shell_exec('wget %s', $url)) { drush_shell_exec('curl -L -O %s', $url); } if (file_exists($filename)) { $patches_txt .= '- ' . $url . "\n"; drush_shell_exec("mv %s %s", $filename, $project_directory); $patched = drush_shell_exec("patch -p0 -d %s < %s/%s", $project_directory, $project_directory, $filename); drush_log($this->name . ' patched with ' . $filename . '.', $patched ? 'ok' : 'error'); drush_op('unlink', $project_directory . '/' . $filename); } else { drush_set_error('Unable to download ' . $filename . ' from ' . $url . '.'); } } if (!empty($patches_txt) && !drush_get_option('no-patch-txt') && !file_exists($project_directory . '/PATCHES.txt')) { $patches_txt = "The following patches have been applied to this project:\n" . $patches_txt . "\nThis file was automatically generated by Drush Make (http://drupal.org/project/drush_make)."; file_put_contents($project_directory . '/PATCHES.txt', $patches_txt); drush_log('Generated PATCHES.txt file for ' . $this->name, 'ok'); } } } /** * Move a project to its final resting place. */ function move($project_directory) { if (empty($this->directory_name)) { drush_shell_exec("mv %s/%s %s", $this->tmp_path, $project_directory, $this->path); } else { list($project_directory) = array_reverse(explode('/', trim($project_directory, '/'))); drush_shell_exec("mv %s/%s %s/%s", $this->tmp_path, $project_directory, $this->path, $this->directory_name); $project_directory = $this->directory_name; } return $this->path . '/' . $project_directory; } /** * Generate the proper path for this project type. * * @param $absolute * Whether to generate an absolute path, including the temporary directory path. * Defaults to true. */ protected function generatePath($base = TRUE) { $path = array(); if ($base) { $path[] = $this->tmp_path; $path[] = '__build__'; } if (!empty($this->install_path)) { $path[] = $this->install_path; } if (!empty($this->subdir)) { $path[] = $this->subdir; } return implode('/', $path); } /** * Return the proper path for dependencies to be placed in. * * @return * The path that dependencies will be placed in. */ protected function buildPath() { return $this->base_install_path; } function recurse($path, $directory) { if (!empty($this->directory_name)) { $directory = $this->directory_name; } $makefile = $this->path . '/' . $directory . '/' . $this->name . '.make'; if (file_exists($makefile)) { drush_log(dt("Found makefile: %makefile", array("%makefile" => basename($makefile))), 'ok'); $build_path = $this->buildPath($directory); $data = $this->queue->addItem('drush_make_get_data', $makefile); $info = $this->queue->addItem('drush_make_parse_info_file', array(), $data); $include = $this->queue->addItem('drush_make_include_info_files', array(dirname($makefile)), array($info, $data)); $valid = $this->queue->addItem('drush_make_validate_info_file', array(), $include); $this->queue->addItem('drush_make_add_projects', array(TRUE, trim($build_path, '/'), $this->tmp_path, $this->base_path), array($valid)); $this->queue->addItem('drush_make_add_libraries', array(trim($build_path, '/'), $this->tmp_path, $this->base_path), array($valid)); } } } class DrushMakeProject_Core extends DrushMakeProject { function __construct(&$project) { parent::__construct($project); $this->install_path = ''; } function makePath($directory) { $this->path = $this->generatePath(); drush_shell_exec('mkdir -p %s', dirname($this->path)); if (is_dir($this->path . '/' . $directory)) { drush_set_error(dt('Directory not empty: %directory', array('%directory' => $directory))); drush_shell_exec('rm -r %s', $directory); return FALSE; } return $this->path; } /** * The core project will always be the base of the build, so it needs to move * itself into place a little differently. * * @TODO ensure that the core project is always created first. */ function move($project_directory) { drush_shell_exec("mv %s/%s %s/__build__", $this->tmp_path, $project_directory, $this->tmp_path); return $this->tmp_path . '/__build__'; } } class DrushMakeProject_Library extends DrushMakeProject { public function __construct(&$project) { parent::__construct($project); // Allow libraries to specify where they should live in the build path. if (isset($project['destination'])) { $project_path = $project['destination']; } else { $project_path = 'libraries'; } $this->install_path = $this->base_install_path .'/'. $project_path; } // No recursion for libraries, sorry :-( function recurse() {} } class DrushMakeProject_Module extends DrushMakeProject { public function __construct(&$project) { parent::__construct($project); $this->install_path = $this->base_install_path .'/modules'; } } class DrushMakeProject_Profile extends DrushMakeProject { public function __construct(&$project) { parent::__construct($project); $this->install_path = 'profiles'; } protected function buildPath($directory) { return $this->generatePath(FALSE) . '/' . $directory; } } class DrushMakeProject_Theme extends DrushMakeProject { public function __construct(&$project) { parent::__construct($project); $this->install_path = $this->base_install_path .'/themes'; } } class DrushMakeProject_Translation extends DrushMakeProject { public function __construct(&$project) { parent::__construct($project); switch($project['core']) { case '5.x': // Don't think there's an automatic place we can put 5.x translations, // so we'll toss them in a translations directory in the Drupal root. $this->install_path = $this->base_install_path .'/translations'; break; default: $this->install_path = ''; break; } } }