Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TIMOB-6928 Android: Don't clobber existing modules when loading binding json file... #1125

Merged
merged 3 commits into from
Jan 9, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.jar.JarFile;
import java.util.zip.ZipEntry;

import org.json.simple.JSONArray;
import org.json.simple.JSONValue;
import org.json.simple.parser.ParseException;

Expand Down Expand Up @@ -212,6 +214,41 @@ protected Map<String, Object> getProxyApiTree(Map<Object, Object> proxy)
return tree;
}

@SuppressWarnings("unchecked")
private void mergeModules(Map<String, Object> source)
{
Set<String> newKeys = source.keySet();
for (String key : newKeys) {
Object newEntry = source.get(key);
if (!modules.containsKey(key)) {
modules.put(key, newEntry);
} else {
Object origEntry = modules.get(key);
if (!(origEntry instanceof Map) || !(newEntry instanceof Map)) {
// That would be odd indeed.
continue;
}

Map<Object, Object> newEntryMap = (Map<Object, Object>) newEntry;
Map<Object, Object> origEntryMap = (Map<Object, Object>) origEntry;

if (newEntryMap.containsKey("apiName") && !origEntryMap.containsKey("apiName")) {
origEntryMap.put("apiName", newEntryMap.get("apiName"));
}

String[] listNames = {"childModules", "createProxies"};
for (String listName : listNames) {
if (newEntryMap.containsKey(listName)) {
JSONArray list = (JSONArray) newEntryMap.get(listName);
for (int i = 0; i < list.size(); i++) {
jsonUtils.appendUniqueObject(origEntryMap, listName, "id", (Map<Object, Object>) list.get(i));
}
}
}
}
}
}

@SuppressWarnings("unchecked")
protected void loadBindings(String jsonPath)
throws ParseException, IOException
Expand All @@ -225,7 +262,7 @@ protected void loadBindings(String jsonPath)
Map<String, Object> modules = jsonUtils.getStringMap(properties, "modules");

this.proxies.putAll(proxies);
this.modules.putAll(modules);
mergeModules(modules);
}

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -267,7 +304,6 @@ protected void generateApiTree()
}
}

@SuppressWarnings("unchecked")
protected void generateBindings()
throws ParseException, IOException
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.appcelerator.kroll.KrollModule;
import org.appcelerator.kroll.KrollProxy;
import org.appcelerator.kroll.annotations.Kroll;
import org.appcelerator.titanium.TiApplication;
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.TiContext;
import org.appcelerator.titanium.proxy.IntentProxy;
Expand Down Expand Up @@ -53,15 +54,13 @@ public void handleCreationArgs(KrollModule createdInModule, Object[] args)
super.handleCreationArgs(createdInModule, args);

pendingIntentContext = getActivity();
//pendingIntentContext = this.context.getActivity();
/*
if (context == null) {
pendingIntentContext = this.context.getRootActivity();
if (pendingIntentContext == null) {
pendingIntentContext = TiApplication.getAppCurrentActivity();
}
if (context == null) {
pendingIntentContext = TiApplication.getInstance().getApplicationContext();
if (pendingIntentContext == null) {
pendingIntentContext = TiApplication.getInstance();
}
*/

if (pendingIntentContext == null || intent == null) {
throw new IllegalStateException("Creation arguments must contain intent");
}
Expand Down
22 changes: 21 additions & 1 deletion android/runtime/v8/tools/genBootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,31 @@ def loadBindings():
if os.path.exists(jsonPath):
bindingPaths.append(jsonPath)

def mergeModules(source, dest):
for k in source.keys():
if k not in dest:
dest[k] = source[k]
else:
origEntry = dest[k]
newEntry = source[k]

if "apiName" in newEntry and "apiName" not in origEntry:
origEntry["apiName"] = newEntry["apiName"]

for listName in ("childModules", "createProxies"):
if listName in newEntry and listName not in origEntry:
origEntry[listName] = newEntry[listName]
elif listName in newEntry:
origIds = [c["id"] for c in origEntry[listName]]
newMembers = [c for c in newEntry[listName] if c["id"] not in origIds]
if newMembers:
origEntry[listName].extend(newMembers)

for bindingPath in bindingPaths:
moduleName = os.path.basename(bindingPath).replace(".json", "")
binding = json.load(open(bindingPath))
bindings["proxies"].update(binding["proxies"])
bindings["modules"].update(binding["modules"])
mergeModules(binding["modules"], bindings["modules"])

return bindings

Expand Down
31 changes: 31 additions & 0 deletions drillbit/tests/android/android/android.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,37 @@ describe("Ti.Android tests", {
intent.setFlags(Ti.Android.FLAG_ACTIVITY_NEW_TASK);
valueOf(intent.getFlags()).shouldBe(Ti.Android.FLAG_ACTIVITY_NEW_TASK);
},

// http://jira.appcelerator.org/browse/TIMOB-6928
proxyInvocation: function() {
var intent, pending, notification;
valueOf(function() {
intent = Ti.Android.createIntent({
className:"org.appcelerator.titanium.TiActivity",
flags: Ti.Android.FLAG_ACTIVITY_CLEAR_TOP | Ti.Android.FLAG_ACTIVITY_SINGLE_TOP,
packageName:Ti.App.id
});
}).shouldNotThrowException();

valueOf(function() {
pending = Ti.Android.createPendingIntent({
intent: intent,
flags:Ti.Android.FLAG_UPDATE_CURRENT
});
}).shouldNotThrowException();

valueOf(function() {
var notification = Ti.Android.createNotification({
contentTitle: "hello",
contentText: "hello",
when: 0,
contentIntent: pending,
icon: Ti.Android.R.drawable.progress_indeterminate_horizontal,
tickerText: "hello",
flags: (Ti.Android.FLAG_ONGOING_EVENT | Ti.Android.FLAG_NO_CLEAR)
});
}).shouldNotThrowException();
},

options: {
forceBuild: true
Expand Down