use of com.taobao.android.builder.dependency.AndroidDependencyTree in project atlas by alibaba.
the class ProcessResAwbsTask method run.
@TaskAction
void run() throws ExecutionException, InterruptedException {
AndroidDependencyTree androidDependencyTree = AtlasBuildContext.androidDependencyTrees.get(getVariantName());
if (null == androidDependencyTree) {
return;
}
final VariantOutputScope outputScope = appVariantOutputContext.getOutputScope();
ExecutorServicesHelper executorServicesHelper = new ExecutorServicesHelper(taskName, getLogger(), 0);
List<Runnable> runnables = new ArrayList<>();
for (final AwbBundle awbBundle : androidDependencyTree.getAwbBundles()) {
runnables.add(new Runnable() {
@Override
public void run() {
File symbolLocation = new File(outputScope.getGlobalScope().getIntermediatesDir(), "awb-symbols/" + outputScope.getVariantScope().getVariantConfiguration().getDirName() + "/" + awbBundle.getName());
//把资源写入ap中,给debug用
if ("debug".equals(appVariantOutputContext.getVariantContext().getBaseVariantData().getName())) {
appVariantOutputContext.appBuildInfo.getOtherFilesMap().put("awo/" + awbBundle.getPackageName() + ".R.txt", new File(symbolLocation, "R.txt"));
}
ProcessAwbAndroidResources.ConfigAction configAction = new ProcessAwbAndroidResources.ConfigAction(outputScope, symbolLocation, true, awbBundle, (AtlasBuilder) getBuilder(), appVariantOutputContext);
ProcessAwbAndroidResources processAwbAndroidResources = TaskCreater.create(getProject(), configAction.getName(), configAction.getType());
configAction.execute(processAwbAndroidResources);
processAwbAndroidResources.execute();
}
});
}
executorServicesHelper.execute(runnables);
}
use of com.taobao.android.builder.dependency.AndroidDependencyTree in project atlas by alibaba.
the class DataBindingExportBuildInfoAwbsConfigAction method execute.
@Override
public void execute(MtlParallelTask parallelTask) {
super.execute(parallelTask);
AndroidDependencyTree androidDependencyTree = AtlasBuildContext.androidDependencyTrees.get(parallelTask.getVariantName());
if (null == androidDependencyTree) {
return;
}
DataBindingBuilder dataBindingBuilder = new DataBindingBuilder();
dataBindingBuilder.setPrintMachineReadableOutput(false);
dataBindingBuilder.setDebugLogEnabled(appVariantContext.getProject().getLogger().isDebugEnabled());
List<DefaultTask> tasks = new ArrayList<DefaultTask>();
for (final AwbBundle awbBundle : androidDependencyTree.getAwbBundles()) {
AwbDataBindingExportBuildInfoConfigAction exportBuildInfoConfigAction = new AwbDataBindingExportBuildInfoConfigAction(appVariantContext, awbBundle, dataBindingBuilder.getPrintMachineReadableOutput(), dataBindingBuilder);
DataBindingExportBuildInfoTask exportBuildInfoTask = TaskCreater.create(appVariantContext.getProject(), exportBuildInfoConfigAction.getName(), exportBuildInfoConfigAction.getType());
exportBuildInfoConfigAction.execute(exportBuildInfoTask);
tasks.add(exportBuildInfoTask);
}
parallelTask.parallelTask = tasks;
parallelTask.uniqueTaskName = getName();
parallelTask.concurrent = true;
}
use of com.taobao.android.builder.dependency.AndroidDependencyTree in project atlas by alibaba.
the class DataBindingRenameTask method createAwbPackages.
/**
* 生成so的目录
*/
@TaskAction
void createAwbPackages() throws ExecutionException, InterruptedException {
AndroidDependencyTree androidDependencyTree = AtlasBuildContext.androidDependencyTrees.get(getVariantName());
if (null == androidDependencyTree) {
return;
}
ExecutorServicesHelper executorServicesHelper = new ExecutorServicesHelper(taskName, getLogger(), 0);
List<Runnable> runnables = new ArrayList<>();
for (final AwbBundle awbBundle : androidDependencyTree.getAwbBundles()) {
runnables.add(new Runnable() {
@Override
public void run() {
try {
File dataBindingClazzFolder = appVariantOutputContext.getVariantContext().getJAwbavaOutputDir(awbBundle);
String packageName = ManifestFileUtils.getPackage(awbBundle.getOrgManifestFile());
String appName = appVariantContext.getVariantConfiguration().getOriginalApplicationId();
//删除那些已经存在的类
File dataMapperClazz = new File(dataBindingClazzFolder, "android/databinding/DataBinderMapper.class");
if (!dataMapperClazz.exists()) {
throw new GradleException("missing datamapper class");
}
FileInputStream fileInputStream = new FileInputStream(dataMapperClazz);
ClassReader in1 = new ClassReader(fileInputStream);
ClassWriter cw = new ClassWriter(0);
Map<String, String> reMapping = new HashedMap();
reMapping.put(appName.replace(".", "/") + "/BR", packageName.replace(".", "/") + "/BR");
RemappingClassAdapter remappingClassAdapter = new RemappingClassAdapter(cw, new SimpleRemapper(reMapping));
in1.accept(remappingClassAdapter, 8);
ClassReader in2 = new ClassReader(cw.toByteArray());
ClassWriter cw2 = new ClassWriter(0);
Set<String> renames = new HashSet<String>();
renames.add("android/databinding/DataBinderMapper");
in2.accept(new ClassRenamer(cw2, renames, packageName.replace(".", "/") + "/DataBinderMapper"), 8);
File destClass = new File(dataBindingClazzFolder, packageName.replace(".", "/") + "/DataBinderMapper.class");
destClass.getParentFile().mkdirs();
FileOutputStream fileOutputStream = new FileOutputStream(destClass);
fileOutputStream.write(cw2.toByteArray());
IOUtils.closeQuietly(fileOutputStream);
IOUtils.closeQuietly(fileInputStream);
FileUtils.deleteDirectory(new File(dataBindingClazzFolder, "android/databinding"));
FileUtils.deleteDirectory(new File(dataBindingClazzFolder, "com/android/databinding"));
File appDir = new File(dataBindingClazzFolder, appName.replace(".", "/"));
if (appDir.exists()) {
File[] files = appDir.listFiles(new FileFilter() {
@Override
public boolean accept(File pathname) {
return pathname.isFile() && !pathname.isDirectory();
}
});
for (File tmp : files) {
FileUtils.forceDelete(tmp);
}
}
} catch (Throwable e) {
e.printStackTrace();
throw new GradleException("package awb failed");
}
}
});
}
executorServicesHelper.execute(runnables);
}
use of com.taobao.android.builder.dependency.AndroidDependencyTree in project atlas by alibaba.
the class PreProcessManifestTask method addAwbManifest2Merge.
private void addAwbManifest2Merge() {
AtlasExtension atlasExtension = appVariantContext.getAtlasExtension();
for (final BaseVariantOutputData vod : appVariantContext.getVariantData().getOutputs()) {
ManifestProcessorTask manifestProcessorTask = vod.manifestProcessorTask;
Set<String> notMergedArtifacts = Sets.newHashSet();
if (null != atlasExtension.getManifestOptions() && null != atlasExtension.getManifestOptions().getNotMergedBundles()) {
notMergedArtifacts = atlasExtension.getManifestOptions().getNotMergedBundles();
}
if (manifestProcessorTask instanceof MergeManifests) {
MergeManifests mergeManifests = (MergeManifests) manifestProcessorTask;
VariantScope variantScope = appVariantContext.getScope();
GradleVariantConfiguration config = variantScope.getVariantConfiguration();
AndroidDependencyTree dependencyTree = AtlasBuildContext.androidDependencyTrees.get(config.getFullName());
if (null == dependencyTree) {
throw new StopExecutionException("DependencyTree cannot be null!");
}
List<? extends AndroidLibrary> awbManifests = ManifestDependencyUtil.getManifestDependencies(dependencyTree.getAwbBundles(), notMergedArtifacts, getLogger());
for (AndroidLibrary manifest : awbManifests) {
getLogger().info("[MTLPlugin]Add manifest:" + manifest.getName() + ",path is:" + manifest.getManifest().getAbsolutePath());
}
//FIXME 不加这一步,每次的getibraries 都会从mapping里去重新计算
mergeManifests.setLibraries(mergeManifests.getLibraries());
mergeManifests.getLibraries().addAll(awbManifests);
}
}
}
use of com.taobao.android.builder.dependency.AndroidDependencyTree in project atlas by alibaba.
the class MergeManifestAwbsConfigAction 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>();
AppVariantOutputContext appVariantOutputContext = getAppVariantOutputContext();
for (final AwbBundle awbBundle : androidDependencyTree.getAwbBundles()) {
List<ManifestMerger2.Invoker.Feature> optionalFeatures = ImmutableList.<ManifestMerger2.Invoker.Feature>of();
MergeAwbManifests.ConfigAction configAction = new MergeAwbManifests.ConfigAction(appVariantOutputContext.getOutputScope(), awbBundle, optionalFeatures, appVariantOutputContext);
MergeAwbManifests mergeAwbManifests = TaskCreater.create(appVariantContext.getProject(), configAction.getName(), configAction.getType());
configAction.execute(mergeAwbManifests);
tasks.add(mergeAwbManifests);
}
parallelTask.parallelTask = tasks;
parallelTask.uniqueTaskName = getName();
}
Aggregations