? 919632-libraries-info-file-10.patch
Index: libraries.api.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/libraries/libraries.api.php,v
retrieving revision 1.3
diff -u -p -r1.3 libraries.api.php
--- libraries.api.php	22 Sep 2010 17:00:56 -0000	1.3
+++ libraries.api.php	6 Oct 2010 22:24:51 -0000
@@ -330,3 +330,26 @@ function hook_libraries_info_alter(&$lib
   );
   $libraries['php_spellchecker']['integration files']['example_module'] = $files;
 }
+
+/**
+ * Specify paths to look for library info files.
+ *
+ * Libraries API looks in the following directories for library info files by
+ * default:
+ * - libraries
+ * - profiles/$profile/libraries
+ * - sites/all/libraries
+ * - sites/$site/libraries
+ * This hook allows you to specify additional locations to look for library info
+ * files. This should only be used for modules that declare many libraries.
+ * Modules that only implement a few libraries should implement
+ * hook_libraries_info().
+ *
+ * @return
+ *   An array of paths.
+ */
+function hook_libraries_paths() {
+  // Taken from the Libraries test module, which needs to specify the path to
+  // the test library.
+  return array(drupal_get_path('module', 'libraries_test') . '/example');
+}
Index: libraries.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/libraries/libraries.module,v
retrieving revision 1.6
diff -u -p -r1.6 libraries.module
--- libraries.module	23 Jul 2010 12:57:01 -0000	1.6
+++ libraries.module	6 Oct 2010 22:24:51 -0000
@@ -113,6 +113,49 @@ function libraries_get_libraries() {
 }
 
 /**
+ * Looks for library info files.
+ *
+ * This function scans the following directories for info files:
+ * - libraries
+ * - profiles/$profilename/libraries
+ * - sites/all/libraries
+ * - sites/$sitename/libraries
+ * - any directories specified via hook_libraries_info_file_paths()
+ *
+ * @return
+ *   An array of info files, keyed by library name. The values are the paths of
+ *   the files.
+ */
+function libraries_info_files() {
+  global $profile;
+  if (!isset($profile)) {
+    $profile = variable_get('install_profile', 'default');
+  }
+  $config = conf_path();
+
+  // Build a list of directories.
+  $directories = module_invoke_all('libraries_info_file_paths');
+  $directories[] = 'libraries';
+  $directories[] = "libraries/$profile/libraries";
+  $directories[] = 'sites/all/libraries';
+  $directories[] = "sites/$config/libraries";
+
+  // Scan for info files.
+  $files = array();
+  foreach ($directories as $dir) {
+    $files += file_scan_directory($dir, '/[a-z[a-z0-9_]+.info/', array(
+      'key' => 'name',
+      'recurse' => FALSE,
+    ));
+  }
+
+  foreach ($files as &$file) {
+    $file = $file->uri;
+  }
+
+  return $files;
+}
+/**
  * Returns information about registered libraries.
  *
  * The returned information is unprocessed, i.e. as registered by modules.
@@ -140,23 +183,31 @@ function libraries_info($library = NULL)
       foreach (module_invoke($module, 'libraries_info') as $name => $properties) {
         $properties['module'] = $module;
         $properties['name'] = $name;
-
-        $properties += array(
-          'title' => $name,
-          'vendor url' => '',
-          'download url' => '',
-          'path' => '',
-          'version callback' => 'libraries_get_version',
-          'version arguments' => array(),
-          'files' => array(),
-          'variants' => array(),
-          'versions' => array(),
-          'integration files' => array(),
-        );
-
         $libraries[$name] = $properties;
       }
     }
+    // Gather information from .info files.
+    foreach (libraries_info_files() as $name => $path) {
+      $file = "$path/$name.info";
+      $libraries[$name] = drupal_parse_info_file($file);
+    }
+
+    // Provide defaults.
+    foreach ($libraries as $name => &$properties) {
+      $properties += array(
+        'title' => $name,
+        'vendor url' => '',
+        'download url' => '',
+        'path' => '',
+        'version callback' => 'libraries_get_version',
+        'version arguments' => array(),
+        'files' => array(),
+        'variants' => array(),
+        'versions' => array(),
+        'integration files' => array(),
+      );
+    }
+
     // Allow modules to alter the registered libraries.
     drupal_alter('libraries_info', $libraries);
   }
Index: tests/libraries.test
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/libraries/tests/libraries.test,v
retrieving revision 1.4
diff -u -p -r1.4 libraries.test
--- tests/libraries.test	22 Sep 2010 17:00:56 -0000	1.4
+++ tests/libraries.test	6 Oct 2010 22:24:51 -0000
@@ -26,6 +26,22 @@ class LibrariesTestCase extends DrupalWe
    * @todo Better method name(s); split into detection/loading/overloading/etc.
    */
   public function testLibraries() {
+    // Test a library specified with an .info file gets detected.
+    $library = libraries_info('example');
+    $expected = array(
+      'title' => 'example',
+      'vendor url' => '',
+      'download url' => '',
+      'path' => '',
+      'version callback' => 'libraries_get_version',
+      'version arguments' => array(),
+      'files' => array(),
+      'variants' => array(),
+      'versions' => array(),
+      'integration files' => array(),
+    );
+    $this->assertEqual($library, $expected, 'Library specified with an .info file found');
+
     // Test missing library.
     $library = libraries_info('example_missing');
     libraries_detect_library($library);
Index: tests/libraries_test.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/libraries/tests/libraries_test.module,v
retrieving revision 1.3
diff -u -p -r1.3 libraries_test.module
--- tests/libraries_test.module	22 Sep 2010 17:00:56 -0000	1.3
+++ tests/libraries_test.module	6 Oct 2010 22:24:51 -0000
@@ -288,6 +288,13 @@ function libraries_test_libraries_info()
 }
 
 /**
+ * Implements hook_libraries_info_file_paths()
+ */
+function libraries_test_libraries_info_file_paths() {
+  return array(drupal_get_path('module', 'libraries_test') . '/example');
+}
+
+/**
  * Gets the version of an example library.
  *
  * Returns exactly the version string entered as the $version parameter. This
Index: tests/example/example.info
===================================================================
RCS file: tests/example/example.info
diff -N tests/example/example.info
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/example/example.info	6 Oct 2010 22:24:51 -0000
@@ -0,0 +1,7 @@
+; $Id$
+
+; This is an example info file for a library used for testing purposes. It
+; contains no actual library information, but, since it is named example.info,
+; if Libraries API detects a library named 'example', we know that this file was
+; properly detected.
+
