String backgroundPageFileName, ExtensionArtifact extension,
SortedSet<PageActionArtifact> pageActions,
SortedSet<BrowserActionArtifact> browserActions,
SortedSet<ContentScriptArtifact> contentScripts,
SortedSet<PluginArtifact> plugins) throws UnableToCompleteException {
final JsonObject config = JsonObject.create();
config.put("name", extension.getName());
config.put("version", extension.getVersion());
if (!extension.getUpdateUrl().equals(Extension.NO_UPDATE_URL)) {
config.put("update_url", extension.getUpdateUrl());
}
// All other fields in the manifest are optional
if (extension.getDescription().length() > 0) {
config.put("description", extension.getDescription());
}
if (backgroundPageFileName.length() > 0) {
config.put("background", createBgScriptsObject(backgroundPageFileName));
}
if (contentScripts.size() > 0) {
config.put("content_scripts", createContentScriptsArray(contentScripts));
}
if (pageActions.size() > 0) {
config.put("page_actions", createPageActionsArray(pageActions));
}
if (browserActions.size() > 0) {
JsonValue browserAction = createBrowserAction(browserActions);
if (browserAction != null) {
config.put("browser_action", browserAction);
}
}
if (plugins.size() > 0) {
config.put("plugins", createPluginsArray(plugins));
}
if (extension.getPermissions().length > 0) {
final JsonArray perms = JsonArray.create();
for (String perm : extension.getPermissions()) {
perms.add(perm);
}
config.put("permissions", perms);
}
if (extension.getIcons().length > 0) {
JsonObject icons = JsonObject.create();
for (IconInfo info : extension.getIcons()) {
icons.put(Integer.toString(info.getSize()), info.getFilename());
}
config.put("icons", icons);
}
if (extension.getPublicKey().length() > 0) {