use of com.taobao.android.builder.tools.bundleinfo.model.BundleInfo in project atlas by alibaba.
the class BundleGraphExecutor method execute.
public static void execute(List<BundleInfo> bundleInfos, int parableCount, BundleItemRunner bundleItemRunner) throws IOException, InterruptedException {
Map<String, BundleInfo> bundleInfoMap = new HashMap<>();
bundleInfos.forEach(new Consumer<BundleInfo>() {
@Override
public void accept(BundleInfo bundleInfo) {
bundleInfoMap.put(bundleInfo.getPkgName(), bundleInfo);
}
});
Map<String, BundleItem> bundleItemMap = getBundleItemMap(bundleInfoMap);
handleCircleDependency(bundleItemMap);
int size = bundleItemMap.size();
ExecutorServicesHelper executorServicesHelper = new ExecutorServicesHelper("bundleGraph", logger, parableCount);
int index = 0;
int j = 0;
while (index <= size) {
List<String> keys = new ArrayList<>();
List<Runnable> runnables = new ArrayList<>();
for (String key : bundleItemMap.keySet()) {
// System.out.println("test" + key);
BundleItem bundleItem = bundleItemMap.get(key);
if (bundleItem.canResolve()) {
index++;
// bundleItem.resolve();
keys.add(key);
final String name = index + bundleItem.bundleInfo.getPkgName();
runnables.add(new Runnable() {
@Override
public void run() {
logger.warn("start to do bundle proguard for " + name);
bundleItemRunner.execute(bundleItem);
logger.warn("end do bundle proguard for " + name);
}
});
}
}
Profiler.enter("execute stage " + j++ + " runnables " + runnables.size());
executorServicesHelper.execute(runnables);
Profiler.release();
if (keys.isEmpty()) {
break;
}
for (String key : keys) {
bundleItemMap.get(key).resolve();
bundleItemMap.remove(key);
}
}
if (index != size) {
throw new GradleException("bundleGraph is some thing wrong");
}
}
use of com.taobao.android.builder.tools.bundleinfo.model.BundleInfo in project atlas by alibaba.
the class BundleGraphExecutor method getBundleItemMap.
private static Map<String, BundleItem> getBundleItemMap(Map<String, BundleInfo> bundleInfoMap) {
Map<String, BundleItem> bundleItemMap = new HashMap<>();
for (BundleInfo bundleInfo : bundleInfoMap.values()) {
BundleItem bundleItem = bundleItemMap.get(bundleInfo.getPkgName());
if (null == bundleItem) {
bundleItem = new BundleItem();
bundleItem.bundleInfo = bundleInfo;
bundleItemMap.put(bundleInfo.getPkgName(), bundleItem);
}
// Computing rely on
for (String dependency : bundleInfo.getDependency()) {
if (StringUtils.isNotEmpty(dependency)) {
BundleItem child = bundleItemMap.get(dependency);
if (null == child) {
child = new BundleItem();
child.bundleInfo = bundleInfoMap.get(dependency);
if (null == child.bundleInfo) {
throw new GradleException("bundle dependency is error , not bundle found for " + dependency + " ; which may define in " + bundleInfo.getPkgName());
}
bundleItemMap.put(dependency, child);
}
bundleItem.children.add(child);
child.parents.add(bundleItem);
}
}
}
return bundleItemMap;
}
use of com.taobao.android.builder.tools.bundleinfo.model.BundleInfo in project atlas by alibaba.
the class PrepareBundleInfoTask method generateBundleListCfg.
private void generateBundleListCfg(AppVariantContext appVariantContext) throws IOException {
List<String> bundleLists = AtlasBuildContext.awbBundleMap.values().stream().filter(awbBundle -> !awbBundle.isMBundle).map(awbBundle -> {
return appVariantOutputContext.getAwbPackageOutputFilePath(awbBundle);
}).sorted().collect(Collectors.toList());
File outputFile = new File(appVariantContext.getScope().getGlobalScope().getOutputsDir(), "bundleList.cfg");
FileUtils.deleteQuietly(outputFile);
outputFile.getParentFile().mkdirs();
FileUtils.writeLines(outputFile, bundleLists);
appVariantContext.bundleListCfg = outputFile;
// Set the bundle dependencies
List<BundleInfo> bundleInfos = new ArrayList<>();
AtlasBuildContext.awbBundleMap.values().stream().forEach(awbBundle -> bundleInfos.add(awbBundle.bundleInfo));
}
use of com.taobao.android.builder.tools.bundleinfo.model.BundleInfo in project atlas by alibaba.
the class AtlasProguardHelper method addParentKeeps.
private static void addParentKeeps(BundleItem bundleItem, Input input, AwbTransform awbTransform, Map<BundleInfo, AwbTransform> bundleInfoAwbTransformMap, AppVariantContext appVariantContext) throws IOException {
Set<AwbBundle> parentBundles = new HashSet<>();
for (BundleItem parent : bundleItem.parents) {
parentBundles.add(bundleInfoAwbTransformMap.get(parent.bundleInfo).getAwbBundle());
for (BundleInfo sub : parent.circles) {
parentBundles.add(bundleInfoAwbTransformMap.get(sub).getAwbBundle());
}
}
if (!parentBundles.isEmpty()) {
List<AwbBundle> bundles = new ArrayList<>(parentBundles);
Collections.sort(bundles, new Comparator<AwbBundle>() {
@Override
public int compare(AwbBundle o1, AwbBundle o2) {
return o1.getName().compareTo(o2.getName());
}
});
File keepFile = generateKeepFile(bundles, appVariantContext.getAwbProguardDir(awbTransform.getAwbBundle()));
input.getParentKeeps().add(keepFile);
}
}
use of com.taobao.android.builder.tools.bundleinfo.model.BundleInfo in project atlas by alibaba.
the class ApkInjectInfoCreator method creteInjectParam.
public InjectParam creteInjectParam(AppVariantContext appVariantContext) throws Exception {
InjectParam injectParam = new InjectParam();
injectParam.removePreverify = !appVariantContext.getAtlasExtension().getTBuildConfig().getDoPreverify();
injectParam.version = appVariantContext.getVariantConfiguration().getVersionName();
AtlasDependencyTree atlasDependencyTree = AtlasBuildContext.androidDependencyTrees.get(appVariantContext.getScope().getVariantConfiguration().getFullName());
List<BasicBundleInfo> basicBundleInfos = new ArrayList<BasicBundleInfo>();
Map<String, BasicBundleInfo> basicBundleInfoMap = new HashMap<>();
List<String> mainDexDependencies = atlasDependencyTree.getMainBundle().getAllDependencies();
Collections.sort(mainDexDependencies, new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
return o1.compareTo(o2);
}
});
String mainMd532 = MD5Util.getMD5(StringUtils.join(mainDexDependencies));
String md5base36 = new BigInteger(mainMd532.substring(8, 24), 16).toString(36);
injectParam.unit_tag = md5base36;
appVariantContext.unit_tag = md5base36;
// Depends on whether the change is sent
DependencyDiff dependencyDiff = appVariantContext.getDependencyDiff();
Map<String, String> baseTagMap = appVariantContext.getBaseUnitTagMap();
for (AwbBundle awbBundle : atlasDependencyTree.getAwbBundles()) {
// if (awbBundle.isMBundle){
// continue;
// }
BundleInfo bundleInfo = awbBundle.bundleInfo;
BasicBundleInfo basicBundleInfo = new BasicBundleInfo();
basicBundleInfo.setApplicationName(bundleInfo.getApplicationName());
basicBundleInfo.setVersion(bundleInfo.getVersion());
basicBundleInfo.setPkgName(bundleInfo.getPkgName());
// set unique_tag
String bundleDependencyMd532 = MD5Util.getMD5(StringUtils.join(awbBundle.getAllDependencies()));
String bundleUnitTag = "";
if (null != dependencyDiff && !dependencyDiff.isDiffBundle(awbBundle)) {
bundleUnitTag = baseTagMap.get(awbBundle.getPackageName());
}
if (StringUtils.isEmpty(bundleUnitTag)) {
String bundleMd532 = MD5Util.getMD5(mainMd532 + bundleDependencyMd532);
bundleUnitTag = new BigInteger(bundleMd532.substring(8, 24), 16).toString(36);
}
basicBundleInfo.setUnique_tag(bundleUnitTag);
bundleInfo.setUnique_tag(bundleUnitTag);
if (!bundleInfo.getIsInternal()) {
basicBundleInfo.setIsInternal(false);
}
if (awbBundle.isMBundle) {
basicBundleInfo.setIsMBundle(true);
}
if (!bundleInfo.getActivities().isEmpty()) {
basicBundleInfo.setActivities(bundleInfo.getActivities());
}
if (!bundleInfo.getContentProviders().isEmpty()) {
basicBundleInfo.setContentProviders(bundleInfo.getContentProviders());
}
if (!bundleInfo.getDependency().isEmpty()) {
basicBundleInfo.setDependency(bundleInfo.getDependency());
}
if (!bundleInfo.getReceivers().isEmpty()) {
basicBundleInfo.setReceivers(bundleInfo.getReceivers());
}
if (!bundleInfo.getServices().isEmpty()) {
basicBundleInfo.setServices(bundleInfo.getServices());
}
if (!bundleInfo.getRemoteFragments().isEmpty()) {
basicBundleInfo.setRemoteFragments(bundleInfo.getRemoteFragments());
}
if (!bundleInfo.getRemoteViews().isEmpty()) {
basicBundleInfo.setRemoteViews(bundleInfo.getRemoteViews());
}
if (!bundleInfo.getRemoteTransactors().isEmpty()) {
basicBundleInfo.setRemoteTransactors(bundleInfo.getRemoteTransactors());
}
basicBundleInfos.add(basicBundleInfo);
basicBundleInfoMap.put(bundleInfo.getPkgName(), basicBundleInfo);
}
// Collections.sort(basicBundleInfos, (o1, o2) -> {
// if (o1.getDependency().contains(o2.getPkgName())){
// return -1;
// }else {
// return 1;
// }
// });
basicBundleInfos.forEach(basicBundleInfo -> checkDependency(basicBundleInfo, atlasDependencyTree.getAwbBundles()));
injectParam.bundleInfo = JSON.toJSONString(basicBundleInfos);
// FIXME MOVE TO MTL-PLUGIN
// List<String> autoStartBundles = new ArrayList<String>(appVariantContext.getAtlasExtension().getTBuildConfig
// ().getAutoStartBundles());
//
// UpdateConfig updateConfig = appVariantContext.getAtlasExtension().getUpdateConfig();
// if (updateConfig.enabled) {
// injectParam.group = updateConfig.getProductName();
// injectParam.outApp = updateConfig.isOutApp();
// autoStartBundles.add(0, updateConfig.getSdkPkgName());
// }
//
injectParam.group = appVariantContext.getAtlasExtension().getTBuildConfig().getGroup();
injectParam.autoStartBundles = StringUtils.join(appVariantContext.getAtlasExtension().getTBuildConfig().getAutoStartBundles(), ",");
injectParam.preLaunch = appVariantContext.getAtlasExtension().getTBuildConfig().getPreLaunch();
mergeBundleInfos(appVariantContext, injectParam, basicBundleInfos, basicBundleInfoMap);
return injectParam;
}
Aggregations