Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
查郁 committed Nov 3, 2017
1 parent f02a366 commit 7298c1d
Show file tree
Hide file tree
Showing 30 changed files with 1,126 additions and 1,155 deletions.
2 changes: 1 addition & 1 deletion atlas-gradle-plugin/atlas-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ tasks.findByName("test").enabled=false
dependencies {
compile localGroovy()
compile gradleApi()
compile "com.taobao.android:dex_patch:1.4.4.4"
compile "com.taobao.android:dex_patch:1.4.4.6-SNAPSHOT"
compile "com.android.tools.build:gradle:2.3.3"
compile "org.apache.commons:commons-lang3:3.4"
compile "commons-lang:commons-lang:2.6"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ protected ProcessInfoBuilder makePackageProcessBuilder(AaptPackageConfig config)
// args.remove(indexD);
//}

//Join the generation of the R.txt file
//Join the outputs of the R.txt file
String sybolOutputDir = config.getSymbolOutputDir().getAbsolutePath();
if (!args.contains("--output-text-symbols") && null != sybolOutputDir) {
args.add("--output-text-symbols");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ public List<String> getArgs() {
args.addAll(origin.getArgs());
//args.remove("--no-version-vectors");

//Join the generation of the R.txt file
//Join the outputs of the R.txt file
if (!args.contains("--output-text-symbols") && null != sybolOutputDir) {
args.add("--output-text-symbols");
args.add(sybolOutputDir);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,18 +209,17 @@

package com.taobao.android.builder.extension;

import com.google.common.collect.Sets;
import com.taobao.android.builder.AtlasBuildContext;
import com.taobao.android.builder.extension.annotation.Config;
import org.apache.commons.lang.StringUtils;

import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.google.common.collect.Sets;
import com.taobao.android.builder.AtlasBuildContext;
import com.taobao.android.builder.extension.annotation.Config;
import com.taobao.android.builder.tools.EnvHelper;
import org.apache.commons.lang.StringUtils;

/**
* Created by shenghua.nish on 2016-05-17 As in the morning.
*/
Expand Down Expand Up @@ -266,6 +265,19 @@ public class PatchConfig {

private String tpatchHistoryUrl = "/rpc/dynamicBundle/getAllPatchInfo.json";

public String getLastPatchUrl() {
if (StringUtils.isEmpty(AtlasBuildContext.sBuilderAdapter.tpatchHistoryUrl)) {
return "";
}
return "http://" + AtlasBuildContext.sBuilderAdapter.tpatchHistoryUrl + LastPatchUrl;
}

public void setLastPatchUrl(String lastPatchUrl) {
LastPatchUrl = lastPatchUrl;
}

private String LastPatchUrl = "/rpc/dynamicBundle/getLastPatch.json?";

private Boolean onlyBuildModifyAwb = false;

private String noPatchBundles = "";
Expand Down Expand Up @@ -440,9 +452,7 @@ public void setTpatchWriteBuildInfo(boolean tpatchWriteBuildInfo) {
* @return
*/
public String getTpatchHistoryUrl() {
if ("true".equals(EnvHelper.getEnv("dexPatchEnabled", "false"))) {
return "";
}

if (StringUtils.isEmpty(AtlasBuildContext.sBuilderAdapter.tpatchHistoryUrl)) {
return "";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@
import com.android.builder.signing.DefaultSigningConfig;
import com.android.builder.signing.SigningException;
import com.android.utils.Pair;
import com.taobao.android.PatchManager;
import com.taobao.android.PatchType;
import com.taobao.android.TPatchTool;
import com.taobao.android.builder.AtlasBuildContext;
import com.taobao.android.builder.dependency.model.AwbBundle;
Expand All @@ -228,6 +230,9 @@
import com.taobao.android.builder.tools.BuildHelper;
import com.taobao.android.builder.tools.VersionUtils;
import com.taobao.android.builder.tools.manifest.ManifestFileUtils;
import com.taobao.android.inputs.BaseInput;
import com.taobao.android.inputs.DexPatchInput;
import com.taobao.android.inputs.TpatchInput;
import com.taobao.android.object.ApkFileList;
import com.taobao.android.object.ArtifactBundleInfo;
import com.taobao.android.tpatch.model.ApkBO;
Expand Down Expand Up @@ -301,15 +306,60 @@ public void doTPatch() throws Exception {

ApkBO apkBO = new ApkBO(baseApk, baseApkVersion, baseApk.getName());
ApkBO newApkBO = new ApkBO(newApk, newApkVersion, newApk.getName());
BaseInput baseInput = createInput(apkBO,newApkBO,retainMainBundleRes);
PatchManager patchManager = new PatchManager(baseInput);
patchManager.setLogger(getILogger());
getLogger().info("start to do patch");

TPatchTool tPatchTool = new TPatchTool(apkBO,
newApkBO,
patchContext.diffBundleDex);
//TODO
if (null != patchContext.patchVersions) {
tPatchTool.setVersionList(patchContext.patchVersions);
patchManager.doPatch();

getLogger().info("finish do patch");



try {

FileUtils.writeStringToFile(new File(getOutPatchFolder(), "tpatch-bundles.json"),
JSON.toJSONString(patchContext.artifactBundleInfos));


FileUtils.forceDelete(patchContext.newApk);

} catch (Exception e) {
throw new GradleException(e.getMessage(), e);
}

}

private BaseInput createInput(ApkBO apkBO, ApkBO newApkBO, boolean retainMainBundleRes) throws IOException {
TpatchInput tpatchInput = new DexPatchInput();
tpatchInput.baseApkBo = apkBO;
tpatchInput.newApkBo = newApkBO;
tpatchInput.baseApkFileList = patchContext.getBaseApkFiles();
tpatchInput.newApkFileList = patchContext.getNewApkFiles(appVariantContext);
tpatchInput.outPatchDir = outPatchFolder;
tpatchInput.productName = patchContext.appSignName;
tpatchInput.outPutJson = new File(getOutPatchFolder(), "patchs.json");
tpatchInput.artifactBundleInfos = patchContext.artifactBundleInfos;
tpatchInput.diffBundleDex = true;
tpatchInput.mainBundleName = patchContext.mainBundleName;
tpatchInput.retainMainBundleRes = retainMainBundleRes;
if (StringUtils.isNotBlank(patchContext.excludeFiles)) {
tpatchInput.notIncludeFiles = (patchContext.excludeFiles.split(","));
}
if (apkBO.getVersionName().equals(newApkBO)){
tpatchInput.patchType = PatchType.DEXPATCH;
tpatchInput.mainBundleName = "com.taobao.maindex";
}else {
tpatchInput.patchType = PatchType.TPATCH;
tpatchInput.createHisPatch = true;
tpatchInput.createAll = StringUtils.isEmpty(patchContext.tpatchHistoryUrl);
tpatchInput.LAST_PATCH_URL = patchContext.LAST_PATCH_URL;
tpatchInput.hisPatchUrl = patchContext.tpatchHistoryUrl;
if (null != patchContext.patchVersions) {
tpatchInput.versionList = patchContext.patchVersions;
}
}
List<Pair<BundleBO, BundleBO>> remoteBundles = new ArrayList<>();

//Get the remote bundle
Expand All @@ -330,7 +380,7 @@ public void doTPatch() throws Exception {
if (baseBundleFile.exists()) {

getProject().getLogger().error(
"add bundle compare " + baseBundleFile.getAbsolutePath() + "->" + bundleFile.getAbsolutePath());
"add bundle compare " + baseBundleFile.getAbsolutePath() + "->" + bundleFile.getAbsolutePath());

baseBundleBO = new BundleBO(awbBundle.getResolvedCoordinates().getArtifactId(), baseBundleFile, "");
}
Expand All @@ -339,49 +389,9 @@ public void doTPatch() throws Exception {
}

if (remoteBundles.size() > 0) {
tPatchTool.setSplitDiffBundle(remoteBundles);
tpatchInput.splitDiffBundle = remoteBundles;
}

tPatchTool.setMainBundleName(patchContext.mainBundleName);
if (StringUtils.isNotBlank(patchContext.excludeFiles)) {
tPatchTool.setNotIncludeFiles(patchContext.excludeFiles.split(","));
}
tPatchTool.setRetainMainBundleRes(retainMainBundleRes);
if (null != patchContext.artifactBundleInfos) {
tPatchTool.setArtifactBundleInfos(patchContext.artifactBundleInfos);
}

tPatchTool.setBaseApkFileList(patchContext.getBaseApkFiles());
tPatchTool.setNewApkFileList(patchContext.getNewApkFiles(appVariantContext));
tPatchTool.setLogger(getILogger());
tPatchTool.setOnlyIncludeModifyBundle(patchContext.onlyBuildModifyAwb);

if (StringUtils.isNotBlank(patchContext.excludeFiles)) {
tPatchTool.setNotIncludeFiles(patchContext.excludeFiles.split(","));
}

ApkFileList apkFileList = appVariantContext.getApkFiles().finalApkFileList;
try {

tPatchTool.setCreateAll(StringUtils.isEmpty(patchContext.tpatchHistoryUrl));
FileUtils.writeStringToFile(new File(getOutPatchFolder(), "tpatch-bundles.json"),
JSON.toJSONString(patchContext.artifactBundleInfos));

getLogger().info("start to do patch");
tPatchTool.doPatch(outPatchFolder,
true,
new File(getOutPatchFolder(), "patchs.json"),
StringUtils.isNotEmpty(patchContext.tpatchHistoryUrl),
patchContext.tpatchHistoryUrl,
patchContext.appSignName);
getLogger().info("finish do patch");


FileUtils.forceDelete(patchContext.newApk);

} catch (Exception e) {
throw new GradleException(e.getMessage(), e);
}

}

Expand Down Expand Up @@ -506,6 +516,7 @@ public TPatchContext call() throws Exception {
.getManifestOutputFile());
tPatchContext.tpatchHistoryUrl = tBuildType.getPatchConfig()
.getTpatchHistoryUrl();
tPatchContext.LAST_PATCH_URL = tBuildType.getPatchConfig().getLastPatchUrl();
tPatchContext.onlyBuildModifyAwb = tBuildType.getPatchConfig()
.getOnlyBuildModifyAwb();
tPatchContext.artifactBundleInfos = appVariantOutputContext.artifactBundleInfos;
Expand Down Expand Up @@ -551,6 +562,8 @@ public static class TPatchContext implements Serializable {

public String tpatchHistoryUrl;

public String LAST_PATCH_URL;

public Boolean onlyBuildModifyAwb;

public String notPatchBundles;
Expand Down
2 changes: 1 addition & 1 deletion atlas-gradle-plugin/dexpatch/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ dependencies {

group 'com.taobao.android'

version "1.4.4.4"
version "1.4.4.6-SNAPSHOT"

Loading

0 comments on commit 7298c1d

Please sign in to comment.