drush_make.drush.inc | 5 ++--- drush_make.project.inc | 46 +++++++++++++++++++++++++++++++++++++++------- 2 files changed, 41 insertions(+), 10 deletions(-) diff --git drush_make.drush.inc drush_make.drush.inc index 9502b55..db5e057 100644 --- drush_make.drush.inc +++ drush_make.drush.inc @@ -214,9 +214,8 @@ function drush_make_projects($recursion, $contrib_destination, $info, $build_pat if ($ignore_checksums) { unset($project['download']['md5']); } - $class_name = 'DrushMakeProject_' . $project['type']; - if (class_exists($class_name)) { - $projects[($project['type'] == 'core' ? 'core' : 'contrib')][$project['name']] = new $class_name($project); + if ($instance = DrushMakeProject::getInstance($project['type'], $project)) { + $projects[($project['type'] == 'core' ? 'core' : 'contrib')][$project['name']] = $instance; } else { drush_make_error('PROJECT-TYPE', dt('Non-existent project type %type on project %project', array('%type' => $project['type'], '%project' => $key))); diff --git drush_make.project.inc drush_make.project.inc index b1df7ae..29b7e84 100644 --- drush_make.project.inc +++ drush_make.project.inc @@ -4,6 +4,19 @@ * The base project class. */ class DrushMakeProject { + + /** + * TRUE if make() has been called, otherwise FALSE. + */ + protected $made = FALSE; + + /** + * Keep track of instances. + * + * @see DrushMakeProject::getInstance() + */ + protected static $self = array(); + /** * Set attributes and retrieve project information. */ @@ -15,12 +28,33 @@ class DrushMakeProject { } /** + * Get an instance for the type and project. + * + * @param $type + * Type of project: core, library, module, profile, or translation. + * @param $project + * Project information. + * @return + * An instance for the project or FALSE if invalid type. + */ + public static function getInstance($type, $project) { + if (!isset(self::$self[$type][$project['name']])) { + $class = 'DrushMakeProject_' . $type; + self::$self[$type][$project['name']] = class_exists($class) ? new $class($project) : FALSE; + } + return self::$self[$type][$project['name']]; + } + + /** * Build a project. */ function make() { - if (!empty($this->made)) { - return FALSE; + if ($this->made) { + drush_log(dt('Attempt to build project @project more then once prevented.', array('@project' => $this->name))); + return TRUE; } + $this->made = TRUE; + $download_location = $this->findDownloadLocation(); if (drush_make_download_factory($this->name, $this->download, $download_location) === FALSE) { return FALSE; @@ -37,7 +71,6 @@ class DrushMakeProject { if (!$this->recurse($download_location)) { return FALSE; } - $this->made = TRUE; return TRUE; } @@ -228,14 +261,11 @@ class DrushMakeProject { } function recurse($path) { - if (!empty($this->directory_name)) { - $directory = $this->directory_name; - } $makefile = $this->download_location . '/' . $this->name . '.make'; if (!file_exists($makefile)) { $makefile = $this->download_location . '/drupal-org.make'; if (!file_exists($makefile)) { - return; + return TRUE; } } drush_log(dt("Found makefile: %makefile", array("%makefile" => basename($makefile))), 'ok'); @@ -247,6 +277,8 @@ class DrushMakeProject { $build_path = $this->buildPath($this->name); drush_make_projects(TRUE, trim($build_path, '/'), $info, $this->build_path); drush_make_libraries(trim($build_path, '/'), $info, $this->build_path); + + return TRUE; } }