/**
 * Copyright 2013 Intel Corporate Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * grunt-tizen: Tizen-related tasks for grunt
 */
var bridgeMaker = require('../lib/bridge-maker');
var tizenConfigMaker = require('../lib/tizen-config-maker');
var tasksMaker = require('../lib/tasks-maker');

module.exports = function (grunt) {
  'use strict';

  var makeTasks = function (config) {
    var bridge = bridgeMaker(config);
    var tizenConfig = tizenConfigMaker(config);
    return tasksMaker({bridge: bridge, tizenConfig: tizenConfig});
  };

  /**
   * tizen_prepare
   * Task to push the tizen-app.sh script to the device.
   *
   * See README.md for details.
   */
  grunt.registerTask(
    'tizen_prepare',
    'Prepare for Tizen grunt tasks',
    function () {
      var config = grunt.config.get('tizen_configuration');
      config.logger = grunt.log;

      var done = this.async();

      try {
        makeTasks(config).tizenPrepareTask.call(this, done);
      }
      catch (e) {
        grunt.fatal(e);
      }
    }
  );

  /**
   * tizen
   * Task to wrap sdb on the host and related commands on the target
   * device.
   *
   * See README.md for details.
   */
  grunt.registerMultiTask(
    'tizen',
    'manage Tizen applications',
    function () {
      var config = grunt.config.get('tizen_configuration');
      config.logger = grunt.log;

      var data = this.data;
      var done = this.async();

      try {
        makeTasks(config).tizenTask.call(this, data, done);
      }
      catch (e) {
        grunt.fatal(e);
      }
    }
  );
};

@@ -864,16 +864,335 @@
 rict';%0A%0A
+  // the tasks have to be constructed on the fly,%0A  // as the configuration they need is not available until the point%0A  // where a task is invoked from grunt; however, we can cache%0A  // them once we've generated them, as they will not change for%0A  // any particular sequence of tasks run together%0A  var tasks = null;%0A%0A
   var ma
@@ -1217,24 +1217,44 @@
  (config) %7B%0A
+    if (!tasks) %7B%0A  
     var brid
@@ -1275,24 +1275,26 @@
 er(config);%0A
+  
     var tize
@@ -1337,14 +1337,17 @@
     
-return
+  tasks =
  tas
@@ -1399,16 +1399,41 @@
 nfig%7D);%0A
+    %7D%0A%0A    return tasks;%0A
   %7D;%0A%0A  

Explain why task functions are constructed for each grunt task