use of com.android.build.gradle.internal.TaskFactory in project atlas by alibaba.
the class AtlasAppTaskManager method runTask.
@Override
public void runTask() {
appExtension.getApplicationVariants().forEach(new Consumer<ApplicationVariant>() {
@Override
public void accept(ApplicationVariant applicationVariant) {
AppVariantContext appVariantContext = AtlasBuildContext.sBuilderAdapter.appVariantContextFactory.getAppVariantContext(project, applicationVariant);
if (!AtlasBuildContext.atlasMainDexHelperMap.containsKey(appVariantContext.getVariantName())) {
AtlasBuildContext.atlasMainDexHelperMap.put(appVariantContext.getVariantName(), new AtlasMainDexHelper());
}
TransformReplacer transformReplacer = new TransformReplacer(appVariantContext);
repalceAndroidBuilder(applicationVariant);
List<MtlTaskContext> mtlTaskContextList = new ArrayList<MtlTaskContext>();
mtlTaskContextList.add(new MtlTaskContext(appVariantContext.getVariantData().preBuildTask));
mtlTaskContextList.add(new MtlTaskContext(BuildAtlasEnvTask.ConfigAction.class, null));
mtlTaskContextList.add(new MtlTaskContext(ScanDupResTask.ConfigActon.class, null));
mtlTaskContextList.add(new MtlTaskContext(LogDependenciesTask.ConfigAction.class, null));
mtlTaskContextList.add(new MtlTaskContext(PrepareAPTask.ConfigAction.class, null));
mtlTaskContextList.add(new MtlTaskContext(appVariantContext.getVariantData().mergeAssetsTask));
mtlTaskContextList.add(new MtlTaskContext(RenderscriptCompile.class));
mtlTaskContextList.add(new MtlTaskContext(StandardizeLibManifestTask.ConfigAction.class, null));
mtlTaskContextList.add(new MtlTaskContext(PrepareBundleInfoTask.ConfigAction.class, null));
if (!atlasExtension.getTBuildConfig().getClassInject() && atlasExtension.isAtlasEnabled()) {
mtlTaskContextList.add(new MtlTaskContext(GenerateAtlasSourceTask.ConfigAction.class, null));
}
mtlTaskContextList.add(new MtlTaskContext(PreparePackageIdsTask.ConfigAction.class, null));
mtlTaskContextList.add(new MtlTaskContext(PrepareAaptTask.ConfigAction.class, null));
mtlTaskContextList.add(new MtlTaskContext(AidlCompile.class));
mtlTaskContextList.add(new MtlTaskContext(GenerateBuildConfig.class));
mtlTaskContextList.add(new MtlTaskContext(MergeResAwbsConfigAction.class, null));
mtlTaskContextList.add(new MtlTaskContext(MergeAssetAwbsConfigAction.class, null));
if (null != androidExtension.getDataBinding() && androidExtension.getDataBinding().isEnabled() && !appVariantContext.getAtlasExtension().getTBuildConfig().getAllBundlesToMdex()) {
// mtlTaskContextList.add(
// new MtlTaskContext(AwbDataBindingProcessLayoutTask.ConfigAction.class, null));
mtlTaskContextList.add(new MtlTaskContext(AwbDataBindingExportBuildInfoTask.ConfigAction.class, null));
mtlTaskContextList.add(new MtlTaskContext(AwbDataBindingMergeArtifactsTask.ConfigAction.class, null));
}
mtlTaskContextList.add(new MtlTaskContext(MergeManifests.class));
mtlTaskContextList.add(new MtlTaskContext(MergeManifestAwbsConfigAction.class, null));
// mtlTaskContextList.add(new MtlTaskContext(MergeResV4Dir.ConfigAction.class, null));
mtlTaskContextList.add(new MtlTaskContext(ProcessAndroidResources.class));
ProcessAndroidResources processAndroidResources = appVariantContext.getScope().getProcessResourcesTask().get(new TaskContainerAdaptor(appVariantContext.getProject().getTasks()));
if (processAndroidResources.isAapt2Enabled()) {
processAndroidResources.doLast(new Action<Task>() {
@Override
public void execute(Task task) {
File processResourcePackageOutputDirectory = appVariantContext.getScope().getProcessResourcePackageOutputDirectory();
File[] files = processResourcePackageOutputDirectory.listFiles((file, name) -> name.endsWith(SdkConstants.DOT_RES));
for (File file : files) {
try {
ResourcePatch.makePatchable(file);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
}
});
}
mtlTaskContextList.add(new MtlTaskContext(ProcessResAwbsTask.ConfigAction.class, null));
mtlTaskContextList.add(new MtlTaskContext(JavacAwbsTask.ConfigAction.class, null));
if (null != androidExtension.getDataBinding() && androidExtension.getDataBinding().isEnabled() && !appVariantContext.getAtlasExtension().getTBuildConfig().getAllBundlesToMdex()) {
mtlTaskContextList.add(new MtlTaskContext(AwbDataBindingRenameTask.ConfigAction.class, null));
}
mtlTaskContextList.add(new MtlTaskContext(TransformTask.class));
mtlTaskContextList.add(new MtlTaskContext(PackageAwbsTask.ConfigAction.class, null));
if (appVariantContext.getAtlasExtension().getTBuildConfig().isIncremental() && (appVariantContext.getBuildType().getPatchConfig() == null || !appVariantContext.getBuildType().getPatchConfig().isCreateTPatch())) {
// mtlTaskContextList.add(new MtlTaskContext(PrepareBaseApkTask.ConfigAction.class, null));
final TaskFactory tasks = new TaskContainerAdaptor(project.getTasks());
VariantScope variantScope = appVariantContext.getVariantData().getScope();
// create the stream generated from this task
variantScope.getTransformManager().addStream(OriginalStream.builder(project, applicationVariant.getName()).addContentType(QualifiedContent.DefaultContentType.RESOURCES).addScope(QualifiedContent.Scope.PROJECT).setFolders(new Supplier<Collection<File>>() {
@Override
public Collection<File> get() {
return ImmutableList.of(new File(appVariantContext.apContext.getBaseApk() + "_"));
}
}).build());
}
final TaskFactory tasks = new TaskContainerAdaptor(project.getTasks());
VariantScope variantScope = appVariantContext.getVariantData().getScope();
mtlTaskContextList.add(new MtlTaskContext(PackageApplication.class));
if (appVariantContext.getAtlasExtension().isInstantAppEnabled()) {
mtlTaskContextList.add(new MtlTaskContext(AtlasBundleInstantApp.ConfigAction.class, null));
}
mtlTaskContextList.add(new MtlTaskContext(ApBuildTask.ConfigAction.class, null));
mtlTaskContextList.add(new MtlTaskContext(DiffBundleInfoTask.ConfigAction.class, null));
mtlTaskContextList.add(new MtlTaskContext(TPatchDiffResAPBuildTask.ConfigAction.class, null));
mtlTaskContextList.add(new MtlTaskContext(TPatchDiffApkBuildTask.ConfigAction.class, null));
mtlTaskContextList.add(new MtlTaskContext(TPatchTask.ConfigAction.class, null));
mtlTaskContextList.add(new MtlTaskContext("assemble"));
new MtlTaskInjector(appVariantContext).injectTasks(mtlTaskContextList, tAndroidBuilder);
List<MtlTransformContext> mtlTransformContextList = new ArrayList<MtlTransformContext>();
if (atlasExtension.getTBuildConfig().getClassInject()) {
mtlTransformContextList.add(new MtlTransformContext(ClassInjectTransform.class, ProGuardTransform.class, DexTransform.class));
}
if (variantScope.getInstantRunBuildContext().isInInstantRunMode() && appVariantContext.getVariantConfiguration().getBuildType().isMinifyEnabled()) {
mtlTransformContextList.add(new MtlTransformContext(DelegateProguardTransform.class, ExtractJarsTransform.class, InstantRunTransform.class));
}
if (!mtlTransformContextList.isEmpty()) {
new MtlTransformInjector(appVariantContext).injectTasks(mtlTransformContextList);
}
Collection<BaseVariantOutput> baseVariantOutputDataList = appVariantContext.getVariantOutputData();
boolean multiDexEnabled = appVariantContext.getVariantData().getVariantConfiguration().isMultiDexEnabled();
if (atlasExtension.getTBuildConfig().isAtlasMultiDex() && multiDexEnabled) {
transformReplacer.replaceMultiDexListTransform();
}
transformReplacer.replaceProguardTransform();
transformReplacer.disableCache();
if (variantScope.getGlobalScope().getExtension().getDataBinding().isEnabled() && !appVariantContext.getAtlasExtension().getTBuildConfig().getAllBundlesToMdex()) {
transformReplacer.replaceDataBindingMergeArtifactsTransform();
}
for (final BaseVariantOutput vod : baseVariantOutputDataList) {
transformReplacer.replaceFixStackFramesTransform(vod);
transformReplacer.replaceDesugarTransform(vod);
transformReplacer.replaceDexArchiveBuilderTransform(vod);
transformReplacer.replaceDexExternalLibMerge(vod);
transformReplacer.replaceDexMerge(vod);
transformReplacer.replaceDexTransform(appVariantContext, vod);
transformReplacer.replaceShrinkResourcesTransform();
transformReplacer.replaceMergeJavaResourcesTransform(appVariantContext, vod);
transformReplacer.repalaceSomeInstantTransform(vod);
if (atlasExtension.getTBuildConfig().isIncremental()) {
InstantRunPatchingPolicy patchingPolicy = variantScope.getInstantRunBuildContext().getPatchingPolicy();
BaseVariantOutputImpl variantOutput = (BaseVariantOutputImpl) vod;
ApkData data = ApkDataUtils.get(variantOutput);
AtlasDependencyTree atlasDependencyTree = AtlasBuildContext.androidDependencyTrees.get(variantScope.getFullVariantName());
//
}
}
// Boolean includeCompileClasspath =
// appVariantContext.getScope().getVariantConfiguration()
// .getJavaCompileOptions()
// .getAnnotationProcessorOptions()
// .getIncludeCompileClasspath();
// appVariantContext.getVariantData().javaCompilerTask.doFirst(task -> {
// JavaCompile compile = (JavaCompile) task;
// Set<File> mainDexFiles = new MainFilesCollection(appVariantContext.getVariantName()).getFiles();
// FileCollection mainFiles = appVariantContext.getProject().files(mainDexFiles);
// FileCollection files = appVariantContext.getScope().getArtifactFileCollection(ANNOTATION_PROCESSOR, ALL, JAR);
// FileCollection bootFiles = appVariantContext.getProject().files(appVariantContext.getScope().getGlobalScope().getAndroidBuilder().getBootClasspath(false));
// mainFiles = mainFiles.plus(bootFiles);
// FileCollection fileCollection = compile.getClasspath();
// File kotlinClasses = null;
// for (File file : fileCollection) {
// if (file.getAbsolutePath().contains("kotlin-classes")) {
// mainFiles = mainFiles.plus(appVariantContext.getProject().files(file));
// kotlinClasses = file;
// break;
// }
// }
// compile.setClasspath(mainFiles);
// if (Boolean.TRUE.equals(includeCompileClasspath)) {
// compile.getOptions().setAnnotationProcessorPath(files.plus(mainFiles));
// }
// });
appVariantContext.getVariantData().javaCompilerTask.doLast(new Action<Task>() {
@Override
public void execute(Task task) {
JavaCompile compile = (JavaCompile) task;
AtlasBuildContext.atlasMainDexHelperMap.get(appVariantContext.getVariantName()).getInputDirs().add(compile.getDestinationDir());
}
});
PackageAndroidArtifact packageAndroidArtifact = appVariantContext.getVariantData().getTaskByType(PackageAndroidArtifact.class);
if (packageAndroidArtifact != null) {
ReflectUtils.updateField(packageAndroidArtifact, "javaResourceFiles", new AbstractFileCollection() {
@Override
public String getDisplayName() {
return "java-merge-res.jar";
}
@Override
public Set<File> getFiles() {
if (AtlasBuildContext.atlasMainDexHelperMap.get(packageAndroidArtifact.getVariantName()).getMainJavaRes() == null) {
return Sets.newHashSet();
}
return Sets.newHashSet(AtlasBuildContext.atlasMainDexHelperMap.get(packageAndroidArtifact.getVariantName()).getMainJavaRes());
}
});
}
TaskCollection<ExtractTryWithResourcesSupportJar> taskCollection = appVariantContext.getProject().getTasks().withType(ExtractTryWithResourcesSupportJar.class);
for (ExtractTryWithResourcesSupportJar task : taskCollection) {
task.doLast(new Action<Task>() {
@Override
public void execute(Task task) {
ConfigurableFileCollection fileCollection = variantScope.getTryWithResourceRuntimeSupportJar();
for (File file : fileCollection.getFiles()) {
if (file.exists()) {
AtlasBuildContext.atlasMainDexHelperMap.get(variantScope.getFullVariantName()).addMainDex(new BuildAtlasEnvTask.FileIdentity("runtime-deps-try-with-resources", file, false, false));
break;
}
}
}
});
}
}
});
}
Aggregations