From 511d76ad1d5f42a4770d9f6acb0cadfdcf9c40af Mon Sep 17 00:00:00 2001
From: Antonio Ospite <ospite@studenti.unina.it>
Date: Wed, 27 Jul 2011 13:13:09 +0200
Subject: [PATCH v3] Issue #1164608 by ao2: handle projects with the same name
 but different types
X-Face: z*RaLf`X<@C75u6Ig9}{oW$H;1_\2t5)({*|jhM<pyWR#k60!#=#>/Vb;]yA5<GWI5`6u&+
 ;6b'@y|8w"wB;4/e!7wYYrcqdJFY,~%Gk_4]cq$Ei/7<j&N3ah(m`ku?pX.&+~:_/wC~dwn^)MizBG
 !pE^+iDQQ1yC6^,)YDKkxDd!T>\I~93>J<_`<4)A{':UrE

Since commit 66bdbaf (Put everything in the projects array) projects
with the same name but different type can override each other in
$info['projects'].

Prepend the project type to the name when indexing the projects, so that
the same name for different projects types (a module and a library, for
instance) does not override previous items.

The problem was showing in modules like 'colorbox', it is natural to
have something like:

projects[colorbox][subdir] = contrib
projects[colorbox][version] = 1.x-dev

libraries[colorbox][download][type] = get
libraries[colorbox][download][url] = http://colorpowered.com/colorbox/colorbox.zip
libraries[colorbox][directory_name] = colorbox
libraries[colorbox][destination] = libraries

but since 66bdbaf this was not working anymore.

---
 drush_make.utilities.inc |   18 +++++++++++++-----
 drush_make.drush.inc     |   12 ++++++------
 2 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/drush_make.utilities.inc b/drush_make.utilities.inc
index 3f02c10..eb019ee 100644
--- a/drush_make.utilities.inc
+++ b/drush_make.utilities.inc
@@ -77,17 +77,25 @@ function drush_make_parse_info_file($makefile, $parsed = TRUE) {
     }
   }
 
-  foreach (_drush_make_top_level_containers(TRUE) as $key => $type) {
-    if (isset($info[$key]) && is_array($info[$key])) {
-      foreach ($info[$key] as $inner_key => $item) {
+  foreach (_drush_make_top_level_containers(TRUE) as $container => $type) {
+    if (isset($info[$container]) && is_array($info[$container])) {
+      foreach ($info[$container] as $project_name => $item) {
         if (isset($item['version']) && !$item['version']) {
-          unset($info[$key][$inner_key]);
+          unset($info[$container][$project_name]);
         }
         else {
+          $item['name'] = $project_name;
+          $project_key = $project_name;
           if ($type != '') {
             $item['type'] = $type;
+
+            // Prepend the project type to the name when indexing the projects,
+            // so that the same name for different projects types (a module and
+            // a library, for instance) does not override previous items, see:
+            // http://drupal.org/node/1164608
+            $project_key = $type . '_' . $project_name;
           }
-          $info['projects'][$inner_key] = $item;
+          $info['projects'][$project_key] = $item;
         }
       }
     }
diff --git a/drush_make.drush.inc b/drush_make.drush.inc
index cce44fa..60169e7 100644
--- a/drush_make.drush.inc
+++ b/drush_make.drush.inc
@@ -167,14 +167,13 @@ function drush_make_projects($recursion, $contrib_destination, $info) {
   foreach ($info['projects'] as $key => $project) {
     // Merge the known data onto the project info.
     $project += array(
-      'name'                => $key,
       'core'                => $info['core'],
       'build_path'          => $build_path,
       'contrib_destination' => $contrib_destination,
       'version'             => DRUSH_MAKE_VERSION_BEST,
       'location'            => drush_get_option('drush-make-update-default-url'),
       'subdir'              => '',
-      'directory_name'      => (isset($project['type']) && $project['type'] == 'library' ? $key : ''),
+      'directory_name'      => (isset($project['type']) && $project['type'] == 'library' ? $project['name'] : ''),
     );
 
     if ($project['location'] != 'http://updates.drupal.org/release-history' && !isset($project['type'])) {
@@ -187,7 +186,8 @@ function drush_make_projects($recursion, $contrib_destination, $info) {
     else {
       $project['download_type'] = ($project['name'] == 'drupal' ? 'core' : 'contrib');
     }
-    $projects[$project['download_type']][$project['name']] = $project;
+
+    $projects[$project['download_type']][$key] = $project;
   }
 
   $cores = !empty($projects['core']) ? count($projects['core']) : 0;
@@ -208,7 +208,7 @@ function drush_make_projects($recursion, $contrib_destination, $info) {
   }
 
   foreach ($projects as $type => $type_projects) {
-    foreach ($type_projects as $project) {
+    foreach ($type_projects as $project_key => $project) {
       if ($project['location'] == 'http://updates.drupal.org/release-history' && (!isset($project['type']) || !isset($project['download']))) {
         $project = drush_make_updatexml($project);
       }
@@ -217,10 +217,10 @@ function drush_make_projects($recursion, $contrib_destination, $info) {
       }
       $class_name = 'DrushMakeProject_' . $project['type'];
       if (class_exists($class_name)) {
-        $projects[($project['type'] == 'core' ? 'core' : 'contrib')][$project['name']] = new $class_name($project);
+        $projects[($project['type'] == 'core' ? 'core' : 'contrib')][$project_key] = new $class_name($project);
       }
       else {
-        drush_make_error('PROJECT-TYPE', dt('Non-existent project type %type on project %project', array('%type' => $project['type'], '%project' => $key)));
+        drush_make_error('PROJECT-TYPE', dt('Non-existent project type %type on project %project', array('%type' => $project['type'], '%project' => $project['name'])));
       }
     }
   }
-- 
1.7.5.4

