You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ni...@apache.org on 2015/05/13 23:15:08 UTC

[13/14] cordova-windows git commit: Merge branch 'master' of https://github.com/apache/cordova-windows into windows10

Merge branch 'master' of https://github.com/apache/cordova-windows into windows10

Conflicts:
	template/cordova/lib/prepare.js


Project: http://git-wip-us.apache.org/repos/asf/cordova-windows/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-windows/commit/18e368d7
Tree: http://git-wip-us.apache.org/repos/asf/cordova-windows/tree/18e368d7
Diff: http://git-wip-us.apache.org/repos/asf/cordova-windows/diff/18e368d7

Branch: refs/heads/master
Commit: 18e368d774e777648fc0334ad622060e5ce14504
Parents: e3071ff e5f54f2
Author: Rob Paveza <Ro...@microsoft.com>
Authored: Tue May 12 14:37:22 2015 -0700
Committer: Rob Paveza <Ro...@microsoft.com>
Committed: Tue May 12 14:37:22 2015 -0700

----------------------------------------------------------------------
 bin/lib/create.js                       |  2 +-
 template/cordova/lib/package.js         |  2 +-
 template/cordova/lib/prepare.js         | 23 +++++++++++++++++++++++
 template/package.phone.appxmanifest     |  4 ++--
 template/package.windows.appxmanifest   |  4 ++--
 template/package.windows80.appxmanifest |  4 ++--
 template/www/cordova.js                 | 26 +++++++++++++++++++++++---
 7 files changed, 54 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/18e368d7/bin/lib/create.js
