Search in sources :

Example 1 with BaseTask

use of com.android.build.gradle.internal.tasks.BaseTask in project atlas by alibaba.

the class MtlTaskInjector method injectTasks.

public void injectTasks(List<MtlTaskContext> mtlTaskContexts, AndroidBuilder androidBuilder) {
    Collection<BaseVariantOutput> baseVariantOutputDataList = variantContext.getVariantOutputData();
    for (final BaseVariantOutput vod : baseVariantOutputDataList) {
        // TODO What if the intermediate step does not generate task
        List<Task> beforeTasks = new ArrayList<Task>();
        for (MtlTaskContext mtlTaskContext : mtlTaskContexts) {
            // Get the task instance
            List<Task> tasks = new ArrayList<Task>();
            if (mtlTaskContext.isSystemTask()) {
                if (null != mtlTaskContext.getSysTask()) {
                    tasks.add(mtlTaskContext.getSysTask());
                } else if (null != mtlTaskContext.getSysTaskClazz()) {
                    Class taskClazz = mtlTaskContext.getSysTaskClazz();
                    tasks.addAll(findTask(taskClazz, variantContext.getVariantName()));
                } else {
                    Task task = project.getTasks().findByName(variantContext.getBaseVariantData().getTaskName(mtlTaskContext.getTaskName(), ""));
                    if (null != task) {
                        tasks.add(task);
                    }
                }
            } else {
                Task task = mtlTaskFactory.createTask(variantContext, vod, mtlTaskContext.getTaskActionClazz());
                if (null != task) {
                    if (null != androidBuilder && task instanceof BaseTask) {
                        ((BaseTask) task).setAndroidBuilder(androidBuilder);
                    }
                    tasks.add(task);
                }
            }
            if (tasks.isEmpty()) {
                // throw new RuntimeException("task is not found " + mtlTaskContext);
                project.getLogger().info("task is not found " + vod.getName() + mtlTaskContext);
            } else {
                if (!beforeTasks.isEmpty()) {
                    for (Task task : tasks) {
                        project.getLogger().debug("[MtlTaskInjector]" + vod.getName() + ":" + task + "->" + StringUtils.join(beforeTasks.toArray()));
                        for (Task before : beforeTasks) {
                            project.getLogger().info("[tasks] set task " + task.getProject().getName() + ":" + task.getName() + "->" + before.getProject().getName() + ":" + before.getName());
                            task.dependsOn(before);
                        }
                    }
                }
                beforeTasks.clear();
                beforeTasks.addAll(tasks);
                if (null != mtlTaskContext.getTaskFilter()) {
                    List<Task> beforeTasks2 = mtlTaskContext.getTaskFilter().getBeforeTasks(project, vod);
                    for (Task task : tasks) {
                        project.getLogger().debug("[MtlTaskInjector]" + vod.getName() + ":" + task + "->" + StringUtils.join(beforeTasks2.toArray()));
                        for (Task before : beforeTasks2) {
                            project.getLogger().info("[tasks] set task " + task.getProject().getName() + ":" + task.getName() + "->" + before.getProject().getName() + ":" + before.getName());
                            task.dependsOn(before);
                        }
                    }
                }
            }
        }
    }
}
Also used : BaseVariantOutput(com.android.build.gradle.api.BaseVariantOutput) BaseTask(com.android.build.gradle.internal.tasks.BaseTask) Task(org.gradle.api.Task) DefaultAndroidTask(com.android.build.gradle.internal.tasks.DefaultAndroidTask) ArrayList(java.util.ArrayList) BaseTask(com.android.build.gradle.internal.tasks.BaseTask)

Aggregations

BaseVariantOutput (com.android.build.gradle.api.BaseVariantOutput)1 BaseTask (com.android.build.gradle.internal.tasks.BaseTask)1 DefaultAndroidTask (com.android.build.gradle.internal.tasks.DefaultAndroidTask)1 ArrayList (java.util.ArrayList)1 Task (org.gradle.api.Task)1