Search in sources :

Example 1 with BundleInfo

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

the class BundleGraphExecutor method execute.

public static void execute(List<BundleInfo> bundleInfos, int parableCount, BundleItemRunner bundleItemRunner) throws IOException, InterruptedException {
    Map<String, BundleInfo> bundleInfoMap = new HashMap<>();
    bundleInfos.forEach(new Consumer<BundleInfo>() {

        @Override
        public void accept(BundleInfo bundleInfo) {
            bundleInfoMap.put(bundleInfo.getPkgName(), bundleInfo);
        }
    });
    Map<String, BundleItem> bundleItemMap = getBundleItemMap(bundleInfoMap);
    handleCircleDependency(bundleItemMap);
    int size = bundleItemMap.size();
    ExecutorServicesHelper executorServicesHelper = new ExecutorServicesHelper("bundleGraph", logger, parableCount);
    int index = 0;
    int j = 0;
    while (index <= size) {
        List<String> keys = new ArrayList<>();
        List<Runnable> runnables = new ArrayList<>();
        for (String key : bundleItemMap.keySet()) {
            // System.out.println("test" + key);
            BundleItem bundleItem = bundleItemMap.get(key);
            if (bundleItem.canResolve()) {
                index++;
                // bundleItem.resolve();
                keys.add(key);
                final String name = index + bundleItem.bundleInfo.getPkgName();
                runnables.add(new Runnable() {

                    @Override
                    public void run() {
                        logger.warn("start to do bundle proguard for " + name);
                        bundleItemRunner.execute(bundleItem);
                        logger.warn("end do bundle proguard for " + name);
                    }
                });
            }
        }
        Profiler.enter("execute stage " + j++ + " runnables " + runnables.size());
        executorServicesHelper.execute(runnables);
        Profiler.release();
        if (keys.isEmpty()) {
            break;
        }
        for (String key : keys) {
            bundleItemMap.get(key).resolve();
            bundleItemMap.remove(key);
        }
    }
    if (index != size) {
        throw new GradleException("bundleGraph is some thing wrong");
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ExecutorServicesHelper(com.taobao.android.builder.tools.concurrent.ExecutorServicesHelper) BundleInfo(com.taobao.android.builder.tools.bundleinfo.model.BundleInfo) GradleException(org.gradle.api.GradleException)

Example 2 with BundleInfo

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

the class BundleGraphExecutor method getBundleItemMap.

private static Map<String, BundleItem> getBundleItemMap(Map<String, BundleInfo> bundleInfoMap) {
    Map<String, BundleItem> bundleItemMap = new HashMap<>();
    for (BundleInfo bundleInfo : bundleInfoMap.values()) {
        BundleItem bundleItem = bundleItemMap.get(bundleInfo.getPkgName());
        if (null == bundleItem) {
            bundleItem = new BundleItem();
            bundleItem.bundleInfo = bundleInfo;
            bundleItemMap.put(bundleInfo.getPkgName(), bundleItem);
        }
        // Computing rely on
        for (String dependency : bundleInfo.getDependency()) {
            if (StringUtils.isNotEmpty(dependency)) {
                BundleItem child = bundleItemMap.get(dependency);
                if (null == child) {
                    child = new BundleItem();
                    child.bundleInfo = bundleInfoMap.get(dependency);
                    if (null == child.bundleInfo) {
                        throw new GradleException("bundle dependency is error , not bundle found for " + dependency + " ; which may define in " + bundleInfo.getPkgName());
                    }
                    bundleItemMap.put(dependency, child);
                }
                bundleItem.children.add(child);
                child.parents.add(bundleItem);
            }
        }
    }
    return bundleItemMap;
}
Also used : BundleInfo(com.taobao.android.builder.tools.bundleinfo.model.BundleInfo) HashMap(java.util.HashMap) GradleException(org.gradle.api.GradleException)

Example 3 with BundleInfo

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

the class PrepareBundleInfoTask method generateBundleListCfg.

private void generateBundleListCfg(AppVariantContext appVariantContext) throws IOException {
    List<String> bundleLists = AtlasBuildContext.awbBundleMap.values().stream().filter(awbBundle -> !awbBundle.isMBundle).map(awbBundle -> {
        return appVariantOutputContext.getAwbPackageOutputFilePath(awbBundle);
    }).sorted().collect(Collectors.toList());
    File outputFile = new File(appVariantContext.getScope().getGlobalScope().getOutputsDir(), "bundleList.cfg");
    FileUtils.deleteQuietly(outputFile);
    outputFile.getParentFile().mkdirs();
    FileUtils.writeLines(outputFile, bundleLists);
    appVariantContext.bundleListCfg = outputFile;
    // Set the bundle dependencies
    List<BundleInfo> bundleInfos = new ArrayList<>();
    AtlasBuildContext.awbBundleMap.values().stream().forEach(awbBundle -> bundleInfos.add(awbBundle.bundleInfo));
}
Also used : BundleInfo(com.taobao.android.builder.tools.bundleinfo.model.BundleInfo) BaseTask(com.android.build.gradle.internal.tasks.BaseTask) Predicate(java.util.function.Predicate) BundleInfoUtils(com.taobao.android.builder.tools.bundleinfo.BundleInfoUtils) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) HashMap(java.util.HashMap) BaseVariantOutput(com.android.build.gradle.api.BaseVariantOutput) Collectors(java.util.stream.Collectors) File(java.io.File) ArrayList(java.util.ArrayList) MtlBaseTaskAction(com.taobao.android.builder.tasks.manager.MtlBaseTaskAction) ExecutionException(java.util.concurrent.ExecutionException) Consumer(java.util.function.Consumer) TaskAction(org.gradle.api.tasks.TaskAction) DocumentException(org.dom4j.DocumentException) List(java.util.List) AppVariantOutputContext(com.android.build.gradle.internal.api.AppVariantOutputContext) Map(java.util.Map) AtlasBuildContext(com.taobao.android.builder.AtlasBuildContext) AppVariantContext(com.android.build.gradle.internal.api.AppVariantContext) AwbBundle(com.taobao.android.builder.dependency.model.AwbBundle) BundleInfo(com.taobao.android.builder.tools.bundleinfo.model.BundleInfo) ArrayList(java.util.ArrayList) File(java.io.File)

Example 4 with BundleInfo

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

the class AtlasProguardHelper method addParentKeeps.

private static void addParentKeeps(BundleItem bundleItem, Input input, AwbTransform awbTransform, Map<BundleInfo, AwbTransform> bundleInfoAwbTransformMap, AppVariantContext appVariantContext) throws IOException {
    Set<AwbBundle> parentBundles = new HashSet<>();
    for (BundleItem parent : bundleItem.parents) {
        parentBundles.add(bundleInfoAwbTransformMap.get(parent.bundleInfo).getAwbBundle());
        for (BundleInfo sub : parent.circles) {
            parentBundles.add(bundleInfoAwbTransformMap.get(sub).getAwbBundle());
        }
    }
    if (!parentBundles.isEmpty()) {
        List<AwbBundle> bundles = new ArrayList<>(parentBundles);
        Collections.sort(bundles, new Comparator<AwbBundle>() {

            @Override
            public int compare(AwbBundle o1, AwbBundle o2) {
                return o1.getName().compareTo(o2.getName());
            }
        });
        File keepFile = generateKeepFile(bundles, appVariantContext.getAwbProguardDir(awbTransform.getAwbBundle()));
        input.getParentKeeps().add(keepFile);
    }
}
Also used : BundleInfo(com.taobao.android.builder.tools.bundleinfo.model.BundleInfo) BundleItem(com.taobao.android.builder.tools.bundleinfo.BundleItem) AwbBundle(com.taobao.android.builder.dependency.model.AwbBundle) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 5 with BundleInfo

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

Aggregations

BundleInfo (com.taobao.android.builder.tools.bundleinfo.model.BundleInfo)15 AwbBundle (com.taobao.android.builder.dependency.model.AwbBundle)9 File (java.io.File)7 AtlasDependencyTree (com.taobao.android.builder.dependency.AtlasDependencyTree)5 HashMap (java.util.HashMap)5 GradleException (org.gradle.api.GradleException)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 BundleItem (com.taobao.android.builder.tools.bundleinfo.BundleItem)3 TypeReference (com.alibaba.fastjson.TypeReference)2 BaseVariantOutput (com.android.build.gradle.api.BaseVariantOutput)2 AppVariantOutputContext (com.android.build.gradle.internal.api.AppVariantOutputContext)2 AwbTransform (com.android.build.gradle.internal.api.AwbTransform)2 Map (java.util.Map)2 JarFile (java.util.jar.JarFile)2 JSONArray (com.alibaba.fastjson.JSONArray)1 JSONObject (com.alibaba.fastjson.JSONObject)1 AppVariantContext (com.android.build.gradle.internal.api.AppVariantContext)1 VariantScope (com.android.build.gradle.internal.scope.VariantScope)1 BaseTask (com.android.build.gradle.internal.tasks.BaseTask)1