----------------------------------------------------------------------
diff --cc bin/lib/create.js
index 8f323d0,88f708f..55347b0
--- a/bin/lib/create.js
+++ b/bin/lib/create.js
@@@ -74,10 -74,10 +74,10 @@@ module.exports.run = function (argv) 
      }
  
      // replace specific values in manifests' templates
 -    ['package.windows.appxmanifest', 'package.windows80.appxmanifest', 'package.phone.appxmanifest'].forEach(function (file) {
 +    ['package.windows.appxmanifest', 'package.windows80.appxmanifest', 'package.phone.appxmanifest', 'package.windows10.appxmanifest'].forEach(function (file) {
          var fileToReplace = path.join(projectPath, file);
          shell.sed('-i', /\$guid1\$/g, guid, fileToReplace);
-         shell.sed('-i', /\$safeprojectname\$/g, packageName, fileToReplace);
+         shell.sed('-i', /\$packagename\$/g, packageName, fileToReplace);
          shell.sed('-i', /\$projectname\$/g, safeAppName, fileToReplace);
      });
  

http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/18e368d7/template/cordova/lib/package.js
----------------------------------------------------------------------
diff --cc template/cordova/lib/package.js
index 74541aa,158ddf6..5998dff
--- a/template/cordova/lib/package.js
+++ b/template/cordova/lib/package.js
@@@ -99,13 -93,10 +99,13 @@@ module.exports.getAppId = function (pla
  
  // return package name fetched from appxmanifest
  // return rejected promise if appxmanifest not valid
 -module.exports.getPackageName = function (platformPath) {
 +function getPackageName(platformPath) {
 +    // Can reliably read from package.windows.appxmanifest even if targeting Windows 10
 +    // because the function is only used for desktop deployment, which always has the same
 +    // package name when uninstalling / reinstalling
      var manifest = path.join(platformPath, 'package.windows.appxmanifest');
      try {
-         return Q.resolve(/Application Id="(.*?)"/gi.exec(fs.readFileSync(manifest, 'utf8'))[1]);
+         return Q.resolve(/Identity Name="(.*?)"/gi.exec(fs.readFileSync(manifest, 'utf8'))[1]);
      } catch (e) {
          return Q.reject('Can\'t read package name from manifest ' + e);
      }

http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/18e368d7/template/cordova/lib/prepare.js
----------------------------------------------------------------------
diff --cc template/cordova/lib/prepare.js
index 4a02c12,a725363..da3ff24
--- a/template/cordova/lib/prepare.js
+++ b/template/cordova/lib/prepare.js
@@@ -111,17 -81,13 +111,18 @@@ function updateManifestFile (config, ma
  
      var manifest =  new et.ElementTree(et.XML(contents));
  
 -    applyCoreProperties(config, manifest, manifestPath, namespacePrefix);
 +    applyCoreProperties(config, manifest, manifestPath, namespacePrefix, !!uapVersionInfo); 
      // sort Capability elements as per CB-5350 Windows8 build fails due to invalid 'Capabilities' definition
      sortCapabilities(manifest);
 -    applyAccessRules(config, manifest);
 +    applyAccessRules(config, manifest, !!uapVersionInfo); 
      applyBackgroundColor(config, manifest, namespacePrefix);
+     applyToastCapability(config, manifest, namespacePrefix);
  
 +    if (uapVersionInfo) {
 +        applyTargetPlatformVersion(config, manifest, uapVersionInfo);
 +        checkForRestrictedCapabilities(config, manifest);
 +        ensureUapPrefixedCapabilities(manifest.find('.//Capabilities'));
 +    }
  
      //Write out manifest
      fs.writeFileSync(manifestPath, manifest.write({indent: 4}), 'utf-8');
@@@ -150,14 -123,8 +151,15 @@@ function applyCoreProperties(config, ma
      if(!app) {
          throw new Error('Invalid manifest file (no <Application> node): ' + manifestPath);
      }
++    
 +    if (pkgName) {
 +        // 64 symbols restriction goes from manifest schema definition
 +        // http://msdn.microsoft.com/en-us/library/windows/apps/br211415.aspx
 +        var appId = pkgName.length <= 64 ? pkgName : pkgName.substr(0, 64);
 +        app.attrib.Id = appId;
 +    }
  
 -    app.attrib.StartPage = 'www/' + startPage;
 +    applyStartPage(app, config, targetWin10); 
  
      var visualElementsName = './/' + xmlnsPrefix + 'VisualElements'; 
      var visualElems = manifest.find(visualElementsName); 
@@@ -548,175 -383,23 +550,196 @@@ function applyBackgroundColor (config, 
      }
  }
  
 +function applyUAPVersionToProject(projectFilePath, uapVersionInfo) {
 +    var fileContents = fs.readFileSync(projectFilePath).toString().trim();
 +    var xml = et.parse(fileContents);
 +    var tpv = xml.find('./PropertyGroup/TargetPlatformVersion');
 +    var tpmv = xml.find('./PropertyGroup/TargetPlatformMinVersion');
 +
 +    tpv.text = uapVersionInfo.targetUAPVersion.toString();
 +    tpmv.text = uapVersionInfo.minUAPVersion.toString();
 +
 +    fs.writeFileSync(projectFilePath, xml.write({ indent: 4 }), {});
 +}
 +
 +function applyTargetPlatformVersion(config, manifest, uapVersionInfo) {
 +    var dependencies = manifest.find('./Dependencies');
 +    while (dependencies.len() > 0) {
 +        dependencies.delItem(0);
 +    }
 +
 +    var uapVersionSet = getAllMinMaxUAPVersions(config);
 +    var platformNames = Object.keys(uapVersionSet);
 +    for (var i = 0; i < platformNames.length; i++) {
 +        var curTargetPlatformName = platformNames[i];
 +        var curTargetPlatformInfo = uapVersionSet[curTargetPlatformName];
 +
 +        var elem = subElement(dependencies, 'TargetDeviceFamily');
 +        elem.set('Name', curTargetPlatformName);
 +        elem.set('MinVersion', curTargetPlatformInfo.MinVersion.toString());
 +        elem.set('MaxVersionTested', curTargetPlatformInfo.MaxVersionTested.toString());
 +    }
 +}
 +
 +// returns {minUAPVersion: Version, targetUAPVersion: Version} | false
 +function getUAPVersions(config) {
 +    // @param config: ConfigParser
 +    var baselineVersions = MSBuildTools.getAvailableUAPVersions();
 +    if (!baselineVersions || baselineVersions.length === 0) {
 +        return false;
 +    }
 +
 +    baselineVersions.sort(Version.comparer);
 +
 +    return {
 +        minUAPVersion: baselineVersions[0],
 +        targetUAPVersion: baselineVersions[baselineVersions.length - 1]
 +    };
 +}
 +
 +/** 
 + * Gets min/max UAP versions from the configuration.  If no version preferences are
 + * in the configuration file, this will provide Windows.Universal at BASE_UAP_VERSION for both min and max.
 + * This will always return a rational object or will fail; for example, if a platform expects
 + * a higher min-version than max-version, it will raise the max version to the min version.
 + * 
 + * @param config {ConfigParser} The configuration parser
 + * @return An object in the shape of: { 'Windows.Mobile': {'MinVersion': Version, 'MaxVersion': Version } } (where Version is a Version object)
 + * @exception {RangeError} Thrown if a Version string is badly formed.
 + */
 +function getAllMinMaxUAPVersions(config) {
 +    var uapVersionPreferenceTest = /(Microsoft.+?|Windows.+?)\-(MinVersion|MaxVersionTested)/i;
 +    var platformBag = Object.create(null);
 +    var preferenceList = config.getMatchingPreferences(uapVersionPreferenceTest);
 +    preferenceList.forEach(function(verPref) {
 +        var matches = uapVersionPreferenceTest.exec(verPref.name);
 +        // 'matches' should look like: ['Windows.Universal-MinVersion', 'Windows.Universal', 'MinVersion']
 +        var platformName = matches[1];
 +        var versionPropertyName = matches[2];
 +
 +        var platformVersionSet = platformBag[platformName];
 +        if (typeof platformVersionSet === 'undefined') {
 +            platformVersionSet = { };
 +            platformBag[platformName] = platformVersionSet;
 +        }
 +
 +        var versionTest = Version.tryParse(verPref.value);
 +        if (!versionTest) {
 +            throw new RangeError('Could not comprehend a valid version from the string "' + verPref.value + '" of platform-boundary "' + verPref.name + '".');
 +        }
 +
 +        platformVersionSet[versionPropertyName] = versionTest;
 +    });
 +
 +    for (var platformName in platformBag) {
 +        // Go through each and make sure there are min/max set
 +        var versionPref = platformBag[platformName];
 +        if (!versionPref.MaxVersionTested && !!versionPref.MinVersion) { // min is set, but max is not
 +            versionPref.MaxVersionTested = versionPref.MinVersion;
 +        }
 +        else if (!versionPref.MinVersion && !!versionPref.MaxVersionTested) { // max is set, min is not
 +            versionPref.MinVersion = versionPref.MaxVersionTested;
 +        }
 +        else if (!versionPref.MinVersion && !versionPref.MaxVersionTested) { // neither are set
 +            versionPref.MinVersion = BASE_UAP_VERSION;
 +            versionPref.MaxVersionTested = BASE_UAP_VERSION;
 +        } 
 +        else { // both are set
 +            if (versionPref.MinVersion.gt(versionPref.MaxVersionTested)) {
 +                versionPref.MaxVersionTested = versionPref.MinVersion;
 +            }
 +        }
 +    }
 +
 +    if (Object.keys(platformBag).length === 0) {
 +        platformBag['Windows.Universal'] = { MinVersion: BASE_UAP_VERSION, MaxVersionTested: BASE_UAP_VERSION };
 +    }
 +
 +    return platformBag;
 +}
 +
 +/**
 + * Checks to see whether access rules or 
 + * @param config {ConfigParser} The configuration parser
 + * @return {boolean} True if the config specifies remote URIs for access or start; false otherwise.
 + */
 +function checkForRemoteModeUris(config) {
 +    var accessRules = config.getNavigationWhitelistRules();
 +    var startPage = config.startPage();
 +    var test = /(https?|ms-appx-web):\/\//i;
 +
 +    var hasRemoteUri = test.test(startPage);
 +    hasRemoteUri = hasRemoteUri || accessRules.some(function(rule) {
 +        return test.test(rule);
 +    });
 +
 +    return hasRemoteUri;
 +}
 +
 +/** 
 + * Checks for capabilities which are Restricted in Windows 10 UAP.
 + * @param appxManifestCapabilitiesElement {ElementTree.Element} The appx manifest element for <capabilities>
 + * @return {string[]|false} An array of restricted capability names, or false.
 + */
 +function checkForRestrictedRemoteCapabilityDeclarations(appxManifestCapabilitiesElement) {
 +    if (!appxManifestCapabilitiesElement)
 +        return false;
 +
 +    var hasRestrictedCapabilities = false;
 +    var foundRestrictedCapabilities = [];
 +
 +    var children = appxManifestCapabilitiesElement.getchildren();
 +    var declaredCapabilities = children.map(function(el) {
 +        return el.attrib.Name;
 +    });
 +
 +    UAP_RESTRICTED_CAPS.forEach(function(cap) {
 +        if (declaredCapabilities.indexOf(cap) > -1) {
 +            hasRestrictedCapabilities = true;
 +            foundRestrictedCapabilities.push(cap);
 +        }
 +    });
 +
 +    return hasRestrictedCapabilities ? foundRestrictedCapabilities : hasRestrictedCapabilities;
 +}
 +
 +/**
 + * Checks for capabilities which require the uap: prefix in Windows 10.
 + * @param appxManifestCapabilitiesElement {ElementTree.Element} The appx manifest element for <capabilities>
 + */
 +function ensureUapPrefixedCapabilities(appxManifestCapabilitiesElement) {
 +    var children = appxManifestCapabilitiesElement.getchildren();
 +    var declaredCapabilities = children.map(function(el) {
 +        return { name: el.attrib.Name, element: el, elementName: el.tag };
 +    });
 +
 +    declaredCapabilities.forEach(function(cap) {
 +        if (CAPS_NEEDING_UAPNS.indexOf(cap.name) > -1) {
 +            if (cap.elementName.indexOf('uap:') === -1) {
 +                cap.elementName = 'uap:' + cap.elementName;
 +                cap.element.tag = cap.elementName;
 +            }
 +        }
 +    });
 +}
++
+ /**
+  * Applies the ToastCapable attribute to the VisualElements tag
+  * @param config {ConfigParser} The configuration reader
+  * @param manifest {et.ElementTree} The manifest file
+  * @namespacePrefix {String} The XML namespace for the VisualElements tag, in the form 'm2:'
+  */
+ function applyToastCapability(config, manifest, namespacePrefix) {
+     var isToastCapable = config.getPreference('WindowsToastCapable');
+     isToastCapable = (isToastCapable && isToastCapable.toString().toLowerCase() === 'true');
+     
+     var visualElementsName = './/' + namespacePrefix + 'VisualElements';
+     var visualElems = manifest.find(visualElementsName);
+     
+     if (isToastCapable) {
+         visualElems.attrib.ToastCapable = 'true';
+     }
+     else {
+         delete visualElems.attrib.ToastCapable;
+     } 
+ }

http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/18e368d7/template/www/cordova.js
----------------------------------------------------------------------


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org