Skip to content

Commit

Permalink
Merge branch 'master' into TIMOB-24610
Browse files Browse the repository at this point in the history
  • Loading branch information
sgtcoolguy committed Nov 29, 2017
2 parents 30ca4a7 + 52aa724 commit ae3aefa
Show file tree
Hide file tree
Showing 60 changed files with 701 additions and 851 deletions.
9 changes: 7 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@ def npmVersion = '5.4.1' // We can change this without any changes to Jenkins.

def unitTests(os, nodeVersion, testSuiteBranch) {
return {
// TODO Customize labels by os we're testing
node('android-emulator && git && android-sdk && osx') {
def labels = 'git && osx'
if ('ios'.equals(os)) {
labels = 'git && osx && xcode-9' // test app fails to build with xcode-8.1 as far as I can tell
} else {
labels = 'git && osx && android-emulator && android-sdk' // FIXME get working on windows/linux!
}
node(labels) {
timeout(20) {
// Unarchive the osx build of the SDK (as a zip)
sh 'rm -rf osx.zip' // delete osx.zip file if it already exists
Expand Down
103 changes: 95 additions & 8 deletions android/cli/commands/_buildModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const AdmZip = require('adm-zip'),
async = require('async'),
Builder = require('../lib/base-builder'),
ejs = require('ejs'),
fields = require('fields'),
fs = require('fs'),
jsanalyze = require('node-titanium-sdk/lib/jsanalyze'),
markdown = require('markdown').markdown,
Expand All @@ -28,6 +29,7 @@ const AdmZip = require('adm-zip'),
tiappxml = require('node-titanium-sdk/lib/tiappxml'),
util = require('util'),
wrench = require('wrench'),
semver = require('semver'),
spawn = require('child_process').spawn, // eslint-disable-line security/detect-child-process
SymbolLoader = require('appc-aar-tools').SymbolLoader,
SymbolWriter = require('appc-aar-tools').SymbolWriter,
Expand All @@ -46,6 +48,97 @@ function AndroidModuleBuilder() {

util.inherits(AndroidModuleBuilder, Builder);

/**
* Migrates an existing module with an outdated "apiversion" in the manifest to the latest one.
* It takes care of migrating the "apiversion", "version", "minsdk" and "architecture" properties.
*
* @param {Function} next Callback function
* @return {undefined}
*/
AndroidModuleBuilder.prototype.migrate = function migrate(next) {
const cliModuleAPIVersion = this.cli.sdk && this.cli.sdk.manifest && this.cli.sdk.manifest.moduleAPIVersion && this.cli.sdk.manifest.moduleAPIVersion.android;
const needsMigration = this.manifest.apiversion && cliModuleAPIVersion && this.manifest.apiversion !== cliModuleAPIVersion;
const cliSDKVersion = this.cli.sdk.manifest.version;
const manifestSDKVersion = this.manifest.minsdk;
const manifestModuleAPIVersion = this.manifest.apiversion;
const newVersion = semver.inc(this.manifest.version, 'major');
const manifestTemplateFile = path.join(this.platformPath, 'templates', 'module', 'default', 'template', 'android', 'manifest.ejs');

var performMigration = function (next) {
this.logger.info(__('Migrating module manifest ...'));

this.logger.info(__('Setting %s to %s', 'apiversion'.cyan, cliModuleAPIVersion.cyan));
this.manifest.apiversion = cliModuleAPIVersion;

this.logger.info(__('Setting %s to %s', 'minsdk'.cyan, cliSDKVersion.cyan));
this.manifest.minsdk = cliSDKVersion;

this.logger.info(__('Bumping version from %s to %s', this.manifest.version.cyan, newVersion.cyan));
this.manifest.version = newVersion;

// Pre-fill placeholders
let manifestContent = ejs.render(fs.readFileSync(manifestTemplateFile).toString(), {
moduleName: this.manifest.name,
moduleId: this.manifest.moduleid,
platform: this.manifest.platform,
tisdkVersion: this.manifest.minsdk,
guid: this.manifest.guid,
author: this.manifest.author,
publisher: this.manifest.author // The publisher does not have an own key in the manifest but can be different. Will override below
});

// Migrate missing keys which don't have a placeholder (version, license, copyright & publisher)
manifestContent = manifestContent.replace(/version.*/, 'version: ' + this.manifest.version);
manifestContent = manifestContent.replace(/license.*/, 'license: ' + this.manifest.license);
manifestContent = manifestContent.replace(/copyright.*/, 'copyright: ' + this.manifest.copyright);

this.logger.info(__('Backing up old manifest to %s', 'manifest.bak'.cyan));
fs.renameSync(path.join(this.projectDir, 'manifest'), path.join(this.projectDir, 'manifest.bak'));

this.logger.info(__('Writing new manifest'));
fs.writeFileSync(path.join(this.projectDir, 'manifest'), manifestContent);

this.logger.info(__(''));
this.logger.info(__('Migration completed! Building module ...'));

next();
}.bind(this);

if (!needsMigration) {
return next();
}
const logger = this.logger;
if (!this.cli.argv.prompt) {
logger.error(__('The module manifest apiversion is currently set to %s', manifestModuleAPIVersion));
logger.error(__('Titanium SDK %s Android module apiversion is at %s', cliSDKVersion, cliModuleAPIVersion));
logger.error(__('Please update module manifest apiversion to match Titanium SDK module apiversion'));
logger.error(__('and the minsdk to %s', cliSDKVersion));
process.exit(1);
}

fields.select({
title: __('Detected Titanium %s that requires API-level %s, but the module currently only supports %s and API-level %s.', cliSDKVersion, cliModuleAPIVersion, manifestSDKVersion, manifestModuleAPIVersion),
promptLabel: __('Do you want to migrate your module now?'),
default: 'yes',
display: 'prompt',
relistOnError: true,
complete: true,
suggest: true,
options: [ '__y__es', '__n__o' ]
}).prompt(function (err, value) {
if (err) {
return next(err);
}

if (value !== 'yes') {
logger.error(__('Please update module manifest apiversion to match Titanium SDK module apiversion.'));
process.exit(1);
}

performMigration(next);
});
};

AndroidModuleBuilder.prototype.validate = function validate(logger, config, cli) {
Builder.prototype.config.apply(this, arguments);
Builder.prototype.validate.apply(this, arguments);
Expand All @@ -56,17 +149,10 @@ AndroidModuleBuilder.prototype.validate = function validate(logger, config, cli)

this.cli = cli;
this.logger = logger;
fields.setup({ colors: cli.argv.colors });

this.manifest = this.cli.manifest;

const sdkModuleAPIVersion = this.cli.sdk && this.cli.sdk.manifest && this.cli.sdk.manifest.moduleAPIVersion && this.cli.sdk.manifest.moduleAPIVersion['android'];
if (this.manifest.apiversion && sdkModuleAPIVersion && this.manifest.apiversion !== sdkModuleAPIVersion) {
logger.error(__('The module manifest apiversion is currently set to %s', this.manifest.apiversion));
logger.error(__('Titanium SDK %s Android module apiversion is at %s', this.titaniumSdkVersion, sdkModuleAPIVersion));
logger.error(__('Please update module manifest apiversion to match Titanium SDK module apiversion.'));
process.exit(1);
}

// detect android environment
androidDetect(config, { packageJson: this.packageJson }, function (androidInfo) {
this.androidInfo = androidInfo;
Expand Down Expand Up @@ -201,6 +287,7 @@ AndroidModuleBuilder.prototype.run = function run(logger, config, cli, finished)
cli.emit('build.module.pre.construct', this, next);
},

'migrate',
'doAnalytics',
'initialize',
'loginfo',
Expand Down
8 changes: 4 additions & 4 deletions android/runtime/v8/src/native/InspectorClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <libplatform/libplatform.h> // to pump message loop
#include "InspectorClient.h"
#include "InspectorFrontend.h" // new InspectorFrontend
#include "V8Util.h" // titanium::TwoByteValue and DEFINE_METHOD
#include "V8Util.h" // v8::String::Value and DEFINE_METHOD
#include "V8Runtime.h" // V8Runtime::v8_isolate
#include "JSDebugger.h" // JSDebugger::WaitForMessage()

Expand All @@ -28,7 +28,7 @@ InspectorClient::InspectorClient(v8::Local<v8::Context> context, v8::Platform* p
// FIXME Replace reference to V8Runtime::v8_isolate with isolate_
isolate_ = V8Runtime::v8_isolate;
inspector_ = v8_inspector::V8Inspector::create(V8Runtime::v8_isolate, this);
titanium::TwoByteValue contextName(STRING_NEW(V8Runtime::v8_isolate, "Titanium Main Context"));
v8::String::Value contextName(STRING_NEW(V8Runtime::v8_isolate, "Titanium Main Context"));
inspector_->contextCreated(v8_inspector::V8ContextInfo(
context, kContextGroupId, v8_inspector::StringView(*contextName, contextName.length())));

Expand Down Expand Up @@ -56,7 +56,7 @@ void InspectorClient::connect()
void InspectorClient::BreakAtStart()
{
v8::HandleScope scope(V8Runtime::v8_isolate);
titanium::TwoByteValue pauseReason(STRING_NEW(V8Runtime::v8_isolate, "PauseOnNextStatement"));
v8::String::Value pauseReason(STRING_NEW(V8Runtime::v8_isolate, "PauseOnNextStatement"));
session_->schedulePauseOnNextStatement(v8_inspector::StringView(*pauseReason, pauseReason.length()), v8_inspector::StringView());
}

Expand All @@ -78,7 +78,7 @@ void InspectorClient::runMessageLoopOnPause(int context_group_id)
running_nested_loop_ = true;
while (!terminated_) {
v8::Local<v8::String> message = JSDebugger::WaitForMessage();
titanium::TwoByteValue buffer(message);
v8::String::Value buffer(message);
v8_inspector::StringView message_view(*buffer, buffer.length());
sendMessage(message_view);

Expand Down
4 changes: 2 additions & 2 deletions android/runtime/v8/src/native/JSDebugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "TypeConverter.h" // TypeConverter::javaStringToJsString
#include "InspectorClient.h" // new InspectorClient
#include "V8Runtime.h" // V8Runtime::platform and V8Runtime::v8_isolate
#include "V8Util.h" // titanium::TwoByteValue
#include "V8Util.h" // v8::String::Value

#include "org_appcelerator_kroll_runtime_v8_JSDebugger.h"

Expand Down Expand Up @@ -87,7 +87,7 @@ void JSDebugger::sendCommand(JNIEnv *env, jstring command)

v8::Local<v8::Value> stringValue = TypeConverter::javaStringToJsString(V8Runtime::v8_isolate, env, command);
v8::Local<v8::String> message = stringValue.As<v8::String>();
titanium::TwoByteValue buffer(message);
v8::String::Value buffer(message);
v8_inspector::StringView message_view(*buffer, buffer.length());
client__->sendMessage(message_view);

Expand Down
10 changes: 5 additions & 5 deletions android/runtime/v8/src/native/KrollBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void KrollBindings::getExternalBinding(const FunctionCallbackInfo<Value>& args)
return;
}

titanium::Utf8Value bindingValue(binding);
v8::String::Utf8Value bindingValue(binding);
int length = bindingValue.length();
struct bindings::BindEntry *externalBinding = KrollBindings::getExternalBinding(*bindingValue, length);
Local<Object> exports = KrollBindings::instantiateBinding(isolate, externalBinding, binding, cache);
Expand Down Expand Up @@ -173,7 +173,7 @@ Local<Object> KrollBindings::getBinding(v8::Isolate* isolate, Local<String> bind
return cache->Get(binding)->ToObject(isolate);
}

titanium::Utf8Value bindingValue(binding);
v8::String::Utf8Value bindingValue(binding);
int length = bindingValue.length();

Local<Object> exports;
Expand Down Expand Up @@ -245,7 +245,7 @@ void KrollBindings::dispose(v8::Isolate* isolate)
uint32_t length = propertyNames->Length();

for (uint32_t i = 0; i < length; i++) {
titanium::Utf8Value binding(propertyNames->Get(i));
v8::String::Utf8Value binding(propertyNames->Get(i));
int bindingLength = binding.length();

struct titanium::bindings::BindEntry *generated = bindings::generated::lookupGeneratedInit(*binding, bindingLength);
Expand Down Expand Up @@ -298,7 +298,7 @@ void KrollBindings::isExternalCommonJsModule(const FunctionCallbackInfo<Value>&
}

v8::Local<v8::String> name = args[0].As<String>();
titanium::Utf8Value nameVal(name);
v8::String::Utf8Value nameVal(name);
std::string nameKey(*nameVal);

bool exists = (externalCommonJsModules.count(nameKey) > 0);
Expand All @@ -320,7 +320,7 @@ void KrollBindings::getExternalCommonJsModule(const FunctionCallbackInfo<Value>&
}

v8::Local<v8::String> name = args[0].As<String>();
titanium::Utf8Value nameVal(name);
v8::String::Utf8Value nameVal(name);
std::string nameKey(*nameVal);
std::string moduleRoot = nameKey;
std::string subPath = nameKey;
Expand Down
4 changes: 2 additions & 2 deletions android/runtime/v8/src/native/Proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ void Proxy::proxyConstructor(const v8::FunctionCallbackInfo<v8::Value>& args)
Local<Object> prototype = jsProxy->GetPrototype()->ToObject(isolate);
Local<Function> constructor = prototype->Get(constructorSymbol.Get(isolate)).As<Function>();
Local<String> javaClassName = constructor->Get(javaClassSymbol.Get(isolate)).As<String>();
titanium::Utf8Value javaClassNameVal(javaClassName);
v8::String::Utf8Value javaClassNameVal(javaClassName);
std::string javaClassNameString(*javaClassNameVal);
std::replace( javaClassNameString.begin(), javaClassNameString.end(), '.', '/');
// Create a copy of the char* since I'm seeing it get mangled when passed on to findClass later
Expand All @@ -380,7 +380,7 @@ void Proxy::proxyConstructor(const v8::FunctionCallbackInfo<v8::Value>& args)
bool extend = true;
Local<Object> createProperties = args[0].As<Object>();
Local<String> constructorName = createProperties->GetConstructorName();
if (strcmp(*titanium::Utf8Value(constructorName), "Arguments") == 0) {
if (strcmp(*v8::String::Utf8Value(constructorName), "Arguments") == 0) {
extend = false;
int32_t argsLength = createProperties->Get(STRING_NEW(isolate, "length"))->Int32Value();
if (argsLength > 1) {
Expand Down
6 changes: 3 additions & 3 deletions android/runtime/v8/src/native/ProxyFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Local<Object> ProxyFactory::createV8Proxy(v8::Isolate* isolate, Local<Value> cla
Local<Object> exports = KrollBindings::getBinding(isolate, className->ToString(isolate));

if (exports.IsEmpty()) {
titanium::Utf8Value classStr(className);
v8::String::Utf8Value classStr(className);
LOGE(TAG, "Failed to find class for %s", *classStr);
LOG_JNIENV_ERROR("while creating V8 Proxy.");
return Local<Object>();
Expand All @@ -55,7 +55,7 @@ Local<Object> ProxyFactory::createV8Proxy(v8::Isolate* isolate, Local<Value> cla
// FIXME: We pick the first item in exports as the constructor. We should do something more intelligent (for ES6 look at default export?)
Local<Array> names = exports->GetPropertyNames();
if (names->Length() < 1) {
titanium::Utf8Value classStr(className);
v8::String::Utf8Value classStr(className);
LOGE(TAG, "Failed to find class for %s", *classStr);
LOG_JNIENV_ERROR("while creating V8 Proxy.");
return Local<Object>();
Expand Down Expand Up @@ -103,7 +103,7 @@ jobject ProxyFactory::createJavaProxy(jclass javaClass, Local<Object> v8Proxy, c

// We also pass the creation URL of the proxy so we can track relative URLs
Local<Value> sourceUrl = args.Callee()->GetScriptOrigin().ResourceName();
titanium::Utf8Value sourceUrlValue(sourceUrl);
v8::String::Utf8Value sourceUrlValue(sourceUrl);

const char *url = "app://app.js";
jstring javaSourceUrl = NULL;
Expand Down
2 changes: 1 addition & 1 deletion android/runtime/v8/src/native/TypeConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ jstring TypeConverter::jsStringToJavaString(v8::Local<v8::String> jsString)

jstring TypeConverter::jsStringToJavaString(JNIEnv *env, v8::Local<v8::String> jsString)
{
titanium::TwoByteValue string(jsString);
v8::String::Value string(jsString);
return env->NewString(reinterpret_cast<const jchar*>(*string), string.length());
}

Expand Down
2 changes: 1 addition & 1 deletion android/runtime/v8/src/native/V8Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Java_org_appcelerator_kroll_runtime_v8_V8Object_nativeFireEvent
Local<Value> jsEvent = TypeConverter::javaStringToJsString(V8Runtime::v8_isolate, env, event);

#ifdef TI_DEBUG
titanium::Utf8Value eventName(jsEvent);
v8::String::Utf8Value eventName(jsEvent);
LOGV(TAG, "firing event \"%s\"", *eventName);
#endif

Expand Down
10 changes: 5 additions & 5 deletions android/runtime/v8/src/native/V8Runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ static void krollLog(const FunctionCallbackInfo<Value>& args)
message = String::Concat(String::Concat(message, space), args[i].As<String>());
}

titanium::Utf8Value tagValue(tag);
titanium::Utf8Value messageValue(message);
v8::String::Utf8Value tagValue(tag);
v8::String::Utf8Value messageValue(message);
__android_log_print(ANDROID_LOG_DEBUG, *tagValue, *messageValue);
}

Expand Down Expand Up @@ -179,11 +179,11 @@ static void logV8Exception(Local<Message> msg, Local<Value> data)
HandleScope scope(V8Runtime::v8_isolate);

// Log reason and location of the error.
LOGD(TAG, *titanium::Utf8Value(msg->Get()));
LOGD(TAG, *v8::String::Utf8Value(msg->Get()));
LOGD(TAG, "%s @ %d >>> %s",
*titanium::Utf8Value(msg->GetScriptResourceName()),
*v8::String::Utf8Value(msg->GetScriptResourceName()),
msg->GetLineNumber(),
*titanium::Utf8Value(msg->GetSourceLine()));
*v8::String::Utf8Value(msg->GetSourceLine()));
}

} // namespace titanium
Expand Down

0 comments on commit ae3aefa

Please sign in to comment.