Search in sources :

Example 1 with BundleInfoSourceCreator

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);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) BundleInfoSourceCreator(com.taobao.android.builder.tasks.app.prepare.BundleInfoSourceCreator) IOException(java.io.IOException) GradleException(org.gradle.api.GradleException) MavenCoordinates(com.android.builder.model.MavenCoordinates) AndroidLibrary(com.android.builder.model.AndroidLibrary) BasicBundleInfo(com.taobao.android.builder.tools.bundleinfo.model.BasicBundleInfo) GradleException(org.gradle.api.GradleException) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) InjectParam(com.taobao.android.builder.tools.classinject.InjectParam) MtlBaseTaskAction(com.taobao.android.builder.tasks.manager.MtlBaseTaskAction) TaskAction(org.gradle.api.tasks.TaskAction)

Aggregations

AndroidLibrary (com.android.builder.model.AndroidLibrary)1 MavenCoordinates (com.android.builder.model.MavenCoordinates)1 BundleInfoSourceCreator (com.taobao.android.builder.tasks.app.prepare.BundleInfoSourceCreator)1 MtlBaseTaskAction (com.taobao.android.builder.tasks.manager.MtlBaseTaskAction)1 BasicBundleInfo (com.taobao.android.builder.tools.bundleinfo.model.BasicBundleInfo)1 InjectParam (com.taobao.android.builder.tools.classinject.InjectParam)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 GradleException (org.gradle.api.GradleException)1 TaskAction (org.gradle.api.tasks.TaskAction)1