use of com.taobao.android.builder.dependency.AtlasDependencyTree 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;
}
use of com.taobao.android.builder.dependency.AtlasDependencyTree in project atlas by alibaba.
the class BundleInfoUtils method getBundleInfoList.
@NotNull
public static List<BundleInfo> getBundleInfoList(AppVariantContext appVariantContext) {
AtlasDependencyTree atlasDependencyTree = AtlasBuildContext.androidDependencyTrees.get(appVariantContext.getScope().getVariantConfiguration().getFullName());
List<BundleInfo> bundleInfoList = new ArrayList<BundleInfo>();
for (AwbBundle awbBundle : atlasDependencyTree.getAwbBundles()) {
bundleInfoList.add(awbBundle.bundleInfo);
}
return bundleInfoList;
}
use of com.taobao.android.builder.dependency.AtlasDependencyTree in project atlas by alibaba.
the class AtlasDataBindingMergeArtifactsTransform method processAwbsDataBindings.
private void processAwbsDataBindings() throws IOException {
AtlasDependencyTree atlasDependencyTree = AtlasBuildContext.androidDependencyTrees.get(variantContext.getVariantName());
for (AwbBundle awbBundle : atlasDependencyTree.getAwbBundles()) {
File awbDataBindDepsOutDir = variantContext.getAwbDataBindingMergeArtifacts(awbBundle);
for (AndroidLibrary androidLibrary : awbBundle.getAndroidLibraries()) {
File artifactFolder = new File(androidLibrary.getFolder(), DataBindingBuilder.DATA_BINDING_ROOT_FOLDER_IN_AAR + "/" + DataBindingBuilder.INCREMENTAL_BIN_AAR_DIR);
if (artifactFolder.exists() && artifactFolder.listFiles() != null) {
for (String artifactName : artifactFolder.list()) {
if (isResource(artifactName)) {
FileUtils.copyFile(new File(artifactFolder, artifactName), new File(awbDataBindDepsOutDir, artifactName));
}
}
}
}
File awbDataBindDir = new File(awbBundle.getAndroidLibrary().getFolder(), DataBindingBuilder.DATA_BINDING_ROOT_FOLDER_IN_AAR + "/" + DataBindingBuilder.INCREMENTAL_BIN_AAR_DIR);
if (awbDataBindDir.exists() && awbDataBindDir.listFiles() != null) {
for (String artifactName : awbDataBindDir.list()) {
if (isResource(artifactName)) {
FileUtils.copyFile(new File(awbDataBindDir, artifactName), new File(awbDataBindDepsOutDir, artifactName));
}
}
}
}
}
use of com.taobao.android.builder.dependency.AtlasDependencyTree in project atlas by alibaba.
the class AtlasDexArchiveBuilderTransform method processAwbDexArchive.
private void processAwbDexArchive(TransformInvocation transformInvocation, List<QualifiedContent> listFiles) throws Exception {
File awbApkOutputDir = ((AppVariantContext) variantContext).getAwbApkOutputDir();
FileUtils.cleanOutputDir(awbApkOutputDir);
AtlasDependencyTree atlasDependencyTree = AtlasBuildContext.androidDependencyTrees.get(variantContext.getScope().getFullVariantName());
if (null == atlasDependencyTree) {
return;
}
for (final AwbBundle awbBundle : atlasDependencyTree.getAwbBundles()) {
Multimap<QualifiedContent, File> cacheableItems = HashMultimap.create();
List<QualifiedContent> qualifiedContents = new LinkedList<>();
long start = System.currentTimeMillis();
// if some of our .jar input files exist, just reset the inputDir to null
AwbTransform awbTransform = variantContext.getAppVariantOutputContext(ApkDataUtils.get(variantOutput)).getAwbTransformMap().get(awbBundle.getName());
List<File> inputFiles = new ArrayList<File>();
inputFiles.addAll(awbTransform.getInputFiles());
inputFiles.addAll(awbTransform.getInputLibraries());
if (null != awbTransform.getInputDirs()) {
inputFiles.addAll(awbTransform.getInputDirs());
}
for (File file : inputFiles) {
logger.warning(awbBundle.getName() + ":" + file.getAbsolutePath());
boolean find = false;
for (QualifiedContent content : listFiles) {
if (content.getFile().getAbsolutePath().equals(file.getAbsolutePath())) {
find = true;
qualifiedContents.add(content);
break;
}
}
if (!find) {
if (file.isDirectory()) {
DirectoryInput directoryInput = TransformInputUtils.makeDirectoryInput(file, variantContext);
qualifiedContents.add(directoryInput);
} else if (file.isFile()) {
JarInput jarInput = TransformInputUtils.makeJarInput(file, variantContext);
qualifiedContents.add(jarInput);
}
}
}
for (QualifiedContent qualifiedContent : qualifiedContents) {
if (qualifiedContent.getFile().isDirectory()) {
List<File> awbFiles = convertAwbToDexArchive(transformInvocation.getContext(), qualifiedContent, variantContext.getAwbDexAchiveOutput(awbBundle), transformInvocation.isIncremental(), true);
cacheableItems.putAll(qualifiedContent, awbFiles);
} else {
List<File> jarFiles = processAwbJarInput(transformInvocation.getContext(), transformInvocation.isIncremental(), (JarInput) qualifiedContent, variantContext.getAwbDexAchiveOutput(awbBundle));
cacheableItems.putAll(qualifiedContent, jarFiles);
}
}
cacheItems.putAll(cacheableItems);
}
}
use of com.taobao.android.builder.dependency.AtlasDependencyTree in project atlas by alibaba.
the class AtlasTransformUtils method getTransformInputs.
public static Collection<File> getTransformInputs(AppVariantContext appVariantContext, TransformInvocation invocation) {
ImmutableSet.Builder<File> builder = ImmutableSet.builder();
Collection<File> transformInputs = TransformInputUtil.getAllFiles(invocation.getInputs());
builder.addAll(transformInputs);
AtlasDependencyTree atlasDependencyTree = AtlasBuildContext.androidDependencyTrees.get(appVariantContext.getVariantConfiguration().getFullName());
if (atlasDependencyTree.getAwbBundles().size() > 0) {
BaseVariantOutput vod = (BaseVariantOutput) appVariantContext.getVariantOutputData().iterator().next();
AppVariantOutputContext appVariantOutputContext = appVariantContext.getAppVariantOutputContext(ApkDataUtils.get(vod));
Collection<AwbTransform> awbTransforms = appVariantOutputContext.getAwbTransformMap().values();
awbTransforms.forEach(awbTransform -> {
builder.addAll(awbTransform.getInputLibraries());
});
}
return builder.build();
}
Aggregations