Search in sources :

Example 1 with DefaultAndroidTask

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

the class MtlTaskInjector method findTask.

protected List<Task> findTask(Class<Task> clazz, String variantName) {
    Task[] androidTasks = project.getTasks().withType(clazz).toArray(new Task[0]);
    List<Task> taskList = new ArrayList();
    for (Task task : androidTasks) {
        if (task instanceof DefaultAndroidTask) {
            if (variantName.equals(((DefaultAndroidTask) task).getVariantName())) {
                taskList.add(task);
            }
        } else {
            String name = task.getName();
            if (name.toLowerCase().contains(variantName)) {
                taskList.add(task);
            }
        }
    }
    return taskList;
}
Also used : DefaultAndroidTask(com.android.build.gradle.internal.tasks.DefaultAndroidTask) 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)

Example 2 with DefaultAndroidTask

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

the class InjectTransformManager method addInjectTransformBeforeTransform.

/**
     * 在某种Transform之前增加一个Transform操作
     *
     * @param transformClazz
     * @param injectTransform
     * @param scope
     * @param <T>
     * @return
     */
public <T extends InjectTransform> TransformTask addInjectTransformBeforeTransform(Class<? extends Transform> transformClazz, T injectTransform, @NonNull VariantScope scope) {
    TaskCollection<DefaultAndroidTask> androidTasks = project.getTasks().withType(DefaultAndroidTask.class);
    SortedMap<String, DefaultAndroidTask> androidTaskSortedMap = androidTasks.getAsMap();
    // 要插入的任务
    TransformTask oprTransformTask = null;
    for (String taskName : androidTaskSortedMap.keySet()) {
        DefaultAndroidTask androidTask = androidTaskSortedMap.get(taskName);
        if (variantName.equals(androidTask.getVariantName())) {
            if (androidTask instanceof TransformTask && ((TransformTask) androidTask).getTransform().getClass().equals(transformClazz)) {
                oprTransformTask = (TransformTask) androidTask;
                break;
            }
        }
    }
    if (null == oprTransformTask) {
        throw new StopExecutionException("TransformTask with transfrom type:" + transformClazz.getName() + " can not found!");
    }
    transforms.add(injectTransform);
    //判断2个Transform的依赖是否正确,即输出的type和下一个输入的type一致
    checkTransformConfig(oprTransformTask.getTransform(), injectTransform);
    String taskName = scope.getTaskName(getTaskNamePrefix(injectTransform));
    try {
        IntermediateStream outputStream = getOutputStream(injectTransform, scope, taskName);
        // 配置TransformTask
        TransformTaskParam transformTaskParam = getTransformParam(oprTransformTask);
        TransformTask.ConfigAction<T> configAction = new TransformTask.ConfigAction<T>(variantName, taskName, injectTransform, transformTaskParam.consumedInputStreams, transformTaskParam.referencedInputStreams, outputStream, null);
        TransformTask injectTransformTask = project.getTasks().create(configAction.getName(), configAction.getType());
        oprTransformTask.dependsOn(injectTransformTask);
        for (TransformStream transformStream : transformTaskParam.consumedInputStreams) {
            if (null != transformStream.getDependencies()) {
                injectTransformTask.dependsOn(transformStream.getDependencies());
            }
        }
        for (TransformStream transformStream : transformTaskParam.referencedInputStreams) {
            if (null != transformStream.getDependencies()) {
                injectTransformTask.dependsOn(transformStream.getDependencies());
            }
        }
        if (transformTaskList.size() > 0) {
            injectTransformTask.dependsOn(transformTaskList.get(transformTaskList.size() - 1));
        }
        transformTaskList.add(taskName);
        configAction.execute(injectTransformTask);
        //修改oprTransformTask的输入
        if (injectTransform.updateNextTransformInput()) {
            Collection<TransformStream> newInputStream = Lists.newArrayList();
            newInputStream.add(outputStream);
            updateTransformTaskConfig(oprTransformTask, newInputStream, transformTaskParam.referencedInputStreams, transformTaskParam.outputStream);
        }
        return injectTransformTask;
    } catch (IllegalAccessException e) {
        throw new StopExecutionException(e.getMessage());
    }
}
Also used : DefaultAndroidTask(com.android.build.gradle.internal.tasks.DefaultAndroidTask) StopExecutionException(org.gradle.api.tasks.StopExecutionException)

Example 3 with DefaultAndroidTask

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

the class MtlBaseTaskAction method execute.

@Override
public void execute(T task) {
    if (task instanceof DefaultAndroidTask) {
        DefaultAndroidTask defaultAndroidTask = (DefaultAndroidTask) task;
        defaultAndroidTask.setVariantName(scope.getVariantScope().getVariantConfiguration().getFullName());
    }
//        ConventionMappingHelper.map(task, "appVariantContext", new Callable<AppVariantContext>() {
//            @Override
//            public AppVariantContext call() throws Exception {
//                return appVariantContext;
//            }
//        });
//
//        ConventionMappingHelper.map(task, "baseVariantOutputData", new Callable<BaseVariantOutputData>() {
//            @Override
//            public BaseVariantOutputData call() throws Exception {
//                return baseVariantOutputData;
//            }
//        });
}
Also used : DefaultAndroidTask(com.android.build.gradle.internal.tasks.DefaultAndroidTask)

Example 4 with DefaultAndroidTask

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

the class TaskQueryHelper method findTask.

public static <T> List<T> findTask(Project project, Class<? extends Task> clazz, BaseVariantData vod) {
    Task[] androidTasks = project.getTasks().withType(clazz).toArray(new Task[0]);
    String variantName = vod.getName();
    List<Task> taskList = new ArrayList();
    for (Task task : androidTasks) {
        if (task instanceof DefaultAndroidTask) {
            if (variantName.equals(((DefaultAndroidTask) task).getVariantName())) {
                taskList.add(task);
            }
        } else {
            String name = task.getName();
            if (name.toLowerCase().contains(variantName)) {
                taskList.add(task);
            }
        }
    }
    return (List<T>) taskList;
}
Also used : DefaultAndroidTask(com.android.build.gradle.internal.tasks.DefaultAndroidTask) Task(org.gradle.api.Task) DefaultAndroidTask(com.android.build.gradle.internal.tasks.DefaultAndroidTask) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

DefaultAndroidTask (com.android.build.gradle.internal.tasks.DefaultAndroidTask)4 ArrayList (java.util.ArrayList)2 Task (org.gradle.api.Task)2 BaseTask (com.android.build.gradle.internal.tasks.BaseTask)1 List (java.util.List)1 StopExecutionException (org.gradle.api.tasks.StopExecutionException)1