Search in sources :

Example 1 with PatchFile

use of com.taobao.android.outputs.PatchFile in project atlas by alibaba.

the class TPatchTool method createTPatchFile.

private File createTPatchFile(File outPatchDir, File patchTmpDir) throws IOException {
    // 首先压缩主bundle,先判断主bundle里有没有文件
    File mainBundleFoder = new File(patchTmpDir, ((TpatchInput) input).mainBundleName);
    File metaFile = new File(mainBundleFoder, SO_PATCH_META);
    if (soFileDefs.size() > 0) {
        com.taobao.android.tpatch.model.PatchFile patchFile = new com.taobao.android.tpatch.model.PatchFile(metaFile);
        soFileDefs.stream().forEach(new Consumer<SoFileDef>() {

            @Override
            public void accept(SoFileDef soFileDef) {
                patchFile.append(soFileDef);
            }
        });
        patchFile.close();
    }
    File mainBundleFile = new File(patchTmpDir, ((TpatchInput) input).mainBundleName + ".so");
    if (FileUtils.listFiles(mainBundleFoder, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE).size() > 0) {
        hasMainBundle = true;
        CommandUtils.exec(mainBundleFoder, "zip -r " + mainBundleFile.getAbsolutePath() + " . -x */ -x .*");
    }
    FileUtils.deleteDirectory(mainBundleFoder);
    // 再压缩各自的bundle
    File patchFile = null;
    patchFile = new File(outPatchDir, "patch-" + input.newApkBo.getVersionName() + "@" + input.baseApkBo.getVersionName() + ".tpatch");
    if (patchFile.exists()) {
        FileUtils.deleteQuietly(patchFile);
    }
    File infoFile = new File(patchTmpDir, "patchInfo");
    FileUtils.writeStringToFile(infoFile, "patch-" + input.newApkBo.getVersionName() + "@" + input.baseApkBo.getVersionName() + ".tpatch");
    // zipBundle(patchTmpDir, patchFile);
    CommandUtils.exec(patchTmpDir, "zip -r " + patchFile.getAbsolutePath() + " . -x */ -x .*");
    FileUtils.deleteDirectory(patchTmpDir);
    return patchFile;
}
Also used : PatchFile(com.taobao.android.outputs.PatchFile) TpatchFile(com.taobao.android.outputs.TpatchFile) ZipFile(java.util.zip.ZipFile) PatchFile(com.taobao.android.outputs.PatchFile) TpatchInput(com.taobao.android.inputs.TpatchInput)

Example 2 with PatchFile

use of com.taobao.android.outputs.PatchFile in project atlas by alibaba.

the class TPatchTool method doPatch.

