美文网首页
Gradle源码

Gradle源码

作者: SMSM | 来源:发表于2017-10-17 15:48 被阅读15次

package org.gradle.api.internal.tasks.execution;
public class ExecuteActionsTaskExecuter implements TaskExecuter {}

public abstract class AbstractTask implements TaskInternal, DynamicObjectAware {}

private final List<ContextAwareTaskAction> actions = new ArrayList<ContextAwareTaskAction>();
    observableActionList = new ObservableActionWrapperList(actions);


public Task doFirst(final Action<? super Task> action) {
    hasCustomActions = true;
    if (action == null) {
        throw new InvalidUserDataException("Action must not be null!");
    }
    taskMutator.mutate("Task.doFirst(Action)", new Runnable() {
        public void run() {
            actions.add(0, wrap(action));
        }
    });
    return this;
}


public Task doLast(final Action<? super Task> action) {
    hasCustomActions = true;
    if (action == null) {
        throw new InvalidUserDataException("Action must not be null!");
    }
    taskMutator.mutate("Task.doLast(Action)", new Runnable() {
        public void run() {
            actions.add(wrap(action));
        }
    });
    return this;
}


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(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;
}

private void executeAction(TaskInternal task, ContextAwareTaskAction action, TaskExecutionContext context) {
    action.contextualise(context);
    try {
        action.execute(task);
    } finally {
        action.contextualise(null);
    }
}

// execute()  和 getTaskActions() 的关系 doFirst 和Action本身的执行顺序
public interface TaskInternal extends Task, Configurable<Task> {
// Can we just override Task.getActions()?
// Would need to change return type on Task API to: List<? super Action<? super Task>> : not certain this is back-compatible
List<ContextAwareTaskAction> getTaskActions();

Set<ClassLoader> getActionClassLoaders();

Spec<? super TaskInternal> getOnlyIf();

void execute();
}

相关文章

网友评论

      本文标题:Gradle源码

      本文链接:https://www.haomeiwen.com/subject/vckduxtx.html