GitHub PullRequestReviewCommentEvent at 2014-05-05 13:27:42
Repository: gaia
Actor: ochameau
Payload: {"comment":{"url":"https://api.github.com/repos/mozilla-b2g/gaia/pulls/comments/12278241","id":12278241,"diff_hunk":"@@ -1,363 +1,171 @@\n-var utils = require('./utils');\n-var config;\n-const { Cc, Ci, Cr, Cu } = require('chrome');\n-Cu.import('resource://gre/modules/Services.jsm');\n-\n-const INSTALL_TIME = Date.now();\n-const UPDATE_TIME = Date.now();\n-const DEBUG = false;\n-// Match this to value in applications-data.js\n-\n-function debug(msg) {\n-//  dump('-*- webapp-manifest.js: ' + msg + '\\n');\n-}\n-\n-let io = Cc['@mozilla.org/network/io-service;1']\n-           .getService(Ci.nsIIOService);\n-\n-let webappsTargetDir = Cc['@mozilla.org/file/local;1']\n-               .createInstance(Ci.nsILocalFile);\n-\n-let uuidGenerator = Cc['@mozilla.org/uuid-generator;1']\n-                      .createInstance(Ci.nsIUUIDGenerator);\n-\n-let manifests = {};\n-let webapps = {};\n-\n-let id = 1;\n-\n-function copyRec(source, target) {\n-  let results = [];\n-  let files = source.directoryEntries;\n-  if (!target.exists())\n-    target.create(Ci.nsIFile.DIRECTORY_TYPE, parseInt('0755', 8));\n-\n-  while (files.hasMoreElements()) {\n-    let file = files.getNext().QueryInterface(Ci.nsILocalFile);\n-    if (file.isDirectory()) {\n-      let subFolder = target.clone();\n-      subFolder.append(file.leafName);\n-      copyRec(file, subFolder);\n-    } else {\n-      file.copyTo(target, file.leafName);\n-    }\n-  }\n-}\n-\n-// Returns the nsIPrincipal compliant integer\n-// from the \"type\" property in manifests.\n-function getAppStatus(status) {\n-  let appStatus = 1; // By default, apps are installed\n-  switch (status) {\n-    case 'certified':\n-      appStatus = 3;\n-      break;\n-    case 'privileged':\n-      appStatus = 2;\n-      break;\n-    case 'web':\n-    default:\n-      appStatus = 1;\n-      break;\n-  }\n-  return appStatus;\n-}\n-\n-function checkOrigin(origin) {\n-  try {\n-    return (io.newURI(origin, null, null).prePath === origin);\n-  } catch (e) {\n-    return false;\n-  }\n-}\n+// Generate webapps_stage.json.\n \n-/**\n- * Updates hostnames for InterApp Communication APIs\n- */\n-function manifestInterAppHostnames(webapp, webappTargetDir) {\n-  function convertToLocalUrl(url) {\n-    var host = config.GAIA_DOMAIN + config.GAIA_PORT;\n-\n-    return url\n-      .replace(/^(http|app):\\/\\//, config.GAIA_SCHEME)\n-      .replace(/gaiamobile.org(:[0-9])?/, host);\n-  }\n-\n-  let manifest = utils.getJSON(\n-    utils.getFile(webappTargetDir.path, 'manifest.webapp'));\n-\n-  if (manifest.connections) {\n-    for (let i in manifest.connections) {\n-      let connection = manifest.connections[i];\n-      if (!connection.rules || !connection.rules.manifestURLs) {\n-        continue;\n-      }\n-\n-      var manifestURLs = connection.rules.manifestURLs;\n-      manifestURLs.forEach(function(url, idx) {\n-        manifestURLs[idx] = convertToLocalUrl(url);\n-      });\n-    }\n-    utils.writeContent(utils.getFile(webappTargetDir.path, 'manifest.webapp'),\n-                       JSON.stringify(manifest));\n-  }\n-}\n-\n-function fillAppManifest(webapp) {\n-  // Compute webapp folder name in profile\n-  let webappTargetDirName = webapp.domain;\n-\n-  // Copy webapp's manifest to the profile\n-  let webappTargetDir = webappsTargetDir.clone();\n-  webappTargetDir.append(webappTargetDirName);\n-  utils.ensureFolderExists(webappTargetDir);\n-  let gaia = utils.gaia.getInstance(config);\n-\n-  if (gaia.l10nManager) {\n-    let manifest = gaia.l10nManager.localizeManifest(webapp);\n-    manifestFile = webappTargetDir.clone();\n-    utils.ensureFolderExists(webappTargetDir);\n-    manifestFile.append('manifest.webapp');\n-    let args = DEBUG ? [manifest, undefined, 2] : [manifest];\n-    utils.writeContent(manifestFile, JSON.stringify.apply(JSON, args));\n-  } else {\n-    webapp.manifestFile.copyTo(webappTargetDir, 'manifest.webapp');\n-  }\n-\n-  manifestInterAppHostnames(webapp, webappTargetDir);\n-\n-  // Add webapp's entry to the webapps global manifest.\n-  // appStatus == 3 means this is a certified app.\n-  // appStatus == 2 means this is a privileged app.\n-  // appStatus == 1 means this is an installed (unprivileged) app\n-\n-  var localId = id++;\n-  let url = webapp.url;\n-  manifests[webappTargetDirName] = {\n-    origin: url,\n-    installOrigin: url,\n-    receipt: null,\n-    installTime: INSTALL_TIME,\n-    updateTime: UPDATE_TIME,\n-    manifestURL: url + '/manifest.webapp',\n-    appStatus: getAppStatus(webapp.manifest.type),\n-    localId: localId\n-  };\n-\n-  webapps[webapp.sourceDirectoryName] = webapp;\n-  webapps[webapp.sourceDirectoryName].webappsJson = manifests[webappTargetDirName];\n-}\n-\n-let errors = [];\n-\n-function fillExternalAppManifest(webapp) {\n-  // Report an error if the app is packaged and has a origin on the metadata file.\n-  let type = getAppStatus(webapp.metaData.type);\n-  let isPackaged = false;\n+var utils = require('./utils');\n \n+var ManifestBuilder = function() {\n+  this.INSTALL_TIME = Date.now();\n+  this.UPDATE_TIME = Date.now();\n+};\n+\n+ManifestBuilder.prototype.setConfig = function(config) {\n+  this.id = 1;\n+  this.config = config;\n+  this.errors = [];\n+  this.gaia = utils.gaia.getInstance(this.config);\n+  this.stageManifests = {};\n+  this.manifests = {};\n+  this.webapps = {};\n+  this.stageDir = utils.getFile(this.config.STAGE_DIR);","path":"build/webapp-manifests.js","position":173,"original_position":173,"commit_id":"6951cec0cef4953c86d0a70fd52e54b9a686aa9b","original_commit_id":"6951cec0cef4953c86d0a70fd52e54b9a686aa9b","user":{"login":"ochameau","id":199907,"avatar_url":"https://avatars.githubusercontent.com/u/199907?","gravatar_id":"da6d769a219551f618ed95bff2c36aca","url":"https://api.github.com/users/ochameau","html_url":"https://github.com/ochameau","followers_url":"https://api.github.com/users/ochameau/followers","following_url":"https://api.github.com/users/ochameau/following{/other_user}","gists_url":"https://api.github.com/users/ochameau/gists{/gist_id}","starred_url":"https://api.github.com/users/ochameau/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ochameau/subscriptions","organizations_url":"https://api.github.com/users/ochameau/orgs","repos_url":"https://api.github.com/users/ochameau/repos","events_url":"https://api.github.com/users/ochameau/events{/privacy}","received_events_url":"https://api.github.com/users/ochameau/received_events","type":"User","site_admin":false},"body":"nit: you might define stageDir in gaia.getInstance to prevent doing this here and in copy-build-stage-data.js's execute().","created_at":"2014-05-05T13:27:42Z","updated_at":"2014-05-05T13:27:42Z","html_url":"https://github.com/mozilla-b2g/gaia/pull/18317#discussion_r12278241","pull_request_url":"https://api.github.com/repos/mozilla-b2g/gaia/pulls/18317","_links":{"self":{"href":"https://api.github.com/repos/mozilla-b2g/gaia/pulls/comments/12278241"},"html":{"href":"https://github.com/mozilla-b2g/gaia/pull/18317#discussion_r12278241"},"pull_request":{"href":"https://api.github.com/repos/mozilla-b2g/gaia/pulls/18317"}}}}