Search in sources :

Example 1 with ExecutorServicesHelper

use of com.taobao.android.task.ExecutorServicesHelper in project atlas by alibaba.

the class PatchFileBuilder method createHistoryTPatches.

/**
     * 创建历史版本的tpatch
     */
public BuildPatchInfos createHistoryTPatches(boolean diffBundleDex, final ILogger logger) throws PatchException {
    final BuildPatchInfos buildPatchInfos = new BuildPatchInfos();
    buildPatchInfos.setBaseVersion(baseVersion);
    List<PatchInfo> patchInfos = historyBuildPatchInfos.getPatches();
    String taskName = "CreateHisPatch";
    ExecutorServicesHelper executorServicesHelper = new ExecutorServicesHelper();
    for (final PatchInfo patchInfo : patchInfos) {
        if (patchInfo.getPatchVersion().split("\\.").length > 3 && TPatchTool.pName.equals("taobao4android")) {
            continue;
        }
        executorServicesHelper.submitTask(taskName, new Callable<Boolean>() {

            @Override
            public Boolean call() throws Exception {
                if (null != logger) {
                    logger.info("[CreateHisPatch]" + patchInfo.getPatchVersion() + "....");
                }
                try {
                    hisPatchInfos.put(patchInfo.getPatchVersion(), patchInfo);
                    PatchInfo newPatchInfo = createHisTPatch(patchInfo.getPatchVersion(), logger);
                    buildPatchInfos.getPatches().add(newPatchInfo);
                } catch (IOException e) {
                    throw new PatchException(e.getMessage(), e);
                }
                return true;
            }
        });
    }
    try {
        executorServicesHelper.waitTaskCompleted(taskName);
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (ExecutionException e) {
        e.printStackTrace();
    }
    executorServicesHelper.stop();
    buildPatchInfos.getPatches().add(currentBuildPatchInfo);
    buildPatchInfos.setDiffBundleDex(diffBundleDex);
    return buildPatchInfos;
}
Also used : PatchInfo(com.taobao.android.object.PatchInfo) PatchException(com.taobao.android.differ.dex.PatchException) ExecutionException(java.util.concurrent.ExecutionException) ExecutorServicesHelper(com.taobao.android.task.ExecutorServicesHelper) PatchException(com.taobao.android.differ.dex.PatchException) ExecutionException(java.util.concurrent.ExecutionException) BuildPatchInfos(com.taobao.android.object.BuildPatchInfos)

Example 2 with ExecutorServicesHelper

use of com.taobao.android.task.ExecutorServicesHelper in project atlas by alibaba.

the class TPatchTool method doPatch.

/**
     * 生成patch文件
     *
     * @param outPatchDir        生成patch文件的目录
     * @param createPatchJson
     * @param outPatchJson
     * @param createHistoryPatch
     * @param patchHistoryUrl
     * @param productName
     * @return 得到最后的patch的地址
     */
public File doPatch(File outPatchDir, boolean createPatchJson, File outPatchJson, boolean createHistoryPatch, String patchHistoryUrl, String productName) throws Exception {
    isTpatch = true;
    File lastPatchFile = null;
    pName = productName;
    lastPatchFile = getLastPatchFile(baseApkVersion, productName, outPatchDir);
    PatchUtils.getTpatchClassDef(lastPatchFile, bundleClassMap);
    final File diffTxtFile = new File(outPatchDir, "tpatch-diff.txt");
    final File patchTmpDir = new File(outPatchDir, "tpatch-tmp");
    File mainDiffFolder = new File(patchTmpDir, mainBundleName);
    FileUtils.deleteDirectory(patchTmpDir);
    FileUtils.deleteDirectory(mainDiffFolder);
    patchTmpDir.mkdirs();
    mainDiffFolder.mkdirs();
    // 解压apk
    File unzipFolder = unzipApk(outPatchDir);
    final File newApkUnzipFolder = new File(unzipFolder, NEW_APK_UNZIP_NAME);
    final File baseApkUnzipFolder = new File(unzipFolder, BASE_APK_UNZIP_NAME);
    // 得到主bundle的dex diff文件
    File mianDiffDestDex = new File(mainDiffFolder, DEX_NAME);
    File tmpDexFile = new File(patchTmpDir, mainBundleName + "-dex");
    createBundleDexPatch(newApkUnzipFolder, baseApkUnzipFolder, mianDiffDestDex, tmpDexFile, diffTxtFile);
    // 是否保留主bundle的资源文件
    if (isRetainMainBundleRes()) {
        copyMainBundleResources(newApkUnzipFolder, baseApkUnzipFolder, new File(patchTmpDir, mainBundleName));
    }
    ExecutorServicesHelper executorServicesHelper = new ExecutorServicesHelper();
    String taskName = "diffBundleTask";
    // 判断主bundle的so和awb的插件
    Collection<File> soFiles = FileUtils.listFiles(newApkUnzipFolder, new String[] { "so" }, true);
    for (final File soFile : soFiles) {
        final String relativePath = PathUtils.toRelative(newApkUnzipFolder, soFile.getAbsolutePath());
        if (null != notIncludeFiles && pathMatcher.match(notIncludeFiles, relativePath)) {
            continue;
        }
        executorServicesHelper.submitTask(taskName, new Callable<Boolean>() {

            @Override
            public Boolean call() throws Exception {
                File baseSoFile = new File(baseApkUnzipFolder, relativePath);
                if (PatchUtils.isBundleFile(soFile)) {
                    // 如果是bundle文件
                    processBundleFiles(soFile, baseSoFile, patchTmpDir, diffTxtFile);
                } else {
                    File destFile = new File(patchTmpDir, mainBundleName + File.separator + relativePath);
                    if (isFileModify(soFile, baseSoFile)) {
                        FileUtils.copyFile(soFile, destFile);
                    }
                }
                return true;
            }
        });
    }
    executorServicesHelper.waitTaskCompleted(taskName);
    executorServicesHelper.stop();
    // 压缩patch文件夹,得到tpatch文件
    File patchFile = createTPatchFile(outPatchDir, patchTmpDir);
    PatchInfo curPatchInfo = createBasePatchInfo(patchFile.getName());
    BuildPatchInfos buildPatchInfos = null;
    // 生成多版本的tpatch文件
    buildPatchInfos = createIncrementPatchFiles(productName, patchFile, outPatchDir, newApkUnzipFolder, curPatchInfo, patchHistoryUrl);
    buildPatchInfos.setDexcode(dexcode);
    if (createPatchJson) {
        FileUtils.writeStringToFile(outPatchJson, JSON.toJSONString(buildPatchInfos));
    }
    // 删除临时的目录
    FileUtils.deleteDirectory(patchTmpDir);
    //        FileUtils.deleteDirectory(unzipFolder);
    return patchFile;
}
Also used : ExecutorServicesHelper(com.taobao.android.task.ExecutorServicesHelper) PatchInfo(com.taobao.android.object.PatchInfo) File(java.io.File) BuildPatchInfos(com.taobao.android.object.BuildPatchInfos) RecognitionException(org.antlr.runtime.RecognitionException) PatchException(com.taobao.android.differ.dex.PatchException) IOException(java.io.IOException)

Aggregations

PatchException (com.taobao.android.differ.dex.PatchException)2 BuildPatchInfos (com.taobao.android.object.BuildPatchInfos)2 PatchInfo (com.taobao.android.object.PatchInfo)2 ExecutorServicesHelper (com.taobao.android.task.ExecutorServicesHelper)2 File (java.io.File)1 IOException (java.io.IOException)1 ExecutionException (java.util.concurrent.ExecutionException)1 RecognitionException (org.antlr.runtime.RecognitionException)1