Commit 516cd43b authored by ZhengCornell's avatar ZhengCornell Committed by Evan W. Patton

Move shared constants from Compiler and ComponentListGenerator into ComponentDescriptorConstants

parent 6f939f64
...@@ -161,6 +161,7 @@ ...@@ -161,6 +161,7 @@
<fileset dir="${local.lib.dir}" includes="*.jar"/> <fileset dir="${local.lib.dir}" includes="*.jar"/>
<fileset dir="${build.dir}" includes="common/CommonUtils.jar" /> <fileset dir="${build.dir}" includes="common/CommonUtils.jar" />
<fileset dir="${build.dir}" includes="common/CommonVersion.jar" /> <fileset dir="${build.dir}" includes="common/CommonVersion.jar" />
<fileset dir="${build.dir}" includes="components/CommonConstants.jar" />
<fileset dir="${lib.dir}" includes="bouncycastle/bcprov-jdk15on-149.jar"/> <fileset dir="${lib.dir}" includes="bouncycastle/bcprov-jdk15on-149.jar"/>
<fileset dir="${lib.dir}" includes="bouncycastle/bcpkix-jdk15on-149.jar"/> <fileset dir="${lib.dir}" includes="bouncycastle/bcpkix-jdk15on-149.jar"/>
<fileset dir="${lib.dir}" includes="android/tools/common-24.3.0.jar"/> <fileset dir="${lib.dir}" includes="android/tools/common-24.3.0.jar"/>
......
...@@ -9,6 +9,7 @@ package com.google.appinventor.buildserver; ...@@ -9,6 +9,7 @@ package com.google.appinventor.buildserver;
import com.google.appinventor.buildserver.util.AARLibraries; import com.google.appinventor.buildserver.util.AARLibraries;
import com.google.appinventor.buildserver.util.AARLibrary; import com.google.appinventor.buildserver.util.AARLibrary;
import com.google.appinventor.common.version.AppInventorFeatures; import com.google.appinventor.common.version.AppInventorFeatures;
import com.google.appinventor.components.common.ComponentDescriptorConstants;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Charsets; import com.google.common.base.Charsets;
import com.google.common.base.Strings; import com.google.common.base.Strings;
...@@ -83,39 +84,6 @@ public final class Compiler { ...@@ -83,39 +84,6 @@ public final class Compiler {
public static final String RUNTIME_FILES_DIR = "/" + "files" + "/"; public static final String RUNTIME_FILES_DIR = "/" + "files" + "/";
// Build info constants. Used for permissions, libraries, assets and activities.
// Must match ComponentProcessor.ARMEABI_V7A_SUFFIX
private static final String ARMEABI_V7A_SUFFIX = "-v7a";
// Must match ComponentProcessor.ARM64_V8A_SUFFIX
private static final String ARM64_V8A_SUFFIX = "-v8a";
// Must match ComponentProcessor.X86_64_SUFFIX
private static final String X86_64_SUFFIX = "-x8a";
// Must match Component.ASSET_DIRECTORY
private static final String ASSET_DIRECTORY = "component";
// Must match ComponentListGenerator.ASSETS_TARGET
private static final String ASSETS_TARGET = "assets";
// Must match ComponentListGenerator.ACTIVITIES_TARGET
private static final String ACTIVITIES_TARGET = "activities";
// Must match ComponentListGenerator.LIBRARIES_TARGET
public static final String LIBRARIES_TARGET = "libraries";
// Must match ComponentListGenerator.NATIVE_TARGET
public static final String NATIVE_TARGET = "native";
// Must match ComponentListGenerator.PERMISSIONS_TARGET
private static final String PERMISSIONS_TARGET = "permissions";
// Must match ComponentListGenerator.BROADCAST_RECEIVERS_TARGET
private static final String BROADCAST_RECEIVERS_TARGET = "broadcastReceivers";
// Must match ComponentListGenerator.ANDROIDMINSDK_TARGET
private static final String ANDROIDMINSDK_TARGET = "androidMinSdk";
// Must match ComponentListGenerator.CONDITIONALS_TARGET
private static final String CONDITIONALS_TARGET = "conditionals";
// TODO(Will): Remove the following target once the deprecated
// @SimpleBroadcastReceiver annotation is removed. It should
// should remain for the time being because otherwise we'll break
// extensions currently using @SimpleBroadcastReceiver.
//
// Must match ComponentListGenerator.BROADCAST_RECEIVER_TARGET
private static final String BROADCAST_RECEIVER_TARGET = "broadcastReceiver";
// Native library directory names // Native library directory names
private static final String LIBS_DIR_NAME = "libs"; private static final String LIBS_DIR_NAME = "libs";
...@@ -291,7 +259,7 @@ public final class Compiler { ...@@ -291,7 +259,7 @@ public final class Compiler {
@VisibleForTesting @VisibleForTesting
void generatePermissions() { void generatePermissions() {
try { try {
loadJsonInfo(permissionsNeeded, PERMISSIONS_TARGET); loadJsonInfo(permissionsNeeded, ComponentDescriptorConstants.PERMISSIONS_TARGET);
if (project != null) { // Only do this if we have a project (testing doesn't provide one :-( ). if (project != null) { // Only do this if we have a project (testing doesn't provide one :-( ).
LOG.log(Level.INFO, "usesLocation = " + project.getUsesLocation()); LOG.log(Level.INFO, "usesLocation = " + project.getUsesLocation());
if (project.getUsesLocation().equals("True")) { // Add location permissions if any WebViewer requests it if (project.getUsesLocation().equals("True")) { // Add location permissions if any WebViewer requests it
...@@ -313,7 +281,7 @@ public final class Compiler { ...@@ -313,7 +281,7 @@ public final class Compiler {
userErrors.print(String.format(ERROR_IN_STAGE, "Permissions")); userErrors.print(String.format(ERROR_IN_STAGE, "Permissions"));
} }
mergeConditionals(conditionals.get(PERMISSIONS_TARGET), permissionsNeeded); mergeConditionals(conditionals.get(ComponentDescriptorConstants.PERMISSIONS_TARGET), permissionsNeeded);
int n = 0; int n = 0;
for (String type : permissionsNeeded.keySet()) { for (String type : permissionsNeeded.keySet()) {
...@@ -409,7 +377,7 @@ public final class Compiler { ...@@ -409,7 +377,7 @@ public final class Compiler {
@VisibleForTesting @VisibleForTesting
void generateLibNames() { void generateLibNames() {
try { try {
loadJsonInfo(libsNeeded, LIBRARIES_TARGET); loadJsonInfo(libsNeeded, ComponentDescriptorConstants.LIBRARIES_TARGET);
} catch (IOException e) { } catch (IOException e) {
// This is fatal. // This is fatal.
e.printStackTrace(); e.printStackTrace();
...@@ -434,7 +402,7 @@ public final class Compiler { ...@@ -434,7 +402,7 @@ public final class Compiler {
@VisibleForTesting @VisibleForTesting
void generateNativeLibNames() { void generateNativeLibNames() {
try { try {
loadJsonInfo(nativeLibsNeeded, NATIVE_TARGET); loadJsonInfo(nativeLibsNeeded, ComponentDescriptorConstants.NATIVE_TARGET);
} catch (IOException e) { } catch (IOException e) {
// This is fatal. // This is fatal.
e.printStackTrace(); e.printStackTrace();
...@@ -459,7 +427,7 @@ public final class Compiler { ...@@ -459,7 +427,7 @@ public final class Compiler {
@VisibleForTesting @VisibleForTesting
void generateAssets() { void generateAssets() {
try { try {
loadJsonInfo(assetsNeeded, ASSETS_TARGET); loadJsonInfo(assetsNeeded, ComponentDescriptorConstants.ASSETS_TARGET);
} catch (IOException e) { } catch (IOException e) {
// This is fatal. // This is fatal.
e.printStackTrace(); e.printStackTrace();
...@@ -484,7 +452,7 @@ public final class Compiler { ...@@ -484,7 +452,7 @@ public final class Compiler {
@VisibleForTesting @VisibleForTesting
void generateActivities() { void generateActivities() {
try { try {
loadJsonInfo(activitiesNeeded, ACTIVITIES_TARGET); loadJsonInfo(activitiesNeeded, ComponentDescriptorConstants.ACTIVITIES_TARGET);
} catch (IOException e) { } catch (IOException e) {
// This is fatal. // This is fatal.
e.printStackTrace(); e.printStackTrace();
...@@ -509,7 +477,7 @@ public final class Compiler { ...@@ -509,7 +477,7 @@ public final class Compiler {
@VisibleForTesting @VisibleForTesting
void generateBroadcastReceivers() { void generateBroadcastReceivers() {
try { try {
loadJsonInfo(broadcastReceiversNeeded, BROADCAST_RECEIVERS_TARGET); loadJsonInfo(broadcastReceiversNeeded, ComponentDescriptorConstants.BROADCAST_RECEIVERS_TARGET);
} }
catch (IOException e) { catch (IOException e) {
// This is fatal. // This is fatal.
...@@ -521,7 +489,7 @@ public final class Compiler { ...@@ -521,7 +489,7 @@ public final class Compiler {
userErrors.print(String.format(ERROR_IN_STAGE, "BroadcastReceivers")); userErrors.print(String.format(ERROR_IN_STAGE, "BroadcastReceivers"));
} }
mergeConditionals(conditionals.get(BROADCAST_RECEIVERS_TARGET), broadcastReceiversNeeded); mergeConditionals(conditionals.get(ComponentDescriptorConstants.BROADCAST_RECEIVERS_TARGET), broadcastReceiversNeeded);
} }
/* /*
...@@ -533,7 +501,7 @@ public final class Compiler { ...@@ -533,7 +501,7 @@ public final class Compiler {
@VisibleForTesting @VisibleForTesting
void generateBroadcastReceiver() { void generateBroadcastReceiver() {
try { try {
loadJsonInfo(componentBroadcastReceiver, BROADCAST_RECEIVER_TARGET); loadJsonInfo(componentBroadcastReceiver, ComponentDescriptorConstants.BROADCAST_RECEIVER_TARGET);
} }
catch (IOException e) { catch (IOException e) {
// This is fatal. // This is fatal.
...@@ -548,7 +516,7 @@ public final class Compiler { ...@@ -548,7 +516,7 @@ public final class Compiler {
private void generateMinSdks() { private void generateMinSdks() {
try { try {
loadJsonInfo(minSdksNeeded, ANDROIDMINSDK_TARGET); loadJsonInfo(minSdksNeeded, ComponentDescriptorConstants.ANDROIDMINSDK_TARGET);
} catch (IOException|JSONException e) { } catch (IOException|JSONException e) {
// This is fatal. // This is fatal.
e.printStackTrace(); e.printStackTrace();
...@@ -1791,24 +1759,24 @@ public final class Compiler { ...@@ -1791,24 +1759,24 @@ public final class Compiler {
try { try {
for (String type : nativeLibsNeeded.keySet()) { for (String type : nativeLibsNeeded.keySet()) {
for (String lib : nativeLibsNeeded.get(type)) { for (String lib : nativeLibsNeeded.get(type)) {
boolean isV7a = lib.endsWith(ARMEABI_V7A_SUFFIX); boolean isV7a = lib.endsWith(ComponentDescriptorConstants.ARMEABI_V7A_SUFFIX);
boolean isV8a = lib.endsWith(ARM64_V8A_SUFFIX); boolean isV8a = lib.endsWith(ComponentDescriptorConstants.ARM64_V8A_SUFFIX);
boolean isx8664 = lib.endsWith(X86_64_SUFFIX); boolean isx8664 = lib.endsWith(ComponentDescriptorConstants.X86_64_SUFFIX);
String sourceDirName; String sourceDirName;
File targetDir; File targetDir;
if (isV7a) { if (isV7a) {
sourceDirName = ARMEABI_V7A_DIR_NAME; sourceDirName = ARMEABI_V7A_DIR_NAME;
targetDir = armeabiV7aDir; targetDir = armeabiV7aDir;
lib = lib.substring(0, lib.length() - ARMEABI_V7A_SUFFIX.length()); lib = lib.substring(0, lib.length() - ComponentDescriptorConstants.ARMEABI_V7A_SUFFIX.length());
} else if (isV8a) { } else if (isV8a) {
sourceDirName = ARM64_V8A_DIR_NAME; sourceDirName = ARM64_V8A_DIR_NAME;
targetDir = arm64V8aDir; targetDir = arm64V8aDir;
lib = lib.substring(0, lib.length() - ARM64_V8A_SUFFIX.length()); lib = lib.substring(0, lib.length() - ComponentDescriptorConstants.ARM64_V8A_SUFFIX.length());
} else if (isx8664) { } else if (isx8664) {
sourceDirName = X86_64_DIR_NAME; sourceDirName = X86_64_DIR_NAME;
targetDir = x8664Dir; targetDir = x8664Dir;
lib = lib.substring(0, lib.length() - X86_64_SUFFIX.length()); lib = lib.substring(0, lib.length() - ComponentDescriptorConstants.X86_64_SUFFIX.length());
} else { } else {
sourceDirName = ARMEABI_DIR_NAME; sourceDirName = ARMEABI_DIR_NAME;
targetDir = armeabiDir; targetDir = armeabiDir;
...@@ -2052,7 +2020,7 @@ public final class Compiler { ...@@ -2052,7 +2020,7 @@ public final class Compiler {
if (e.getMessage().contains("broadcastReceiver")) { if (e.getMessage().contains("broadcastReceiver")) {
LOG.log(Level.INFO, "Component \"" + type + "\" does not have a broadcast receiver."); LOG.log(Level.INFO, "Component \"" + type + "\" does not have a broadcast receiver.");
continue; continue;
} else if (e.getMessage().contains(ANDROIDMINSDK_TARGET)) { } else if (e.getMessage().contains(ComponentDescriptorConstants.ANDROIDMINSDK_TARGET)) {
LOG.log(Level.INFO, "Component \"" + type + "\" does not specify a minimum SDK."); LOG.log(Level.INFO, "Component \"" + type + "\" does not specify a minimum SDK.");
continue; continue;
} else { } else {
...@@ -2096,7 +2064,7 @@ public final class Compiler { ...@@ -2096,7 +2064,7 @@ public final class Compiler {
// Strip off the package name since SCM and BKY use unqualified names // Strip off the package name since SCM and BKY use unqualified names
type = type.substring(type.lastIndexOf('.') + 1); type = type.substring(type.lastIndexOf('.') + 1);
JSONObject conditionals = compJson.optJSONObject(CONDITIONALS_TARGET); JSONObject conditionals = compJson.optJSONObject(ComponentDescriptorConstants.CONDITIONALS_TARGET);
if (conditionals != null) { if (conditionals != null) {
JSONObject jsonBlockMap = conditionals.optJSONObject(targetInfo); JSONObject jsonBlockMap = conditionals.optJSONObject(targetInfo);
if (jsonBlockMap != null) { if (jsonBlockMap != null) {
......
// -*- mode: java; c-basic-offset: 2; -*-
// Copyright 2011-2019 MIT, All rights reserved
// Released under the Apache License, Version 2.0
// http://www.apache.org/licenses/LICENSE-2.0
package com.google.appinventor.components.common;
/**
* Contains constants related to the description of Simple components.
*
*/
public final class ComponentDescriptorConstants {
private ComponentDescriptorConstants() {
// nothing
}
// shared constants between ComponentListGenerator.java and Compiler.java
public static final String ARMEABI_V7A_SUFFIX = "-v7a";
public static final String ARM64_V8A_SUFFIX = "-v8a";
public static final String X86_64_SUFFIX = "-x8a";
public static final String ASSET_DIRECTORY = "component";
public static final String ASSETS_TARGET = "assets";
public static final String ACTIVITIES_TARGET = "activities";
public static final String LIBRARIES_TARGET = "libraries";
public static final String NATIVE_TARGET = "native";
public static final String PERMISSIONS_TARGET = "permissions";
public static final String BROADCAST_RECEIVERS_TARGET = "broadcastReceivers";
public static final String ANDROIDMINSDK_TARGET = "androidMinSdk";
public static final String CONDITIONALS_TARGET = "conditionals";
// TODO(Will): Remove the following target once the deprecated
// @SimpleBroadcastReceiver annotation is removed. It should
// should remain for the time being because otherwise we'll break
// extensions currently using @SimpleBroadcastReceiver.
public static final String BROADCAST_RECEIVER_TARGET = "broadcastReceiver";
}
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
package com.google.appinventor.components.scripts; package com.google.appinventor.components.scripts;
import com.google.appinventor.common.utils.StringUtils; import com.google.appinventor.common.utils.StringUtils;
import com.google.appinventor.components.common.ComponentDescriptorConstants;
import java.io.IOException; import java.io.IOException;
import java.io.Writer; import java.io.Writer;
...@@ -23,22 +24,6 @@ import javax.tools.FileObject; ...@@ -23,22 +24,6 @@ import javax.tools.FileObject;
* @author lizlooney@google.com (Liz Looney) * @author lizlooney@google.com (Liz Looney)
*/ */
public final class ComponentListGenerator extends ComponentProcessor { public final class ComponentListGenerator extends ComponentProcessor {
// Names of component information types to be output. Must match buildserver.compiler constants.
private static final String PERMISSIONS_TARGET = "permissions";
private static final String LIBRARIES_TARGET = "libraries";
private static final String ASSETS_TARGET = "assets";
private static final String NATIVE_TARGET = "native";
private static final String BROADCAST_RECEIVERS_TARGET = "broadcastReceivers";
private static final String ACTIVITIES_TARGET = "activities";
private static final String ANDROIDMINSDK_TARGET = "androidMinSdk";
private static final String CONDITONAL_TARGET = "conditional";
// TODO(Will): Remove the following target once the deprecated
// @SimpleBroadcastReceiver annotation is removed. It should
// should remain for the time being because otherwise we'll break
// extensions currently using @SimpleBroadcastReceiver.
private static final String BROADCAST_RECEIVER_TARGET = "broadcastReceiver";
// Where to write results. Build Info is the collection of permissions, asset and library info. // Where to write results. Build Info is the collection of permissions, asset and library info.
private static final String COMPONENT_LIST_OUTPUT_FILE_NAME = "simple_components.txt"; private static final String COMPONENT_LIST_OUTPUT_FILE_NAME = "simple_components.txt";
private static final String COMPONENT_BUILD_INFO_OUTPUT_FILE_NAME = private static final String COMPONENT_BUILD_INFO_OUTPUT_FILE_NAME =
...@@ -91,19 +76,19 @@ public final class ComponentListGenerator extends ComponentProcessor { ...@@ -91,19 +76,19 @@ public final class ComponentListGenerator extends ComponentProcessor {
private static void outputComponentBuildInfo(ComponentInfo component, StringBuilder sb) { private static void outputComponentBuildInfo(ComponentInfo component, StringBuilder sb) {
sb.append("{\"type\": \""); sb.append("{\"type\": \"");
sb.append(component.type).append("\""); sb.append(component.type).append("\"");
appendComponentInfo(sb, PERMISSIONS_TARGET, component.permissions); appendComponentInfo(sb, ComponentDescriptorConstants.PERMISSIONS_TARGET, component.permissions);
appendComponentInfo(sb, LIBRARIES_TARGET, component.libraries); appendComponentInfo(sb, ComponentDescriptorConstants.LIBRARIES_TARGET, component.libraries);
appendComponentInfo(sb, NATIVE_TARGET, component.nativeLibraries); appendComponentInfo(sb, ComponentDescriptorConstants.NATIVE_TARGET, component.nativeLibraries);
appendComponentInfo(sb, ASSETS_TARGET, component.assets); appendComponentInfo(sb, ComponentDescriptorConstants.ASSETS_TARGET, component.assets);
appendComponentInfo(sb, ACTIVITIES_TARGET, component.activities); appendComponentInfo(sb, ComponentDescriptorConstants.ACTIVITIES_TARGET, component.activities);
appendComponentInfo(sb, ANDROIDMINSDK_TARGET, Collections.singleton(Integer.toString(component.getAndroidMinSdk()))); appendComponentInfo(sb, ComponentDescriptorConstants.ANDROIDMINSDK_TARGET, Collections.singleton(Integer.toString(component.getAndroidMinSdk())));
appendComponentInfo(sb, BROADCAST_RECEIVERS_TARGET, component.broadcastReceivers); appendComponentInfo(sb, ComponentDescriptorConstants.BROADCAST_RECEIVERS_TARGET, component.broadcastReceivers);
appendConditionalComponentInfo(component, sb); appendConditionalComponentInfo(component, sb);
// TODO(Will): Remove the following call once the deprecated // TODO(Will): Remove the following call once the deprecated
// @SimpleBroadcastReceiver annotation is removed. It should // @SimpleBroadcastReceiver annotation is removed. It should
// should remain for the time being because otherwise we'll break // should remain for the time being because otherwise we'll break
// extensions currently using @SimpleBroadcastReceiver. // extensions currently using @SimpleBroadcastReceiver.
appendComponentInfo(sb, BROADCAST_RECEIVER_TARGET, component.classNameAndActionsBR); appendComponentInfo(sb, ComponentDescriptorConstants.BROADCAST_RECEIVER_TARGET, component.classNameAndActionsBR);
sb.append("}"); sb.append("}");
} }
...@@ -119,10 +104,10 @@ public final class ComponentListGenerator extends ComponentProcessor { ...@@ -119,10 +104,10 @@ public final class ComponentListGenerator extends ComponentProcessor {
component.conditionalBroadcastReceivers.size() == 0) { component.conditionalBroadcastReceivers.size() == 0) {
return; return;
} }
sb.append(", \"conditionals\": { "); sb.append(", \"" + ComponentDescriptorConstants.CONDITIONALS_TARGET + "\": { ");
sb.append("\"permissions\": "); sb.append("\"" + ComponentDescriptorConstants.PERMISSIONS_TARGET + "\": ");
appendMap(sb, component.conditionalPermissions); appendMap(sb, component.conditionalPermissions);
sb.append(", \"broadcastReceivers\": "); sb.append(", \"" + ComponentDescriptorConstants.BROADCAST_RECEIVERS_TARGET + "\": ");
appendMap(sb, component.conditionalBroadcastReceivers); appendMap(sb, component.conditionalBroadcastReceivers);
sb.append("}"); sb.append("}");
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment