package com.github.blindpirate.gogradle.core.dependency.install;

import com.github.blindpirate.gogradle.core.dependency.LocalDirectoryDependency;
import com.github.blindpirate.gogradle.core.dependency.ResolvedDependency;
import com.github.blindpirate.gogradle.core.dependency.VendorResolvedDependency;
import com.github.blindpirate.gogradle.util.IOUtils;

import javax.inject.Singleton;
import java.io.File;
import java.nio.file.Path;

@Singleton
public class LocalDirectoryDependencyInstaller implements DependencyInstaller {
    @Override
    public void install(ResolvedDependency dependency, File targetDirectory) {
        LocalDirectoryDependency realDependency = (LocalDirectoryDependency) determineDependency(dependency);
        Path realPath = realDependency.getRootDir().toPath().resolve(determineRelativePath(dependency));

        IOUtils.copyDirectory(realPath.toFile(), targetDirectory, DependencyInstallFileFilter.INSTANCE);
    }

    // TODO duplicated code
    private ResolvedDependency determineDependency(ResolvedDependency dependency) {
        if (dependency instanceof VendorResolvedDependency) {
            return VendorResolvedDependency.class.cast(dependency).getHostDependency();
        } else {
            return dependency;
        }
    }

    private String determineRelativePath(ResolvedDependency dependency) {
        if (dependency instanceof VendorResolvedDependency) {
            return VendorResolvedDependency.class.cast(dependency).getRelativePathToHost();
        } else {
            return ".";
        }
    }
}

@@ -219,89 +219,8 @@
 cy;%0A
-import com.github.blindpirate.gogradle.core.dependency.VendorResolvedDependency;%0A
 impo
@@ -418,16 +418,29 @@
 lements 
+VendorSupport
 Dependen
@@ -450,16 +450,21 @@
 nstaller
+Mixin
  %7B%0A    @
@@ -881,620 +881,7 @@
    %7D
-%0A%0A    // TODO duplicated code%0A    private ResolvedDependency determineDependency(ResolvedDependency dependency) %7B%0A        if (dependency instanceof VendorResolvedDependency) %7B%0A            return VendorResolvedDependency.class.cast(dependency).getHostDependency();%0A        %7D else %7B%0A            return dependency;%0A        %7D%0A    %7D%0A%0A    private String determineRelativePath(ResolvedDependency dependency) %7B%0A        if (dependency instanceof VendorResolvedDependency) %7B%0A            return VendorResolvedDependency.class.cast(dependency).getRelativePathToHost();%0A        %7D else %7B%0A            return %22.%22;%0A        %7D%0A    %7D
 %0A%7D%0A

Remove common methods