Search in sources :

Example 11 with StopExecutionException

use of org.gradle.api.tasks.StopExecutionException in project gradle by gradle.

the class ExecuteActionsTaskExecuter method executeActions.

private GradleException executeActions(TaskInternal task, TaskStateInternal state, TaskExecutionContext context) {
    LOGGER.debug("Executing actions for {}.", task);
    final List<ContextAwareTaskAction> actions = new ArrayList<ContextAwareTaskAction>(task.getTaskActions());
    for (ContextAwareTaskAction action : actions) {
        state.setDidWork(true);
        task.getStandardOutputCapture().start();
        try {
            executeAction(action.getDisplayName(), task, action, context);
        } catch (StopActionException e) {
            // Ignore
            LOGGER.debug("Action stopped by some action with message: {}", e.getMessage());
        } catch (StopExecutionException e) {
            LOGGER.info("Execution stopped by some action with message: {}", e.getMessage());
            break;
        } catch (Throwable t) {
            return new TaskExecutionException(task, t);
        } finally {
            task.getStandardOutputCapture().stop();
        }
    }
    return null;
}
Also used : TaskExecutionException(org.gradle.api.tasks.TaskExecutionException) StopExecutionException(org.gradle.api.tasks.StopExecutionException) ContextAwareTaskAction(org.gradle.api.internal.tasks.ContextAwareTaskAction) StopActionException(org.gradle.api.tasks.StopActionException) ArrayList(java.util.ArrayList)

Example 12 with StopExecutionException

use of org.gradle.api.tasks.StopExecutionException in project atlas by alibaba.

the class ApkFileListUtils method recordApkFileInfos.

/**
 * Records resource information for apk files
 */
public static ApkFiles recordApkFileInfos(AppVariantContext appVariantContext) {
    ApkFiles apkFiles = new ApkFiles();
    List<File> mainBundleResFolders = new ArrayList<File>();
    mainBundleResFolders.add(appVariantContext.getScope().getVariantData().mergeResourcesTask.getOutputDir());
    prepareApkFileList(appVariantContext.getScope().getVariantData().mergeAssetsTask.getOutputDir(), "assets", apkFiles);
    for (File resFolder : mainBundleResFolders) {
        prepareApkFileList(resFolder, "res", apkFiles);
    }
    // Record the resource information for each bundle
    AtlasDependencyTree dependencyTree = AtlasBuildContext.androidDependencyTrees.get(appVariantContext.getScope().getVariantConfiguration().getFullName());
    if (null == dependencyTree) {
        throw new StopExecutionException("DependencyTree cannot be null!");
    }
    List<AwbBundle> libs = dependencyTree.getAwbBundles();
    for (AwbBundle awbLib : libs) {
        File mergeAssertFolder = appVariantContext.getMergeAssets(awbLib);
        File mergeResFolder = appVariantContext.getMergeResources(awbLib);
        String awbName = awbLib.getName();
        prepareApkFileList(mergeAssertFolder, "assets", awbName, apkFiles);
        prepareApkFileList(mergeResFolder, "res", awbName, apkFiles);
    }
    return apkFiles;
}
Also used : ApkFiles(com.android.build.gradle.internal.api.ApkFiles) StopExecutionException(org.gradle.api.tasks.StopExecutionException) ArrayList(java.util.ArrayList) AwbBundle(com.taobao.android.builder.dependency.model.AwbBundle) CompiledFile(android.aapt.pb.internal.ResourcesInternal.CompiledFile) File(java.io.File) AtlasDependencyTree(com.taobao.android.builder.dependency.AtlasDependencyTree)

Example 13 with StopExecutionException

use of org.gradle.api.tasks.StopExecutionException in project atlas by alibaba.

the class InjectTransformManager method updateTransformTaskConfig.

/**
 * Update the parameters for the transformTask
 *
 * @param transformTask
 * @param consumedInputStreams
 * @param referencedInputStreams
 * @param outputStream
 */
