use of com.taobao.android.object.ArtifactBundleInfo in project atlas by alibaba.
the class DiffBundleInfoTask method getMainArtifactBundInfo.
private static ArtifactBundleInfo getMainArtifactBundInfo(File manifestFile) {
ArtifactBundleInfo mainBundleInfo = new ArtifactBundleInfo();
SAXReader reader = new SAXReader();
// 读取XML文件
Document document = null;
try {
document = reader.read(manifestFile);
} catch (DocumentException e) {
throw new GradleException(e.getMessage(), e);
}
// 得到根节点
Element root = document.getRootElement();
List<? extends Node> metadataNodes = root.selectNodes("//meta-data");
for (Node node : metadataNodes) {
Element element = (Element) node;
Attribute attribute = element.attribute("name");
if (attribute.getValue().equals("label")) {
Attribute labelAttribute = element.attribute("value");
mainBundleInfo.setName(labelAttribute.getValue());
}
}
List<? extends Node> applicatNodes = root.selectNodes("//application");
for (Node node : applicatNodes) {
Element element = (Element) node;
Attribute attribute = element.attribute("name");
if (attribute != null) {
mainBundleInfo.setApplicationName(attribute.getValue());
}
}
if ("manifest".equalsIgnoreCase(root.getName())) {
List<Attribute> attributes = root.attributes();
for (Attribute attr : attributes) {
if (StringUtils.equalsIgnoreCase(attr.getName(), "versionName")) {
String versionName = attr.getValue();
mainBundleInfo.setVersion(versionName);
}
}
}
String pkgName = root.attributeValue("package");
mainBundleInfo.setPkgName(pkgName);
return mainBundleInfo;
}
use of com.taobao.android.object.ArtifactBundleInfo 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);
}
use of com.taobao.android.object.ArtifactBundleInfo in project atlas by alibaba.
the class TPatchTool method createBasePatchInfo.
/**
* 获取基准patch包的patchInfo对象
*
* @param fileName
* @return
*/
public PatchInfo createBasePatchInfo(String fileName) {
PatchInfo patchInfo = new PatchInfo();
patchInfo.setPatchVersion(newApkVersion);
patchInfo.setTargetVersion(baseApkVersion);
patchInfo.setFileName(fileName);
for (ArtifactBundleInfo artifactBundleInfo : 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(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.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;
}
use of com.taobao.android.object.ArtifactBundleInfo in project atlas by alibaba.
the class BasePatchTool method isModifyBundle.
/**
* 判断当前bundle是否有变化
*
* @param bundleSoFileName
* @return
*/
public boolean isModifyBundle(String bundleSoFileName) {
for (ArtifactBundleInfo artifactBundleInfo : artifactBundleInfos) {
String packageName = artifactBundleInfo.getPkgName();
if (null == packageName) {
return false;
}
String bundleName = "lib" + packageName.replace('.', '_') + ".so";
if (bundleName.equals(bundleSoFileName)) {
if (null != logger) {
logger.info("[BundleDiffType]" + bundleSoFileName + ":" + artifactBundleInfo.getDiffType());
}
if (DiffType.ADD.equals(artifactBundleInfo.getDiffType()) || DiffType.MODIFY.equals(artifactBundleInfo.getDiffType())) {
return true;
}
}
}
return false;
}
use of com.taobao.android.object.ArtifactBundleInfo in project atlas by alibaba.
the class DiffBundleInfoTask method getArtifactBundleInfo.
private Set<ArtifactBundleInfo> getArtifactBundleInfo(DependencyDiff dependencyDiff, File mainfestFile, File apDir) throws IOException, DocumentException {
Set<ArtifactBundleInfo> artifactBundleInfos = new HashSet<ArtifactBundleInfo>();
if (null == apDir) {
throw new GradleException("No Ap dependency found!");
}
File apManifest = new File(apDir, "AndroidManifest.xml");
String apVersion = null;
try {
apVersion = ManifestFileUtils.getVersionName(apManifest);
} catch (Exception e) {
throw new GradleException(e.getMessage(), e);
}
// 1. 首先添加主bundle
ArtifactBundleInfo mainBundleInfo = getMainArtifactBundInfo(mainfestFile);
mainBundleInfo.setBaseVersion(apVersion);
mainBundleInfo.setMainBundle(true);
mainBundleInfo.setVersion(appVariantOutputContext.getVariantContext().getVariantConfiguration().getVersionName());
if (dependencyDiff.getMainDexDiffs().size() > 0) {
mainBundleInfo.setDiffType(DiffType.MODIFY);
} else {
mainBundleInfo.setDiffType(DiffType.NONE);
}
artifactBundleInfos.add(mainBundleInfo);
// 2. 添加各自的bundle
AndroidDependencyTree androidDependencyTree = AtlasBuildContext.androidDependencyTrees.get(appVariantOutputContext.getVariantContext().getVariantConfiguration().getFullName());
for (AwbBundle awbBundle : androidDependencyTree.getAwbBundles()) {
BundleInfo bundleInfo = awbBundle.bundleInfo;
ArtifactBundleInfo awbBundleInfo = new ArtifactBundleInfo();
awbBundleInfo.setMainBundle(false);
awbBundleInfo.setDependency(bundleInfo.getDependency());
awbBundleInfo.setPkgName(bundleInfo.getPkgName());
awbBundleInfo.setApplicationName(bundleInfo.getApplicationName());
awbBundleInfo.setArtifactId(awbBundle.getResolvedCoordinates().getArtifactId());
awbBundleInfo.setName(bundleInfo.getName());
String version = bundleInfo.getVersion();
if (version.indexOf("@") > 0) {
String[] arr = version.split("@");
version = arr[arr.length - 1];
}
awbBundleInfo.setVersion(version);
String libBundleName = getBundleName(awbBundle);
if (dependencyDiff.getAwbDiffs().contains(libBundleName)) {
if (dependencyDiff.getNewAwbs().contains(libBundleName)) {
awbBundleInfo.setDiffType(DiffType.ADD);
} else {
awbBundleInfo.setDiffType(DiffType.MODIFY);
}
} else {
awbBundleInfo.setDiffType(DiffType.NONE);
}
artifactBundleInfos.add(awbBundleInfo);
}
return artifactBundleInfos;
}
Aggregations