Skip to content

Commit

Permalink
Merge branch 'feature_newDemo' of github.com:alibaba/atlas into featu…
Browse files Browse the repository at this point in the history
…re_newDemo
  • Loading branch information
jiawulu committed Mar 21, 2017
2 parents 8af072c + 7ce4ff8 commit 03f3700
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 15 deletions.
2 changes: 1 addition & 1 deletion atlas-demo/AtlasDemo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ buildscript {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
dependencies {
classpath "com.taobao.android:atlasplugin:2.3.0.alpha2"
classpath "com.taobao.android:atlasplugin:2.3.0.alpha3"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,17 +249,14 @@
import java.net.URL;
import java.net.URLConnection;
import java.sql.Date;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.jar.Attributes;
import java.util.jar.JarOutputStream;
import java.util.jar.Manifest;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

/**
* 生成为atlas做动态部署的diff工具类
Expand Down Expand Up @@ -296,6 +293,12 @@ public class TPatchTool extends BasePatchTool {

protected File baseApkFileList;

public void setCreateAll(boolean createAll) {
this.createAll = createAll;
}

private boolean createAll = false;

public String getDexcode() {
return dexcode;
}
Expand Down Expand Up @@ -453,7 +456,7 @@ public Boolean call() throws Exception {
// 压缩patch文件夹,得到tpatch文件
File patchFile = createTPatchFile(outPatchDir, patchTmpDir);

PatchInfo curPatchInfo = createBasePatchInfo(patchFile.getName());
PatchInfo curPatchInfo = createBasePatchInfo(patchFile);
BuildPatchInfos buildPatchInfos = null;
// 生成多版本的tpatch文件
buildPatchInfos = createIncrementPatchFiles(productName,
Expand Down Expand Up @@ -570,7 +573,7 @@ private void processBundleFiles(File newBundleFile,
File diffTxtFile) throws IOException, RecognitionException, PatchException {
String bundleName = FilenameUtils.getBaseName(newBundleFile.getName());
File destPatchBundleDir = new File(patchTmpDir, bundleName);
if (!isModifyBundle(newBundleFile.getName())) {
if (!isModifyBundle(newBundleFile.getName())&&!createAll) {
return;
}
final File newBundleUnzipFolder = new File(newBundleFile.getParentFile(), bundleName);
Expand Down Expand Up @@ -775,11 +778,28 @@ private File unzipApk(File outPatchDir) {
* @param fileName
* @return
*/
public PatchInfo createBasePatchInfo(String fileName) {
public PatchInfo createBasePatchInfo(File file) {
PatchInfo patchInfo = new PatchInfo();
patchInfo.setPatchVersion(newApkVersion);
patchInfo.setTargetVersion(baseApkVersion);
patchInfo.setFileName(fileName);
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(File.separator)!= -1){
modifyBundles.add(zipEntry.getName().substring(3,zipEntry.getName().indexOf(File.separator)).replace("_","."));
}else if (zipEntry.getName().endsWith(".so")&&zipEntry.getName().indexOf(File.separator)== -1){
modifyBundles.add(zipEntry.getName().substring(3,zipEntry.getName().lastIndexOf(".")).replace("_","."));
}

}
try {
zipFile.close();
} catch (IOException e) {
e.printStackTrace();
}
for (ArtifactBundleInfo artifactBundleInfo : artifactBundleInfos) {
if (artifactBundleInfo.getMainBundle()) {
if (DiffType.MODIFY.equals(artifactBundleInfo.getDiffType()) || hasMainBundle) {
Expand Down Expand Up @@ -809,12 +829,35 @@ public PatchInfo createBasePatchInfo(String fileName) {
patchBundleInfo.setDependency(artifactBundleInfo.getDependency());
// patchBundleInfo.setBaseVersion(artifactBundleInfo.getBaseVersion());
patchInfo.getBundles().add(patchBundleInfo);
}else if (modifyBundles.contains(artifactBundleInfo.getPkgName())){
PatchBundleInfo patchBundleInfo = new PatchBundleInfo();
patchBundleInfo.setNewBundle(false);
patchBundleInfo.setMainBundle(false);
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);
}
}



return patchInfo;
}

private ZipFile newZipFile(File file) {
try {
return new ZipFile(file);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}

/**
* 生成增量的patch文件
*/
Expand Down Expand Up @@ -1157,16 +1200,16 @@ public static void main(String[] args) throws Exception {
// URL url1 = new URL(aaa.substring(1,aaa.length()-1));
//// downloadTPath(aaa.substring(1,aaa.length()-1), new File("/Users/lilong/Downloads/1111.patch"));
//// PatchUtils.getTpatchClassDef(lastPatchFile, bundleClassMap)
Map<String, Map<String, ClassDef>> bundleClassMap = new ConcurrentHashMap<String, Map<String, ClassDef>>();
PatchUtils.getTpatchClassDef(new File("/Users/lilong/Downloads/temp/[email protected]"),
bundleClassMap);
System.out.println(bundleClassMap.size());
// Map<String, Map<String, ClassDef>> bundleClassMap = new ConcurrentHashMap<String, Map<String, ClassDef>>();
// PatchUtils.getTpatchClassDef(new File("/Users/lilong/Downloads/temp/[email protected]"),
// bundleClassMap);
// System.out.println(bundleClassMap.size());
TPatchTool tPatchTool = new TPatchTool(new File("/Users/lilong/Downloads/taobao-android.apk"),
new File("/Users/lilong/Downloads/tpatch-diff.apk"),
"1.0.0",
"2.0.0",
true);
tPatchTool.bundleClassMap = bundleClassMap;
// tPatchTool.bundleClassMap = bundleClassMap;
tPatchTool.doPatch(new File("/Users/lilong/Downloads/aaa"),
false,
null,
Expand All @@ -1187,4 +1230,5 @@ public static void main(String[] args) throws Exception {
// tPatchTool.doPatch(dexDiffFile,false,null,false,null,null);

}

}

0 comments on commit 03f3700

Please sign in to comment.