Search in sources :

Example 1 with BasicBundleInfo

use of com.taobao.android.builder.tools.bundleinfo.model.BasicBundleInfo in project atlas by alibaba.

the class BundleInfoSourceCreator method createBundleInfoSourceStr.

public StringBuffer createBundleInfoSourceStr(List<BasicBundleInfo> basicBundleInfos, boolean supportRemotecomponent) {
    supportRemote = supportRemotecomponent;
    StringBuffer buffer = new StringBuffer();
    buffer.append("package android.taobao.atlas.bundleInfo;\n" + "\n" + "import java.util.ArrayList;\n" + "import java.util.HashMap;\n" + "import java.util.LinkedHashMap;\n" + "import java.util.List;\n" + "\n" + "\n" + "public class AtlasBundleInfoGenerator {\n" + "    public static BundleListing generateBundleInfo(){\n" + "        LinkedHashMap<String,BundleListing.BundleInfo> bundleInfos = new LinkedHashMap<>();\n" + "        HashMap<String,Boolean> activities;\n" + "        HashMap<String,Boolean> services;\n" + "        HashMap<String,Boolean> receivers;\n" + "        HashMap<String,Boolean> providers;\n" + "        HashMap<String,String> remoteFragments;\n" + "        HashMap<String,String> remoteViews;\n" + "        HashMap<String,String> remoteTransactors;\n" + "        List<String> dependencies;\n" + "        BundleListing.BundleInfo info;\n" + "\n" + "        BundleListing listing = new BundleListing();\n" + "        listing.bundles = bundleInfos;\n");
    if (basicBundleInfos != null && basicBundleInfos.size() > 0) {
        for (BasicBundleInfo info : basicBundleInfos) {
            buffer.append(generateBundleInfoItem(info));
        }
    }
    buffer.append("        return listing;\n" + "    }\n" + "}");
    return buffer;
}
Also used : BasicBundleInfo(com.taobao.android.builder.tools.bundleinfo.model.BasicBundleInfo)

Example 2 with BasicBundleInfo

use of com.taobao.android.builder.tools.bundleinfo.model.BasicBundleInfo 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)

Example 3 with BasicBundleInfo

use of com.taobao.android.builder.tools.bundleinfo.model.BasicBundleInfo in project atlas by alibaba.

the class ApkInjectInfoCreator method creteInjectParam.

