Task.java /** * <p>Adds the given closure to the end of this task's action list. The closure is passed this task as a parameter * when executed. You can call this method from your build script using the << left shift operator.</p> * * @param action The action closure to execute. * @return This task. * * @deprecated Use {@link #doLast(Closure action)} */ @Deprecated Task leftShift(Closure action);
leftShift方法和doLast方法实现
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
@Override public Task leftShift(final Closure action) { DeprecationLogger.nagUserOfDiscontinuedMethod("Task.leftShift(Closure)", "Please use Task.doLast(Action) instead.");
hasCustomActions = true; if (action == null) { thrownewInvalidUserDataException("Action must not be null!"); } taskMutator.mutate("Task.leftShift(Closure)", newRunnable() { publicvoidrun() { getTaskActions().add(taskMutator.leftShift(convertClosureToAction(action, "doLast {} action"))); } }); returnthis; }
1 2 3 4 5 6 7 8 9 10 11 12 13
@Override public Task doLast(final Closure action) { hasCustomActions = true; if (action == null) { thrownewInvalidUserDataException("Action must not be null!"); } taskMutator.mutate("Task.doLast(Closure)", newRunnable() { publicvoidrun() { getTaskActions().add(convertClosureToAction(action, "doLast {} action")); } }); returnthis; }
@Override publicvoidprependParallelSafeAction(final Action<? super Task> action) { if (action == null) { thrownewInvalidUserDataException("Action must not be null!"); } getTaskActions().add(0, wrap(action)); }
添加到actions list里面。这时候Task刚被创建,所以不会有其他的action。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
@Override public Task doFirst(final Action<? super Task> action) { return doFirst("doFirst {} action", action); }
@Override public Task doFirst(final String actionName, final Action<? super Task> action) { hasCustomActions = true; if (action == null) { thrownewInvalidUserDataException("Action must not be null!"); } taskMutator.mutate("Task.doFirst(Action)", newRunnable() { publicvoidrun() { getTaskActions().add(0, wrap(action, actionName)); } }); returnthis; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
@Override public Task doLast(final Action<? super Task> action) { return doLast("doLast {} action", action); }
@Override public Task doLast(final String actionName, final Action<? super Task> action) { hasCustomActions = true; if (action == null) { thrownewInvalidUserDataException("Action must not be null!"); } taskMutator.mutate("Task.doLast(Action)", newRunnable() { publicvoidrun() { getTaskActions().add(wrap(action, actionName)); } }); returnthis; }
public T findName(String name){ Tvalue= findByNameWithoutRules(name); if(value != null){ return value; } applyRules(name); return findByNameWithoutRules(name); }
以名字查找的时候,如果没有找到则调用applyRules(name)应用我们添加的规则。
我们可以通过调用addRule来添加我们自定义的规则,它有两个用法:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/** * Adds a rule to this collection. The given rule is invoked when an unknown object is requested by name. * * @param rule The rule to add. * @return The added rule. */ Rule addRule(Rule rule);
/** * Adds a rule to this collection. The given closure is executed when an unknown object is requested by name. The * requested name is passed to the closure as a parameter. * * @param description The description of the rule. * @param ruleAction The closure to execute to apply the rule. * @return The added rule. */ Rule addRule(String description, Closure ruleAction);