@Override
public PatchFile doPatch() throws Exception {
    TpatchInput tpatchInput = (TpatchInput) input;
    TpatchFile tpatchFile = new TpatchFile();
    File hisPatchJsonFile = new File(tpatchInput.outPutJson.getParentFile(), "patchs-" + input.newApkBo.getVersionName() + ".json");
    hisTpatchFolder = new File(tpatchInput.outPatchDir.getParentFile().getParentFile().getParentFile().getParentFile(), "hisTpatch");
    tpatchFile.diffJson = new File(((TpatchInput) input).outPatchDir, "diff.json");
    tpatchFile.patchInfo = new File(((TpatchInput) input).outPatchDir, "patchInfo.json");
    final File patchTmpDir = new File(((TpatchInput) input).outPatchDir, "tpatch-tmp");
    final File mainDiffFolder = new File(patchTmpDir, ((TpatchInput) input).mainBundleName);
    patchTmpDir.mkdirs();
    FileUtils.cleanDirectory(patchTmpDir);
    mainDiffFolder.mkdirs();
    File lastPatchFile = null;
    readWhiteList(((TpatchInput) input).bundleWhiteList);
    lastPatchFile = getLastPatchFile(input.baseApkBo.getVersionName(), ((TpatchInput) input).productName, ((TpatchInput) input).outPatchDir);
    PatchUtils.getTpatchClassDef(lastPatchFile, bundleClassMap);
    Profiler.release();
    Profiler.enter("unzip apks");
    // unzip apk
    File unzipFolder = unzipApk(((TpatchInput) input).outPatchDir);
    final File newApkUnzipFolder = new File(unzipFolder, NEW_APK_UNZIP_NAME);
    final File baseApkUnzipFolder = new File(unzipFolder, BASE_APK_UNZIP_NAME);
    Profiler.release();
    ExecutorServicesHelper executorServicesHelper = new ExecutorServicesHelper();
    String taskName = "diffBundleTask";
    // 
    Collection<File> soFiles = FileUtils.listFiles(newApkUnzipFolder, new String[] { "so" }, true);
    // process remote bumdle
    if ((((TpatchInput) input).splitDiffBundle != null)) {
        for (final Pair<BundleBO, BundleBO> bundle : ((TpatchInput) input).splitDiffBundle) {
            if (bundle.getFirst() == null || bundle.getSecond() == null) {
                logger.warning("remote bundle is not set to splitDiffBundles");
                continue;
            }
            executorServicesHelper.submitTask(taskName, new Callable<Boolean>() {

                @Override
                public Boolean call() throws Exception {
                    TPatchTool.this.processBundleFiles(bundle.getSecond().getBundleFile(), bundle.getFirst().getBundleFile(), patchTmpDir);
                    return true;
                }
            });
        }
    }
    Profiler.enter("awbspatch");
    Collection<File> retainFiles = FileUtils.listFiles(newApkUnzipFolder, new IOFileFilter() {

        @Override
        public boolean accept(File file) {
            String relativePath = PathUtils.toRelative(newApkUnzipFolder, file.getAbsolutePath());
            if (pathMatcher.match(DEFAULT_NOT_INCLUDE_RESOURCES, relativePath)) {
                return false;
            }
            if (null != ((TpatchInput) (input)).notIncludeFiles && pathMatcher.match(((TpatchInput) (input)).notIncludeFiles, relativePath)) {
                return false;
            }
            return true;
        }

        @Override
        public boolean accept(File file, String s) {
            return accept(new File(file, s));
        }
    }, TrueFileFilter.INSTANCE);
    executorServicesHelper.submitTask(taskName, new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            // 得到主bundle的dex diff文件
            // File mianDiffDestDex = new File(mainDiffFolder, DEX_NAME);
            // File tmpDexFolder = new File(patchTmpDir, ((TpatchInput)input).mainBundleName + "-dex");
            createBundleDexPatch(newApkUnzipFolder, baseApkUnzipFolder, mainDiffFolder, // tmpDexFolder,
            true);
            // 是否保留主bundle的资源文件
            if (isRetainMainBundleRes()) {
                copyMainBundleResources(newApkUnzipFolder, baseApkUnzipFolder, new File(patchTmpDir, ((TpatchInput) input).mainBundleName), retainFiles);
            }
            return true;
        }
    });
    for (final File soFile : soFiles) {
        System.out.println("do patch:" + soFile.getAbsolutePath());
        final String relativePath = PathUtils.toRelative(newApkUnzipFolder, soFile.getAbsolutePath());
        if (null != ((TpatchInput) input).notIncludeFiles && pathMatcher.match(((TpatchInput) input).notIncludeFiles, relativePath)) {
            continue;
        }
        executorServicesHelper.submitTask(taskName, new Callable<Boolean>() {

            @Override
            public Boolean call() throws Exception {
                File destFile = new File(patchTmpDir, ((TpatchInput) input).mainBundleName + "/" + relativePath);
                File baseSoFile = new File(baseApkUnzipFolder, relativePath);
                if (isBundleFile(soFile)) {
                    processBundleFiles(soFile, baseSoFile, patchTmpDir);
                } else if (isFileModify(soFile, baseSoFile)) {
                    if (destFile.exists()) {
                        FileUtils.deleteQuietly(destFile);
                    }
                    if (!baseSoFile.exists() || !((TpatchInput) input).diffNativeSo) {
                        // 新增
                        FileUtils.copyFile(soFile, destFile);
                    } else {
                        destFile = new File(destFile.getParentFile(), destFile.getName() + ".patch");
                        SoDiffUtils.diffSo(patchTmpDir, baseSoFile, soFile, destFile);
                        soFileDefs.add(new SoFileDef(baseSoFile, soFile, destFile, relativePath));
                    }
                }
                return true;
            }
        });
    }
    executorServicesHelper.waitTaskCompleted(taskName);
    executorServicesHelper.stop();
    Profiler.release();
    Profiler.enter("ziptpatchfile");
    // zip file
    File patchFile = createTPatchFile(((TpatchInput) input).outPatchDir, patchTmpDir);
    tpatchFile.patchFile = patchFile;
    PatchInfo curPatchInfo = createBasePatchInfo(patchFile);
    Profiler.release();
    Profiler.enter("createhistpatch");
    BuildPatchInfos buildPatchInfos = createIncrementPatchFiles(((TpatchInput) input).productName, patchFile, ((TpatchInput) input).outPatchDir, newApkUnzipFolder, curPatchInfo, ((TpatchInput) input).hisPatchUrl);
    Profiler.release();
    Profiler.enter("writejson");
    buildPatchInfos.getPatches().add(curPatchInfo);
    buildPatchInfos.setBaseVersion(input.baseApkBo.getVersionName());
    buildPatchInfos.setDiffBundleDex(input.diffBundleDex);
    FileUtils.writeStringToFile(((TpatchInput) input).outPutJson, JSON.toJSONString(buildPatchInfos));
    BuildPatchInfos testForBuildPatchInfos = new BuildPatchInfos();
    testForBuildPatchInfos.setBaseVersion(buildPatchInfos.getBaseVersion());
    List<PatchInfo> patchInfos = new ArrayList<>();
    testForBuildPatchInfos.setPatches(patchInfos);
    testForBuildPatchInfos.setDiffBundleDex(buildPatchInfos.isDiffBundleDex());
    for (PatchInfo patchInfo : buildPatchInfos.getPatches()) {
        if (patchInfo.getTargetVersion().equals(buildPatchInfos.getBaseVersion())) {
            patchInfos.add(patchInfo);
        }
    }
    FileUtils.writeStringToFile(hisPatchJsonFile, JSON.toJSONString(testForBuildPatchInfos));
    tpatchFile.updateJsons = new ArrayList<File>();
    Map<String, List<String>> map = new HashMap<>();
    for (PatchInfo patchInfo : buildPatchInfos.getPatches()) {
        UpdateInfo updateInfo = new UpdateInfo(patchInfo, buildPatchInfos.getBaseVersion());
        // System.out.println("start to check:"+patchInfo.getTargetVersion()+"......");
        // List<PatchChecker.ReasonMsg> msgs = new PatchChecker(updateInfo,bundleInfos.get(patchInfo.getTargetVersion()),new File(((TpatchInput) input).outPatchDir,patchInfo.getFileName())).check();
        // map.put(patchInfo.getFileName(),msgToString(msgs));
        File updateJson = new File(((TpatchInput) input).outPatchDir, "update-" + patchInfo.getTargetVersion() + ".json");
        FileUtils.writeStringToFile(updateJson, JSON.toJSONString(updateInfo, true));
        tpatchFile.updateJsons.add(updateJson);
    }
    // tpatchFile.patchChecker = new File(((TpatchInput) input).outPatchDir,"patch-check.json");
    // FileUtils.writeStringToFile(tpatchFile.patchChecker, JSON.toJSONString(map, true));
    // 删除临时的目录
    FileUtils.deleteDirectory(patchTmpDir);
    apkDiff.setBaseApkVersion(input.baseApkBo.getVersionName());
    apkDiff.setNewApkVersion(input.newApkBo.getVersionName());
    apkDiff.setBundleDiffResults(bundleDiffResults);
    boolean newApkFileExist = input.newApkBo.getApkFile().exists() && input.newApkBo.getApkFile().isFile();
    if (newApkFileExist) {
        apkDiff.setNewApkMd5(MD5Util.getFileMD5String(input.newApkBo.getApkFile()));
    }
    apkDiff.setFileName(input.newApkBo.getApkName());
    apkPatchInfos.setBaseApkVersion(input.baseApkBo.getVersionName());
    apkPatchInfos.setNewApkVersion(input.newApkBo.getVersionName());
    apkPatchInfos.setBundleDiffResults(diffPatchInfos);
    apkPatchInfos.setFileName(patchFile.getName());
    apkPatchInfos.setNewApkMd5(MD5Util.getFileMD5String(patchFile));
    FileUtils.writeStringToFile(tpatchFile.diffJson, JSON.toJSONString(apkDiff));
    FileUtils.writeStringToFile(tpatchFile.patchInfo, JSON.toJSONString(apkPatchInfos));
    FileUtils.copyFileToDirectory(tpatchFile.diffJson, ((TpatchInput) input).outPatchDir.getParentFile(), true);
    if (newApkFileExist) {
        FileUtils.copyFileToDirectory(input.newApkBo.getApkFile(), ((TpatchInput) input).outPatchDir.getParentFile(), true);
    }
    Profiler.release();
    logger.warning(Profiler.dump());
    return tpatchFile;
}
Also used : BundleBO(com.taobao.android.tpatch.model.BundleBO) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TpatchFile(com.taobao.android.outputs.TpatchFile) TpatchInput(com.taobao.android.inputs.TpatchInput) RecognitionException(org.antlr.runtime.RecognitionException) PatchException(com.taobao.android.differ.dex.PatchException) ExecutorServicesHelper(com.taobao.android.task.ExecutorServicesHelper) IOFileFilter(org.apache.commons.io.filefilter.IOFileFilter) TpatchFile(com.taobao.android.outputs.TpatchFile) ZipFile(java.util.zip.ZipFile) PatchFile(com.taobao.android.outputs.PatchFile) UpdateInfo(com.taobao.update.UpdateInfo)