public InjectParam creteInjectParam(AppVariantContext appVariantContext) throws Exception {
    InjectParam injectParam = new InjectParam();
    injectParam.removePreverify = !appVariantContext.getAtlasExtension().getTBuildConfig().getDoPreverify();
    injectParam.version = appVariantContext.getVariantConfiguration().getVersionName();
    AtlasDependencyTree atlasDependencyTree = AtlasBuildContext.androidDependencyTrees.get(appVariantContext.getScope().getVariantConfiguration().getFullName());
    List<BasicBundleInfo> basicBundleInfos = new ArrayList<BasicBundleInfo>();
    Map<String, BasicBundleInfo> basicBundleInfoMap = new HashMap<>();
    List<String> mainDexDependencies = atlasDependencyTree.getMainBundle().getAllDependencies();
    Collections.sort(mainDexDependencies, new Comparator<String>() {

        @Override
        public int compare(String o1, String o2) {
            return o1.compareTo(o2);
        }
    });
    String mainMd532 = MD5Util.getMD5(StringUtils.join(mainDexDependencies));
    String md5base36 = new BigInteger(mainMd532.substring(8, 24), 16).toString(36);
    injectParam.unit_tag = md5base36;
    appVariantContext.unit_tag = md5base36;
    // Depends on whether the change is sent
    DependencyDiff dependencyDiff = appVariantContext.getDependencyDiff();
    Map<String, String> baseTagMap = appVariantContext.getBaseUnitTagMap();
    for (AwbBundle awbBundle : atlasDependencyTree.getAwbBundles()) {
        // if (awbBundle.isMBundle){
        // continue;
        // }
        BundleInfo bundleInfo = awbBundle.bundleInfo;
        BasicBundleInfo basicBundleInfo = new BasicBundleInfo();
        basicBundleInfo.setApplicationName(bundleInfo.getApplicationName());
        basicBundleInfo.setVersion(bundleInfo.getVersion());
        basicBundleInfo.setPkgName(bundleInfo.getPkgName());
        // set unique_tag
        String bundleDependencyMd532 = MD5Util.getMD5(StringUtils.join(awbBundle.getAllDependencies()));
        String bundleUnitTag = "";
        if (null != dependencyDiff && !dependencyDiff.isDiffBundle(awbBundle)) {
            bundleUnitTag = baseTagMap.get(awbBundle.getPackageName());
        }
        if (StringUtils.isEmpty(bundleUnitTag)) {
            String bundleMd532 = MD5Util.getMD5(mainMd532 + bundleDependencyMd532);
            bundleUnitTag = new BigInteger(bundleMd532.substring(8, 24), 16).toString(36);
        }
        basicBundleInfo.setUnique_tag(bundleUnitTag);
        bundleInfo.setUnique_tag(bundleUnitTag);
        if (!bundleInfo.getIsInternal()) {
            basicBundleInfo.setIsInternal(false);
        }
        if (awbBundle.isMBundle) {
            basicBundleInfo.setIsMBundle(true);
        }
        if (!bundleInfo.getActivities().isEmpty()) {
            basicBundleInfo.setActivities(bundleInfo.getActivities());
        }
        if (!bundleInfo.getContentProviders().isEmpty()) {
            basicBundleInfo.setContentProviders(bundleInfo.getContentProviders());
        }
        if (!bundleInfo.getDependency().isEmpty()) {
            basicBundleInfo.setDependency(bundleInfo.getDependency());
        }
        if (!bundleInfo.getReceivers().isEmpty()) {
            basicBundleInfo.setReceivers(bundleInfo.getReceivers());
        }
        if (!bundleInfo.getServices().isEmpty()) {
            basicBundleInfo.setServices(bundleInfo.getServices());
        }
        if (!bundleInfo.getRemoteFragments().isEmpty()) {
            basicBundleInfo.setRemoteFragments(bundleInfo.getRemoteFragments());
        }
        if (!bundleInfo.getRemoteViews().isEmpty()) {
            basicBundleInfo.setRemoteViews(bundleInfo.getRemoteViews());
        }
        if (!bundleInfo.getRemoteTransactors().isEmpty()) {
            basicBundleInfo.setRemoteTransactors(bundleInfo.getRemoteTransactors());
        }
        basicBundleInfos.add(basicBundleInfo);
        basicBundleInfoMap.put(bundleInfo.getPkgName(), basicBundleInfo);
    }
    // Collections.sort(basicBundleInfos, (o1, o2) -> {
    // if (o1.getDependency().contains(o2.getPkgName())){
    // return -1;
    // }else {
    // return 1;
    // }
    // });
    basicBundleInfos.forEach(basicBundleInfo -> checkDependency(basicBundleInfo, atlasDependencyTree.getAwbBundles()));
    injectParam.bundleInfo = JSON.toJSONString(basicBundleInfos);
    // FIXME MOVE TO MTL-PLUGIN
    // List<String> autoStartBundles = new ArrayList<String>(appVariantContext.getAtlasExtension().getTBuildConfig
    // ().getAutoStartBundles());
    // 
    // UpdateConfig updateConfig = appVariantContext.getAtlasExtension().getUpdateConfig();
    // if (updateConfig.enabled) {
    // injectParam.group = updateConfig.getProductName();
    // injectParam.outApp = updateConfig.isOutApp();
    // autoStartBundles.add(0, updateConfig.getSdkPkgName());
    // }
    // 
    injectParam.group = appVariantContext.getAtlasExtension().getTBuildConfig().getGroup();
    injectParam.autoStartBundles = StringUtils.join(appVariantContext.getAtlasExtension().getTBuildConfig().getAutoStartBundles(), ",");
    injectParam.preLaunch = appVariantContext.getAtlasExtension().getTBuildConfig().getPreLaunch();
    mergeBundleInfos(appVariantContext, injectParam, basicBundleInfos, basicBundleInfoMap);
    return injectParam;
}
Also used : HashMap(java.util.HashMap) DependencyDiff(com.taobao.android.builder.dependency.diff.DependencyDiff) ArrayList(java.util.ArrayList) AtlasDependencyTree(com.taobao.android.builder.dependency.AtlasDependencyTree) BundleInfo(com.taobao.android.builder.tools.bundleinfo.model.BundleInfo) BasicBundleInfo(com.taobao.android.builder.tools.bundleinfo.model.BasicBundleInfo) BasicBundleInfo(com.taobao.android.builder.tools.bundleinfo.model.BasicBundleInfo) BigInteger(java.math.BigInteger) AwbBundle(com.taobao.android.builder.dependency.model.AwbBundle)

Example 4 with BasicBundleInfo

use of com.taobao.android.builder.tools.bundleinfo.model.BasicBundleInfo in project atlas by alibaba.

