use of com.alibaba.fastjson.TypeReference in project atlas by alibaba.
the class ManifestFileUtils method addApplicationMetaData.
/**
* 往主的manifest中添加metadata信息,作为atals的兜底方案
*
* @param document
* @param libManifestMap
* @param baseBunfleInfoFile
* @param manifestOptions
*/
private static void addApplicationMetaData(Document document, Map<String, File> libManifestMap, File baseBunfleInfoFile, ManifestOptions manifestOptions, Set<String> remoteBundles) throws IOException, DocumentException {
Map<String, BundleInfo> bundleFileMap = Maps.newHashMap();
// 解析基础信息
if (null != baseBunfleInfoFile && baseBunfleInfoFile.exists() && baseBunfleInfoFile.canRead()) {
String bundleBaseInfo = FileUtils.readFileToString(baseBunfleInfoFile, "utf-8");
bundleFileMap = JSON.parseObject(bundleBaseInfo, new TypeReference<Map<String, BundleInfo>>() {
});
}
Map<String, LibBundleInfo> awbManifestMap = Maps.newHashMap();
for (Map.Entry<String, File> entry : libManifestMap.entrySet()) {
String artifactId = entry.getKey();
String libName = artifactId.substring(artifactId.indexOf("-") + 1);
File libManifest = entry.getValue();
libManifest = getOrgManifestFile(libManifest);
if (libManifest.exists()) {
SAXReader reader = new SAXReader();
// 读取XML文件
Document libDocument = reader.read(libManifest);
// 得到根节点
Element libRoot = libDocument.getRootElement();
String packageName = libRoot.attributeValue("package");
Element applicationElement = libRoot.element("application");
String applicationName = null;
if (null != applicationElement) {
applicationName = applicationElement.attributeValue("name");
}
LibBundleInfo libBundleInfo = new LibBundleInfo(artifactId, packageName, applicationName, bundleFileMap.get(libName), libName);
awbManifestMap.put(artifactId, libBundleInfo);
}
}
// 写入meta-data信息
// 得到根节点
Element root = document.getRootElement();
List<? extends Node> nodes = root.selectNodes("//application");
for (Node node : nodes) {
Element element = (Element) node;
for (String artifactId : libManifestMap.keySet()) {
LibBundleInfo libBundleInfo = awbManifestMap.get(artifactId);
if (StringUtils.isNotBlank(libBundleInfo.applicationName)) {
String bundlePackageName = libBundleInfo.packageName;
BundleInfo bundleInfo = libBundleInfo.bundleInfo;
Element metaData = element.addElement("meta-data");
String bundleDepValue = "";
if (null != bundleInfo && bundleInfo.getDependency() != null) {
bundleDepValue = StringUtils.join(bundleInfo.getDependency(), "|");
}
String value = libBundleInfo.applicationName + "," + !remoteBundles.contains(libBundleInfo.libName) + "," + bundleDepValue;
logger.info("[bundleInfo] add bundle value : " + value + " to manifest");
metaData.addAttribute("android:name", "bundle_" + bundlePackageName);
metaData.addAttribute("android:value", value);
}
}
}
}
Aggregations