Example 3 with PatchFile

use of com.taobao.android.outputs.PatchFile in project atlas by alibaba.

the class APatchTool method doPatch.

@Override
public PatchFile doPatch() throws Exception {
    APatchFile patchFile = new APatchFile();
    ApatchInput apatchInput = (ApatchInput) input;
    mappingMap = apatchInput.mappingMap;
    if (apatchInput.mappingMap.get(apatchInput.replaceAnnotation) != null) {
        MethodReplaceAnnotation.ANNOTATION = apatchInput.mappingMap.get(apatchInput.replaceAnnotation);
    }
    File patchTmpDir = new File(input.outPutFile.getParentFile(), "apatch-tmp");
    patchTmpDir.mkdirs();
    patchFile.aDiffText = new File(input.outPutFile.getParentFile(), "apatch-diff.txt");
    patchFile.diffJson = new File(input.outPutFile.getParentFile(), "apatch-diff.json");
    FileUtils.deleteQuietly(patchFile.aDiffText);
    patchFile.aDiffText.createNewFile();
    // unzip apk
    File unzipFolder = unzipApk(patchTmpDir);
    final File newApkUnzipFolder = new File(unzipFolder, NEW_APK_UNZIP_NAME);
    final File baseApkUnzipFolder = new File(unzipFolder, BASE_APK_UNZIP_NAME);
    // first generate main bundle patch file
    List<File> aPatches = createBundleAPatch(newApkUnzipFolder, baseApkUnzipFolder, patchTmpDir, apatchInput.andfixMainBundleName, patchFile.aDiffText, patchFile.diffJson);
    // second generate common bundle patch file
    // 
    Collection<File> soFiles = FileUtils.listFiles(newApkUnzipFolder, new String[] { "so" }, true);
    if (input.splitDiffBundle != null) {
        for (Pair<BundleBO, BundleBO> bundle : input.splitDiffBundle) {
            if (bundle.getFirst() == null || bundle.getSecond() == null) {
                continue;
            }
            List<File> aPatchFiles = processBundleFiles(bundle.getSecond().getBundleFile(), bundle.getFirst().getBundleFile(), patchTmpDir, patchFile.aDiffText, patchFile.diffJson);
            if (null != aPatchFiles) {
                for (File aPatchFile : aPatchFiles) {
                    if (null != aPatchFile && aPatchFile.exists()) {
                        aPatches.add(aPatchFile);
                    }
                }
            }
        }
    }
    for (File soFile : soFiles) {
        String relativePath = PathUtils.toRelative(newApkUnzipFolder, soFile.getAbsolutePath());
        if (null != apatchInput.notIncludeFiles && pathMatcher.match(apatchInput.notIncludeFiles, relativePath)) {
            continue;
        }
        File baseSoFile = new File(baseApkUnzipFolder, relativePath);
        if (PatchUtils.isBundleFile(soFile)) {
            // if bundle file
            List<File> aPatchFiles = processBundleFiles(soFile, baseSoFile, patchTmpDir, patchFile.aDiffText, patchFile.diffJson);
            if (null != aPatchFiles) {
                for (File aPatchFile : aPatchFiles) {
                    if (null != aPatchFile && aPatchFile.exists()) {
                        aPatches.add(aPatchFile);
                    }
                }
            }
        }
    }
    if (aPatches.size() <= 0) {
        throw new Exception("No apatch files! No classes modify!");
    }
    // merge apatch file
    File[] aPatchFiles = new File[aPatches.size()];
    aPatchFiles = aPatches.toArray(aPatchFiles);
    File mergePatchFile = null;
    if (null != aPatchFiles && aPatchFiles.length > 1) {
        MergePatch mergePatch = new MergePatch(aPatchFiles, apatchInput.projectArtifactId, patchTmpDir);
        mergePatchFile = mergePatch.doMerge();
    } else if (null != aPatchFiles && aPatchFiles.length == 1) {
        mergePatchFile = aPatchFiles[0];
    }
    if (null != mergePatchFile && mergePatchFile.exists()) {
        FileUtils.moveFile(mergePatchFile, input.outPutFile);
    }
    FileUtils.deleteDirectory(unzipFolder);
    FileUtils.deleteDirectory(patchTmpDir);
    patchFile.patchFile = input.outPutFile;
    return patchFile;
}
Also used : BundleBO(com.taobao.android.tpatch.model.BundleBO) ApatchInput(com.taobao.android.inputs.ApatchInput) APatchFile(com.taobao.android.outputs.APatchFile) File(java.io.File) APatchFile(com.taobao.android.outputs.APatchFile) PatchFile(com.taobao.android.outputs.PatchFile) MergePatch(com.taobao.android.apatch.MergePatch) IOException(java.io.IOException) RecognitionException(org.antlr.runtime.RecognitionException) PatchException(com.taobao.android.differ.dex.PatchException)