the class ApkInjectInfoCreator method mergeBundleInfos.

private void mergeBundleInfos(AppVariantContext appVariantContext, InjectParam injectParam, List<BasicBundleInfo> basicBundleInfos, Map<String, BasicBundleInfo> basicBundleInfoMap) throws IOException {
    if (appVariantContext.getAtlasExtension().getTBuildConfig().isIncremental()) {
        File atlasFrameworkPropertiesFile = new File(appVariantContext.apContext.getApExploredFolder(), "atlasFrameworkProperties.json");
        if (!atlasFrameworkPropertiesFile.exists()) {
            return;
        }
        String atlasFrameworkPropertiesStr = FileUtils.readFileToString(atlasFrameworkPropertiesFile);
        FrameworkProperties atlasFrameworkProperties = JSON.parseObject(atlasFrameworkPropertiesStr, FrameworkProperties.class);
        List<BasicBundleInfo> baseBundleInfos = atlasFrameworkProperties.bundleInfo;
        for (BasicBundleInfo baseBundleInfo : baseBundleInfos) {
            BasicBundleInfo basicBundleInfo = basicBundleInfoMap.get(baseBundleInfo.getPkgName());
            if (basicBundleInfo == null) {
                basicBundleInfos.add(baseBundleInfo);
                continue;
            }
            if (!baseBundleInfo.getActivities().isEmpty()) {
                basicBundleInfo.setActivities(concatList(baseBundleInfo.getActivities(), basicBundleInfo.getActivities()));
            }
            if (!baseBundleInfo.getContentProviders().isEmpty()) {
                basicBundleInfo.setContentProviders(concatList(baseBundleInfo.getContentProviders(), basicBundleInfo.getContentProviders()));
            }
            if (!baseBundleInfo.getDependency().isEmpty()) {
                basicBundleInfo.setDependency(concatList(baseBundleInfo.getDependency(), basicBundleInfo.getDependency()));
            }
            if (!baseBundleInfo.getReceivers().isEmpty()) {
                basicBundleInfo.setReceivers(concatList(baseBundleInfo.getReceivers(), basicBundleInfo.getReceivers()));
            }
            if (!baseBundleInfo.getServices().isEmpty()) {
                basicBundleInfo.setServices(concatList(baseBundleInfo.getServices(), basicBundleInfo.getServices()));
            }
            if (!baseBundleInfo.getRemoteFragments().isEmpty()) {
                basicBundleInfo.getRemoteFragments().putAll(baseBundleInfo.getRemoteFragments());
            }
            if (!baseBundleInfo.getRemoteViews().isEmpty()) {
                basicBundleInfo.getRemoteViews().putAll(baseBundleInfo.getRemoteViews());
            }
            if (!baseBundleInfo.getRemoteTransactors().isEmpty()) {
                basicBundleInfo.getRemoteTransactors().putAll(baseBundleInfo.getRemoteTransactors());
            }
        }
        injectParam.bundleInfo = JSON.toJSONString(basicBundleInfos);
        injectParam.autoStartBundles = atlasFrameworkProperties.autoStartBundles;
        injectParam.preLaunch = atlasFrameworkProperties.preLaunch;
    }
}
Also used : BasicBundleInfo(com.taobao.android.builder.tools.bundleinfo.model.BasicBundleInfo) File(java.io.File)

Aggregations

BasicBundleInfo (com.taobao.android.builder.tools.bundleinfo.model.BasicBundleInfo)4 File (java.io.File)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 AndroidLibrary (com.android.builder.model.AndroidLibrary)1 MavenCoordinates (com.android.builder.model.MavenCoordinates)1 AtlasDependencyTree (com.taobao.android.builder.dependency.AtlasDependencyTree)1 DependencyDiff (com.taobao.android.builder.dependency.diff.DependencyDiff)1 AwbBundle (com.taobao.android.builder.dependency.model.AwbBundle)1 BundleInfoSourceCreator (com.taobao.android.builder.tasks.app.prepare.BundleInfoSourceCreator)1 MtlBaseTaskAction (com.taobao.android.builder.tasks.manager.MtlBaseTaskAction)1 BundleInfo (com.taobao.android.builder.tools.bundleinfo.model.BundleInfo)1 InjectParam (com.taobao.android.builder.tools.classinject.InjectParam)1 IOException (java.io.IOException)1 BigInteger (java.math.BigInteger)1 Map (java.util.Map)1 GradleException (org.gradle.api.GradleException)1 TaskAction (org.gradle.api.tasks.TaskAction)1