use of com.taobao.android.builder.tasks.app.prepare.BundleInfoSourceCreator in project atlas by alibaba.
the class GenerateAtlasSourceTask method generate.
@TaskAction
void generate() {
InjectParam injectParam = getInput();
boolean supportRemoteComponent = true;
if (AtlasBuildContext.androidDependencyTrees.get(getVariantName()) != null) {
List<AndroidLibrary> libraries = AtlasBuildContext.androidDependencyTrees.get(getVariantName()).getMainBundle().getAndroidLibraries();
if (libraries.size() > 0) {
for (AndroidLibrary library : libraries) {
MavenCoordinates coordinates = library.getResolvedCoordinates();
if (coordinates.getArtifactId().equals("atlas_core") && coordinates.getGroupId().equals("com.taobao.android")) {
if (coordinates.getVersion().compareTo("5.0.8") < 0) {
supportRemoteComponent = false;
}
}
}
}
}
List<BasicBundleInfo> info = JSON.parseArray(injectParam.bundleInfo, BasicBundleInfo.class);
File outputSourceGeneratorFile = new File(outputDir, "android/taobao/atlas/framework/AtlasBundleInfoGenerator.java");
StringBuffer infoGeneratorSourceStr = new BundleInfoSourceCreator().createBundleInfoSourceStr(info, supportRemoteComponent);
outputSourceGeneratorFile.getParentFile().mkdirs();
try {
FileUtils.writeStringToFile(outputSourceGeneratorFile, infoGeneratorSourceStr.toString());
} catch (IOException e) {
throw new GradleException(e.getMessage(), e);
}
File outputPropertiesFile = new File(outputDir, "android/taobao/atlas/framework/FrameworkProperties.java");
List<String> lines = new ArrayList<>();
outputPropertiesFile.getParentFile().mkdirs();
lines.add("package android.taobao.atlas.framework;");
lines.add("public class FrameworkProperties {");
lines.add("private String version = \"" + injectParam.version + "\";");
lines.add("public String getVersion() {return version;}");
String escapeExprBundleInfo = escapeExprSpecialWord(injectParam.bundleInfo);
if (injectParam.bundleInfo.length() < 65535) {
lines.add("public static String bundleInfo = \"" + escapeExprBundleInfo + "\";");
lines.add("public static final boolean compressInfo = false;");
} else {
String compressBundleInfo = compressBundleInfo(injectParam.bundleInfo);
lines.add("public static String bundleInfo = \"" + compressBundleInfo + "\";");
lines.add("public static final boolean compressInfo = true;");
}
// lines.add("public static String bunleInfo = \"\";");
if (StringUtils.isNotEmpty(injectParam.autoStartBundles)) {
lines.add("public static String autoStartBundles = \"" + injectParam.autoStartBundles + "\";");
}
if (StringUtils.isNotEmpty(injectParam.blackDialogActivity)) {
lines.add("public static String blackDialogActivity = \"" + injectParam.blackDialogActivity + "\";");
}
lines.add("public static String autoStart = \"" + injectParam.autoStart + "\";");
if (StringUtils.isNotEmpty(injectParam.preLaunch)) {
lines.add("public static String preLaunch = \"" + injectParam.preLaunch + "\";");
}
if (StringUtils.isNotEmpty(injectParam.group)) {
lines.add("public static String group = \"" + injectParam.group + "\";");
}
lines.add("public static String outApp = \"" + injectParam.outApp + "\";");
lines.add("}");
try {
FileUtils.writeLines(outputPropertiesFile, lines);
Map output = new HashMap();
output.put("bundleInfo", JSON.parseArray(injectParam.bundleInfo));
output.put("autoStartBundles", injectParam.autoStartBundles);
output.put("preLaunch", injectParam.preLaunch);
output.put("group", injectParam.group);
output.put("outApp", injectParam.outApp);
output.put("unit_tag", injectParam.unit_tag);
output.put("autoStart", injectParam.autoStart);
output.put("blackDialogActivity", injectParam.blackDialogActivity);
FileUtils.write(new File(appVariantContext.getProject().getBuildDir(), "outputs/atlasFrameworkProperties.json"), JSON.toJSONString(output, true));
} catch (Exception e) {
throw new GradleException(e.getMessage(), e);
}
}
Aggregations