Search in sources :

Example 1 with TpatchInput

use of com.taobao.android.inputs.TpatchInput 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 2 with TpatchInput

use of com.taobao.android.inputs.TpatchInput in project atlas by alibaba.

the class TPatchTool method processBundleFiles.

/**
 * process bundle files
 *
 * @param newBundleFile
 * @param baseBundleFile
 * @param patchTmpDir
 * @param diffTxtFile
 */
public void processBundleFiles(File newBundleFile, File baseBundleFile, File patchTmpDir) throws Exception {
    String bundleName = FilenameUtils.getBaseName(newBundleFile.getName());
    File destPatchBundleDir = new File(patchTmpDir, bundleName);
    final File newBundleUnzipFolder = new File(newBundleFile.getParentFile(), bundleName);
    final File baseBundleUnzipFolder = new File(baseBundleFile.getParentFile(), bundleName);
    DiffType modifyType = getModifyType(newBundleFile.getName());
    long startTime = System.currentTimeMillis();
    logger.warning(">>> start to process bundle for patch " + bundleName + " >> difftype " + modifyType.toString() + " createALl:" + ((TpatchInput) input).createAll);
    if (modifyType == DiffType.ADD) {
        FileUtils.copyFileToDirectory(newBundleFile, patchTmpDir);
    } else if (((TpatchInput) input).createAll || (modifyType == DiffType.MODIFY)) {
        if (null != baseBundleFile && baseBundleFile.isFile() && baseBundleFile.exists() && !((TpatchInput) input).noPatchBundles.contains(baseBundleFile.getName().replace("_", ".").substring(3, baseBundleFile.getName().length() - 3)) && input.diffBundleDex) {
            doBundlePatch(newBundleFile, baseBundleFile, patchTmpDir, bundleName, destPatchBundleDir, newBundleUnzipFolder, baseBundleUnzipFolder);
        }
    }
    logger.warning(">>> fininsh to process bundle for patch " + bundleName + " >> difftype " + modifyType.toString() + " consume:" + (System.currentTimeMillis() - startTime));
}
Also used : TpatchFile(com.taobao.android.outputs.TpatchFile) ZipFile(java.util.zip.ZipFile) PatchFile(com.taobao.android.outputs.PatchFile) TpatchInput(com.taobao.android.inputs.TpatchInput)

Example 3 with TpatchInput

use of com.taobao.android.inputs.TpatchInput 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 4 with TpatchInput

use of com.taobao.android.inputs.TpatchInput 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 5 with TpatchInput

use of com.taobao.android.inputs.TpatchInput in project atlas by alibaba.

the class TPatchTool method createBasePatchInfo.

/**
 * 获取基准patch包的patchInfo对象
 *
 * @param fileName
 * @return
 */
