7 package com.google.appinventor.components.scripts;
12 import java.io.IOException;
13 import java.io.Writer;
14 import java.util.Collections;
17 import javax.tools.Diagnostic;
18 import javax.tools.FileObject;
28 private static final String COMPONENT_LIST_OUTPUT_FILE_NAME =
"simple_components.txt";
29 private static final String COMPONENT_BUILD_INFO_OUTPUT_FILE_NAME =
30 "simple_components_build_info.json";
35 StringBuilder componentList =
new StringBuilder();
36 StringBuilder componentBuildInfo =
new StringBuilder();
37 componentBuildInfo.append(
"[\n");
40 String listSeparator =
"";
41 String jsonSeparator =
"";
45 componentList.append(listSeparator).append(component.
type);
48 componentBuildInfo.append(jsonSeparator);
49 outputComponentBuildInfo(component, componentBuildInfo);
50 jsonSeparator =
",\n";
53 componentBuildInfo.append(
"\n]");
55 FileObject src = createOutputFileObject(COMPONENT_LIST_OUTPUT_FILE_NAME);
56 Writer writer = src.openWriter();
58 writer.write(componentList.toString());
63 messager.printMessage(Diagnostic.Kind.NOTE,
"Wrote file " + src.toUri());
65 src = createOutputFileObject(COMPONENT_BUILD_INFO_OUTPUT_FILE_NAME);
66 writer = src.openWriter();
68 writer.write(componentBuildInfo.toString());
73 messager.printMessage(Diagnostic.Kind.NOTE,
"Wrote file " + src.toUri());
76 private static void outputComponentBuildInfo(ComponentInfo component, StringBuilder sb) {
77 sb.append(
"{\"type\": \"");
78 sb.append(component.type).append(
"\"");
90 appendConditionalComponentInfo(component, sb);
106 private static void appendConditionalComponentInfo(ComponentInfo component, StringBuilder sb) {
107 if (component.conditionalPermissions.size() +
108 component.conditionalBroadcastReceivers.size() +
109 component.conditionalServices.size() +
110 component.conditionalContentProviders.size() == 0) {
113 sb.append(
", \"" + ComponentDescriptorConstants.CONDITIONALS_TARGET +
"\": { ");
114 sb.append(
"\"" + ComponentDescriptorConstants.PERMISSIONS_TARGET +
"\": ");
115 appendMap(sb, component.conditionalPermissions);
116 sb.append(
", \"" + ComponentDescriptorConstants.BROADCAST_RECEIVERS_TARGET +
"\": ");
117 appendMap(sb, component.conditionalBroadcastReceivers);
118 sb.append(
", \"" + ComponentDescriptorConstants.SERVICES_TARGET +
"\": ");
119 appendMap(sb, component.conditionalServices);
120 sb.append(
", \"" + ComponentDescriptorConstants.CONTENT_PROVIDERS_TARGET +
"\": ");
121 appendMap(sb, component.conditionalContentProviders);
132 private static void appendMap(StringBuilder sb, Map<String, String[]> map) {
134 boolean first =
true;
135 for (Map.Entry<String, String[]> entry : map.entrySet()) {
136 if (!first) sb.append(
", ");
138 sb.append(entry.getKey());
139 sb.append(
"\": [\"");
140 StringUtils.join(sb,
"\", \"", entry.getValue());
147 private static void appendComponentInfo(StringBuilder sb,
148 String infoName, Set<String> infoEntries) {
149 sb.append(
", \"").append(infoName).append(
"\": [");
150 String separator =
"";
151 for (String infoEntry : infoEntries) {
152 sb.append(separator).append(
"\"").append(infoEntry).append(
"\"");