Example 4 with PatchFile

use of com.taobao.android.outputs.PatchFile in project atlas by alibaba.

the class DexPatchTool method doPatch.

@Override
public PatchFile doPatch() throws Exception {
    TpatchInput tpatchInput = (TpatchInput) input;
    DexPatchFile tpatchFile = new DexPatchFile();
    tpatchFile.diffJson = new File(tpatchInput.outPatchDir, "diff.json");
    tpatchFile.patchInfo = new File(tpatchInput.outPatchDir, "patchInfo.json");
    final File patchTmpDir = new File(tpatchInput.outPatchDir, "dexpatch-tmp");
    final File mainDiffFolder = new File(patchTmpDir, tpatchInput.mainBundleName);
    patchTmpDir.mkdirs();
    FileUtils.cleanDirectory(patchTmpDir);
    mainDiffFolder.mkdirs();
    Profiler.release();
    Profiler.enter("unzip apks");
    // unzip apk
    File unzipFolder = unzipApk(((TpatchInput) input).outPatchDir);
    final File newApkUnzipFolder = new File(unzipFolder, NEW_APK_UNZIP_NAME);
    final File baseApkUnzipFolder = new File(unzipFolder, BASE_APK_UNZIP_NAME);
    Profiler.release();
    ExecutorServicesHelper executorServicesHelper = new ExecutorServicesHelper();
    String taskName = "diffBundleTask";
    // 
    Collection<File> soFiles = FileUtils.listFiles(newApkUnzipFolder, new String[] { "so" }, true);
    // process remote bumdle
    if (tpatchInput.splitDiffBundle != null) {
        for (final Pair<BundleBO, BundleBO> bundle : ((TpatchInput) input).splitDiffBundle) {
            executorServicesHelper.submitTask(taskName, new Callable<Boolean>() {

                @Override
                public Boolean call() throws Exception {
                    processBundleFiles(bundle.getSecond().getBundleFile(), bundle.getFirst().getBundleFile(), patchTmpDir);
                    return true;
                }
            });
        }
    }
    Profiler.enter("awbspatch");
    executorServicesHelper.submitTask(taskName, new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            // 得到主bundle的dex diff文件
            createBundleDexPatch(newApkUnzipFolder, baseApkUnzipFolder, mainDiffFolder, true);
            return true;
        }
    });
    for (final File soFile : soFiles) {
        System.out.println("do dexpatch:" + soFile.getAbsolutePath());
        final String relativePath = PathUtils.toRelative(newApkUnzipFolder, soFile.getAbsolutePath());
        if (null != tpatchInput.notIncludeFiles && pathMatcher.match(tpatchInput.notIncludeFiles, relativePath)) {
            continue;
        }
        executorServicesHelper.submitTask(taskName, new Callable<Boolean>() {

            @Override
            public Boolean call() throws Exception {
                File destFile = new File(patchTmpDir, tpatchInput.mainBundleName + "/" + relativePath);
                File baseSoFile = new File(baseApkUnzipFolder, relativePath);
                if (isBundleFile(soFile)) {
                    processBundleFiles(soFile, baseSoFile, patchTmpDir);
                }
                return true;
            }
        });
    }
    executorServicesHelper.waitTaskCompleted(taskName);
    executorServicesHelper.stop();
    Profiler.release();
    Profiler.enter("ziptpatchfile");
    // zip file
    File patchFile = createDexPatchFile(tpatchInput.outPatchDir, patchTmpDir);
    tpatchFile.patchFile = patchFile;
    if (!patchFile.exists()) {
        return null;
    }
    PatchInfo curPatchInfo = createBasePatchInfo(patchFile);
    Profiler.release();
    Profiler.enter("writejson");
    BuildPatchInfos buildPatchInfos = new BuildPatchInfos();
    buildPatchInfos.getPatches().add(curPatchInfo);
    buildPatchInfos.setBaseVersion(input.baseApkBo.getVersionName());
    buildPatchInfos.setDiffBundleDex(true);
    FileUtils.writeStringToFile(tpatchInput.outPutJson, JSON.toJSONString(buildPatchInfos));
    // 删除临时的目录
    FileUtils.deleteDirectory(patchTmpDir);
    apkDiff.setBaseApkVersion(input.baseApkBo.getVersionName());
    apkDiff.setNewApkVersion(input.newApkBo.getVersionName());
    apkDiff.setBundleDiffResults(bundleDiffResults);
    boolean newApkFileExist = input.newApkBo.getApkFile().exists() && input.newApkBo.getApkFile().isFile();
    if (newApkFileExist) {
        apkDiff.setNewApkMd5(MD5Util.getFileMD5String(input.newApkBo.getApkFile()));
    }
    apkDiff.setFileName(input.newApkBo.getApkName());
    apkPatchInfos.setBaseApkVersion(input.baseApkBo.getVersionName());
    apkPatchInfos.setNewApkVersion(input.newApkBo.getVersionName());
    apkPatchInfos.setBundleDiffResults(diffPatchInfos);
    apkPatchInfos.setFileName(patchFile.getName());
    apkPatchInfos.setNewApkMd5(MD5Util.getFileMD5String(patchFile));
    FileUtils.writeStringToFile(tpatchFile.diffJson, JSON.toJSONString(apkDiff));
    FileUtils.writeStringToFile(tpatchFile.patchInfo, JSON.toJSONString(apkPatchInfos));
    FileUtils.copyFileToDirectory(tpatchFile.diffJson, tpatchInput.outPatchDir.getParentFile(), true);
    if (newApkFileExist) {
        FileUtils.copyFileToDirectory(input.newApkBo.getApkFile(), tpatchInput.outPatchDir.getParentFile(), true);
    }
    Profiler.release();
    logger.warning(Profiler.dump());
    return tpatchFile;
}
Also used : BundleBO(com.taobao.android.tpatch.model.BundleBO) DexPatchFile(com.taobao.android.outputs.DexPatchFile) PatchInfo(com.taobao.android.object.PatchInfo) TpatchInput(com.taobao.android.inputs.TpatchInput) IOException(java.io.IOException) ExecutorServicesHelper(com.taobao.android.task.ExecutorServicesHelper) File(java.io.File) DexPatchFile(com.taobao.android.outputs.DexPatchFile) PatchFile(com.taobao.android.outputs.PatchFile) BuildPatchInfos(com.taobao.android.object.BuildPatchInfos)

