use of com.taobao.android.builder.dependency.model.AwbBundle in project atlas by alibaba.
the class PreparePackageIdsTask method generate.
/**
* packageid 范围是 30 - 127
*/
@TaskAction
void generate() throws IOException {
File packageIdFile = appVariantContext.getAtlasExtension().getTBuildConfig().getPackageIdFile();
File apPackageIdFile = appVariantContext.apContext.getPackageIdFile();
boolean isAutoPackageId = appVariantContext.getAtlasExtension().getTBuildConfig().isAutoPackageId();
Map<String, String> autoConfigMap = new HashMap<String, String>();
if (null != apPackageIdFile && apPackageIdFile.exists()) {
autoConfigMap.putAll(loadPackageIdProperties(apPackageIdFile));
} else if (null != packageIdFile && packageIdFile.exists()) {
autoConfigMap.putAll(loadPackageIdProperties(packageIdFile));
}
AndroidDependencyTree androidDependencyTree = AtlasBuildContext.androidDependencyTrees.get(getVariantName());
for (AwbBundle awbBundle : androidDependencyTree.getAwbBundles()) {
String key = awbBundle.getResolvedCoordinates().getGroupId() + ":" + awbBundle.getResolvedCoordinates().getArtifactId();
if (autoConfigMap.containsKey(key)) {
continue;
}
File customPackageIDFile = new File(awbBundle.getFolder(), "customPackageID.txt");
String packageId = getCustomPackageId(customPackageIDFile);
if (StringUtils.isNotEmpty(packageId) && StringUtils.isNumeric(packageId)) {
autoConfigMap.put(key, packageId);
} else {
autoConfigMap.put(key, "");
}
}
if (isAutoPackageId && autoConfigMap.containsValue("")) {
//自动分配autoConfig
List<String> keys = new ArrayList<String>(autoConfigMap.keySet());
Collections.sort(keys);
for (String key : keys) {
if ("".equals(autoConfigMap.get(key))) {
for (int i = 30; i <= 127; i++) {
if (!autoConfigMap.values().contains(String.valueOf(i))) {
autoConfigMap.put(key, String.valueOf(i));
break;
}
}
}
}
}
AtlasBuildContext.customPackageIdMaps = autoConfigMap;
//wite package Id file
File outPkgFile = new File(getProject().getBuildDir(), "outputs/packageIdFile.properties");
writeProperties(autoConfigMap, outPkgFile);
appBuildInfo.setPackageIdFile(outPkgFile);
//check value
if (autoConfigMap.containsValue("")) {
getLogger().error(JSON.toJSONString(autoConfigMap, true));
throw new GradleException("packageId 配置错误,请检查");
}
if (autoConfigMap.size() != new HashSet(autoConfigMap.values()).size()) {
// getLogger().error(JSON.toJSONString(autoConfigMap, true));
Map<String, PackageIdItem> idItemMap = new HashMap<String, PackageIdItem>();
for (String key : autoConfigMap.keySet()) {
String customPackageId = autoConfigMap.get(key);
PackageIdItem packageIdItem = idItemMap.get(customPackageId);
if (null == packageIdItem) {
String[] split = customPackageId.split("\\.");
packageIdItem = new PackageIdItem();
packageIdItem.packageId = Integer.valueOf(split[0]);
if (split.length > 1) {
packageIdItem.typeIdOffset = Integer.valueOf(split[1]);
}
idItemMap.put(customPackageId, packageIdItem);
}
packageIdItem.bundles.add(key);
}
Collection<PackageIdItem> collection = idItemMap.values();
List<PackageIdItem> packageList = new ArrayList<PackageIdItem>(collection);
Collections.sort(packageList, new Comparator<PackageIdItem>() {
@Override
public int compare(PackageIdItem o1, PackageIdItem o2) {
return o1.packageId - o2.packageId;
}
});
getLogger().error(JSON.toJSONString(packageList, true));
throw new GradleException("packageId 配置错误,有重复,请检查");
}
// check if packageID is not used
Map<String, String> autoConfigMap2 = new HashMap<>(autoConfigMap);
for (AwbBundle awbBundle : androidDependencyTree.getAwbBundles()) {
String key = awbBundle.getResolvedCoordinates().getGroupId() + ":" + awbBundle.getResolvedCoordinates().getArtifactId();
autoConfigMap2.remove(key);
}
if (autoConfigMap2.size() > 0) {
File outPkgFile2 = new File(getProject().getBuildDir(), "outputs/warning-unusedPackageIdFile.properties");
writeProperties(autoConfigMap2, outPkgFile2);
}
}
use of com.taobao.android.builder.dependency.model.AwbBundle in project atlas by alibaba.
the class MergeAssetAwbsConfigAction method execute.
@Override
public void execute(MtlParallelTask parallelTask) {
super.execute(parallelTask);
AndroidDependencyTree androidDependencyTree = AtlasBuildContext.androidDependencyTrees.get(parallelTask.getVariantName());
if (null == androidDependencyTree) {
return;
}
List<DefaultTask> tasks = new ArrayList<DefaultTask>();
for (final AwbBundle awbBundle : androidDependencyTree.getAwbBundles()) {
MergeAwbAssetConfigAction mergeAwbAssetConfigAction = new MergeAwbAssetConfigAction(appVariantContext, baseVariantOutputData, awbBundle);
MergeSourceSetFolders mergeTask = TaskCreater.create(appVariantContext.getProject(), mergeAwbAssetConfigAction.getName(), mergeAwbAssetConfigAction.getType());
mergeAwbAssetConfigAction.execute(mergeTask);
tasks.add(mergeTask);
}
parallelTask.parallelTask = tasks;
parallelTask.uniqueTaskName = getName();
}
use of com.taobao.android.builder.dependency.model.AwbBundle in project atlas by alibaba.
the class MergeResAwbsConfigAction method execute.
@Override
public void execute(MtlParallelTask parallelTask) {
super.execute(parallelTask);
AndroidDependencyTree androidDependencyTree = AtlasBuildContext.androidDependencyTrees.get(parallelTask.getVariantName());
if (null == androidDependencyTree) {
return;
}
List<DefaultTask> tasks = new ArrayList<DefaultTask>();
for (final AwbBundle awbBundle : androidDependencyTree.getAwbBundles()) {
MergeAwbResourceConfigAction mergeAwbResourceConfigAction = new MergeAwbResourceConfigAction(appVariantContext, baseVariantOutputData, awbBundle);
final MergeResources mergeTask = TaskCreater.create(appVariantContext.getProject(), mergeAwbResourceConfigAction.getName(), mergeAwbResourceConfigAction.getType());
mergeAwbResourceConfigAction.execute(mergeTask);
tasks.add(mergeTask);
mergeTask.doLast(new Action<Task>() {
@Override
public void execute(Task task) {
File publicRes = new File(awbBundle.getResFolder(), "values/public.xml");
if (publicRes.exists()) {
try {
FileUtils.copyFile(publicRes, new File(mergeTask.getOutputDir(), "values/public.xml"));
} catch (IOException e) {
e.printStackTrace();
}
}
}
});
}
parallelTask.parallelTask = tasks;
parallelTask.uniqueTaskName = getName();
parallelTask.concurrent = true;
}
use of com.taobao.android.builder.dependency.model.AwbBundle in project atlas by alibaba.
the class BundleInfoUtils method getBundleInfoList.
@NotNull
public static List<BundleInfo> getBundleInfoList(AppVariantContext appVariantContext) {
AndroidDependencyTree androidDependencyTree = AtlasBuildContext.androidDependencyTrees.get(appVariantContext.getScope().getVariantConfiguration().getFullName());
List<BundleInfo> bundleInfoList = new ArrayList<BundleInfo>();
for (AwbBundle awbBundle : androidDependencyTree.getAwbBundles()) {
bundleInfoList.add(awbBundle.bundleInfo);
}
return bundleInfoList;
}
use of com.taobao.android.builder.dependency.model.AwbBundle in project atlas by alibaba.
the class ApkInjectInfoCreator method creteInjectParam.
public InjectParam creteInjectParam(AppVariantContext appVariantContext) throws IOException, DocumentException {
InjectParam injectParam = new InjectParam();
injectParam.removePreverify = !appVariantContext.getAtlasExtension().getTBuildConfig().getDoPreverify();
injectParam.version = appVariantContext.getVariantConfiguration().getVersionName();
AndroidDependencyTree androidDependencyTree = AtlasBuildContext.androidDependencyTrees.get(appVariantContext.getScope().getVariantConfiguration().getFullName());
List<BasicBundleInfo> basicBundleInfos = new ArrayList<BasicBundleInfo>();
for (AwbBundle awbBundle : androidDependencyTree.getAwbBundles()) {
BundleInfo muppBundleInfo = awbBundle.bundleInfo;
BasicBundleInfo basicBundleInfo = new BasicBundleInfo();
basicBundleInfo.setApplicationName(muppBundleInfo.getApplicationName());
basicBundleInfo.setVersion(muppBundleInfo.getVersion());
basicBundleInfo.setPkgName(muppBundleInfo.getPkgName());
if (!muppBundleInfo.getIsInternal()) {
basicBundleInfo.setIsInternal(false);
}
if (!muppBundleInfo.getActivities().isEmpty()) {
basicBundleInfo.setActivities(muppBundleInfo.getActivities());
}
if (!muppBundleInfo.getContentProviders().isEmpty()) {
basicBundleInfo.setContentProviders(muppBundleInfo.getContentProviders());
}
if (!muppBundleInfo.getDependency().isEmpty()) {
basicBundleInfo.setDependency(muppBundleInfo.getDependency());
}
if (!muppBundleInfo.getReceivers().isEmpty()) {
basicBundleInfo.setReceivers(muppBundleInfo.getReceivers());
}
if (!muppBundleInfo.getServices().isEmpty()) {
basicBundleInfo.setServices(muppBundleInfo.getServices());
}
basicBundleInfos.add(basicBundleInfo);
}
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.autoStartBundles = StringUtils.join(appVariantContext.getAtlasExtension().getTBuildConfig().getAutoStartBundles(), ",");
injectParam.preLaunch = appVariantContext.getAtlasExtension().getTBuildConfig().getPreLaunch();
return injectParam;
}
Aggregations