/*
 * Copyright 2014 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.gradle.language.base.plugins;

import org.gradle.api.*;
import org.gradle.api.internal.project.ProjectInternal;
import org.gradle.api.tasks.Delete;
import org.gradle.language.base.internal.plugins.CleanRule;
import org.gradle.language.base.internal.tasks.AssembleBinariesTask;

import java.io.File;
import java.util.concurrent.Callable;

/**
 * <p>A {@link org.gradle.api.Plugin} which defines a basic project lifecycle.</p>
 */
@Incubating
public class LifecycleBasePlugin implements Plugin<ProjectInternal> {
    public static final String CLEAN_TASK_NAME = "clean";
    public static final String ASSEMBLE_TASK_NAME = "assemble";
    public static final String CHECK_TASK_NAME = "check";
    public static final String BUILD_TASK_NAME = "build";
    public static final String BUILD_GROUP = "build";
    public static final String VERIFICATION_GROUP = "verification";

    public void apply(ProjectInternal project) {
        addClean(project);
        addCleanRule(project);
        addAssemble(project);
        addCheck(project);
        addBuild(project);
    }

    private void addClean(final Project project) {
        Delete clean = project.getTasks().create(CLEAN_TASK_NAME, Delete.class);
        clean.setDescription("Deletes the build directory.");
        clean.setGroup(BUILD_GROUP);
        clean.delete(new Callable<File>() {
            public File call() throws Exception {
                return project.getBuildDir();
            }
        });
    }

    private void addCleanRule(Project project) {
        project.getTasks().addRule(new CleanRule(project.getTasks()));
    }

    private void addAssemble(Project project) {
        Task assembleTask = project.getTasks().create(ASSEMBLE_TASK_NAME, AssembleBinariesTask.class);
        assembleTask.setDescription("Assembles the outputs of this project.");
        assembleTask.setGroup(BUILD_GROUP);
    }

    private void addCheck(ProjectInternal project) {
        project.getTasks().addPlaceholderAction(CHECK_TASK_NAME, DefaultTask.class, new Action<DefaultTask>() {
            @Override
            public void execute(DefaultTask checkTask) {
                checkTask.setDescription("Runs all checks.");
                checkTask.setGroup(VERIFICATION_GROUP);
            }
        });
    }

    private void addBuild(ProjectInternal project) {
        project.getTasks().addPlaceholderAction(BUILD_TASK_NAME, DefaultTask.class, new Action<DefaultTask>() {
            @Override
            public void execute(DefaultTask buildTask) {
                buildTask.setDescription("Assembles and tests this project.");
                buildTask.setGroup(BUILD_GROUP);
                buildTask.dependsOn(ASSEMBLE_TASK_NAME);
                buildTask.dependsOn(CHECK_TASK_NAME);
            }
        });
    }
}

@@ -2530,16 +2530,22 @@
 ddCheck(
+final 
 ProjectI
@@ -2632,50 +2632,20 @@
 ME, 
-DefaultTask.class, new Action%3CDefaultTask%3E
+new Runnable
 () %7B
@@ -2695,40 +2695,97 @@
 oid 
-execute(DefaultTask checkTask) %7B
+run() %7B%0A                Task checkTask = project.getTasks().maybeCreate(CHECK_TASK_NAME);
 %0A   
@@ -2958,16 +2958,22 @@
 ddBuild(
+final 
 ProjectI
@@ -3060,50 +3060,20 @@
 ME, 
-DefaultTask.class, new Action%3CDefaultTask%3E
+new Runnable
 () %7B
@@ -3123,40 +3123,97 @@
 oid 
-execute(DefaultTask buildTask) %7B
+run() %7B%0A                Task buildTask = project.getTasks().maybeCreate(BUILD_TASK_NAME);
 %0A   

Use correct api for placeholder actions in release branch