public PatchInfo createBasePatchInfo(File file) {
    PatchInfo patchInfo = new PatchInfo();
    patchInfo.setPatchVersion(input.newApkBo.getVersionName());
    patchInfo.setTargetVersion(input.baseApkBo.getVersionName());
    patchInfo.setFileName(file.getName());
    Set<String> modifyBundles = new HashSet<>();
    ZipFile zipFile = newZipFile(file);
    Enumeration<? extends ZipEntry> enumeration = zipFile.entries();
    while (enumeration.hasMoreElements()) {
        ZipEntry zipEntry = enumeration.nextElement();
        if (zipEntry.getName().startsWith("lib") && zipEntry.getName().indexOf("/") != -1) {
            modifyBundles.add(zipEntry.getName().substring(3, zipEntry.getName().indexOf("/")).replace("_", "."));
        } else if (zipEntry.getName().endsWith(".so") && zipEntry.getName().indexOf("/") == -1) {
            modifyBundles.add(zipEntry.getName().substring(3, zipEntry.getName().lastIndexOf(".")).replace("_", "."));
        }
    }
    for (ArtifactBundleInfo artifactBundleInfo : input.artifactBundleInfos) {
        if (artifactBundleInfo.getMainBundle()) {
            if (DiffType.MODIFY.equals(artifactBundleInfo.getDiffType()) || hasMainBundle) {
                PatchBundleInfo patchBundleInfo = new PatchBundleInfo();
                patchBundleInfo.setNewBundle(DiffType.ADD.equals(artifactBundleInfo.getDiffType()));
                patchBundleInfo.setMainBundle(true);
                patchBundleInfo.setVersion(artifactBundleInfo.getVersion());
                patchBundleInfo.setName(((TpatchInput) input).mainBundleName);
                patchBundleInfo.setSrcUnitTag(artifactBundleInfo.getSrcUnitTag());
                patchBundleInfo.setUnitTag(artifactBundleInfo.getUnitTag());
                patchBundleInfo.setPatchType(bundleTypes.get(((TpatchInput) input).mainBundleName) == null ? 0 : bundleTypes.get(((TpatchInput) input).mainBundleName));
                patchBundleInfo.setApplicationName(artifactBundleInfo.getApplicationName());
                patchBundleInfo.setArtifactId(artifactBundleInfo.getArtifactId());
                patchBundleInfo.setPkgName(artifactBundleInfo.getPkgName());
                patchBundleInfo.setDependency(artifactBundleInfo.getDependency());
                patchBundleInfo.setBaseVersion(artifactBundleInfo.getBaseVersion());
                patchInfo.getBundles().add(patchBundleInfo);
                continue;
            }
        } else if (DiffType.MODIFY.equals(artifactBundleInfo.getDiffType()) || DiffType.ADD.equals(artifactBundleInfo.getDiffType())) {
            PatchBundleInfo patchBundleInfo = new PatchBundleInfo();
            patchBundleInfo.setNewBundle(DiffType.ADD.equals(artifactBundleInfo.getDiffType()));
            patchBundleInfo.setMainBundle(false);
            patchBundleInfo.setSrcUnitTag(artifactBundleInfo.getSrcUnitTag());
            patchBundleInfo.setUnitTag(artifactBundleInfo.getUnitTag());
            patchBundleInfo.setVersion(artifactBundleInfo.getVersion());
            patchBundleInfo.setPatchType(bundleTypes.get(artifactBundleInfo.getPkgName()) == null ? 0 : bundleTypes.get(artifactBundleInfo.getPkgName()));
            patchBundleInfo.setName(artifactBundleInfo.getPkgName());
            if (!modifyBundles.contains(artifactBundleInfo.getPkgName().replace("_", "."))) {
                patchBundleInfo.setInherit(true);
            }
            patchBundleInfo.setApplicationName(artifactBundleInfo.getApplicationName());
            patchBundleInfo.setArtifactId(artifactBundleInfo.getArtifactId());
            patchBundleInfo.setPkgName(artifactBundleInfo.getPkgName());
            patchBundleInfo.setDependency(artifactBundleInfo.getDependency());
            patchBundleInfo.setBaseVersion(artifactBundleInfo.getBaseVersion());
            patchInfo.getBundles().add(patchBundleInfo);
        } else if (modifyBundles.contains(artifactBundleInfo.getPkgName().replace("_", "."))) {
            PatchBundleInfo patchBundleInfo = new PatchBundleInfo();
            patchBundleInfo.setNewBundle(false);
            patchBundleInfo.setMainBundle(false);
            patchBundleInfo.setPatchType(bundleTypes.get(artifactBundleInfo.getPkgName()) == null ? 0 : bundleTypes.get(artifactBundleInfo.getPkgName()));
            patchBundleInfo.setSrcUnitTag(artifactBundleInfo.getSrcUnitTag());
            patchBundleInfo.setUnitTag(artifactBundleInfo.getUnitTag());
            patchBundleInfo.setVersion(artifactBundleInfo.getVersion());
            patchBundleInfo.setName(artifactBundleInfo.getName());
            patchBundleInfo.setApplicationName(artifactBundleInfo.getApplicationName());
            patchBundleInfo.setArtifactId(artifactBundleInfo.getArtifactId());
            patchBundleInfo.setPkgName(artifactBundleInfo.getPkgName());
            patchBundleInfo.setDependency(artifactBundleInfo.getDependency());
            patchBundleInfo.setBaseVersion(artifactBundleInfo.getBaseVersion());
            patchInfo.getBundles().add(patchBundleInfo);
            if (artifactBundleInfo.getUnitTag().equals(artifactBundleInfo.getSrcUnitTag())) {
                throw new RuntimeException(artifactBundleInfo.getPkgName() + "has contents change,but unitTag equals srcUnitTag" + artifactBundleInfo.getUnitTag() + ",please upgrade bundle version and reintegration");
            }
        }
    }
    try {
        zipFile.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return patchInfo;
}
Also used : ZipFile(java.util.zip.ZipFile) ZipEntry(java.util.zip.ZipEntry) TpatchInput(com.taobao.android.inputs.TpatchInput)

Aggregations

TpatchInput (com.taobao.android.inputs.TpatchInput)9 PatchFile (com.taobao.android.outputs.PatchFile)7 ZipFile (java.util.zip.ZipFile)6 TpatchFile (com.taobao.android.outputs.TpatchFile)5 BundleBO (com.taobao.android.tpatch.model.BundleBO)4 PatchException (com.taobao.android.differ.dex.PatchException)2 DexPatchFile (com.taobao.android.outputs.DexPatchFile)2 ExecutorServicesHelper (com.taobao.android.task.ExecutorServicesHelper)2 File (java.io.File)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 RecognitionException (org.antlr.runtime.RecognitionException)2 Pair (com.android.utils.Pair)1 AwbBundle (com.taobao.android.builder.dependency.model.AwbBundle)1 DexPatchInput (com.taobao.android.inputs.DexPatchInput)1 HotPatchInput (com.taobao.android.inputs.HotPatchInput)1 BuildPatchInfos (com.taobao.android.object.BuildPatchInfos)1 PatchInfo (com.taobao.android.object.PatchInfo)1 PatchFileBuilder (com.taobao.android.tpatch.builder.PatchFileBuilder)1 UpdateInfo (com.taobao.update.UpdateInfo)1 IOException (java.io.IOException)1