private void updateTransformTaskConfig(TransformTask transformTask, @NonNull Collection<TransformStream> consumedInputStreams, @NonNull Collection<TransformStream> referencedInputStreams, @Nullable IntermediateStream outputStream) throws IllegalAccessException {
    Field consumedInputStreamsField = FieldUtils.getDeclaredField(StreamBasedTask.class, "consumedInputStreams", true);
    Field referencedInputStreamsField = FieldUtils.getDeclaredField(StreamBasedTask.class, "referencedInputStreams", true);
    Field outputStreamField = FieldUtils.getDeclaredField(StreamBasedTask.class, "outputStream", true);
    if (null == consumedInputStreamsField || null == referencedInputStreamsField || null == outputStreamField) {
        throw new StopExecutionException("The TransformTask does not has field with name: consumedInputStreams or referencedInputStreams or outputStream! Plugin version does not support!");
    }
    consumedInputStreamsField.set(transformTask, consumedInputStreams);
    referencedInputStreamsField.set(transformTask, referencedInputStreams);
    outputStreamField.set(transformTask, outputStream);
}
Also used : Field(java.lang.reflect.Field) StopExecutionException(org.gradle.api.tasks.StopExecutionException)

Example 14 with StopExecutionException

use of org.gradle.api.tasks.StopExecutionException in project atlas by alibaba.

the class InjectTransformManager method addInjectTransformBeforeTransform.

/**
 * Add a Transform operation before some 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();
    // The task to be inserted
    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);
    // Determines whether the two Transform dependencies are correct, that is, the output type is consistent with the next input type
    checkTransformConfig(oprTransformTask.getTransform(), injectTransform);
    String taskName = scope.getTaskName(getTaskNamePrefix(injectTransform));
    try {
        IntermediateStream outputStream = getOutputStream(injectTransform, scope, taskName);
        // Configuration TransformTask
        TransformTaskParam transformTaskParam = getTransformParam(oprTransformTask);
        TransformTask.ConfigAction<T> configAction = new TransformTask.ConfigAction<T>(variantName, taskName, injectTransform, transformTaskParam.consumedInputStreams, transformTaskParam.referencedInputStreams, outputStream, ThreadRecorder.get(), null);
        TransformTask injectTransformTask = project.getTasks().create(configAction.getName(), configAction.getType());
        oprTransformTask.dependsOn(injectTransformTask);
        for (TransformStream transformStream : transformTaskParam.consumedInputStreams) {
            if (null != transformStream.getFileCollection()) {
                injectTransformTask.dependsOn(transformStream.getFileCollection());
            }
        }
        if (transformTaskList.size() > 0) {
            injectTransformTask.dependsOn(transformTaskList.get(transformTaskList.size() - 1));
        }
        transformTaskList.add(taskName);
        configAction.execute(injectTransformTask);
        // Modify the input of the 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)

Aggregations

StopExecutionException (org.gradle.api.tasks.StopExecutionException)14 File (java.io.File)5 VariantScope (com.android.build.gradle.internal.scope.VariantScope)2 BaseVariantOutputData (com.android.build.gradle.internal.variant.BaseVariantOutputData)2 AndroidDependencyTree (com.taobao.android.builder.dependency.AndroidDependencyTree)2 IOException (java.io.IOException)2 Field (java.lang.reflect.Field)2 ArrayList (java.util.ArrayList)2 GradleException (org.gradle.api.GradleException)2 StopActionException (org.gradle.api.tasks.StopActionException)2 TaskAction (org.gradle.api.tasks.TaskAction)2 CompiledFile (android.aapt.pb.internal.ResourcesInternal.CompiledFile)1 ApkFiles (com.android.build.gradle.internal.api.ApkFiles)1 AppVariantOutputContext (com.android.build.gradle.internal.api.AppVariantOutputContext)1 GradleVariantConfiguration (com.android.build.gradle.internal.core.GradleVariantConfiguration)1 TransformTask (com.android.build.gradle.internal.pipeline.TransformTask)1 GlobalScope (com.android.build.gradle.internal.scope.GlobalScope)1 DefaultAndroidTask (com.android.build.gradle.internal.tasks.DefaultAndroidTask)1 ProGuardTransform (com.android.build.gradle.internal.transforms.ProGuardTransform)1 ManifestProcessorTask (com.android.build.gradle.tasks.ManifestProcessorTask)1