Example 5 with PatchFile

use of com.taobao.android.outputs.PatchFile in project atlas by alibaba.

the class DexPatchTool method createDexPatchFile.

private File createDexPatchFile(File outPatchDir, File patchTmpDir) throws IOException {
    File mainBundleFoder = new File(patchTmpDir, ((TpatchInput) input).mainBundleName);
    File mainBundleFile = new File(patchTmpDir, "lib" + ((TpatchInput) input).mainBundleName.replace(".", "_") + ".so");
    if (FileUtils.listFiles(mainBundleFoder, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE).size() > 0) {
        CommandUtils.exec(mainBundleFoder, "zip -r " + mainBundleFile.getAbsolutePath() + " . -x */ -x .*");
    }
    FileUtils.deleteDirectory(mainBundleFoder);
    // 再压缩各自的bundle
    File patchFile = null;
    patchFile = new File(outPatchDir, input.newApkBo.getVersionName() + "@" + input.baseApkBo.getVersionName() + ".tpatch");
    if (patchFile.exists()) {
        FileUtils.deleteQuietly(patchFile);
    }
    // zipBundle(patchTmpDir, patchFile);
    CommandUtils.exec(patchTmpDir, "zip -r " + patchFile.getAbsolutePath() + " . -x */ -x .*");
    FileUtils.deleteDirectory(patchTmpDir);
    return patchFile;
}
Also used : File(java.io.File) DexPatchFile(com.taobao.android.outputs.DexPatchFile) PatchFile(com.taobao.android.outputs.PatchFile) TpatchInput(com.taobao.android.inputs.TpatchInput)

Aggregations

PatchFile (com.taobao.android.outputs.PatchFile)5 TpatchInput (com.taobao.android.inputs.TpatchInput)4 BundleBO (com.taobao.android.tpatch.model.BundleBO)3 File (java.io.File)3 PatchException (com.taobao.android.differ.dex.PatchException)2 DexPatchFile (com.taobao.android.outputs.DexPatchFile)2 TpatchFile (com.taobao.android.outputs.TpatchFile)2 ExecutorServicesHelper (com.taobao.android.task.ExecutorServicesHelper)2 IOException (java.io.IOException)2 ZipFile (java.util.zip.ZipFile)2 RecognitionException (org.antlr.runtime.RecognitionException)2 MergePatch (com.taobao.android.apatch.MergePatch)1 ApatchInput (com.taobao.android.inputs.ApatchInput)1 BuildPatchInfos (com.taobao.android.object.BuildPatchInfos)1 PatchInfo (com.taobao.android.object.PatchInfo)1 APatchFile (com.taobao.android.outputs.APatchFile)1 UpdateInfo (com.taobao.update.UpdateInfo)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 IOFileFilter (org.apache.commons.io.filefilter.IOFileFilter)1