From f75dcd9ad30f508b4f8e7151ae81dcefaa1a83a2 Mon Sep 17 00:00:00 2001 From: Florian Pechwitz Date: Fri, 12 May 2017 11:58:51 +0200 Subject: [PATCH 01/15] Added windows support --- plugin.xml | 70 +++++++++++++++++++---------------- src/windows/BuildInfoProxy.js | 19 ++++++++++ 2 files changed, 57 insertions(+), 32 deletions(-) create mode 100644 src/windows/BuildInfoProxy.js diff --git a/plugin.xml b/plugin.xml index 4b7ea06..e0695d2 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,39 +1,45 @@ - BuildInfo - Cordova/Phonegap Build Information Plugin. Get PackageName, Version, Debug and more... - MIT - debug,buildconfig,buildinfo,phonegap,cordova - Mikihiro Hayashi + xmlns="http://apache.org/cordova/ns/plugins/1.0" + xmlns:android="http://schemas.android.com/apk/res/android" + id="cordova-plugin-buildinfo" + version="1.1.0"> + BuildInfo + Cordova/Phonegap Build Information Plugin. Get PackageName, Version, Debug and more... + MIT + debug,buildconfig,buildinfo,phonegap,cordova + Mikihiro Hayashi - - - + + + - - - + + + - - - - - - - - + + + + + + + + - - - - - - - - - + + + + + + + + + + + + + + + diff --git a/src/windows/BuildInfoProxy.js b/src/windows/BuildInfoProxy.js new file mode 100644 index 0000000..28e4627 --- /dev/null +++ b/src/windows/BuildInfoProxy.js @@ -0,0 +1,19 @@ +cordova.define("cordova-plugin-buildinfo.BuildInfoProxy", function (require, exports, module) { + BuildInfoProxy = { + init: function (successCallback, errorCallback, args) { + var res = {}; + var packId = Windows.ApplicationModel.Package.current.id; + res.packageName = packId.name; + res.basePackageName = packId.name; + res.displayName = Windows.ApplicationModel.Package.current.displayName; + res.name = Windows.ApplicationModel.Package.current.displayName; + var version = packId.version; + res.version = [version.major, version.minor, version.build].join('.'); + res.versionCode = packId.version.build; + res.debug = Windows.ApplicationModel.Package.current.isDevelopmentMode; + res.buildType = (res.debug) ? "debug" : "release"; + successCallback(res); + } + }; + cordova.commandProxy.add("BuildInfo", BuildInfoProxy); +}); From bef7b24513b62cb1bd287c1985a3e977d36e41d0 Mon Sep 17 00:00:00 2001 From: Florian Pechwitz Date: Fri, 12 May 2017 15:29:20 +0200 Subject: [PATCH 02/15] Fixed windows support platform --- src/windows/BuildInfoProxy.js | 36 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/src/windows/BuildInfoProxy.js b/src/windows/BuildInfoProxy.js index 28e4627..fa383a7 100644 --- a/src/windows/BuildInfoProxy.js +++ b/src/windows/BuildInfoProxy.js @@ -1,19 +1,17 @@ -cordova.define("cordova-plugin-buildinfo.BuildInfoProxy", function (require, exports, module) { - BuildInfoProxy = { - init: function (successCallback, errorCallback, args) { - var res = {}; - var packId = Windows.ApplicationModel.Package.current.id; - res.packageName = packId.name; - res.basePackageName = packId.name; - res.displayName = Windows.ApplicationModel.Package.current.displayName; - res.name = Windows.ApplicationModel.Package.current.displayName; - var version = packId.version; - res.version = [version.major, version.minor, version.build].join('.'); - res.versionCode = packId.version.build; - res.debug = Windows.ApplicationModel.Package.current.isDevelopmentMode; - res.buildType = (res.debug) ? "debug" : "release"; - successCallback(res); - } - }; - cordova.commandProxy.add("BuildInfo", BuildInfoProxy); -}); +BuildInfoProxy = { + init: function (successCallback, errorCallback, args) { + var res = {}; + var packId = Windows.ApplicationModel.Package.current.id; + res.packageName = packId.name; + res.basePackageName = packId.name; + res.displayName = Windows.ApplicationModel.Package.current.displayName; + res.name = Windows.ApplicationModel.Package.current.displayName; + var version = packId.version; + res.version = [version.major, version.minor, version.build].join('.'); + res.versionCode = packId.version.build; + res.debug = Windows.ApplicationModel.Package.current.isDevelopmentMode; + res.buildType = (res.debug) ? "debug" : "release"; + successCallback(res); + } +}; +cordova.commandProxy.add("BuildInfo", BuildInfoProxy); \ No newline at end of file From b3c616595ca3226c4f11430afc73a7775b9d272a Mon Sep 17 00:00:00 2001 From: Henry Moews Date: Fri, 18 Aug 2017 18:19:50 +0200 Subject: [PATCH 03/15] added build date and time for both iOS and Android --- src/android/BuildInfo.java | 34 ++++++++++++++++++++++++++++++---- src/ios/CDVBuildInfo.m | 21 ++++++++++++++++++--- www/buildinfo.js | 5 +++++ 3 files changed, 53 insertions(+), 7 deletions(-) diff --git a/src/android/BuildInfo.java b/src/android/BuildInfo.java index b86aa7d..1b515e3 100644 --- a/src/android/BuildInfo.java +++ b/src/android/BuildInfo.java @@ -25,6 +25,8 @@ of this software and associated documentation files (the "Software"), to deal package org.apache.cordova.buildinfo; import android.app.Activity; +import android.content.Context; +import android.content.pm.ApplicationInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.util.Log; @@ -35,7 +37,10 @@ of this software and associated documentation files (the "Software"), to deal import org.json.JSONException; import org.json.JSONObject; +import java.io.File; import java.lang.reflect.Field; +import java.text.SimpleDateFormat; +import java.util.TimeZone; /** * BuildInfo Cordova Plugin @@ -145,8 +150,9 @@ private void init(String buildConfigClassName, CallbackContext callbackContext) mBuildInfoCache.put("name" , displayName); // same as displayName mBuildInfoCache.put("version" , getClassFieldString(c, "VERSION_NAME", "")); mBuildInfoCache.put("versionCode" , getClassFieldInt(c, "VERSION_CODE", 0)); - mBuildInfoCache.put("debug" , debug); - mBuildInfoCache.put("buildType" , getClassFieldString(c, "BUILD_TYPE", "")); + mBuildInfoCache.put("debug" , debug); + mBuildInfoCache.put("buildTime" , getAppTimeStamp(activity)); + mBuildInfoCache.put("buildType" , getClassFieldString(c, "BUILD_TYPE", "")); mBuildInfoCache.put("flavor" , getClassFieldString(c, "FLAVOR", "")); if (debug) { @@ -156,8 +162,9 @@ private void init(String buildConfigClassName, CallbackContext callbackContext) Log.d(TAG, "name : \"" + mBuildInfoCache.getString("name") + "\""); Log.d(TAG, "version : \"" + mBuildInfoCache.getString("version") + "\""); Log.d(TAG, "versionCode : " + mBuildInfoCache.getInt("versionCode")); - Log.d(TAG, "debug : " + (mBuildInfoCache.getBoolean("debug") ? "true" : "false")); - Log.d(TAG, "buildType : \"" + mBuildInfoCache.getString("buildType") + "\""); + Log.d(TAG, "debug : " + (mBuildInfoCache.getBoolean("debug") ? "true" : "false")); + Log.d(TAG, "buildTime : \"" + mBuildInfoCache.getString("buildTime") + "\""); + Log.d(TAG, "buildType : \"" + mBuildInfoCache.getString("buildType") + "\""); Log.d(TAG, "flavor : \"" + mBuildInfoCache.getString("flavor") + "\""); } } catch (JSONException e) { @@ -252,4 +259,23 @@ private static Field getClassField(Class c, String fieldName) { return field; } + + private static String getAppTimeStamp(Context context) { + String timeStamp = ""; + + try { + ApplicationInfo appInfo = context.getPackageManager().getApplicationInfo(context.getPackageName(), 0); + String appFile = appInfo.sourceDir; + long time = new File(appFile).lastModified(); + + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); + timeStamp = formatter.format(time); + + } catch (Exception e) { + e.printStackTrace(); + } + + return timeStamp; + + } } diff --git a/src/ios/CDVBuildInfo.m b/src/ios/CDVBuildInfo.m index a68f1ca..02c1b3e 100644 --- a/src/ios/CDVBuildInfo.m +++ b/src/ios/CDVBuildInfo.m @@ -37,7 +37,20 @@ - (void)init:(CDVInvokedUrlCommand*)command #else NSNumber* debug = [NSNumber numberWithBool:NO]; #endif - + + // timestamp at compile time + NSString *compileDate = [NSString stringWithUTF8String:__DATE__]; + NSString *compileTime = [NSString stringWithUTF8String:__TIME__]; + + NSDateFormatter *dfParser = [[NSDateFormatter alloc] init]; + [dfParser setDateFormat:@"MMM d yyyy"]; + NSDate *buildDate = [dfParser dateFromString:compileDate]; + + NSDateFormatter *dfOutput = [[NSDateFormatter alloc] init]; + [dfOutput setDateFormat:@"yyyy-MM-dd"]; + + NSString *buildTime = [NSString stringWithFormat:@"%@T%@Z", [dfOutput stringFromDate:buildDate], compileTime]; + NSDictionary* result = @{ @"packageName" : [bundle bundleIdentifier], @"basePackageName": [bundle bundleIdentifier], @@ -46,6 +59,7 @@ - (void)init:(CDVInvokedUrlCommand*)command @"version" : [info objectForKey:@"CFBundleShortVersionString"], @"versionCode" : [info objectForKey:@"CFBundleVersion"], @"debug" : debug, + @"buildTime" : buildTime, @"buildType" : @"", // Android Only @"flavor" : @"" // Android Only }; @@ -57,8 +71,9 @@ - (void)init:(CDVInvokedUrlCommand*)command NSLog(@"BuildInfo name : \"%@\"", [result objectForKey:@"name"]); NSLog(@"BuildInfo version : \"%@\"", [result objectForKey:@"version"]); NSLog(@"BuildInfo versionCode : \"%@\"", [result objectForKey:@"versionCode"]); - NSLog(@"BuildInfo debug : %@" , [[result objectForKey:@"debug"] boolValue] ? @"YES" : @"NO"); - NSLog(@"BuildInfo buildType : \"%@\"", [result objectForKey:@"buildType"]); + NSLog(@"BuildInfo debug : %@" , [[result objectForKey:@"debug"] boolValue] ? @"YES" : @"NO"); + NSLog(@"BuildInfo buildType : \"%@\"", [result objectForKey:@"buildType"]); + NSLog(@"BuildInfo buildTime : \"%@\"", [result objectForKey:@"buildTime"]); NSLog(@"BuildInfo flavor : \"%@\"", [result objectForKey:@"flavor"]); } diff --git a/www/buildinfo.js b/www/buildinfo.js index 3eb8a43..497411e 100644 --- a/www/buildinfo.js +++ b/www/buildinfo.js @@ -33,6 +33,7 @@ module.exports = { version: '', versionCode: 0, debug: false, + buildTime: '', buildType: '', flavor: '' }; @@ -90,6 +91,10 @@ channel.onCordovaReady.subscribe(function () { if ('undefined' !== typeof res.flavor) { module.exports.flavor = res.flavor; } + + if ('undefined' !== typeof res.buildTime) { + module.exports.buildTime = res.buildTime; + } }, function (msg) { console.error('BuildInfo init fail'); From 91728630b0d9933b0874967bf7b059950fe6d078 Mon Sep 17 00:00:00 2001 From: Henry Moews Date: Fri, 18 Aug 2017 18:23:55 +0200 Subject: [PATCH 04/15] updated readme --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index 78ec3ea..bce502e 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ function onDeviceReady() { console.log('BuildInfo.version =' + BuildInfo.version); console.log('BuildInfo.versionCode =' + BuildInfo.versionCode); console.log('BuildInfo.debug =' + BuildInfo.debug); + console.log('BuildInfo.buildTime =' + BuildInfo.buildTime); console.log('BuildInfo.buildType =' + BuildInfo.buildType); console.log('BuildInfo.flavor =' + BuildInfo.flavor); } @@ -44,6 +45,7 @@ cordova plugin add cordova-plugin-buildinfo - `BuildInfo.version` - `BuildInfo.versionCode` - `BuildInfo.debug` +- `BuildInfo.buildTime` - `BuildInfo.buildType` - `BuildInfo.flavor` @@ -122,6 +124,20 @@ Get the debug flag. |iOS|defined "DEBUG" is true|Boolean| +### BuildInfo.buildTime + +Get the build date and time in the same format new Date().toJSON() returns. + +Attention: There is no information about the timezones saved. +iOS: The iOS date is written in developer local time but interpreted in UTC +Android: The Android date is written in developer's local time and interpret in user's local time + +|Platform|Value|Type| +|--------|-----|----| +|Android|Datetime of last build folder modification|String| +|iOS|Combination of __DATE__ and __TIME__ |String| + + ### BuildInfo.buildType Android Only. From 440176b5ff58d941633461ed334076a921c4bae4 Mon Sep 17 00:00:00 2001 From: Henry Moews Date: Fri, 18 Aug 2017 18:36:30 +0200 Subject: [PATCH 05/15] corrected formatting in README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index bce502e..95d8340 100644 --- a/README.md +++ b/README.md @@ -129,13 +129,13 @@ Get the debug flag. Get the build date and time in the same format new Date().toJSON() returns. Attention: There is no information about the timezones saved. -iOS: The iOS date is written in developer local time but interpreted in UTC -Android: The Android date is written in developer's local time and interpret in user's local time +- iOS: The iOS date is written in developer local time but interpreted in UTC +- Android: The Android date is written in developer's local time and interpret in user's local time |Platform|Value|Type| |--------|-----|----| |Android|Datetime of last build folder modification|String| -|iOS|Combination of __DATE__ and __TIME__ |String| +|iOS|Combination of \_\_DATE\_\_ and \_\_TIME\_\_ |String| ### BuildInfo.buildType From 116221962100676da07ab6c585c6e81e757f0261 Mon Sep 17 00:00:00 2001 From: Henry Moews Date: Fri, 18 Aug 2017 18:38:35 +0200 Subject: [PATCH 06/15] changed code formatting from spaces to tabs to have fewer changes in pull request --- src/android/BuildInfo.java | 12 ++++++------ src/ios/CDVBuildInfo.m | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/android/BuildInfo.java b/src/android/BuildInfo.java index 1b515e3..6375eb8 100644 --- a/src/android/BuildInfo.java +++ b/src/android/BuildInfo.java @@ -150,9 +150,9 @@ private void init(String buildConfigClassName, CallbackContext callbackContext) mBuildInfoCache.put("name" , displayName); // same as displayName mBuildInfoCache.put("version" , getClassFieldString(c, "VERSION_NAME", "")); mBuildInfoCache.put("versionCode" , getClassFieldInt(c, "VERSION_CODE", 0)); - mBuildInfoCache.put("debug" , debug); - mBuildInfoCache.put("buildTime" , getAppTimeStamp(activity)); - mBuildInfoCache.put("buildType" , getClassFieldString(c, "BUILD_TYPE", "")); + mBuildInfoCache.put("debug" , debug); + mBuildInfoCache.put("buildTime" , getAppTimeStamp(activity)); + mBuildInfoCache.put("buildType" , getClassFieldString(c, "BUILD_TYPE", "")); mBuildInfoCache.put("flavor" , getClassFieldString(c, "FLAVOR", "")); if (debug) { @@ -162,9 +162,9 @@ private void init(String buildConfigClassName, CallbackContext callbackContext) Log.d(TAG, "name : \"" + mBuildInfoCache.getString("name") + "\""); Log.d(TAG, "version : \"" + mBuildInfoCache.getString("version") + "\""); Log.d(TAG, "versionCode : " + mBuildInfoCache.getInt("versionCode")); - Log.d(TAG, "debug : " + (mBuildInfoCache.getBoolean("debug") ? "true" : "false")); - Log.d(TAG, "buildTime : \"" + mBuildInfoCache.getString("buildTime") + "\""); - Log.d(TAG, "buildType : \"" + mBuildInfoCache.getString("buildType") + "\""); + Log.d(TAG, "debug : " + (mBuildInfoCache.getBoolean("debug") ? "true" : "false")); + Log.d(TAG, "buildTime : \"" + mBuildInfoCache.getString("buildTime") + "\""); + Log.d(TAG, "buildType : \"" + mBuildInfoCache.getString("buildType") + "\""); Log.d(TAG, "flavor : \"" + mBuildInfoCache.getString("flavor") + "\""); } } catch (JSONException e) { diff --git a/src/ios/CDVBuildInfo.m b/src/ios/CDVBuildInfo.m index 02c1b3e..a34b232 100644 --- a/src/ios/CDVBuildInfo.m +++ b/src/ios/CDVBuildInfo.m @@ -59,7 +59,7 @@ - (void)init:(CDVInvokedUrlCommand*)command @"version" : [info objectForKey:@"CFBundleShortVersionString"], @"versionCode" : [info objectForKey:@"CFBundleVersion"], @"debug" : debug, - @"buildTime" : buildTime, + @"buildTime" : buildTime, @"buildType" : @"", // Android Only @"flavor" : @"" // Android Only }; @@ -71,9 +71,9 @@ - (void)init:(CDVInvokedUrlCommand*)command NSLog(@"BuildInfo name : \"%@\"", [result objectForKey:@"name"]); NSLog(@"BuildInfo version : \"%@\"", [result objectForKey:@"version"]); NSLog(@"BuildInfo versionCode : \"%@\"", [result objectForKey:@"versionCode"]); - NSLog(@"BuildInfo debug : %@" , [[result objectForKey:@"debug"] boolValue] ? @"YES" : @"NO"); - NSLog(@"BuildInfo buildType : \"%@\"", [result objectForKey:@"buildType"]); - NSLog(@"BuildInfo buildTime : \"%@\"", [result objectForKey:@"buildTime"]); + NSLog(@"BuildInfo debug : %@" , [[result objectForKey:@"debug"] boolValue] ? @"YES" : @"NO"); + NSLog(@"BuildInfo buildType : \"%@\"", [result objectForKey:@"buildType"]); + NSLog(@"BuildInfo buildTime : \"%@\"", [result objectForKey:@"buildTime"]); NSLog(@"BuildInfo flavor : \"%@\"", [result objectForKey:@"flavor"]); } From 62c9a7f57e37b6800303321649f6bd6eec265c73 Mon Sep 17 00:00:00 2001 From: Mikihiro Hayashi Date: Mon, 4 Sep 2017 01:05:19 +0900 Subject: [PATCH 07/15] Add: BuildInfo.windows properties Change: The value of BuildInfo.displayName is obtained from the AppxManifest.xml file. --- README.md | 62 ++++++++++++++++++++++- src/windows/BuildInfoProxy.js | 92 +++++++++++++++++++++++++++++++++-- tests/package.json | 25 ++++++++++ www/buildinfo.js | 4 ++ 4 files changed, 177 insertions(+), 6 deletions(-) create mode 100644 tests/package.json diff --git a/README.md b/README.md index 78ec3ea..4d60d60 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ cordova plugin add cordova-plugin-buildinfo * Android * iOS +* Windows ## Properties @@ -46,6 +47,10 @@ cordova plugin add cordova-plugin-buildinfo - `BuildInfo.debug` - `BuildInfo.buildType` - `BuildInfo.flavor` +- `BuildInfo.windows` + - `logo` + - `version` + ### BuildInfo.packageName @@ -55,6 +60,7 @@ Get the packageName of Application ID. |--------|-----|----| |Android|Package Name|String| |iOS|Bundle Identifier|String| +|Windows|Identity name|String| ### BuildInfo.basePackageName @@ -71,6 +77,7 @@ If you use the configure of "build types" or "product flavors", because you can |--------|-----|----| |Android|Package name of BuildConfig class|String| |iOS|Bundle Identifier(equals BuildInfo.packageName)|String| +|Windows|Identity name(equals BuildInfo.packageName)|String| ### BuildInfo.displayName @@ -81,6 +88,7 @@ Get the displayName. |--------|-----|----| |Android|Application Label|String| |iOS|CFBundleDisplayName|String| +|Windows|Display a package name|String| ### BuildInfo.name @@ -90,6 +98,7 @@ Get the name. |--------|-----|----| |Android|Application Label(equal BuildInfo.displayName)|String| |iOS|CFBundleName|String| +|Windows|Windows Store display name|String| ### BuildInfo.version @@ -100,6 +109,7 @@ Get the version. |--------|-----|----| |Android|BuildConfig.VERSION_NAME|String| |iOS|CFBundleShortVersionString|String| +|Windows|Major . Minor . Build|String| ### BuildInfo.versionCode @@ -110,6 +120,7 @@ Get the version code. |--------|-----|----| |Android|BuildConfig.VERSION_CODE|int| |iOS|CFBundleVersion|string| +|Windows|Major . Minor . Build . Revision|String| ### BuildInfo.debug @@ -120,11 +131,12 @@ Get the debug flag. |--------|-----|----| |Android|BuildConfig.DEBUG|Boolean |iOS|defined "DEBUG" is true|Boolean| +|Windows|isDevelopmentMode is true|Boolean| ### BuildInfo.buildType -Android Only. +Android , Windows Only. Get the build type. @@ -132,6 +144,7 @@ Get the build type. |--------|-----|----| |Android|BuildConfig.BUILD_TYPE|String| |iOS|empty string|String| +|Windows|"release" or "debug"|String| ### BuildInfo.flavor @@ -144,3 +157,50 @@ Get the flavor. |--------|-----|----| |Android|BuildConfig.FLAVOR|String| |iOS|empty string|String| +|Windows|empty string|String| + +### BuildInfo.windows + +Windows Only. + +Get the windows extra information. + +|Platform|Value|Type| +|--------|-----|----| +|Android|undefined|undefined| +|iOS|undefined|undefined| +|Windows|Object|Object| + +|Property name|Value|Type| +|-------------|-----|----| +|architecture|Windows.ApplicationModel.Package.current.id.architecture|integer| +|description|Windows.ApplicationModel.Package.current.description|String| +|displayName|Windows.ApplicationModel.Package.current.displayName|String| +|familyName|Windows.ApplicationModel.Package.current.id.familyName|String| +|fullName|Windows.ApplicationModel.Package.current.id.fullName|String| +|logo|Object|Object| +|publisher|Windows.ApplicationModel.Package.current.id.publisher|String| +|publisherId|Windows.ApplicationModel.Package.current.id.publisherId|String| +|publisherDisplayName|Windows.ApplicationModel.Package.current.publisherDisplayName|String| +|resourceId|Windows.ApplicationModel.Package.current.id.resourceId|String| +|version|Windows.ApplicationModel.Package.current.id.version|Object| + +#### BuildInfo.windows.logo + +|Property name|Value|Type| +|-------------|-----|----| +|absoluteCannonicalUri|Windows.ApplicationModel.Package.logo.absoluteCanonicalUri|String| +|absoluteUri|Windows.ApplicationModel.Package.logo.absoluteUri|String| +|displayIri|Windows.ApplicationModel.Package.logo.displayIri|String| +|displayUri|Windows.ApplicationModel.Package.logo.displayUri|String| +|path|Windows.ApplicationModel.Package.logo.path|String| +|rawUri|Windows.ApplicationModel.Package.logo.rawUri|String| + +#### BuildInfo.windows.version + +|Property name|Value|Type| +|-------------|-----|----| +|major|Windows.ApplicationModel.Package.current.id.version.major|integer| +|minor|Windows.ApplicationModel.Package.current.id.version.minor|integer| +|build|Windows.ApplicationModel.Package.current.id.version.build|integer| +|revision|Windows.ApplicationModel.Package.current.id.version.revision|integer| \ No newline at end of file diff --git a/src/windows/BuildInfoProxy.js b/src/windows/BuildInfoProxy.js index fa383a7..0fd0247 100644 --- a/src/windows/BuildInfoProxy.js +++ b/src/windows/BuildInfoProxy.js @@ -1,17 +1,99 @@ BuildInfoProxy = { init: function (successCallback, errorCallback, args) { var res = {}; - var packId = Windows.ApplicationModel.Package.current.id; + + var package = Windows.ApplicationModel.Package.current; + var packId = package.id; + var version = packId.version; + res.packageName = packId.name; res.basePackageName = packId.name; res.displayName = Windows.ApplicationModel.Package.current.displayName; res.name = Windows.ApplicationModel.Package.current.displayName; - var version = packId.version; res.version = [version.major, version.minor, version.build].join('.'); - res.versionCode = packId.version.build; + res.versionCode = [version.major, version.minor, version.build, version.revision].join('.'); res.debug = Windows.ApplicationModel.Package.current.isDevelopmentMode; res.buildType = (res.debug) ? "debug" : "release"; - successCallback(res); + res.flavor = ""; + + // Windows + res.windows = { + description: package.description, + displayName: package.displayName, + publisherDisplayName: package.publisherDisplayName, + architecture: packId.architecture, + familyName: packId.familyName, + fullName: packId.fullName, + publisher: packId.publisher, + publisherId: packId.publisherId, + resourceId: packId.resourceId, + version: packId.version, + logo: { + absoluteCanonicalUri: package.logo.absoluteCanonicalUri, + absoluteUri: package.logo.absoluteUri, + displayIri: package.logo.displayIri, + displayUri: package.logo.displayUri, + path: package.logo.path, + rawUri: package.logo.rawUri + } + }; + + var promiseDoneFunc = function done(res) { + if (res.debug) { + var log = console.debug ? console.debug : console.log; + log("packageName : \"" + res.packageName + "\""); + log("basePackageName: \"" + res.basePackageName + "\""); + log("displayName : \"" + res.displayName + "\""); + log("name : \"" + res.name + "\""); + log("version : \"" + res.version + "\""); + log("versionCode : \"" + res.versionCode + "\""); + log("debug : " + (res.debug ? "true" : "false")); + log("buildType : \"" + res.buildType + "\""); + log("flavor : \"" + res.flavor + "\""); + } + successCallback(res); + }; + + package.installedLocation.getFileAsync('AppxManifest.xml') + .then(function (file) { + return Windows.Storage.FileIO.readTextAsync(file); + }) + .then(function (text) { + var xdoc = new Windows.Data.Xml.Dom.XmlDocument(); + xdoc.loadXml(text); + + var node = xdoc.selectSingleNode("//*[local-name()='VisualElements']"); + var displayName = res.displayName; + if (node && node.attributes) { + var nodeDisplayName = node.attributes.getNamedItem('DisplayName'); + + if (nodeDisplayName && nodeDisplayName.nodeValue) { + displayName = nodeDisplayName.nodeValue; + } + } + + // ms-resource: + if (displayName.startsWith('ms-resource:')) { + const res = WinJS.Resources.getString(displayName.substr(12)); + if (res) { + displayName = res.value; + } + } + + res.displayName = displayName; + + return res; + }) + .done( + function (res) { + promiseDoneFunc(res); + }, + function (err) { + console.error(err); + promiseDoneFunc(res); + } + ); } }; -cordova.commandProxy.add("BuildInfo", BuildInfoProxy); \ No newline at end of file + +cordova.commandProxy.add("BuildInfo", BuildInfoProxy); diff --git a/tests/package.json b/tests/package.json new file mode 100644 index 0000000..7853426 --- /dev/null +++ b/tests/package.json @@ -0,0 +1,25 @@ +{ + "name": "cordova-plugin-buildinfo", + "version": "1.1.0", + "description": "Cordova/Phonegap Build Information Plugin. Get PackageName, Version, Debug and more... TEST!", + "cordova": { + "id": "cordova-plugin-buildinfo-test", + "platforms": [ + "android", + "ios", + "windows" + ] + }, + "engines": [ + { + "name": "cordova", + "version": ">=4.0.0" + } + ], + "author": "Mikihiro Hayashi", + "license": "MIT", + "bugs": { + "url": "https://github.com/lynrin/cordova-plugin-buildinfo/issues" + }, + "homepage": "https://github.com/lynrin/cordova-plugin-buildinfo#readme" +} diff --git a/www/buildinfo.js b/www/buildinfo.js index 3eb8a43..3e7b819 100644 --- a/www/buildinfo.js +++ b/www/buildinfo.js @@ -90,6 +90,10 @@ channel.onCordovaReady.subscribe(function () { if ('undefined' !== typeof res.flavor) { module.exports.flavor = res.flavor; } + + if ('undefined' !== typeof res.windows) { + module.exports.windows = res.windows; + } }, function (msg) { console.error('BuildInfo init fail'); From 4b8c959575b8973c62dc716519639084bf9027bf Mon Sep 17 00:00:00 2001 From: Mikihiro Hayashi Date: Mon, 4 Sep 2017 01:16:03 +0900 Subject: [PATCH 08/15] Edit package.json Added windows to platforms. Added cordova-windows to keywords. --- package.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 97b99be..45c031f 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "id": "cordova-plugin-buildinfo", "platforms": [ "android", - "ios" + "ios", + "windows" ] }, "repository": { @@ -21,7 +22,8 @@ "cordova", "ecosystem:cordova", "cordova-android", - "cordova-ios" + "cordova-ios", + "cordova-windows" ], "scripts": { "test": "npm run jshint", From 71570a9e10a057cb13e07eba7074ea128f05ba37 Mon Sep 17 00:00:00 2001 From: Mikihiro Hayashi Date: Sat, 9 Sep 2017 00:32:44 +0900 Subject: [PATCH 09/15] Version 2.0.0 Added buildDate, installDate property. Windows platform: Changed the buildDate and installDate, displayName property. iOS platform: Changed the __DATE __, __ TIME__ predefine macro has been changed to the date obtained from the executionPath property of the main bundle. Android platform: Added BuildInfo.gradle file. --- README.md | 52 ++++++++++++++++---------- package.json | 2 +- plugin.xml | 4 +- src/android/BuildInfo.gradle | 5 +++ src/android/BuildInfo.java | 54 +++++++++++++++------------ src/ios/CDVBuildInfo.m | 42 +++++++++++++-------- src/windows/BuildInfoProxy.js | 69 ++++++++++++++++++++++++----------- tests/package.json | 2 +- tests/tests.js | 10 +++++ www/buildinfo.js | 19 ++++++++-- 10 files changed, 175 insertions(+), 84 deletions(-) create mode 100644 src/android/BuildInfo.gradle diff --git a/README.md b/README.md index 5bc2df7..8d37ab8 100644 --- a/README.md +++ b/README.md @@ -19,9 +19,10 @@ function onDeviceReady() { console.log('BuildInfo.version =' + BuildInfo.version); console.log('BuildInfo.versionCode =' + BuildInfo.versionCode); console.log('BuildInfo.debug =' + BuildInfo.debug); - console.log('BuildInfo.buildTime =' + BuildInfo.buildTime); console.log('BuildInfo.buildType =' + BuildInfo.buildType); console.log('BuildInfo.flavor =' + BuildInfo.flavor); + console.log('BuildInfo.buildDate =' + BuildInfo.buildDate); + console.log('BuildInfo.installDate =' + BuildInfo.installDate); } ``` @@ -46,9 +47,10 @@ cordova plugin add cordova-plugin-buildinfo - `BuildInfo.version` - `BuildInfo.versionCode` - `BuildInfo.debug` -- `BuildInfo.buildTime` - `BuildInfo.buildType` - `BuildInfo.flavor` +- `BuildInfo.buildDate` +- `BuildInfo.installDate` - `BuildInfo.windows` - `logo` - `version` @@ -90,7 +92,7 @@ Get the displayName. |--------|-----|----| |Android|Application Label|String| |iOS|CFBundleDisplayName|String| -|Windows|Display a package name|String| +|Windows|Get DisplayName attribute of VisualElements element in AppxManifest.xml file.|String| ### BuildInfo.name @@ -111,7 +113,7 @@ Get the version. |--------|-----|----| |Android|BuildConfig.VERSION_NAME|String| |iOS|CFBundleShortVersionString|String| -|Windows|Major . Minor . Build|String| +|Windows|Major.Minor.Build ex) "1.2.3"|String| ### BuildInfo.versionCode @@ -122,7 +124,7 @@ Get the version code. |--------|-----|----| |Android|BuildConfig.VERSION_CODE|int| |iOS|CFBundleVersion|string| -|Windows|Major . Minor . Build . Revision|String| +|Windows|Major.Minor.Build.Revision ex) "1.2.3.4"|String| ### BuildInfo.debug @@ -136,20 +138,6 @@ Get the debug flag. |Windows|isDevelopmentMode is true|Boolean| -### BuildInfo.buildTime - -Get the build date and time in the same format new Date().toJSON() returns. - -Attention: There is no information about the timezones saved. -- iOS: The iOS date is written in developer local time but interpreted in UTC -- Android: The Android date is written in developer's local time and interpret in user's local time - -|Platform|Value|Type| -|--------|-----|----| -|Android|Datetime of last build folder modification|String| -|iOS|Combination of \_\_DATE\_\_ and \_\_TIME\_\_ |String| - - ### BuildInfo.buildType Android , Windows Only. @@ -175,6 +163,32 @@ Get the flavor. |iOS|empty string|String| |Windows|empty string|String| +### BuildInfo.buildDate + +Get the build date and time in the Date object returns. + +Attention: +- Android: Add the BuildInfo.gradle file to your Android project. + The BuildInfo.gradle file contains the setting to add the _BUILDINFO_TIMESTAMP field to the BuildConfig class. + +|Platform|Value|Type| +|--------|-----|----| +|Android|BuildConfig.\_BUILDINFO\_TIMESTAMP value|Date| +|iOS|Get the creation date and time of the Info.plist file acquired from the executionPath property of the main bundle.|Date| +|Windows|Get Last modified date of AppxManifest.xml file.|Date| + + +### BuildInfo.installDate + +Get the install date and time in the Date object returns. + +|Platform|Value|Type| +|--------|-----|----| +|Android|The firstInstallTime property of PackageInfo|Date| +|iOS|Get creation date and time from executionPath property of main bundle.|Date| +|Windows|The installedDate property of Windows.ApplicatinoModel.Package.current|Date| + + ### BuildInfo.windows Windows Only. diff --git a/package.json b/package.json index 45c031f..0608ed3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-buildinfo", - "version": "1.1.0", + "version": "2.0.0", "description": "Cordova/Phonegap Build Information Plugin. Get PackageName, Version, Debug and more...", "cordova": { "id": "cordova-plugin-buildinfo", diff --git a/plugin.xml b/plugin.xml index e0695d2..3e265ff 100644 --- a/plugin.xml +++ b/plugin.xml @@ -3,12 +3,13 @@ xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android" id="cordova-plugin-buildinfo" - version="1.1.0"> + version="2.0.0"> BuildInfo Cordova/Phonegap Build Information Plugin. Get PackageName, Version, Debug and more... MIT debug,buildconfig,buildinfo,phonegap,cordova Mikihiro Hayashi + https://github.com/lynrin/cordova-plugin-buildinfo @@ -25,6 +26,7 @@ + diff --git a/src/android/BuildInfo.gradle b/src/android/BuildInfo.gradle new file mode 100644 index 0000000..c6401fc --- /dev/null +++ b/src/android/BuildInfo.gradle @@ -0,0 +1,5 @@ +android { + defaultConfig { + buildConfigField "long", "_BUILDINFO_TIMESTAMP", System.currentTimeMillis() + "L" + } +} \ No newline at end of file diff --git a/src/android/BuildInfo.java b/src/android/BuildInfo.java index 6375eb8..b4dade1 100644 --- a/src/android/BuildInfo.java +++ b/src/android/BuildInfo.java @@ -25,8 +25,6 @@ of this software and associated documentation files (the "Software"), to deal package org.apache.cordova.buildinfo; import android.app.Activity; -import android.content.Context; -import android.content.pm.ApplicationInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.util.Log; @@ -37,10 +35,8 @@ of this software and associated documentation files (the "Software"), to deal import org.json.JSONException; import org.json.JSONObject; -import java.io.File; import java.lang.reflect.Field; import java.text.SimpleDateFormat; -import java.util.TimeZone; /** * BuildInfo Cordova Plugin @@ -102,11 +98,13 @@ private void init(String buildConfigClassName, CallbackContext callbackContext) String packageName = activity.getPackageName(); String basePackageName = packageName; CharSequence displayName = ""; + long firstInstallTime = 0; PackageManager pm = activity.getPackageManager(); try { PackageInfo pi = pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES); + firstInstallTime = pi.firstInstallTime; if (null != pi.applicationInfo) { displayName = pi.applicationInfo.loadLabel(pm); @@ -151,7 +149,8 @@ private void init(String buildConfigClassName, CallbackContext callbackContext) mBuildInfoCache.put("version" , getClassFieldString(c, "VERSION_NAME", "")); mBuildInfoCache.put("versionCode" , getClassFieldInt(c, "VERSION_CODE", 0)); mBuildInfoCache.put("debug" , debug); - mBuildInfoCache.put("buildTime" , getAppTimeStamp(activity)); + mBuildInfoCache.put("buildDate" , convertLongToDateTimeString(getClassFieldLong(c, "_BUILDINFO_TIMESTAMP", 0L))); + mBuildInfoCache.put("installDate" , convertLongToDateTimeString(firstInstallTime)); mBuildInfoCache.put("buildType" , getClassFieldString(c, "BUILD_TYPE", "")); mBuildInfoCache.put("flavor" , getClassFieldString(c, "FLAVOR", "")); @@ -163,9 +162,10 @@ private void init(String buildConfigClassName, CallbackContext callbackContext) Log.d(TAG, "version : \"" + mBuildInfoCache.getString("version") + "\""); Log.d(TAG, "versionCode : " + mBuildInfoCache.getInt("versionCode")); Log.d(TAG, "debug : " + (mBuildInfoCache.getBoolean("debug") ? "true" : "false")); - Log.d(TAG, "buildTime : \"" + mBuildInfoCache.getString("buildTime") + "\""); Log.d(TAG, "buildType : \"" + mBuildInfoCache.getString("buildType") + "\""); Log.d(TAG, "flavor : \"" + mBuildInfoCache.getString("flavor") + "\""); + Log.d(TAG, "buildDate : \"" + mBuildInfoCache.getString("buildDate") + "\""); + Log.d(TAG, "installDate : \"" + mBuildInfoCache.getString("installDate") + "\""); } } catch (JSONException e) { e.printStackTrace(); @@ -242,6 +242,28 @@ private static int getClassFieldInt(Class c, String fieldName, int defaultReturn return ret; } + /** + * Get long of field from Class + * @param c + * @param fieldName + * @param defaultReturn + * @return + */ + private static long getClassFieldLong(Class c, String fieldName, long defaultReturn) { + long ret = defaultReturn; + Field field = getClassField(c, fieldName); + + if (null != field) { + try { + ret = field.getLong(c); + } catch (IllegalAccessException iae) { + iae.printStackTrace(); + } + } + + return ret; + } + /** * Get field from Class * @param c @@ -260,22 +282,8 @@ private static Field getClassField(Class c, String fieldName) { return field; } - private static String getAppTimeStamp(Context context) { - String timeStamp = ""; - - try { - ApplicationInfo appInfo = context.getPackageManager().getApplicationInfo(context.getPackageName(), 0); - String appFile = appInfo.sourceDir; - long time = new File(appFile).lastModified(); - - SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); - timeStamp = formatter.format(time); - - } catch (Exception e) { - e.printStackTrace(); - } - - return timeStamp; - + private static String convertLongToDateTimeString(long mills) { + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); + return formatter.format(mills); } } diff --git a/src/ios/CDVBuildInfo.m b/src/ios/CDVBuildInfo.m index a34b232..a804451 100644 --- a/src/ios/CDVBuildInfo.m +++ b/src/ios/CDVBuildInfo.m @@ -38,19 +38,29 @@ - (void)init:(CDVInvokedUrlCommand*)command NSNumber* debug = [NSNumber numberWithBool:NO]; #endif - // timestamp at compile time - NSString *compileDate = [NSString stringWithUTF8String:__DATE__]; - NSString *compileTime = [NSString stringWithUTF8String:__TIME__]; - - NSDateFormatter *dfParser = [[NSDateFormatter alloc] init]; - [dfParser setDateFormat:@"MMM d yyyy"]; - NSDate *buildDate = [dfParser dateFromString:compileDate]; - - NSDateFormatter *dfOutput = [[NSDateFormatter alloc] init]; - [dfOutput setDateFormat:@"yyyy-MM-dd"]; - - NSString *buildTime = [NSString stringWithFormat:@"%@T%@Z", [dfOutput stringFromDate:buildDate], compileTime]; - + // Info.plist modification date + NSString *buildDate = @""; + NSString *installDate = @""; + + NSDateFormatter *dfRFC3339 = [[NSDateFormatter alloc] init]; + [dfRFC3339 setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZZZZ"]; + + NSString *exePath = [[NSBundle mainBundle] executablePath]; + NSString *path = [[NSBundle mainBundle] pathForResource:@"Info.plist" ofType:nil]; + if (path) { + NSDictionary* attr = [[NSFileManager defaultManager] attributesOfItemAtPath:path error:nil]; + NSDate* creationDate = [attr objectForKey:NSFileCreationDate]; + + buildDate = [dfRFC3339 stringFromDate:creationDate]; + } + + if (exePath) { + NSDictionary* attrExe = [[NSFileManager defaultManager] attributesOfItemAtPath:exePath error:nil]; + NSDate *appCreationDate = [attrExe objectForKey:NSFileCreationDate]; + + installDate = [dfRFC3339 stringFromDate:appCreationDate]; + } + NSDictionary* result = @{ @"packageName" : [bundle bundleIdentifier], @"basePackageName": [bundle bundleIdentifier], @@ -59,7 +69,8 @@ - (void)init:(CDVInvokedUrlCommand*)command @"version" : [info objectForKey:@"CFBundleShortVersionString"], @"versionCode" : [info objectForKey:@"CFBundleVersion"], @"debug" : debug, - @"buildTime" : buildTime, + @"buildDate" : buildDate, + @"installDate" : installDate, @"buildType" : @"", // Android Only @"flavor" : @"" // Android Only }; @@ -73,7 +84,8 @@ - (void)init:(CDVInvokedUrlCommand*)command NSLog(@"BuildInfo versionCode : \"%@\"", [result objectForKey:@"versionCode"]); NSLog(@"BuildInfo debug : %@" , [[result objectForKey:@"debug"] boolValue] ? @"YES" : @"NO"); NSLog(@"BuildInfo buildType : \"%@\"", [result objectForKey:@"buildType"]); - NSLog(@"BuildInfo buildTime : \"%@\"", [result objectForKey:@"buildTime"]); + NSLog(@"BuildInfo buildDate : \"%@\"", [result objectForKey:@"buildDate"]); + NSLog(@"BuildInfo installDate : \"%@\"", [result objectForKey:@"installDate"]); NSLog(@"BuildInfo flavor : \"%@\"", [result objectForKey:@"flavor"]); } diff --git a/src/windows/BuildInfoProxy.js b/src/windows/BuildInfoProxy.js index 0fd0247..8dcc8f7 100644 --- a/src/windows/BuildInfoProxy.js +++ b/src/windows/BuildInfoProxy.js @@ -8,13 +8,14 @@ BuildInfoProxy = { res.packageName = packId.name; res.basePackageName = packId.name; - res.displayName = Windows.ApplicationModel.Package.current.displayName; - res.name = Windows.ApplicationModel.Package.current.displayName; + res.displayName = package.displayName; + res.name = package.displayName; res.version = [version.major, version.minor, version.build].join('.'); res.versionCode = [version.major, version.minor, version.build, version.revision].join('.'); - res.debug = Windows.ApplicationModel.Package.current.isDevelopmentMode; + res.debug = package.isDevelopmentMode; res.buildType = (res.debug) ? "debug" : "release"; res.flavor = ""; + res.installDate = package.installedDate; // Windows res.windows = { @@ -50,37 +51,63 @@ BuildInfoProxy = { log("debug : " + (res.debug ? "true" : "false")); log("buildType : \"" + res.buildType + "\""); log("flavor : \"" + res.flavor + "\""); + log("buildDate : \"" + res.buildDate + "\""); + log("installDate : \"" + res.installDate + "\""); } successCallback(res); }; package.installedLocation.getFileAsync('AppxManifest.xml') .then(function (file) { - return Windows.Storage.FileIO.readTextAsync(file); - }) - .then(function (text) { - var xdoc = new Windows.Data.Xml.Dom.XmlDocument(); - xdoc.loadXml(text); + var promises = []; + + // Get Basic Properties + promises.push(file.getBasicPropertiesAsync().then(function (props) { + return props; + })); + + // File read and parse + promises.push(Windows.Storage.FileIO.readTextAsync(file).then(function (text) { + var xdoc = new Windows.Data.Xml.Dom.XmlDocument(); + xdoc.loadXml(text); - var node = xdoc.selectSingleNode("//*[local-name()='VisualElements']"); - var displayName = res.displayName; - if (node && node.attributes) { - var nodeDisplayName = node.attributes.getNamedItem('DisplayName'); + var node = xdoc.selectSingleNode("//*[local-name()='VisualElements']"); + var displayName = res.displayName; + if (node && node.attributes) { + var nodeDisplayName = node.attributes.getNamedItem('DisplayName'); - if (nodeDisplayName && nodeDisplayName.nodeValue) { - displayName = nodeDisplayName.nodeValue; + if (nodeDisplayName && nodeDisplayName.nodeValue) { + displayName = nodeDisplayName.nodeValue; + } } - } - // ms-resource: - if (displayName.startsWith('ms-resource:')) { - const res = WinJS.Resources.getString(displayName.substr(12)); - if (res) { - displayName = res.value; + // ms-resource: + if (displayName.startsWith('ms-resource:')) { + var resDisplayName = WinJS.Resources.getString(displayName.substr(12)); + if (resDisplayName) { + displayName = resDisplayName.value; + } + } + + return { displayName: displayName }; + })); + + return WinJS.Promise.join(promises); + }) + .then(function (results) { + // BasicProperties + if (results && results[0]) { + if (results[0].dateModified) { + res.buildDate = results[0].dateModified; } } - res.displayName = displayName; + // File read and parse + if (results && results[1]) { + if (results[1].displayName) { + res.displayName = results[1].displayName; + } + } return res; }) diff --git a/tests/package.json b/tests/package.json index 7853426..e91561f 100644 --- a/tests/package.json +++ b/tests/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-buildinfo", - "version": "1.1.0", + "version": "2.0.0", "description": "Cordova/Phonegap Build Information Plugin. Get PackageName, Version, Debug and more... TEST!", "cordova": { "id": "cordova-plugin-buildinfo-test", diff --git a/tests/tests.js b/tests/tests.js index 4749cb6..28b6f4a 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -52,6 +52,16 @@ exports.defineAutoTests = function () { expect(window.BuildInfo.flavor).toBeDefined(); expect(typeof window.BuildInfo.flavor).toBe('string'); }); + + it ('should contain a BuildDate specification that is a Date', function () { + expect(window.BuildInfo.buildDate).toBeDefined(); + expect(window.BuildInfo.buildDate instanceof Date).toBe(true); + }); + + it ('should contain a InstallDate specification that is a Date', function () { + expect(window.BuildInfo.installDate).toBeDefined(); + expect(window.BuildInfo.installDate instanceof Date).toBe(true); + }); }); }; diff --git a/www/buildinfo.js b/www/buildinfo.js index 352bb3f..91887f9 100644 --- a/www/buildinfo.js +++ b/www/buildinfo.js @@ -33,7 +33,8 @@ module.exports = { version: '', versionCode: 0, debug: false, - buildTime: '', + buildDate: '', + installDate: '', buildType: '', flavor: '' }; @@ -92,8 +93,20 @@ channel.onCordovaReady.subscribe(function () { module.exports.flavor = res.flavor; } - if ('undefined' !== typeof res.buildTime) { - module.exports.buildTime = res.buildTime; + if ('undefined' !== typeof res.buildDate) { + if (res.buildDate instanceof Date) { + module.exports.buildDate = res.buildDate; + } else { + module.exports.buildDate = new Date(res.buildDate); + } + } + + if ('undefined' !== typeof res.installDate) { + if (res.installDate instanceof Date) { + module.exports.installDate = res.installDate; + } else { + module.exports.installDate = new Date(res.installDate); + } } if ('undefined' !== typeof res.windows) { From e4267e699276d2b4693890a95bed584b5264dce0 Mon Sep 17 00:00:00 2001 From: Mikihiro Hayashi Date: Mon, 11 Sep 2017 11:55:12 +0900 Subject: [PATCH 10/15] Windows platform: Changed to write build date and time to strings/buildinfo.resjson file. --- package.json | 20 ++++++++--- plugin.xml | 9 ++++- scripts/after_install.js | 65 +++++++++++++++++++++++++++++++++++ scripts/before_uninstall.js | 50 +++++++++++++++++++++++++++ src/windows/BuildInfoProxy.js | 43 ++++++++++------------- src/windows/buildinfo.resjson | 2 ++ 6 files changed, 159 insertions(+), 30 deletions(-) create mode 100644 scripts/after_install.js create mode 100644 scripts/before_uninstall.js create mode 100644 src/windows/buildinfo.resjson diff --git a/package.json b/package.json index 0608ed3..f9666cf 100644 --- a/package.json +++ b/package.json @@ -29,12 +29,22 @@ "test": "npm run jshint", "jshint": "node node_modules/jshint/bin/jshint www && node node_modules/jshint/bin/jshint src && node node_modules/jshint/bin/jshint tests" }, - "engines": [ - { - "name": "cordova", - "version": ">=4.0.0" + "engines": { + "cordovaDependencies": { + "0.0.0": { + "cordova": ">=4.0.0" + }, + "2.0.0": { + "cordova": ">=5.4.0", + "cordova-ios": ">=4.0.0", + "cordova-android": ">=5.0.0", + "cordova-windows": ">=4.0.0" + }, + "3.0.0": { + "cordova": ">100" + } } - ], + }, "author": "Mikihiro Hayashi", "license": "MIT", "bugs": { diff --git a/plugin.xml b/plugin.xml index 3e265ff..dcab8cf 100644 --- a/plugin.xml +++ b/plugin.xml @@ -11,12 +11,18 @@ Mikihiro Hayashi https://github.com/lynrin/cordova-plugin-buildinfo + + + - + + + + @@ -43,5 +49,6 @@ + diff --git a/scripts/after_install.js b/scripts/after_install.js new file mode 100644 index 0000000..5f5dcde --- /dev/null +++ b/scripts/after_install.js @@ -0,0 +1,65 @@ +'use strict'; + +var path = require('path'), + fs = require('fs'); + +function installWindows(windowsPath) { + + const targetPath = path.join(windowsPath, 'CordovaApp.projitems'); + var projitems = fs.readFileSync(targetPath).toString(); + var changed = false; + + // Replace to + if (projitems.match(/[\s]*?[\s]*?/m; + + const replace + = "\r\n" + + " \r\n" + + " "; + + projitems = projitems.replace(search, replace); + changed = true; + } + + // Add + if (!projitems.match(//; + + const replace + = " \r\n" + + " \r\n" + + " $([System.DateTime]::Now.ToString(\"yyyy-MM-dd\THH:mm:sszzz\"))\r\n" + + " \r\n" + + " \r\n" + + " \r\n" + + " \r\n" + + " \r\n" + + " \r\n" + + " \r\n" + + " \r\n" + + ""; + + projitems = projitems.replace(search, replace); + changed = true; + } + + // if variable "changed" is true, write to file. + if (changed) { + fs.writeFileSync(targetPath, projitems); + } +} + +module.exports = function (context) { + var projectRoot = context.opts.projectRoot; + + // Exists platform/windows + var windowsPath = path.join(projectRoot, 'platforms','windows'); + if (fs.existsSync(windowsPath) && context.opts.plugin.platform == 'windows') { + installWindows(windowsPath); + } +}; \ No newline at end of file diff --git a/scripts/before_uninstall.js b/scripts/before_uninstall.js new file mode 100644 index 0000000..4e6d8f9 --- /dev/null +++ b/scripts/before_uninstall.js @@ -0,0 +1,50 @@ +'use strict'; + +var path = require('path'), + fs = require('fs'); + +function uninstallWindows(windowsPath) { + const targetPath = path.join(windowsPath, 'CordovaApp.projitems'); + var projitems = fs.readFileSync(targetPath).toString(); + var changed = false; + + // Replace to + if (projitems.match(/[\s]*?[\s]*?/m; + + var replace + = "\r\n" + + " \r\n" + + " "; + + projitems = projitems.replace(search, replace); + changed = true; + } + + // Remove + if (projitems.match(//gm; + + projitems = projitems.replace(search, ''); + changed = true; + } + + // if variable "changed" is true, write to file. + if (changed) { + fs.writeFileSync(targetPath, projitems); + } +} + +module.exports = function (context) { + var projectRoot = context.opts.projectRoot; + + // Exists platform/windows + var windowsPath = path.join(projectRoot, 'platforms','windows'); + if (fs.existsSync(windowsPath) && context.opts.plugin.platform == 'windows') { + uninstallWindows(windowsPath); + } +}; \ No newline at end of file diff --git a/src/windows/BuildInfoProxy.js b/src/windows/BuildInfoProxy.js index 8dcc8f7..02a6700 100644 --- a/src/windows/BuildInfoProxy.js +++ b/src/windows/BuildInfoProxy.js @@ -1,11 +1,21 @@ BuildInfoProxy = { + _cache: null, + init: function (successCallback, errorCallback, args) { + if (null != this._cache) { + successCallback(this._cache); + return; + } + + var self = this; var res = {}; var package = Windows.ApplicationModel.Package.current; var packId = package.id; var version = packId.version; + var timestamp = WinJS.Resources.getString('/buildinfo/Timestamp'); + res.packageName = packId.name; res.basePackageName = packId.name; res.displayName = package.displayName; @@ -16,6 +26,7 @@ BuildInfoProxy = { res.buildType = (res.debug) ? "debug" : "release"; res.flavor = ""; res.installDate = package.installedDate; + res.buildDate = timestamp ? new Date(timestamp.value) : null; // Windows res.windows = { @@ -54,20 +65,16 @@ BuildInfoProxy = { log("buildDate : \"" + res.buildDate + "\""); log("installDate : \"" + res.installDate + "\""); } + + self._cache = res; + successCallback(res); }; package.installedLocation.getFileAsync('AppxManifest.xml') .then(function (file) { - var promises = []; - - // Get Basic Properties - promises.push(file.getBasicPropertiesAsync().then(function (props) { - return props; - })); - // File read and parse - promises.push(Windows.Storage.FileIO.readTextAsync(file).then(function (text) { + return Windows.Storage.FileIO.readTextAsync(file).then(function (text) { var xdoc = new Windows.Data.Xml.Dom.XmlDocument(); xdoc.loadXml(text); @@ -90,23 +97,11 @@ BuildInfoProxy = { } return { displayName: displayName }; - })); - - return WinJS.Promise.join(promises); + }); }) - .then(function (results) { - // BasicProperties - if (results && results[0]) { - if (results[0].dateModified) { - res.buildDate = results[0].dateModified; - } - } - - // File read and parse - if (results && results[1]) { - if (results[1].displayName) { - res.displayName = results[1].displayName; - } + .then(function (result) { + if (result.displayName) { + res.displayName = result.displayName; } return res; diff --git a/src/windows/buildinfo.resjson b/src/windows/buildinfo.resjson new file mode 100644 index 0000000..e02aef2 --- /dev/null +++ b/src/windows/buildinfo.resjson @@ -0,0 +1,2 @@ +{ +} \ No newline at end of file From 66e83c25f4ff5e041f446c43c52eeac14c01b6eb Mon Sep 17 00:00:00 2001 From: Mikihiro Hayashi Date: Mon, 11 Sep 2017 12:03:51 +0900 Subject: [PATCH 11/15] Update README.md Changed the description of BuildInfo.buildDate. --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8d37ab8..c62e0b4 100644 --- a/README.md +++ b/README.md @@ -170,12 +170,15 @@ Get the build date and time in the Date object returns. Attention: - Android: Add the BuildInfo.gradle file to your Android project. The BuildInfo.gradle file contains the setting to add the _BUILDINFO_TIMESTAMP field to the BuildConfig class. +- Windows: Add the buildinfo.resjson file to your Windows project. + The buildinfo.resjson file into the "strings" folder. + And also add a task to rewrite buildinfo.resjson in the CordovaApp.projitems file. |Platform|Value|Type| |--------|-----|----| |Android|BuildConfig.\_BUILDINFO\_TIMESTAMP value|Date| |iOS|Get the creation date and time of the Info.plist file acquired from the executionPath property of the main bundle.|Date| -|Windows|Get Last modified date of AppxManifest.xml file.|Date| +|Windows|Resource value of "/buildinfo/Timestamp" string.|Date| ### BuildInfo.installDate From 90b9c4c293112502f214466cc91059e2e2ab5c27 Mon Sep 17 00:00:00 2001 From: Mikihiro Hayashi Date: Mon, 11 Sep 2017 16:11:54 +0900 Subject: [PATCH 12/15] Update iOS Changed to obtain the installed date and time from the creation date and time of the document directory. Changed to cache results. Added processing time measurement. --- src/ios/CDVBuildInfo.m | 60 +++++++++++++++++++++++++++++++++++------- 1 file changed, 50 insertions(+), 10 deletions(-) diff --git a/src/ios/CDVBuildInfo.m b/src/ios/CDVBuildInfo.m index a804451..3982398 100644 --- a/src/ios/CDVBuildInfo.m +++ b/src/ios/CDVBuildInfo.m @@ -25,11 +25,42 @@ of this software and associated documentation files (the "Software"), to deal #import "CDVBuildInfo.h" #import +#import + @implementation CDVBuildInfo +CDVPluginResult* _cachePluginResult = nil; + +static mach_timebase_info_data_t sTimebaseInfo; + +void reportProfileProcessTime(const uint64_t start, const NSString *text) { + uint64_t end = mach_absolute_time(); + + uint64_t elapsedNano = (end - start) * sTimebaseInfo.numer / sTimebaseInfo.denom; + + double elapsedSec = elapsedNano / 1000000000.0; + + NSLog(@"BuildInfo init: %.4f sec(%llu nsec): %@", elapsedSec, elapsedNano, text); +} + /* init */ - (void)init:(CDVInvokedUrlCommand*)command { + // init mach_timebase + if (sTimebaseInfo.denom == 0) { + mach_timebase_info(&sTimebaseInfo); + } + + // Method start time. + uint64_t profilrStart = mach_absolute_time(); + + // Cache + if (nil != _cachePluginResult) { + [self.commandDelegate sendPluginResult:_cachePluginResult callbackId:command.callbackId]; + reportProfileProcessTime(profilrStart, @"Cache data return"); + return; + } + NSBundle* bundle = [NSBundle mainBundle]; NSDictionary* info = [bundle infoDictionary]; #ifdef DEBUG @@ -37,28 +68,31 @@ - (void)init:(CDVInvokedUrlCommand*)command #else NSNumber* debug = [NSNumber numberWithBool:NO]; #endif - - // Info.plist modification date + NSString *buildDate = @""; NSString *installDate = @""; NSDateFormatter *dfRFC3339 = [[NSDateFormatter alloc] init]; [dfRFC3339 setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZZZZ"]; - NSString *exePath = [[NSBundle mainBundle] executablePath]; - NSString *path = [[NSBundle mainBundle] pathForResource:@"Info.plist" ofType:nil]; + // Info.plist modification date + NSString *path = [bundle pathForResource:@"Info.plist" ofType:nil]; if (path) { NSDictionary* attr = [[NSFileManager defaultManager] attributesOfItemAtPath:path error:nil]; NSDate* creationDate = [attr objectForKey:NSFileCreationDate]; - buildDate = [dfRFC3339 stringFromDate:creationDate]; + if (creationDate) { + buildDate = [dfRFC3339 stringFromDate:creationDate]; + } } - if (exePath) { - NSDictionary* attrExe = [[NSFileManager defaultManager] attributesOfItemAtPath:exePath error:nil]; - NSDate *appCreationDate = [attrExe objectForKey:NSFileCreationDate]; - - installDate = [dfRFC3339 stringFromDate:appCreationDate]; + // Document folder creation date + NSURL *urlDocument = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]; + if (urlDocument) { + NSDate *creationDate = [[[NSFileManager defaultManager] attributesOfItemAtPath:urlDocument.path error:nil] objectForKey:NSFileCreationDate]; + if (creationDate) { + installDate = [dfRFC3339 stringFromDate:creationDate]; + } } NSDictionary* result = @{ @@ -90,8 +124,14 @@ - (void)init:(CDVInvokedUrlCommand*)command } CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:result]; + + // Reulst cache + if (nil == _cachePluginResult) { + _cachePluginResult = pluginResult; + } [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + reportProfileProcessTime(profilrStart, @"Return"); } @end From 7a505096ba9d23e8a59e8ed8ab2acf2e1c85ed54 Mon Sep 17 00:00:00 2001 From: Mikihiro Hayashi Date: Mon, 11 Sep 2017 16:31:35 +0900 Subject: [PATCH 13/15] Update iOS Changed to obtain modification date and time of Info.plist. --- src/ios/CDVBuildInfo.m | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/ios/CDVBuildInfo.m b/src/ios/CDVBuildInfo.m index 3982398..fd197bd 100644 --- a/src/ios/CDVBuildInfo.m +++ b/src/ios/CDVBuildInfo.m @@ -34,13 +34,10 @@ @implementation CDVBuildInfo static mach_timebase_info_data_t sTimebaseInfo; void reportProfileProcessTime(const uint64_t start, const NSString *text) { - uint64_t end = mach_absolute_time(); - uint64_t elapsedNano = (end - start) * sTimebaseInfo.numer / sTimebaseInfo.denom; + uint64_t elapsedNano = (mach_absolute_time() - start) * sTimebaseInfo.numer / sTimebaseInfo.denom; - double elapsedSec = elapsedNano / 1000000000.0; - - NSLog(@"BuildInfo init: %.4f sec(%llu nsec): %@", elapsedSec, elapsedNano, text); + NSLog(@"BuildInfo init: %.4f sec(%llu nsec): %@", elapsedNano / 1000000000.0, elapsedNano, text); } /* init */ @@ -61,6 +58,7 @@ - (void)init:(CDVInvokedUrlCommand*)command return; } + NSBundle* bundle = [NSBundle mainBundle]; NSDictionary* info = [bundle infoDictionary]; #ifdef DEBUG @@ -79,10 +77,10 @@ - (void)init:(CDVInvokedUrlCommand*)command NSString *path = [bundle pathForResource:@"Info.plist" ofType:nil]; if (path) { NSDictionary* attr = [[NSFileManager defaultManager] attributesOfItemAtPath:path error:nil]; - NSDate* creationDate = [attr objectForKey:NSFileCreationDate]; + NSDate* modificationDate = [attr objectForKey:NSFileModificationDate]; - if (creationDate) { - buildDate = [dfRFC3339 stringFromDate:creationDate]; + if (modificationDate) { + buildDate = [dfRFC3339 stringFromDate:modificationDate]; } } From cb0a1009847baa66ba88f3eee9a9072b979c2d74 Mon Sep 17 00:00:00 2001 From: Mikihiro Hayashi Date: Mon, 11 Sep 2017 16:34:16 +0900 Subject: [PATCH 14/15] Update README.md Changed iOS description of BuildInfo.buildDate and installDate. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c62e0b4..9d8c37b 100644 --- a/README.md +++ b/README.md @@ -177,7 +177,7 @@ Attention: |Platform|Value|Type| |--------|-----|----| |Android|BuildConfig.\_BUILDINFO\_TIMESTAMP value|Date| -|iOS|Get the creation date and time of the Info.plist file acquired from the executionPath property of the main bundle.|Date| +|iOS|Get the creation date and time of the document directory.|Date| |Windows|Resource value of "/buildinfo/Timestamp" string.|Date| @@ -188,7 +188,7 @@ Get the install date and time in the Date object returns. |Platform|Value|Type| |--------|-----|----| |Android|The firstInstallTime property of PackageInfo|Date| -|iOS|Get creation date and time from executionPath property of main bundle.|Date| +|iOS|Get the modification date and time of the Info.plist file acquired from the executionPath property of the main bundle.|Date| |Windows|The installedDate property of Windows.ApplicatinoModel.Package.current|Date| From 2f9264c24aa825094f1cd6e67cbf33b4eaaa7747 Mon Sep 17 00:00:00 2001 From: Mikihiro Hayashi Date: Mon, 11 Sep 2017 17:06:29 +0900 Subject: [PATCH 15/15] Add .npmignore --- .gitignore | 1 - .npmignore | 5 +++++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 .npmignore diff --git a/.gitignore b/.gitignore index c3d3d7b..f4734b8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ .DS_Store ignore/ - node_modules diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..1b335cf --- /dev/null +++ b/.npmignore @@ -0,0 +1,5 @@ +.npmignore +.travis.yml +.DS_Store +ignore/ +node_modules \ No newline at end of file