diff --git a/cake/console/libs/task_collection.php b/cake/console/libs/task_collection.php index fe876ed6f..40ed967d5 100644 --- a/cake/console/libs/task_collection.php +++ b/cake/console/libs/task_collection.php @@ -27,6 +27,13 @@ class TaskCollection extends ObjectCollection { protected $_Shell; protected $_Dispatch; +/** + * The directory inside each shell path that contains tasks. + * + * @var string + */ + public $taskPathPrefix = 'tasks/'; + /** * Constructor * @@ -56,8 +63,9 @@ class TaskCollection extends ObjectCollection { $taskFile = Inflector::underscore($name); $taskClass = $name . 'Task'; if (!class_exists($taskClass)) { - $taskFile = $this->_getPath($taskFile); - require_once $taskFile; + if (!App::import('Shell', $plugin . $this->taskPathPrefix . $name)) { + throw new MissingTaskFileException($taskFile . '.php'); + } if (!class_exists($taskClass)) { throw new MissingTaskClassException($taskClass); } @@ -72,21 +80,4 @@ class TaskCollection extends ObjectCollection { return $this->_loaded[$name]; } -/** - * Find a task file on one of the paths. - * - * @param string $file Underscored name of the file to find missing .php - * @return string Filename to the task - * @throws MissingTaskFileException - */ - protected function _getPath($file) { - foreach ($this->_Shell->shellPaths as $path) { - $taskPath = $path . 'tasks' . DS . $file . '.php'; - if (file_exists($taskPath)) { - return $taskPath; - } - } - throw new MissingTaskFileException($file . '.php'); - } - } diff --git a/cake/libs/configure.php b/cake/libs/configure.php index fe0ef2897..9373f907f 100644 --- a/cake/libs/configure.php +++ b/cake/libs/configure.php @@ -1142,6 +1142,15 @@ class App { } return array('class' => $type, 'suffix' => null, 'path' => $path); break; + case 'shell': + if (!class_exists('Shell')) { + App::import($type, 'Shell', false); + } + if ($plugin) { + $path = $pluginPath . DS . 'console' . DS . 'shells' . DS; + } + return array('class' => $type, 'suffix' => null, 'path' => $path); + break; case 'vendor': if ($plugin) { $path = $pluginPath . DS . 'vendors' . DS; diff --git a/cake/tests/cases/console/libs/task_collection.test.php b/cake/tests/cases/console/libs/task_collection.test.php index b277c6c60..da7d6eaef 100644 --- a/cake/tests/cases/console/libs/task_collection.test.php +++ b/cake/tests/cases/console/libs/task_collection.test.php @@ -29,7 +29,6 @@ class TaskCollectionTest extends CakeTestCase { */ function setup() { $shell = $this->getMock('Shell', array(), array(), '', false); - $shell->shellPaths = App::path('shells'); $dispatcher = $this->getMock('ShellDispatcher', array(), array(), '', false); $this->Tasks = new TaskCollection($shell, $dispatcher); } @@ -89,9 +88,9 @@ class TaskCollectionTest extends CakeTestCase { function testLoadPluginTask() { $dispatcher = $this->getMock('ShellDispatcher', array(), array(), '', false); $shell = $this->getMock('Shell', array(), array(), '', false); - $shell->shellPaths = App::path('shells'); - $shell->shellPaths[] = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin' . DS . 'vendors' . DS . 'shells' . DS; - $dispatcher->shellPaths = $shell->shellPaths; + App::build(array( + 'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS) + )); $this->Tasks = new TaskCollection($shell, $dispatcher); $result = $this->Tasks->load('TestPlugin.OtherTask'); diff --git a/cake/tests/test_app/plugins/test_plugin/vendors/shells/example.php b/cake/tests/test_app/plugins/test_plugin/console/shells/example.php similarity index 100% rename from cake/tests/test_app/plugins/test_plugin/vendors/shells/example.php rename to cake/tests/test_app/plugins/test_plugin/console/shells/example.php diff --git a/cake/tests/test_app/plugins/test_plugin/vendors/shells/tasks/empty b/cake/tests/test_app/plugins/test_plugin/console/shells/tasks/empty similarity index 100% rename from cake/tests/test_app/plugins/test_plugin/vendors/shells/tasks/empty rename to cake/tests/test_app/plugins/test_plugin/console/shells/tasks/empty diff --git a/cake/tests/test_app/plugins/test_plugin/vendors/shells/tasks/other_task.php b/cake/tests/test_app/plugins/test_plugin/console/shells/tasks/other_task.php similarity index 100% rename from cake/tests/test_app/plugins/test_plugin/vendors/shells/tasks/other_task.php rename to cake/tests/test_app/plugins/test_plugin/console/shells/tasks/other_task.php diff --git a/cake/tests/test_app/plugins/test_plugin/vendors/shells/templates/empty b/cake/tests/test_app/plugins/test_plugin/console/shells/templates/empty similarity index 100% rename from cake/tests/test_app/plugins/test_plugin/vendors/shells/templates/empty rename to cake/tests/test_app/plugins/test_plugin/console/shells/templates/empty