package com.github.blindpirate.gogradle.task;

import com.github.blindpirate.gogradle.build.BuildManager;
import com.github.blindpirate.gogradle.core.dependency.GolangDependency;
import com.github.blindpirate.gogradle.core.dependency.tree.DependencyTreeNode;
import org.gradle.api.tasks.TaskAction;

import javax.inject.Inject;

import static com.github.blindpirate.gogradle.build.Configuration.BUILD;


public class InstallBuildDependenciesTask extends AbstractGolangTask {
    @Inject
    private BuildManager buildManager;

    public InstallBuildDependenciesTask() {
        dependsOn(GolangTaskContainer.RESOLVE_BUILD_DEPENDENCIES_TASK_NAME);
    }

    @TaskAction
    public void installDependencies() {
        DependencyTreeNode rootNode = getTask(ResolveBuildDependenciesTask.class).getDependencyTree();
        rootNode.flatten()
                .stream()
                .map(GolangDependency::resolve)
                .forEach((dependency) -> buildManager.installDependency(dependency, BUILD));
    }
}

@@ -154,22 +154,24 @@
 endency.
-Golang
+Resolved
 Dependen
@@ -887,15 +887,9 @@
 map(
-GolangD
+d
 epen
@@ -897,17 +897,43 @@
 ency
-::resolve
+ -%3E (ResolvedDependency) dependency
 )%0A  

Use type casting instead of resolve() since we know it is actually ResolvedDependency