use of com.taobao.atlas.dexmerge.DexMergeClient in project atlas by alibaba.
the class PatchMerger method merge.
public void merge() throws MergeException, IOException {
try {
File outputDirectory = updateInfo.workDir;
File oringnalDir = new File(outputDirectory.getParentFile(), "orignal_" + updateInfo.baseVersion);
if (!outputDirectory.exists()) {
outputDirectory.mkdirs();
}
if (!oringnalDir.exists()) {
oringnalDir.mkdirs();
}
ZipFile patchZip = new ZipFile(patchFile);
Pair<File, String>[] updateBundles = new Pair[updateInfo.updateBundles.size()];
List<MergeObject> toMergeList = new ArrayList<MergeObject>();
//find original bundle and store in pair struct
for (int x = 0; x < updateInfo.updateBundles.size(); x++) {
UpdateInfo.Item item = updateInfo.updateBundles.get(x);
String bundleName = item.name;
String entryNamePrefix = String.format("%s%s", "lib", bundleName.replace(".", "_"));
String entryName = entryNamePrefix + ".so";
ZipEntry entry = patchZip.getEntry(entryName);
if (patchZip.getEntry(entryName) != null && !supportMerge(bundleName)) {
//全量部署
File targetBundle = new File(outputDirectory, entryName);
OutputStream outputStream = new FileOutputStream(targetBundle);
InputStream inputStream = patchZip.getInputStream(entry);
copyStream(inputStream, outputStream);
mergeOutputs.put(bundleName, new Pair<>(targetBundle.getAbsolutePath(), item.version));
} else {
//差量部署
File originalBundle = findOriginalBundleFile(bundleName, oringnalDir.getAbsolutePath(), item);
if (originalBundle != null && originalBundle.exists()) {
updateBundles[x] = new Pair<File, String>(originalBundle, bundleName);
File targetBundle = new File(outputDirectory, "lib" + bundleName.replace(".", "_") + ".so");
if (targetBundle.exists()) {
targetBundle.delete();
}
toMergeList.add(new MergeObject(updateBundles[x].first.getAbsolutePath(), updateBundles[x].second, targetBundle.getAbsolutePath()));
mergeOutputs.put(bundleName, new Pair<>(targetBundle.getAbsolutePath(), item.version));
}
}
}
if (toMergeList.size() > 0) {
DexMergeClient dexMergeClient = getMergeClient();
boolean mergeFinish = dexMergeClient.dexMerge(patchFile.getAbsolutePath(), toMergeList, true);
dexMergeClient.unPrepare();
if (!mergeFinish) {
throw new MergeException("merge failed!");
}
}
} catch (Exception e) {
e.printStackTrace();
throw new MergeException("merge failed!");
} finally {
if (apkZip != null) {
try {
apkZip.close();
} catch (Throwable e) {
}
}
}
}
use of com.taobao.atlas.dexmerge.DexMergeClient in project atlas by alibaba.
the class PatchMerger method getMergeClient.
private DexMergeClient getMergeClient() {
DexMergeClient mergeClient = new DexMergeClient(mergeCallback);
boolean result = mergeClient.prepare();
if (result) {
return mergeClient;
}
throw new RuntimeException("prepare client error");
}
Aggregations