Search in sources :

Example 1 with PatchFileBuilder

use of com.taobao.android.tpatch.builder.PatchFileBuilder in project atlas by alibaba.

the class TPatchTool method createIncrementPatchFiles.

/**
     * 生成增量的patch文件
     */
private BuildPatchInfos createIncrementPatchFiles(String productionName, File curTPatchFile, File targetDirectory, File newApkUnzipFolder, PatchInfo curPatchInfo, String patchHistoryUrl) throws IOException, PatchException {
    BuildPatchInfos historyBuildPatchInfos = null;
    if (!StringUtils.isEmpty(patchHistoryUrl)) {
        String patchHisUrl = patchHistoryUrl + "?baseVersion=" + baseApkVersion + "&productIdentifier=" + productionName;
        String response = HttpClientUtils.getUrl(patchHisUrl);
        historyBuildPatchInfos = JSON.parseObject(response, BuildPatchInfos.class);
    }
    Map<String, File> awbBundleMap = new HashMap<String, File>();
    for (ArtifactBundleInfo artifactBundleInfo : artifactBundleInfos) {
        String bundleFileSoName = "lib" + artifactBundleInfo.getPkgName().replace('.', '_') + ".so";
        File bundleFile = new File(newApkUnzipFolder, "lib" + File.separator + "armeabi" + File.separator + bundleFileSoName);
        if (bundleFile.exists()) {
            awbBundleMap.put(artifactBundleInfo.getArtifactId(), bundleFile);
        }
    }
    PatchFileBuilder patchFileBuilder = new PatchFileBuilder(historyBuildPatchInfos, curTPatchFile, curPatchInfo, awbBundleMap, targetDirectory, baseApkVersion);
    patchFileBuilder.setNoPatchBundles(noPatchBundles);
    return patchFileBuilder.createHistoryTPatches(diffBundleDex, logger);
}
Also used : ArtifactBundleInfo(com.taobao.android.object.ArtifactBundleInfo) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) BuildPatchInfos(com.taobao.android.object.BuildPatchInfos) File(java.io.File) PatchFileBuilder(com.taobao.android.tpatch.builder.PatchFileBuilder)

Example 2 with PatchFileBuilder

use of com.taobao.android.tpatch.builder.PatchFileBuilder in project atlas by alibaba.

the class TPatchTool method createIncrementPatchFiles.

/**
 * create increment patch
 * file
 */
private BuildPatchInfos createIncrementPatchFiles(String productionName, File curTPatchFile, File targetDirectory, File newApkUnzipFolder, PatchInfo curPatchInfo, String patchHistoryUrl) throws IOException, PatchException {
    BuildPatchInfos historyBuildPatchInfos = null;
    String response = null;
    if (!StringUtils.isEmpty(patchHistoryUrl)) {
        String patchHisUrl = patchHistoryUrl + "?baseVersion=" + input.baseApkBo.getVersionName() + "&productIdentifier=" + productionName;
        try {
            response = HttpClientUtils.getUrl(patchHisUrl);
            historyBuildPatchInfos = JSON.parseObject(response, BuildPatchInfos.class);
        } catch (Throwable e) {
            historyBuildPatchInfos = null;
        }
    } else {
        File[] files = hisTpatchFolder.listFiles(new FilenameFilter() {

            @Override
            public boolean accept(File dir, String filename) {
                return filename.startsWith("patchs-") && filename.endsWith(".json");
            }
        });
        if (files != null && files.length > 0) {
            historyBuildPatchInfos = mergeHisPatchInfo(files);
        }
    }
    if (historyBuildPatchInfos == null) {
        return new BuildPatchInfos();
    }
    Iterator<PatchInfo> patchInfos = historyBuildPatchInfos.getPatches().iterator();
    while (patchInfos.hasNext()) {
        PatchInfo patchInfo = patchInfos.next();
        if (!patchInfo.getTargetVersion().equals(input.baseApkBo.getVersionName())) {
            patchInfos.remove();
        }
    }
    Map<String, File> awbBundleMap = new HashMap<String, File>();
    for (ArtifactBundleInfo artifactBundleInfo : input.artifactBundleInfos) {
        String bundleFileSoName = "lib" + artifactBundleInfo.getPkgName().replace('.', '_') + ".so";
        File bundleFile = new File(newApkUnzipFolder, "lib" + "/" + "armeabi" + "/" + bundleFileSoName);
        File assetsBundleFile = new File(newApkUnzipFolder, "assets" + "/" + bundleFileSoName);
        if (bundleFile.exists()) {
            awbBundleMap.put(artifactBundleInfo.getArtifactId(), bundleFile);
        } else if (assetsBundleFile.exists()) {
            awbBundleMap.put(artifactBundleInfo.getArtifactId(), assetsBundleFile);
        }
    }
    if (((TpatchInput) input).splitDiffBundle != null) {
        for (Pair<BundleBO, BundleBO> bundle : ((TpatchInput) input).splitDiffBundle) {
            awbBundleMap.put(bundle.getSecond().getBundleName(), bundle.getSecond().getBundleFile());
        }
    }
    PatchFileBuilder patchFileBuilder = new PatchFileBuilder(historyBuildPatchInfos, curTPatchFile, curPatchInfo, awbBundleMap, targetDirectory, input.baseApkBo.getVersionName());
    patchFileBuilder.setNoPatchBundles(((TpatchInput) input).noPatchBundles);
    patchFileBuilder.setHistroyVersionList(((TpatchInput) input).versionList);
    return patchFileBuilder.createHistoryTPatches(input.diffBundleDex, logger);
}
Also used : BundleBO(com.taobao.android.tpatch.model.BundleBO) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TpatchInput(com.taobao.android.inputs.TpatchInput) TpatchFile(com.taobao.android.outputs.TpatchFile) ZipFile(java.util.zip.ZipFile) PatchFile(com.taobao.android.outputs.PatchFile) PatchFileBuilder(com.taobao.android.tpatch.builder.PatchFileBuilder)

Aggregations

PatchFileBuilder (com.taobao.android.tpatch.builder.PatchFileBuilder)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 TpatchInput (com.taobao.android.inputs.TpatchInput)1 ArtifactBundleInfo (com.taobao.android.object.ArtifactBundleInfo)1 BuildPatchInfos (com.taobao.android.object.BuildPatchInfos)1 PatchFile (com.taobao.android.outputs.PatchFile)1 TpatchFile (com.taobao.android.outputs.TpatchFile)1 BundleBO (com.taobao.android.tpatch.model.BundleBO)1 File (java.io.File)1 HashMap (java.util.HashMap)1 ZipFile (java.util.zip.ZipFile)1